how to saving last position after logout,crash,disconect
#1

if i logout my position not my last position before logout. how to save last position before logout ?
Reply
#2

https://sampwiki.blast.hk/wiki/OnPlayerDisconnect
Reply
#3

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.
pawn Код:
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;}
Reply
#4

up.....
Reply
#5

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.
Reply
#6

I use this method in my gamemode. But you'll need to edit it so it'll fit yours or whatever.

PHP код:
new IsPlayerLoggedIn[MAX_PLAYERS char];
public 
OnPlayerDisconnect(playeridreason)
{
    if(
IsPlayerLoggedIn{playerid} == 1)
    {
        new 
Float:XFloat:YFloat:ZFloat:A;
        
GetPlayerPos(playeridXYZ);
        
GetPlayerFacingAngle(playeridA);
        
        
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.
Reply
#7

Depends on what system you use, MYSQL or DINI to save your data.
Reply
#8

@ itsCody shouldnt it be IsPlayerLoggedIn[playerid] instead of IsPlayerLoggedIn{playerid} ?
Reply
#9

Quote:
Originally Posted by BGTrucker
Посмотреть сообщение
@ itsCody shouldnt it be IsPlayerLoggedIn[playerid] instead of IsPlayerLoggedIn{playerid} ?
with char, it's {}.

Read this: https://sampforum.blast.hk/showthread.php?tid=216730
Look for char arrays.
Reply
#10

Quote:
Originally Posted by itsCody
Посмотреть сообщение
with char, it's {}.

Read this: https://sampforum.blast.hk/showthread.php?tid=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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)