Author Topic: Help with a modified Hunters Housing script  (Read 366 times)

Legacy_lordofworms

  • Sr. Member
  • ****
  • Posts: 422
  • Karma: +0/-0
Help with a modified Hunters Housing script
« on: January 13, 2011, 02:17:00 pm »


               'ello

I have been using Hunters Housing for awhile now and I was suggested to adjust the convo for manipulating placeables so that you can adjust its position in more ways then it has now
(currently it only allows you to ROTATE the placeable)

I thus added in an adjust
North
South
East
West
Up
Down

with this script:
//////////////////////////////////////////////////////////////////////////////
void main()
{
object oArea = GetArea(OBJECT_SELF);
string sResRef = GetResRef(OBJECT_SELF);
float fFacing = GetFacing(OBJECT_SELF);
vector vVector = GetPosition(OBJECT_SELF) + Vector(0.0, -1.0, 0.0);//south
location lSpawn = Location(oArea, vVector, 0.0);
object oObject = CreateObject(OBJECT_TYPE_PLACEABLE, sResRef, lSpawn);
AssignCommand(oObject, SetFacing(fFacing));
DestroyObject(OBJECT_SELF, 1.0);
}
/////////////////////////////////////////////////////////////////////////////////

the rest are similar in that only this line changes
vector vVector = GetPosition(OBJECT_SELF) + Vector(0.0, -1.0, 0.0);//south
to accomodate the other directions...



now there is a 'Save to database' option on the dialog that does this:

//////////////////////////////////////////////////////////////////////////////
void main()
{
    object oItem    =   OBJECT_SELF;
    object oArea    =   GetArea(oItem);
    string sDoorID  =   GetLocalString(oArea, "TempArea");
    int iIndex      =   GetLocalInt(oItem, "index");
    SetCampaignVector("hh_property", sDoorID + IntToString(iIndex) + "position", GetPosition(oItem));
    SetCampaignFloat("hh_property", sDoorID + IntToString(iIndex) + "facing", GetFacing(oItem));
}
/////////////////////////////////////////////////////////////////////////////

and then on the OnAreaEnter basically this:
/////////////////////////////////////////////////////////////////////////////
//Load all objects from Campaign Database
    //SendMessageToPC(oPC, IntToString(iObjectCount) + " items found");
    for (x=1; x<=iObjectCount; x++)
    {
        vector vPosition = GetCampaignVector("hh_property", sDoorID + IntToString(x) + "position");
        float fOrientation = GetCampaignFloat("hh_property", sDoorID + IntToString(x) + "facing");
        locLocation = Location(oArea, vPosition, fOrientation);
        oObject = RetrieveCampaignObject("hh_property", sDoorID + IntToString(x), locLocation);
        SetLocalInt(oObject, "index", x);
        //SendMessageToPC(oPC, "item loaded");
        // If the Object is supposed to be placeable...  Do this...
        if (GetResRef(oObject) == "hh_plac_dummy")
        {
            object oPlaceable = CreateObject(OBJECT_TYPE_PLACEABLE, GetTag(oObject), locLocation, FALSE, GetLocalString(oObject, "ItemResRef"));
            SetLocalInt(oPlaceable, "index", x);
            SetPlotFlag(oPlaceable, 1);
            DestroyObject(oObject);
        }
    }



the problem is that when I go back in and that OnArea script fires, my placeable's rotate position is saved but none of my other custom additions,
yet? from what I can understand GetPosition should get the x,y,z coordinates of the placeable as it is correct?
so why is it seeming to 'skip' my adjustments?
I just cant seem to see what i am missing here?
or is what i am trying to do impossible from a store/reload from database perspective?


I am using NWN default database just FYI.

any help would be appreciated, I did a search already but only found how to move placeables not how to restore one and its position from a database


Thanks alot !
               
               

               
            

Legacy_lordofworms

  • Sr. Member
  • ****
  • Posts: 422
  • Karma: +0/-0
Help with a modified Hunters Housing script
« Reply #1 on: January 13, 2011, 02:20:15 pm »


               I should note also that

OBJECT_SELF relates to the placeable furniture I am manipulating



and that all these changes work just fine WHILE I am in my house, but when i leave and the area is cleaned and then rebuilt on re-entering house, thats when I have my issues...where none of my chaged positions seem to be saving.





               
               

               
            

Baaleos

  • Administrator
  • Hero Member
  • *****
  • Posts: 1916
  • Karma: +0/-0
Help with a modified Hunters Housing script
« Reply #2 on: January 13, 2011, 04:52:27 pm »


               

void main()
{
    object oItem    =   OBJECT_SELF;
    object oArea    =   GetArea(oItem);
    string sDoorID  =   GetLocalString(oArea, "TempArea");
    int iIndex      =   GetLocalInt(oItem, "index");
    SetCampaignVector("hh_property", sDoorID + IntToString(iIndex) + "position", GetPosition(oItem));
    SetCampaignFloat("hh_property", sDoorID + IntToString(iIndex) + "facing", GetFacing(oItem));
}
Correct me if I am wrong, but you are destroying the object, and creating a new one, in the new location - correct?
But it does not look like you are transfering the index variable from the old one, to the new one?
Without this variable, all placeables would have the same index number, and end up having their data overwriting eachother.

try changing your code to be

void main()
{
object oArea = GetArea(OBJECT_SELF);
string sResRef = GetResRef(OBJECT_SELF);
float fFacing = GetFacing(OBJECT_SELF);
vector vVector = GetPosition(OBJECT_SELF) + Vector(0.0, -1.0, 0.0);//south
location lSpawn = Location(oArea, vVector, 0.0);
[b]int iIndex = GetLocalInt(OBJECT_SELF,"index");
[/b]object oObject = CreateObject(OBJECT_TYPE_PLACEABLE, sResRef, lSpawn);
[b]SetLocalInt(oObject,"index",iIndex);
[/b]AssignCommand(oObject, SetFacing(fFacing));
DestroyObject(OBJECT_SELF, 1.0);
}

               
               

               
            

Legacy_lordofworms

  • Sr. Member
  • ****
  • Posts: 422
  • Karma: +0/-0
Help with a modified Hunters Housing script
« Reply #3 on: January 13, 2011, 05:08:28 pm »


               wow...

thats it and of course i realized it as soon as I saw it written here.

man, it is SOO helpful to have these forums..



thank you truly, saved me over 3 hours of hairpulling