SA-MP Forums Archive
variable reset? +rep! - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: variable reset? +rep! (/showthread.php?tid=322790)



variable reset? +rep! - PawnoQ - 03.03.2012

hi,

if you have variables in your script e.g. like:

pawn Code:
new Money[MAX_PLAYERS];
Where would you reset them?
On OnPlayerConnect or under OnPlayerDisconnect?
Does it make any difference at all?
pawn Code:
Money[playerid]=0;

thank you.


Re: variable reset? +rep! - Walsh - 03.03.2012

Quote:
Originally Posted by PawnoQ
View Post
hi,

if you have variables in your script e.g. like:

pawn Code:
new Money[MAX_PLAYERS];
Where would you reset them?
On OnPlayerConnect or under OnPlayerDisconnect?
Does it make any difference at all?
pawn Code:
Money[playerid]=0;

thank you.
You could put it under OnPlayerDisconnect or OnPlayerSpawn. Both will work, however if you are trying to make Money equal GetPlayerMoney(playerid) do it under OnPlayerSpawn as when a player connects he has zero dollars.


Re: variable reset? +rep! - PawnoQ - 03.03.2012

when playerid 0 joins and makes some money lets say 200$.
Then he leaves.

After another player connects he would get the playerid 0 and therefor also the money[playerid] variable of that playerid including 200$.

Thats why i want to reset them.
Under OnPlayerSpawn wouldnt be such a smart decission i guess

But it doesnt really make a difference if i place it under OnPlayerConnect or OnPlayerDisconnect right?


Re: variable reset? +rep! - Konstantinos - 03.03.2012

OnPlayerConnect Callback reset the variables.


Re: variable reset? +rep! - Walsh - 03.03.2012

Well, what type of gamemode is this for?


Re: variable reset? +rep! - PawnoQ - 03.03.2012

TDM, does that matter?

But OnPlayerDisconnect also should work, right?


Re: variable reset? +rep! - Walsh - 03.03.2012

pawn Code:
new Money[MAX_PLAYERS];
public OnPlayerConnect(playerid)
{
    Money[playerid] = 0;
    return 1;
}
Everytime someone connects their money var will be reset.


Re: variable reset? +rep! - PawnoQ - 03.03.2012

i know that but my question actually was if the reset also works properly under OnPlayerDisconnect?
Or what efficiency differences there would be?


Re: variable reset? +rep! - Walsh - 03.03.2012

Whether you put it under OnPlayerDisconnect or OnPlayerConnect, both will work %100. Niether of them have more efficiency than the other.


Re: variable reset? +rep! - PawnoQ - 03.03.2012

if its so then thx +rep