Author Topic: PW store player location?  (Read 344 times)

Legacy_Buddywarrior

  • Hero Member
  • *****
  • Posts: 512
  • Karma: +0/-0
PW store player location?
« on: June 29, 2012, 09:13:11 pm »


               Either it's bult in and I've replaced the script with my own or I don't understand how the game stores the players location. Here is what's happening on my server during testing.

Like most worlds, I have a 'starting' area. You select the faction you want to be on and it sends you away correctly.
If the player dies, you respawn correctly in the area you should. When you log out and back in, you continue where you left off (in middle of a field for example).

But if I restart my server, every player is again sent back to the 'starting' area.

How does a PW solve this without NWNX2?
               
               

               
            

Legacy_Thayan

  • Sr. Member
  • ****
  • Posts: 435
  • Karma: +0/-0
PW store player location?
« Reply #1 on: June 29, 2012, 09:43:06 pm »


               That is the way it works be default. If you want to save a player's location though, you can use a script that saves the location of the PC every so often. And rather than reinvent the wheel, I use the following functions that Knat developed for his NBDE system.


// serialize location to padded string
string NBDE_LocationToString(location lLoc)
{
  // serialization garbage... more or less "redo if it screws" code
  string sLoc = IntToString(FloatToInt(GetPositionFromLocation(lLoc).x*100));
  sLoc = (GetStringLength(sLoc) < 5) ? sLoc + GetStringLeft("     ",5 - GetStringLength(sLoc)) : GetStringLeft(sLoc,5);
  sLoc += IntToString(FloatToInt(GetPositionFromLocation(lLoc).y*100));
  sLoc = (GetStringLength(sLoc) < 10) ? sLoc + GetStringLeft("     ",10 - GetStringLength(sLoc)) : GetStringLeft(sLoc,10);
  sLoc += IntToString(FloatToInt(GetPositionFromLocation(lLoc).z*100));
  sLoc = (GetStringLength(sLoc) < 15) ? sLoc + GetStringLeft("     ",15 - GetStringLength(sLoc)) : GetStringLeft(sLoc,15);
  sLoc += IntToString(FloatToInt(GetFacingFromLocation(lLoc)*100));
  sLoc = (GetStringLength(sLoc) < 20) ? sLoc + GetStringLeft("     ",20 - GetStringLength(sLoc)) : GetStringLeft(sLoc,20);
  sLoc += GetTag(GetAreaFromLocation(lLoc));
  sLoc = (GetStringLength(sLoc) < 52) ? sLoc + GetStringLeft("                                ",52 - GetStringLength(sLoc)) : GetStringLeft(sLoc,52);
  return sLoc;
}

// de-serialize string to location
location NBDE_StringToLocation(string sLoc)
{
  // fast de-serialize code using padded strings
  vector vVec;
  // build vector
  vVec.x = StringToFloat(GetStringLeft(sLoc,5)) / 100;
  vVec.y = StringToFloat(GetSubString(sLoc,5,5)) / 100;
  vVec.z = StringToFloat(GetSubString(sLoc,10,5)) / 100;;
  int nPad = FindSubString(GetSubString(sLoc, 20,32)," ");
  // build & return location
  return Location(GetObjectByTag((nPad != -1) ? GetSubString(sLoc, 20,nPad) : GetSubString(sLoc, 20,32)), vVec, StringToFloat(GetSubString(sLoc,15,5)) / 100);
}

The first function is used to convert the location to a string which can then be stored in a database, or on a non-droppable item in the PC's inventory. I call that function for each PC with our psuedo heartbeat in the modules OnUserDefined event every 4 minutes when we also save/export each PC to the servervault as well.

Then, the second function is used in the module's ClientOnEnter event in conjunction with code that first checks if the PC is logging into the start area and they are not a new PC and, if not, it is used to convert that string to a location which can then be jumped to.
               
               

               
            

Legacy_Buddywarrior

  • Hero Member
  • *****
  • Posts: 512
  • Karma: +0/-0
PW store player location?
« Reply #2 on: June 29, 2012, 09:53:53 pm »


               Thanks a thousand fold Thayan! You've saved me a headache!
Thanks again!