Author Topic: Teleport player to stored location after server reset?  (Read 417 times)

Legacy_Buddywarrior

  • Hero Member
  • *****
  • Posts: 512
  • Karma: +0/-0
Teleport player to stored location after server reset?
« on: May 17, 2013, 10:45:33 pm »


                I'm storing the player location when they rest. Then during a conversation when they come in from a server reset, the script will not teleport them to the stored location, However, when I walk to the other side of the starting area and rest, then prompt the script to teleport me to the last stored location, it works.. Thoughts?

Note: same process works fine for storing faction information after server reset.
               
               

               
            

Legacy_Buddywarrior

  • Hero Member
  • *****
  • Posts: 512
  • Karma: +0/-0
Teleport player to stored location after server reset?
« Reply #1 on: May 17, 2013, 10:47:38 pm »


               in case anyone is interested in the code from the conversation.

//teleport player to last stored location.
void main()
{
object oPC = GetPCSpeaker();
if (!GetIsPC(oPC)) return;
    int iHaveXp = GetXP(oPC);
    //If entering player has xp, send them off, otherwise, give them goodies.
    if (iHaveXp !=0){
    object oDatabase = GetItemPossessedBy(oPC, "playerbook");
    location lLocation = GetLocalLocation(oDatabase, "PC_LOCATION");// Now we have the PC and the location, time to make the jump.
    // Now we have the PC and the location, time to make the jump.
    AssignCommand(oPC, ActionJumpToLocation(lLocation));
    return;
   }

}


And the snippet of code that stores the players location to the playerbook.

object oDatabase = GetItemPossessedBy(oPC, "playerbook");            location lLocation = GetLocation(oPC);            // Store the location in the PC's database            SetLocalLocation(oDatabase, "PC_LOCATION", lLocation);           // SendMessageToPC(oPC, "---location saved---");

               
               

               


                     Modifié par Buddywarrior, 17 mai 2013 - 09:49 .
                     
                  


            

Legacy_The Amethyst Dragon

  • Hero Member
  • *****
  • Posts: 2981
  • Karma: +0/-0
Teleport player to stored location after server reset?
« Reply #2 on: May 18, 2013, 02:28:16 am »


               Locations do not get stored over resets, even on items in inventory.  Instead, you'll need to split up the area information and store the pieces as separate variables, then recombine them when restoring the location.

I'm not able to access the toolset right now (on my phone), but there is a "position" include that has functions for getting the x, y, z (float values), and position (vector) information from a location.  You'll also need the area tag (string).  Store them on your book item, then read them back and reassemble with the Location() function.
               
               

               
            

Legacy_Squatting Monk

  • Hero Member
  • *****
  • Posts: 776
  • Karma: +0/-0
Teleport player to stored location after server reset?
« Reply #3 on: May 18, 2013, 09:49:07 am »


               Here's the functions for that from NWNX's APS include:

string SQLLocationToString(location lLocation)
{
    object oArea        = GetAreaFromLocation(lLocation);
    vector vPosition    = GetPositionFromLocation(lLocation);
    float  fOrientation = GetFacingFromLocation(lLocation);
    string sReturnValue = "#AREA#"        + GetTag(oArea) +
                                                    "#POSITION_X#"  + FloatToString(vPosition.x)  +
                                                    "#POSITION_Y#"  + FloatToString(vPosition.y)  +
                                                    "#POSITION_Z#"  + FloatToString(vPosition.z)  +
                                                    "#ORIENTATION#" + FloatToString(fOrientation) + "#END#";

    return sReturnValue;
}

