Author Topic: Help with rebuilt location  (Read 345 times)

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Help with rebuilt location
« on: June 24, 2011, 12:10:46 am »


               

Lightfoot8 wrote...

Why not just store a LocalLocation and the TagOf the Area.

object oPlayer = OBJECT_SELF;
location lPlayer = GetLocation(oPlayer);
string sAreaTag = GetTag(GetArea(oPlayer));

ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectVisualEffect(925), oPlayer, 0.0);
object oJewel = CreateItemOnObject("starjewel", oPlayer);
SetLocalLocation( oJewel,"JewelLoc",lPlayer);
SetLocalString ( oJewel,"JewelArea",sAreaTag);
SetCutsceneMode(oPlayer, TRUE);
DelayCommand(4.0, SetCutsceneMode(oPlayer, FALSE));


then to rebuild you location to make sure the area is correct would look something like this.

location lLoc = GetLocalLocation( oJewel,"JewelLoc");
string sAreaTag =GetLocalString ( oJewel,"JewelArea");
lLoc = Location(GetObjectByTag(sAreaTag),
                          GetPositionFromLocation( lLoc),
                          GetFacingFromLocation( lLoc)
                          );


I wanted to try out the above method of rebuilding a location to jump to and for the life of me I can not get it to work. I know everything else is working because of the debugging lines that I use to store the information. I even have a separate object OnUsed script which returns the stored tag, position, and facing from the iem, in a message to the player.

Here is the script I have for the player to jump to the location (the rebuilt location is currently commented out but it works the way it is now. It does NOT work with the rebuilt location):

void main()
{
    object oPC = GetEnteringObject();
    if (!GetIsPC(oPC)) return;
    object oDBItem = GetItemPossessedBy(oPC, "Rulebook");
    if (GetIsObjectValid(oDBItem))
    {
        SendMessageToPC(oPC, "DB Item is valid");
        location lSavedLoc = GetLocalLocation(oDBItem, "PERSISTENT_LOC");
        string sSavedAreaTag = GetLocalString(oDBItem, "PERSISTENT_AREA)");
        /*location lLoc = Location(GetObjectByTag(sSavedAreaTag),
                                               GetPositionFromLocation(lSavedLoc),
                                               GetFacingFromLocation(lSavedLoc));*/

        AssignCommand(oPC, ClearAllActions(TRUE));
        //AssignCommand(oPC, JumpToLocation(lLoc));
        AssignCommand(oPC, JumpToLocation(lSavedLoc));
    }
    SendMessageToPC(oPC, "Trigger or area entered.");
}



This is the section of my OnRest script that pertains to saving the location and tag:

if (GetLocalInt(GetModule(), "SAVE_CHARACTERS") == TRUE)
        {
            object oDBItem = GetItemPossessedBy(oPC, "Rulebook");
            if (GetIsObjectValid(oDBItem))
            {
                SendMessageToPC(oPC, "DB Item is valid.");
                SetLocalLocation(oDBItem, "PERSISTENT_LOC", GetLocation(oPC));
                SetLocalString(oDBItem, "PERSISTENT_AREA", GetTag(GetArea(oPC)));
            }
            DelayCommand(1.0, ExportSingleCharacter(oPC));
            SendMessageToPC(oPC, "Your character and location have been saved.");
        }


And this is the object OnUsed script that DOES return all the information from the item:

#include "x0_i0_position"
void main()
{
    object oPC = GetLastUsedBy();
    object oDBItem = GetItemPossessedBy(oPC, "Rulebook");
    string sArea = GetLocalString(oDBItem, "PERSISTENT_AREA");
    location lLoc = GetLocalLocation(oDBItem, "PERSISTENT_LOC");
    float fFace = GetFacingFromLocation(lLoc);
    string sVector = VectorToString(GetPositionFromLocation(lLoc));
    string sFloat = FloatToString(fFace, 18, 9);
   
SendMessageToPC(oPC, "The stored area tag: " + sArea + "\\nThe stored
vector: " + sVector + "\\nThe stored facing: " + sFloat);
}


I have been looking over this for a whole day now and am so frustrated with it I need another set of eyes. Am I rebuilding the location incorrectly? Or is there something else about locations that make this not work right?

Any help appreciated.
               
               

               


                     Modifié par GhostOfGod, 23 juin 2011 - 11:13 .
                     
                  


            

Legacy_Xardex

  • Sr. Member
  • ****
  • Posts: 414
  • Karma: +0/-0
Help with rebuilt location
« Reply #1 on: June 24, 2011, 12:32:41 am »


               I have heard that there are internal problems with stored local locations on items... Though that was ages ago, might have been fixed in a patch.

Im really tired, but I don't see the point of rebuilding a location from a stored location, using another local variable for the area. a Location includes 3 variables, the area (object), position (vector) and angle (float).
               
               

               


                     Modifié par Xardex, 23 juin 2011 - 11:33 .
                     
                  


            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Help with rebuilt location
« Reply #2 on: June 24, 2011, 12:36:31 am »


               The problem is that the Object in stored locations becomes invalid if you change areas in your module. The above method rebuilds the location with a new area object using the GetObjectByTag function with the stored area tag and is supposed to fix the problem.

Seems like it should work fine but it isn't. Well it isn't for me anyway. '<img'>
               
               

               


                     Modifié par GhostOfGod, 23 juin 2011 - 11:36 .
                     
                  


            

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0
Help with rebuilt location
« Reply #3 on: June 24, 2011, 01:28:54 am »


               I suggest you add some debug lines to find out what the Gets are Getting from the stored location.

Funky
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Help with rebuilt location
« Reply #4 on: June 24, 2011, 03:37:07 am »


               ':blink:'':whistle:'

string sSavedAreaTag = GetLocalString(oDBItem, "PERSISTENT_AREA)");

:facepalm: