Author Topic: how to save pos?  (Read 1109 times)

SM999pgrz

  • Newbie
  • *
  • Posts: 12
  • Karma: +0/-1
    • View Profile
how to save pos?
« on: August 13, 2015, 04:53:58 pm »
i want to save the players pos wen the player move and reconnect to te server
 
    what is wrong?

//////////////////////////////////////////////////////////////////////////////////////////
   function onScriptLoad()
{
   LoadHashes();
}
function onScriptUnload()
{
   SaveHashes();
   CloseHashes();
}
function CreateHashes()
{
    Pos<- HashTable( "Pos" );
}
function SaveHashes()
{
   Pos.Save( "Accounts/Stats/Pos.hsh" );
}
function LoadHashes()
{
   CreateHashes();
   Pos.Load( "Accounts/Stats/Pos.hsh" );
}
function CloseHashes()
{
   Pos.Close();
   Pos<- null;
}

g_Positions <- array( GetMaxPlayers(), null ); // Storage for old positions
 
function HasPlayerMoved( v1, v2 )
{
     return ( ( fabs( v1.x - v2.x ) > 0.1 ) || ( fabs( v1.y - v2.y ) > 0.1 ) || ( fabs( v1.z - v2.z ) > 0.1 ) );
}
 
function onPlayerUpdate( player )
{
     local id = player.ID;
     
     // Grab the current and old positions and store values for future reference
     local oldpos = g_Positions[ id ];
     local newpos = player.Pos;     
 
     g_Positions[ id ] = newpos;
     
     // Do we have stored info about the previous position yet?
     if ( !oldpos ) return 1;
     
     if ( HasPlayerMoved( oldpos, newpos ) )
     {
          // Player has moved, trigger the event
          onPlayerMove( player, oldpos, newpos );
     }
 
     return 1;
}
function onPlayerMove( player, oldpos, newpos )
{
    local pos = pos.x, pos.y, pos.z;   

     Pos.Add( player.Name , pos );
     Pos.Save( "Accounts/Stats/Pos.hsh" );

   return 1;
}
function onPlayerSpawn( player, spawn )
{
    Pos.Load( "Accounts/Stats/Pos.hsh" );   
    local newpos = Pos.Get( player.Name );
    player.Pos = newpos;

   return 1;
}
//////////////////////////
if someone can help me I appreciate  :D!

Benedani

  • Newbie
  • *
  • Posts: 17
  • Karma: +2/-0
    • View Profile
Re: how to save pos?
« Reply #1 on: August 20, 2015, 05:57:01 pm »
Like, your player doesn't go to the new position? I mean, when the player spawns, update is called first (I think), which changes the position you have stored. You should store it only when the player leaves or dies, or whatever you want.

SM999pgrz

  • Newbie
  • *
  • Posts: 12
  • Karma: +0/-1
    • View Profile
Re: how to save pos?
« Reply #2 on: August 22, 2015, 07:49:28 pm »
Like, your player doesn't go to the new position? I mean, when the player spawns, update is called first (I think), which changes the position you have stored. You should store it only when the player leaves or dies, or whatever you want.

thank you Benedani, you helped me with my doubts :D!

 

© Liberty Unleashed Team.