Author Topic: Default player location after server reset.  (Read 393 times)

Legacy_Buddywarrior

  • Hero Member
  • *****
  • Posts: 512
  • Karma: +0/-0
Default player location after server reset.
« on: July 31, 2012, 01:33:58 am »


                This is becoming a drag and I'm not sure what I'm doing wrong.  I store the players location OnPlayerRest, OnAquire etc. If they log out and back into the game, they log into the in the area and location where they should (I believe it's the 
ExportSingleCharacter makeing this happen). However, if the server restarts, they always start at the 'start area' instead of the strored location. 
This is the script I use in the OnClient Enter to return the player to the stored location.

object oPC = GetEnteringObject();object oDatabase = GetItemPossessedBy(oPC, "playerbook");location lLocation = GetLocalLocation(oDatabase, "PC_LOCATION");// Now we have the PC and the location, time to make the jump.AssignCommand(oPC, ActionJumpToLocation(lLocation)); 

This is what I use in OnPlayerRest
object oDatabase = GetItemPossessedBy(oPC, "playerbook");location lLocation = GetLocation(oPC);// Store the location in the PC's databaseSetLocalLocation(oDatabase, "PC_LOCATION", lLocation);
---

Basic, non nwnx world. Any suggestions welcomed for sure.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Default player location after server reset.
« Reply #1 on: July 31, 2012, 03:02:11 am »


               OnClientEnter is a bad place to put that code.  PC's are not yet fully in the game during that event.   Try placing the code on a trigger around your default start location.
               
               

               
            

Legacy_The Amethyst Dragon

  • Hero Member
  • *****
  • Posts: 2981
  • Karma: +0/-0
Default player location after server reset.
« Reply #2 on: July 31, 2012, 03:31:10 am »


               Also, local location variables don't always properly save over resets.  You may want to split up the location info into a string (the area's tag) and position vector.  Then on the PCs logging back in, reassemble the desired location with the Location() function and send them there.

I would also save on the running of said script a little by checking the area tag a few seconds after they log in.  If it's the starting area's tag, then do the restoration of the saved location and jump them there.  If not, then there's no need to do all the rest.
               
               

               
            

Legacy_ShadowM

  • Hero Member
  • *****
  • Posts: 1373
  • Karma: +0/-0
Default player location after server reset.
« Reply #3 on: July 31, 2012, 03:36:38 am »


               To avoid the delay issue I use a default conversation that all the pc can start that let them select jump me to my last saved location and it only show up in the conversation if the pc is in the start location '<img'> I have another one that only show up if they are not in the start location and let them save their location so they can save it before logging.
               
               

               
            

Legacy_Lazarus Magni

  • Hero Member
  • *****
  • Posts: 1837
  • Karma: +0/-0
Default player location after server reset.
« Reply #4 on: July 31, 2012, 07:39:01 pm »


               Hi,
We use a combination of things to do this. I don’t fully understand it (I inherited the system), but from what I gather it is a combination of the on enter script in the loading area, the on mod load script, on client enter script, and on client exit script. We have it set up so that after a restart, a player’s location will be preserved if they log back in within 5 minutes of the server restarting. You could prolly un-comment out that delayed command.

Loading area on enter script:

