16.10.2016, 22:26
Hello guys, how can I save the player position before he disconnects, and how do I make him spawn right after he enters his password? thanks in advance

To save a player's position before they disconnect, simply retrieve their x,y,z coords via GetPlayerPos and save it to the player's account under OnPlayerDisconnect. As for having them spawn in right after logging into their account, use SpawnPlayer(playerid) after they've successfully logged in.
|
public OnPlayerConnect(playerid) { TogglePlayerSpectating(playerid, true); //Get pos data to an array and set it in onplayerspawn. TogglePlayerSpectating(playerid, false); SpawnPlayer(playerid); } public OnPlayerRequestClass(playerid,classid) { TogglePlayerSpectating(playerid, 1); SetTimerEx("SkipOnPlayerRequestClass", 100, false, "i", playerid); return 1; } forward SkipOnPlayerRequestClass(playerid); public SkipOnPlayerRequestClass(playerid) { TogglePlayerSpectating(playerid, 0); return 1; } public OnPlayerSpawn(playerid) { SetPlayerSkin(playerid,50); SetPlayerPos(playerid, 0,0,0); SetPlayerFacingAngle(playerid, 0); SetPlayerInterior(playerid, 0); SetPlayerVirtualWorld(playerid, 0); return 1; }
Код:
public OnPlayerConnect(playerid) { TogglePlayerSpectating(playerid, true); //Get pos data to an array and set it in onplayerspawn. TogglePlayerSpectating(playerid, false); SpawnPlayer(playerid); } public OnPlayerRequestClass(playerid,classid) { TogglePlayerSpectating(playerid, 1); SetTimerEx("SkipOnPlayerRequestClass", 100, false, "i", playerid); return 1; } forward SkipOnPlayerRequestClass(playerid); public SkipOnPlayerRequestClass(playerid) { TogglePlayerSpectating(playerid, 0); return 1; } public OnPlayerSpawn(playerid) { SetPlayerSkin(playerid,50); SetPlayerPos(playerid, 0,0,0); SetPlayerFacingAngle(playerid, 0); SetPlayerInterior(playerid, 0); SetPlayerVirtualWorld(playerid, 0); return 1; } But probably, SetSpawnInfo should be used before SpawnPlayer for a better solution. IDK. |
Im using mysql for storing data. There are couple of ways to do that like file systems. Im checking login name and password on onplayerconnect via mysql_query. I have x,y,z datas for each player in players table. So if login successful, i set that datas to my players array like; cache_get_value_index_float(i, columnno, myplayers[playerid][x]); after that my previous answer comes and solves everything. Lastly, im using setplayerpos like SetPlayerPos(playerid, myplayers[playerid][x],myplayers[playerid][y],myplayers[playerid][z]); Ofcouse you will need to update players mysql row for his last x,y,z positions on onplayerdisconnect too. Thats it.
|
Consult a tutorial on how to save and load data.
Use TogglePlayerSpectating to hide the class selection buttons. Use SetSpawnInfo then SpawnPlayer to remove the need of the class selection. |