Aller au contenu

Photo

Teleport player to stored location after server reset?


  • Veuillez vous connecter pour répondre
8 réponses à ce sujet

#1
Buddywarrior

Buddywarrior
  • Members
  • 256 messages
 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.

#2
Buddywarrior

Buddywarrior
  • Members
  • 256 messages
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 .


#3
The Amethyst Dragon

The Amethyst Dragon
  • Members
  • 1 882 messages
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.

#4
Squatting Monk

Squatting Monk
  • Members
  • 446 messages
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 .


#5
Buddywarrior

Buddywarrior
  • Members
  • 256 messages
lol, that does not look like something made using Lilac Soul's Script Generator.

#6
The Amethyst Dragon

The Amethyst Dragon
  • Members
  • 1 882 messages
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 .


#7
Buddywarrior

Buddywarrior
  • Members
  • 256 messages

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.

#8
Buddywarrior

Buddywarrior
  • Members
  • 256 messages
Just an update..this worked like a charm. Thank you kindly.

#9
The Amethyst Dragon

The Amethyst Dragon
  • Members
  • 1 882 messages

Buddywarrior wrote...

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

Good to hear.