hello. i need a system in which .. if player left the server save pos where he last pos .. and when ever he join server he spawn at last pos where he left ..
anyone help me?
locs <- {};
function onPlayerSpawn( player ) if( locs[player.Name] ) player.Pos = locs[ player.Name ];
function onPlayerPart( player, reason ) locs[ player.Name ] = player.Pos;
Untested. But should give an idea.
Here you go .
function onScriptLoad( )
{
db <- ConnectSQL( "lastpos.db" );
QuerySQL( db , "CREATE TABLE IF NOT EXISTS LastPos ( Name VARCHAR(255), Pos VARCHAR(255) )" ); //Creating Table For Storing Data
}
function onPlayerPart( player, reason )
{
local q = QuerySQL( db , "SELECT * FROM LastPos WHERE Name='" + player.Name + "'" );
if ( q )//Checking if the data of player is present on Database
{
QuerySQL( db , "UPDATE LastPos SET Pos='"+player.Pos+"' WHERE Name='" + player.Name + "'" );//As the player's data is present we are UPDATING data.
}
else
{
QuerySQL( db , "INSERT INTO LastPos ( Name, Pos ) VALUES ( '" + player.Name + "', '" + player.Pos + "')" );//As the player's data is not present we are INSERTING data.
}
}
function onPlayerSpawn( player )
{
local q = QuerySQL( db , "SELECT * FROM LastPos WHERE Name='" + player.Name + "'" );
if ( q )//Checking if the data of player is present on Database
{
local p = split( GetSQLColumnData( q, 1 ), "(" ), po = split( p[0], ")" ), pos = split( po[0] , ", ");
player.Pos = Vector( pos[0].tofloat() , pos[1].tofloat() , pos[2].tofloat() );//Teleporting the player
MessagePlayer("Teleported To Your Last Position",player);
}
else return 0;
}
array is better then query queries can cause lagg :P
create a file called pos.txt
and try using this:
function onPlayerSpawn(player)
{
player.Pos.x =ReadIniNumber("pos.txt","posx",player.UID)
player.Pos.y =ReadIniNumber("pos.txt","posy",player.UID)
player.Pos.z =ReadIniNumber("pos.txt","posz",player.UID)
}
function onPlayerPart(player,part)
{
WriteIniNumber("pos.txt","posx",player.UID,player.Pos.x)
WriteIniNumber("pos.txt","posy",player.UID,player.Pos.y)
WriteIniNumber("pos.txt","posz",player.UID,player.Pos.z)
}
untested but should work
you will need loaded ini parser plugin ( the official one )
Quote from: Hercules on Sep 27, 2016, 12:44 PMarray is better then query queries can cause lagg :P
not actually. Well if you use array it will be deleted when server crashes/stops. But if database then its saved.
Quote from: Kewun on Sep 27, 2016, 12:45 PMcreate a file called pos.txt
and try using this:
function onPlayerSpawn(player)
{
player.Pos.x =ReadIniNumber("pos.txt","posx",player.UID)
player.Pos.y =ReadIniNumber("pos.txt","posy",player.UID)
player.Pos.z =ReadIniNumber("pos.txt","posz",player.UID)
}
function onPlayerPart(player,part)
{
WriteIniNumber("pos.txt","posx",player.UID,player.Pos.x)
WriteIniNumber("pos.txt","posy",player.UID,player.Pos.y)
WriteIniNumber("pos.txt","posz",player.UID,player.Pos.z)
}
untested but should work
you will need loaded ini parser plugin ( the official one )
What if any other player plays with the same PC??
Quote from: Anik on Sep 27, 2016, 12:47 PMQuote from: Kewun on Sep 27, 2016, 12:45 PMcreate a file called pos.txt
and try using this:
function onPlayerSpawn(player)
{
player.Pos.x =ReadIniNumber("pos.txt","posx",player.UID)
player.Pos.y =ReadIniNumber("pos.txt","posy",player.UID)
player.Pos.z =ReadIniNumber("pos.txt","posz",player.UID)
}
function onPlayerPart(player,part)
{
WriteIniNumber("pos.txt","posx",player.UID,player.Pos.x)
WriteIniNumber("pos.txt","posy",player.UID,player.Pos.y)
WriteIniNumber("pos.txt","posz",player.UID,player.Pos.z)
}
untested but should work
you will need loaded ini parser plugin ( the official one )
What if any other player plays with the same PC??
then he will have to use player.Name instead of player.Uid and a register/login system.
Quote from: Anik on Sep 27, 2016, 12:46 PMQuote from: Hercules on Sep 27, 2016, 12:44 PMarray is better then query queries can cause lagg :P
not actually. Well if you use array it will be deleted when server crashes/stops. But if database then its saved.
What if you also store the array in the database or in a JSON file?
Array can hold the temporary data, and a server will not crash until you make it to( or use SLC's plugin if you see crashes in Linux with the bad old Squirrel plugin, we've discussed over it :p it's due to memory leak )
Quote from: KAKAN on Sep 27, 2016, 12:29 PMlocs <- {};
function onPlayerSpawn( player ) if( locs[player.Name] ) player.Pos = locs[ player.Name ];
function onPlayerPart( player, reason ) locs[ player.Name ] = player.Pos;
Untested. But should give an idea.
thanks
@KAKAN :) .. and Thanks to
@Anik :) and Thanks to
@Kewun :D For idea :)
I have one question guys if player drowning and player do /q ... then next time when player join the last position is in water then how can we solved it .... !? obviously player don't to spawn in water ...
Quote from: Saiyan Attack on Sep 27, 2016, 03:06 PMI have one question guys if player drowning and player do /q ... then next time when player join the last position is in water then how can we solved it .... !? obviously player don't to spawn in water ...
if palyer do /q in water ...when he join server again he will drown.
Quote from: Saiyan Attack on Sep 27, 2016, 03:06 PMI have one question guys if player drowning and player do /q ... then next time when player join the last position is in water then how can we solved it .... !? obviously player don't to spawn in water ...
He will spawn again in water.
Quote from: Saiyan Attack on Sep 27, 2016, 03:06 PMI have one question guys if player drowning and player do /q ... then next time when player join the last position is in water then how can we solved it .... !? obviously player don't to spawn in water ...
I think getting player anime and then using it is the best option because it will help also when player is falling? :-D ...
Quote from: zeus on Sep 28, 2016, 12:26 PMQuote from: Saiyan Attack on Sep 27, 2016, 03:06 PMI have one question guys if player drowning and player do /q ... then next time when player join the last position is in water then how can we solved it .... !? obviously player don't to spawn in water ...
I think getting player anime and then using it is the best option because it will help also when player is falling? :-D ...
You mean checking the animation of the player but I don't know if it ability to do that?
Quote from: Saiyan Attack on Sep 27, 2016, 03:06 PMI have one question guys if player drowning and player do /q ... then next time when player join the last position is in water then how can we solved it .... !? obviously player don't to spawn in water ...
umm... Can be solved by checking Z axis of player excluding some places. And also as
@zeus said by checking the anim of the player.
I don't see why spawning in water is such an issue? They obviously tried to death evade by leaving. If your script puts them right back into the water when they rejoin I'd say the script is working fine.
Quote from: Thijn on Sep 29, 2016, 05:50 AMI don't see why spawning in water is such an issue? They obviously tried to death evade by leaving. If your script puts them right back into the water when they rejoin I'd say the script is working fine.
@Thijn u are right its not an issue but if we let the player to respawn in water then the only thing needs to be improve is to check if player is in vehicle and jump from any place or is in helicopter and use quit or kicked due to any reason so disable this system so on reconnect player will be spawned to his spawnloc not in air etc