save quit pos.!

Started by Slark__, Sep 27, 2016, 10:43 AM

Previous topic - Next topic

Slark__

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?

KAKAN

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.
oh no

Anik

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;
}

Cool

array is better then query queries can cause lagg :P

Kewun

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 )

Anik

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.

Anik

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??

Kewun

Quote from: Anik on Sep 27, 2016, 12:47 PM
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??

then he will have to use player.Name instead of player.Uid and a register/login system.

KAKAN

Quote from: Anik on Sep 27, 2016, 12:46 PM
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.
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 )
oh no

Slark__

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 :)

Saiyan Attack

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 ...

Slark__

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.

Anik

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 ...

Discord: zeus#5155

EightyVice

Quote from: zeus on Sep 28, 2016, 12:26 PM
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 ...
You mean checking the animation of the player but I don't know if it ability to do that?