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.
Teleport player to stored location after server reset?
Débuté par
Buddywarrior
, mai 17 2013 09:45
#1
Posté 17 mai 2013 - 09:45
#2
Posté 17 mai 2013 - 09:47
in case anyone is interested in the code from the conversation.
And the snippet of code that stores the players location to the playerbook.
//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
Posté 18 mai 2013 - 01:28
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.
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
Posté 18 mai 2013 - 08:49
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
Posté 18 mai 2013 - 09:21
lol, that does not look like something made using Lilac Soul's Script Generator.
#6
Posté 19 mai 2013 - 06:38
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
Posté 19 mai 2013 - 10:39
You're great!. Thank you for this. I'll test it this evening.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; } }
#8
Posté 20 mai 2013 - 03:54
Just an update..this worked like a charm. Thank you kindly.
#9
Posté 22 mai 2013 - 03:17
Good to hear.Buddywarrior wrote...
Just an update..this worked like a charm. Thank you kindly.





Retour en haut







