Last Position.

Mahmoud Tornado

  • Full Member
  • Posts: 216
Last Position.
«  »
Just sharing to help, no thing can be explained.

Code: [Select]
function onScriptLoad()
{
Stats <- array(GetMaxPlayers(), null);
Lastpos <- ConnectSQL( "MT-LastVectors.db" );
QuerySQL( Lastpos, "CREATE TABLE IF NOT EXISTS Locations ( Name VARCHAR(32), LastPosX VARCHAR(25), LastPosY VARCHAR(25), LastPosZ VARCHAR(25), LastPos TEXT )" );
}

function onPlayerSpawn(player)
{
if ( player.World == 1 )
{
local q = QuerySQL(Lastpos, "SELECT * FROM Locations WHERE Name = '" + player.Name + "'");
if( q && GetSQLColumnData(q, 4) == "on" )
{
local Y = GetSQLColumnData(q, 2).tointeger(),
X = GetSQLColumnData(q, 1).tointeger(),
Z = GetSQLColumnData(q, 3).tointeger();
player.Pos = Vector( X, Y, Z);
MessagePlayer("You has been landed in your last location.", player);
}
}
}

function onPlayerCommand( player, cmd, text )
{
if(cmd == "lastpos")
{
if(!text) MessagePlayer("[#ff0000]/" + cmd + " <on/off>", player);
local q = QuerySQL(Lastpos, "SELECT * FROM Locations WHERE Name = '" + player.Name + "'");
if(!q) QuerySQL(Lastpos, "INSERT INTO Locations ( Name, LastPosX, LastPosY, LastPosZ, Lastpos ) VALUES ( '" + player.Name + "', '0' , '0' , '0','null' ) ");
else
{
if(text == "on")
{
QuerySQL(Lastpos, "UPDATE Locations SET Lastpos = 'on' WHERE Name = '" + player.Name + "'");

Announce( "~t~Lastpos Enabled", player , 0 );
}
if(text == "off")
{
QuerySQL(Lastpos, "UPDATE Accounts SET Lastpos = 'off' WHERE Name = '" + player.Name + "'");
Announce( "~y~Lastpos Disabled", player , 0 );
}
}
}
}

function onPlayerPart( player, reason )
{
local q = QuerySQL(Lastpos, "SELECT * FROM Locations WHERE Name = '" + player.Name + "'");
if(!q) return 0;
else{
QuerySQL(Lastpos, "UPDATE Locations SET LastPosX = '" + player.Pos.x + "' WHERE Name = '" + player.Name + "'");
QuerySQL(Lastpos, "UPDATE Locations SET LastPosY = '" + player.Pos.y + "' WHERE Name = '" + player.Name + "'");
QuerySQL(Lastpos, "UPDATE Locations SET LastPosZ = '" + player.Pos.z + "' WHERE Name = '" + player.Name + "'");
}
}

function onPlayerKill( killer, player, reason, bodypart )
{
local q = QuerySQL(Lastpos, "SELECT * FROM Locations WHERE Name = '" + player.Name + "'");
if(!q) return 0;
else{
QuerySQL(Lastpos, "UPDATE Locations SET LastPosX = '" + player.Pos.x + "' WHERE Name = '" + player.Name + "'");
QuerySQL(Lastpos, "UPDATE Locations SET LastPosY = '" + player.Pos.y + "' WHERE Name = '" + player.Name + "'");
QuerySQL(Lastpos, "UPDATE Locations SET LastPosZ = '" + player.Pos.z + "' WHERE Name = '" + player.Name + "'");
}
}

function onPlayerDeath( player, reason )
{
local q = QuerySQL(Lastpos, "SELECT * FROM Locations WHERE Name = '" + player.Name + "'");
if(!q) return 0;
else{
QuerySQL(Lastpos, "UPDATE Locations SET LastPosX = '" + player.Pos.x + "' WHERE Name = '" + player.Name + "'");
QuerySQL(Lastpos, "UPDATE Locations SET LastPosY = '" + player.Pos.y + "' WHERE Name = '" + player.Name + "'");
QuerySQL(Lastpos, "UPDATE Locations SET LastPosZ = '" + player.Pos.z + "' WHERE Name = '" + player.Name + "'");
}
}