location SQLStringToLocation(string sLocation)
{
    location lReturnValue;
    object oArea;
    vector vPosition;
    float fOrientation, fX, fY, fZ;

    int nPos, nCount, nLen = GetStringLength(sLocation);

    if (nLen > 0)
    {
        nPos   = FindSubString(sLocation, "#AREA#") + 6;
        nCount = FindSubString(GetSubString(sLocation, nPos, nLen - nPos), "#");
        oArea  = GetObjectByTag(GetSubString(sLocation, nPos, nCount));

        nPos   = FindSubString(sLocation, "#POSITION_X#") + 12;
        nCount = FindSubString(GetSubString(sLocation, nPos, nLen - nPos), "#");
        fX     = StringToFloat(GetSubString(sLocation, nPos, nCount));

        nPos   = FindSubString(sLocation, "#POSITION_Y#") + 12;
        nCount = FindSubString(GetSubString(sLocation, nPos, nLen - nPos), "#");
        fY     = StringToFloat(GetSubString(sLocation, nPos, nCount));

        nPos   = FindSubString(sLocation, "#POSITION_Z#") + 12;
        nCount = FindSubString(GetSubString(sLocation, nPos, nLen - nPos), "#");
        fZ     = StringToFloat(GetSubString(sLocation, nPos, nCount));

        vPosition = Vector(fX, fY, fZ);

        nPos         = FindSubString(sLocation, "#ORIENTATION#") + 13;
        nCount       = FindSubString(GetSubString(sLocation, nPos, nLen - nPos), "#");
        fOrientation = StringToFloat(GetSubString(sLocation, nPos, nCount));

        lReturnValue = Location(oArea, vPosition, fOrientation);
    }

    return lReturnValue;
}

               
               

               


                     Modifié par Squatting Monk, 18 mai 2013 - 08:56 .
                     
                  


            

Legacy_Buddywarrior

  • Hero Member
  • *****
  • Posts: 512
  • Karma: +0/-0
Teleport player to stored location after server reset?
« Reply #4 on: May 18, 2013, 10:21:27 pm »


               lol, that does not look like something made using Lilac Soul's Script Generator.
               
               

               
            

Legacy_The Amethyst Dragon

  • Hero Member
  • *****
  • Posts: 2981
  • Karma: +0/-0
Teleport player to stored location after server reset?
« Reply #5 on: May 19, 2013, 07:38:44 am »


               Let's give this a try.  It compiled in the toolset just fine.  You'll want to break out the pieces of code to fit your module's uses.


void main()
{
// Save location
object oPC = GetPCSpeaker();
if (!GetIsPC(oPC)) return;


object oDatabase = GetItemPossessedBy(oPC, "playerbook");
location lLocation = GetLocation(oPC);
string sAreaTag = GetTag(GetAreaFromLocation(lLocation));
vector vPosition = GetPositionFromLocation(lLocation);
float fX = vPosition.x;
float fY = vPosition.y;
float fZ = vPosition.z;
float fFacing = GetFacingFromLocation(lLocation);
SetLocalString(oDatabase, "STARTLOC_AREA", sAreaTag);
SetLocalFloat(oDatabase, "STARTLOC_X", fX);
SetLocalFloat(oDatabase, "STARTLOC_Y", fY);
SetLocalFloat(oDatabase, "STARTLOC_Z", fZ);
SetLocalFloat(oDatabase, "STARTLOC_F", fFacing);
// // Debug saving ... remove or comment this out once testing is done
SendMessageToPC(oPC, "debug location: area tag: " + sAreaTag);
SendMessageToPC(oPC, "debug location: z: " + FloatToString(fX));
SendMessageToPC(oPC, "debug location: y: " + FloatToString(fY));
SendMessageToPC(oPC, "debug location: z: " + FloatToString(fZ));
SendMessageToPC(oPC, "debug location: facing: " + FloatToString(fFacing));
// //


int iHaveXp = GetXP(oPC);
//If entering player has xp, send them off, otherwise, give them goodies.
if (iHaveXp !=0)
   {
   // Location restoration
   string sAreaData = GetLocalString(oDatabase, "STARTLOC_AREA");
   float fXd = GetLocalFloat(oDatabase, "STARTLOC_X");
   float fYd = GetLocalFloat(oDatabase, "STARTLOC_Y");
   float fZd = GetLocalFloat(oDatabase, "STARTLOC_Z");
   float fFacingd = GetLocalFloat(oDatabase, "STARTLOC_F");
   vector vPositionRestore = Vector(fXd, fYd, fZd);
   location lLocationRestore = Location(GetObjectByTag(sAreaData), vPositionRestore, fFacingd);
   // Now we have the PC and the location, time to make the jump.
   AssignCommand(oPC, ActionJumpToLocation(lLocationRestore));
   return;
   }

}

               
               

               


                     Modifié par The Amethyst Dragon, 19 mai 2013 - 06:39 .
                     
                  


            

