how to saving last position after logout,crash,disconect -
glory88 - 10.10.2015
if i logout my position not my last position before logout. how to save last position before logout ?
Re: how to saving last position after logout,crash,disconect -
Unte99 - 10.10.2015
https://sampwiki.blast.hk/wiki/OnPlayerDisconnect
Re: how to saving last position after logout,crash,disconect -
BGTrucker - 10.10.2015
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;}
Re: how to saving last position after logout,crash,disconect -
glory88 - 11.10.2015
up.....
Re: how to saving last position after logout,crash,disconect -
Sew_Sumi - 11.10.2015
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.
Re: how to saving last position after logout,crash,disconect -
itsCody - 11.10.2015
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(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.
Re: how to saving last position after logout,crash,disconect -
Morpheine - 11.10.2015
Depends on what system you use, MYSQL or DINI to save your data.
Re: how to saving last position after logout,crash,disconect -
BGTrucker - 11.10.2015
@
itsCody shouldnt it be IsPlayerLoggedIn
[playerid
] instead of IsPlayerLoggedIn
{playerid
} ?
Re: how to saving last position after logout,crash,disconect -
itsCody - 11.10.2015
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.
Re: how to saving last position after logout,crash,disconect -
Sew_Sumi - 11.10.2015
Quote:
Originally Posted by itsCody
|
Wow, I didn't even know that, but yes, it does make your code look weird to those who don't know, but awesome.