Posts: 181
Threads: 38
Joined: Aug 2010
Reputation:
0
In some cases. Basically you gotta reset a player's variable when the player connects/disconnects if you want to avoid the next player connecting have the same variable values.
Posts: 435
Threads: 2
Joined: Jul 2017
Reputation:
0
Because variables aren't tied to players, and aren't automatically reset. When a player joins the server with the ID of a player that had left the server before, the connecting player inherits their variables/arrays.
Meaning if you have a variable called spawned and it is set true on spawn and a player leaves while the variable remains set to true without resetting it. A player connects and the player will be identified as spawned by any system that uses the variable spawned in an if-then.
OMG, spawn, spawned, spawned...
Posts: 1,208
Threads: 36
Joined: Apr 2015
It is necessary, but who need reset all variables in enum manualy...
PHP код:
enum e_PlayerData {
data1,
data2,
data3,
...
data99
};
new PlayerData[MAX_PLAYERS][e_PlayerData];
//the same on player complete disconnect but why you need reset data two time
public OnPlayerConnect(playerid){
/*
PlayerData[playerid][data1] = 0;
PlayerData[playerid][data2] = 0;
PlayerData[playerid][data3] = 0;
...
PlayerData[playerid][data99] = 0;
//rly ?
*/
PlayerData[playerid] = PlayerDataReset(playerid); //all data is 0, data2 is 1
//your code
return 1;
}
stock PlayerDataReset(playerid){
new data_construct[e_PlayerData];
PlayerData[playerid][data2] = 1;
return data_construct;
}
Posts: 10,066
Threads: 38
Joined: Sep 2007
Reputation:
0
I suppose it makes sense if you want to iterate over the variable later. Like if you would want to average the score or something like that. Suppose you have a function like avg(values[]) which would then calculate the average over all the (non-zero) values in the array. In that case it would include the score of the disconnected player.
In other cases ... I really don't know what's the best best and I don't think it really matters. Using both callbacks seems to be the safest best overall and can prevent weird bugs and glitches. I'd just make a separate function so you only have one line in each callback.
Posts: 435
Threads: 2
Joined: Jul 2017
Reputation:
0
Only reset the variables that can cause wrong results in any case (this being god mode toggle, spawn check, log in check, etc.).
Variables that get overwritten and don't inherit their old values are not needed to be reset. For example storing a dialog response.
Posts: 311
Threads: 27
Joined: May 2016
Reputation:
0
Yeah, I get it.
I was really curious why I need to 'reset' them in first place when I reset them for players when Itheyconnect ( above is the script im talking about ).
But I've never faced that issue that variable sticks to playerid, at all. That is another reason why I made this.
Thanks all, is there anything else important or just-to-know?