PDA

View Full Version : how to saving last position after logout,crash,disconect


glory88
10/10/2015, 04:55 PM
if i logout my position not my last position before logout. how to save last position before logout ?

Unte99
10/10/2015, 05:11 PM
https://wiki.sa-mp.com/wiki/OnPlayerDisconnect

BGTrucker
10/10/2015, 06:27 PM
From the page Unte99 gave you you will notice that GetPlayerPos doesnt work in OnPlayerDisconnect callback so you'll have to use a timer to get player's position every X amount of time,and when he disconnects for any reason,you'll have to store his position in some file,then on his next connect to server to load it from the file and use it to SetPlayerPos for him,if thats what you wanna do.
public OnPlayerConnect(playerid){
SetTimerEx("SavePlayerPos",1000,true,"d",playerid);
return 1;}

forward SavePlayerPos(playerid);
public SavePlayerPos(playerid){
new Float:x,Float:y,Float:z;
GetPlayerPos(playerid,x,y,z);
return 1;}

public OnPlayerDisconnect(playerid,reason){
//here you put the stuff where you store x,y and z into a file so you can load it the next time when the player connects
return 1;}

glory88
11/10/2015, 12:56 AM
up.....

Sew_Sumi
11/10/2015, 01:56 AM
BGTrucker has given you a lot of info, and you should be able to make it from that along with SetPlayerPos.

The SetPlayerPos section shouldn't be under OnPlayerConnect, but in another function (Same as BGTrucker did with the OnPlayerDisconnect statement), which runs after they've logged in (Because you are going to need file loading, and for that you'll need a login setup).

You will however need to use userfiles, and adding to this a login system. You'd probably find that some thread will detail how to do it, if you actually searched.

If you aren't capable of doing this, you need to learn some. People shouldn't need to write code for you, and if you need code written for you there is the "Looking for scripters" thread.

itsCody
11/10/2015, 03:54 AM
I use this method in my gamemode. But you'll need to edit it so it'll fit yours or whatever.


new IsPlayerLoggedIn[MAX_PLAYERS char];

public OnPlayerDisconnect(playerid, reason)
{
if(IsPlayerLoggedIn{playerid} == 1)
{
new Float:X, Float:Y, Float:Z, Float:A;
GetPlayerPos(playerid, X, Y, Z);
GetPlayerFacingAngle(playerid, A);

PlayerData[playerid][Position_X] = X;
PlayerData[playerid][Position_Y] = Y;
PlayerData[playerid][Position_Z] = Z;
PlayerData[playerid][Position_A] = A; // Facing Angle
IsPlayerLoggedIn{playerid} = 0;
}
return 1;
}


I use MySQL so I don't really know how to explain this in a more friendly form, so there's my attempt.

You'll need to place IsPlayerLoggedIn{playerid} = 1; under where he successfully logs into his account.

Morpheine
11/10/2015, 06:30 AM
Depends on what system you use, MYSQL or DINI to save your data.

BGTrucker
11/10/2015, 06:35 AM
@ itsCody shouldnt it be IsPlayerLoggedIn[playerid] instead of IsPlayerLoggedIn{playerid} ? :D

itsCody
11/10/2015, 09:29 AM
@ itsCody shouldnt it be IsPlayerLoggedIn[playerid] instead of IsPlayerLoggedIn{playerid} ? :D

with char, it's {}.

Read this: http://forum.sa-mp.com/showthread.php?t=216730
Look for char arrays.

Sew_Sumi
11/10/2015, 09:59 AM
with char, it's {}.

Read this: http://forum.sa-mp.com/showthread.php?t=216730
Look for char arrays.

Wow, I didn't even know that, but yes, it does make your code look weird to those who don't know, but awesome.