SA-MP Forums Archive
Player Variables - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP (https://sampforum.blast.hk/forumdisplay.php?fid=3)
+--- Forum: Bug Reports (https://sampforum.blast.hk/forumdisplay.php?fid=20)
+--- Thread: Player Variables (/showthread.php?tid=348758)



Player Variables - NickName3 - 06.06.2012

I'm saving player's data with OnPlayerDisconnect

OnPlayerDisconnect is being called for every one when the game mode is restarting

The problem is that player's variables are restarted before OnPlayerDisconnect is called

I mean GetPVar
and GetPlayerIP is returning 255.255.255.255 when the gamemode is restarting


Re: Player Variables - MP2 - 06.06.2012

Confirmed:

pawn Код:
#include <a_samp>

main() {}

public OnPlayerConnect(playerid)
{
    SetPVarInt(playerid, "test", 69);
    return 1;
}

public OnPlayerSpawn(playerid)
{
    print("OnPlayerSpawn");
    printf("test: %i", GetPVarInt(playerid, "test"));
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    print("OnPlayerDisconnect");
    printf("test: %i", GetPVarInt(playerid, "test"));
    return 1;
}
Output:
[19:08:54] [join] James has joined the server (0:127.0.0.1)
Console input: gmx
[19:09:03] test: 0

----------
Loaded log file: "server_log.txt".
----------

SA-MP Dedicated Server
----------------------
v0.3e, ©2005-2012 SA-MP Team

- plugins etc. removed to shorten -
[19:09:49] Loaded 5 filterscripts.

[19:09:49] Number of vehicle models: 0
[19:09:52] Incoming connection: 127.0.0.1:53367
[19:09:52] [join] James has joined the server (0:127.0.0.1)
[19:09:55] OnPlayerSpawn
[19:09:55] test: 69
Console input: gmx
[19:10:00] OnPlayerDisconnect
[19:10:00] test: 0
[19:10:12] Number of vehicle models: 0
[19:10:14] OnPlayerSpawn
[19:10:14] test: 69
[19:10:16] [chat] [James]: now i /q
[19:10:17] OnPlayerDisconnect
[19:10:17] test: 69
[19:10:17] [part] James has left the server (0:1)

I suggest not using the default gmx command, and instead using SendRconCommand in your game-mode, and BEFORE you send 'gmx' with SendRconCommand set a global 'gmx' variable to 1, and under OnPlayerDisconnect if that gmx variable is 1 don't save the data. You can save it in your restart command. You can also make a 'restart' (for example) command for your console with OnRconCommand, but if your server is hosted that's not a problem.

I don't think things can be saved when a GMX occurs, I've not tried it.


Re: Player Variables - draugfriend - 31.07.2012

What I can suggest (and what am I using) is:

below #include:
pawn Код:
forward Restart();
new save;
my restart command:
pawn Код:
CMD:rr(playerid, params[]){
    if(!playerDB[playerid][owner])  return SendClientMessage(playerid, S_ERROR, "You're not an owner!");
    //SendClientMessageToAll
    //GameTextForAll
    PlayerPlaySoundToAll(1058, 0.0, 0.0, 0.0);
    SetTimer("Restart", 5000, false);
    return 1;
}
Restart() function:
pawn Код:
public Restart(){
    //SendClientMessageToAll
    //GameTextForAll
    for(new i = 0; i < MAX_PLAYERS; i ++){
        if(IsPlayerConnected(i))    SavePlayerData(i);
    }
    save = false;
    SendRconCommand("changemode ****");
}
And SavePlayerData() function:
pawn Код:
public SavePlayerData(playerid){
    if(!save)   return 1;
//...
It works for me