Legacy_Buddywarrior

  • Hero Member
  • *****
  • Posts: 512
  • Karma: +0/-0
Teleport player to stored location after server reset?
« Reply #6 on: May 19, 2013, 11:39:06 pm »


               

The Amethyst Dragon wrote...

Let's give this a try.  It compiled in the toolset just fine.  You'll want to break out the pieces of code to fit your module's uses.


void main()
{
// Save location
object oPC = GetPCSpeaker();
if (!GetIsPC(oPC)) return;


object oDatabase = GetItemPossessedBy(oPC, "playerbook");
location lLocation = GetLocation(oPC);
string sAreaTag = GetTag(GetAreaFromLocation(lLocation));
vector vPosition = GetPositionFromLocation(lLocation);
float fX = vPosition.x;
float fY = vPosition.y;
float fZ = vPosition.z;
float fFacing = GetFacingFromLocation(lLocation);
SetLocalString(oDatabase, "STARTLOC_AREA", sAreaTag);
SetLocalFloat(oDatabase, "STARTLOC_X", fX);
SetLocalFloat(oDatabase, "STARTLOC_Y", fY);
SetLocalFloat(oDatabase, "STARTLOC_Z", fZ);
SetLocalFloat(oDatabase, "STARTLOC_F", fFacing);
// // Debug saving ... remove or comment this out once testing is done
SendMessageToPC(oPC, "debug location: area tag: " + sAreaTag);
SendMessageToPC(oPC, "debug location: z: " + FloatToString(fX));
SendMessageToPC(oPC, "debug location: y: " + FloatToString(fY));
SendMessageToPC(oPC, "debug location: z: " + FloatToString(fZ));
SendMessageToPC(oPC, "debug location: facing: " + FloatToString(fFacing));
// //


int iHaveXp = GetXP(oPC);
//If entering player has xp, send them off, otherwise, give them goodies.
if (iHaveXp !=0)
   {
   // Location restoration
   string sAreaData = GetLocalString(oDatabase, "STARTLOC_AREA");
   float fXd = GetLocalFloat(oDatabase, "STARTLOC_X");
   float fYd = GetLocalFloat(oDatabase, "STARTLOC_Y");
   float fZd = GetLocalFloat(oDatabase, "STARTLOC_Z");
   float fFacingd = GetLocalFloat(oDatabase, "STARTLOC_F");
   vector vPositionRestore = Vector(fXd, fYd, fZd);
   location lLocationRestore = Location(GetObjectByTag(sAreaData), vPositionRestore, fFacingd);
   // Now we have the PC and the location, time to make the jump.
   AssignCommand(oPC, ActionJumpToLocation(lLocationRestore));
   return;
   }

}

You're great!. Thank you for this. I'll test it this evening.
               
               

               
            

Legacy_Buddywarrior

  • Hero Member
  • *****
  • Posts: 512
  • Karma: +0/-0
Teleport player to stored location after server reset?
« Reply #7 on: May 20, 2013, 04:54:44 pm »


               Just an update..this worked like a charm. Thank you kindly.
               
               

               
            

Legacy_The Amethyst Dragon

  • Hero Member
  • *****
  • Posts: 2981
  • Karma: +0/-0
Teleport player to stored location after server reset?
« Reply #8 on: May 22, 2013, 04:17:09 am »


               

Buddywarrior wrote...

Just an update..this worked like a charm. Thank you kindly.

Good to hear.