else if ( GetLocalInt( GetModule( ), "RecentRestart" ) &&
             GetStringLength( GetLocalString( oPC, "LastCDKey" )) > 2 )
   {
     string sSQL = "SELECT location FROM " + MODULE_PC_LOCATION_TABLE + " WHERE player='" + sPCName + "' AND name='" + sCharName + "'";
     SQLExecDirect(sSQL);
     if ( SQLFetch( ) == SQL_SUCCESS )
     {
       lLoc = StringToLocation( SQLGetData( 1 ));
       DelayCommand(2.0, AssignCommand( oPC, JumpToLocation( lLoc )));



At the top of the mod load script:

void ClearRecentRestart( )
{
 WriteTimestampedLogEntry( "[Location] Clearing RecentRestart Flag" );
 DeleteLocalInt( GetModule( ), "RecentRestart" );

 string sSQL = "TRUNCATE " + MODULE_PC_LOCATION_TABLE;
 SQLExecDirect( sSQL );
}


and in the void main:

SetLocalInt( GetModule( ), "RecentRestart", 1 );
DelayCommand( 600.0, ClearRecentRestart( ));

At the top of client enter script:
void SaveLocation(object oPC)
{
 if(!GetIsObjectValid(oPC)) return;
 string sPCName = SQLEncodeSpecialChars(GetPCPlayerName(oPC));
 string sCharName = SQLEncodeSpecialChars(GetName(oPC));
 location lLocation = GetLocation(oPC);
 string sSQL = "REPLACE INTO " + MODULE_PC_LOCATION_TABLE + " SET player='" + sPCName
 + "', name = '" + sCharName + "', location='" + LocationToString(lLocation) + "'";
 SQLExecDirect(sSQL);
 DelayCommand(MODULE_PC_LOCATION_SAVE_INTERVAL, SaveLocation(oPC));
}

And in the void main of the client exit script:

object oPC = GetExitingObject( );
 string sName  = GetName( oPC );
 string sAccount = GetLocalString( oPC, "AccountName" );

 DeleteLocalInt( GetModule( ), sName + "LoggedIn" );
 SetLocalInt( GetModule( ), sName + sAccount + "_SessionActive", 2 );

 //Clear dominated effect from player
 
 //Clean up Variables if player does not log in for 20 minutes
 DelayCommand( 1200.0, SetLocalInt( GetModule( ), sName + sAccount + "_SessionActive", 1 ));

In fact, the log out might not even be needed. Perhaps you can use something from that.
Laz

P.S. On a related but different note, I have actually been looking for kinda the opposite. I would like a toon’s location to get cleared after being logged out for 15 min, to prevent area farming. This is the same reason why there is the delayed command after a restart. It preserves players locations if they log back in immediately after a restart, but won’t carry over if they don’t. Hence restarts don’t interrupt a current run, but prevent farming.
               
               

               
            

Legacy_Lazarus Magni

  • Hero Member
  • *****
  • Posts: 1837
  • Karma: +0/-0
Default player location after server reset.
« Reply #5 on: July 31, 2012, 07:44:54 pm »


               P.P.S. I forgot there is also a constant for auto saving locations on a 3 min interval. The config module script has the constant:

const float  MODULE_PC_LOCATION_SAVE_INTERVAL   = 180.0; // value in seconds
               
               

               
            

Legacy_Buddywarrior

  • Hero Member
  • *****
  • Posts: 512
  • Karma: +0/-0
Default player location after server reset.
« Reply #6 on: July 31, 2012, 09:25:32 pm »


               

ShadowM wrote...

To avoid the delay issue I use a default conversation that all the pc can start that let them select jump me to my last saved location and it only show up in the conversation if the pc is in the start location '<img'> I have another one that only show up if they are not in the start location and let them save their location so they can save it before logging.


That sounds ideal. Like a game enter menu would be perfect. How did you get the conversation to show from the 
area's onenter though? The scipt works from the onenter of a trigger but not the 'start' area.

object oPC = GetEnteringObject();
int iHaveXp = GetXP(oPC);if (!GetIsPC(oPC)) return;
ActionStartConversation(oPC, "start01");
SendMessageToPC(oPC, "tested");
               
               

               
            

Legacy_ShadowM

  • Hero Member
  • *****
  • Posts: 1373
  • Karma: +0/-0
Default player location after server reset.
« Reply #7 on: July 31, 2012, 10:44:09 pm »


               All my players are give a feat information/emotes that when they use it, it bring up a conversation with all sorts of information / emotes and setting they can pick. Like how many times they have died, how many creatures they have killed etc.. And the save/load location is in this conversation. So when a first time character would leave the start area and then they could save their position anytime. Then when they log out and say while they gone the server resets then they come back at the start area and bring up the conversation and jump to where they left off and on they go with their adventure. Like the others said it all depends on lag and load weather or not the on enter way will fire either through the oncliententer script or through a trigger. So by making the PC start the conversation after they are in you know the script will work and fire properly. Hope that helps I use to try the on client enter way and the trigger but the timing was always a pain so went this way. There are other benifits to this too, like it give the pc some time before they decide to jump to their save location and allow time if the PC is waiting for a group that all saved at the same location to get all together and not worry about someone jumping into a potential dangerous area without the group. If you do not want to use a feat/player tool you could use a player token with tag base scripting. Hope that helps good luck. 'B)'
               
               

               


                     Modifié par ShadowM, 31 juillet 2012 - 09:50 .
                     
                  


            

Legacy_Buddywarrior

  • Hero Member
  • *****
  • Posts: 512
  • Karma: +0/-0
Default player location after server reset.
« Reply #8 on: July 31, 2012, 11:27:54 pm »


               Ahh ok. I was under the impression that the conversation was forced open and they had to supply what they wanted before they could continue. Thanks a bunch ShadowM!