Liberty Unleashed
Scripting => Script Help => Topic started by: SM999pgrz on August 13, 2015, 03: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!
-
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.
-
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!