SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 03/03/2012, 04:01 PM   #1
PawnoQ
Huge Clucker
 
Join Date: Nov 2011
Posts: 375
Reputation: 7
Question variable reset? +rep!

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.
PawnoQ is offline   Reply With Quote
Old 03/03/2012, 04:05 PM   #2
Walsh
Big Clucker
 
Walsh's Avatar
 
Join Date: Feb 2012
Posts: 189
Reputation: 5
Default Re: variable reset? +rep!

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.
__________________
Walsh is offline   Reply With Quote
Old 03/03/2012, 04:10 PM   #3
PawnoQ
Huge Clucker
 
Join Date: Nov 2011
Posts: 375
Reputation: 7
Default Re: variable reset? +rep!

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?
PawnoQ is offline   Reply With Quote
Old 03/03/2012, 04:11 PM   #4
Konstantinos
Spam Machine
 
Konstantinos's Avatar
 
Join Date: Dec 2011
Posts: 11,828
Reputation: 1401
Default Re: variable reset? +rep!

OnPlayerConnect Callback reset the variables.
__________________
Life is like riding a bicycle. To keep your balance, you must keep moving.

[Tutorial] How to use SQLite
[FilterScript] Tune System
Konstantinos is offline   Reply With Quote
Old 03/03/2012, 04:11 PM   #5
Walsh
Big Clucker
 
Walsh's Avatar
 
Join Date: Feb 2012
Posts: 189
Reputation: 5
Default Re: variable reset? +rep!

Well, what type of gamemode is this for?
__________________
Walsh is offline   Reply With Quote
Old 03/03/2012, 04:13 PM   #6
PawnoQ
Huge Clucker
 
Join Date: Nov 2011
Posts: 375
Reputation: 7
Default Re: variable reset? +rep!

TDM, does that matter?

But OnPlayerDisconnect also should work, right?
PawnoQ is offline   Reply With Quote
Old 03/03/2012, 04:21 PM   #7
Walsh
Big Clucker
 
Walsh's Avatar
 
Join Date: Feb 2012
Posts: 189
Reputation: 5
Default Re: variable reset? +rep!

pawn Code:
new Money[MAX_PLAYERS];
public OnPlayerConnect(playerid)
{
    Money[playerid] = 0;
    return 1;
}

Everytime someone connects their money var will be reset.
__________________
Walsh is offline   Reply With Quote
Old 03/03/2012, 04:23 PM   #8
PawnoQ
Huge Clucker
 
Join Date: Nov 2011
Posts: 375
Reputation: 7
Default Re: variable reset? +rep!

i know that but my question actually was if the reset also works properly under OnPlayerDisconnect?
Or what efficiency differences there would be?
PawnoQ is offline   Reply With Quote
Old 03/03/2012, 04:25 PM   #9
Walsh
Big Clucker
 
Walsh's Avatar
 
Join Date: Feb 2012
Posts: 189
Reputation: 5
Default Re: variable reset? +rep!

Whether you put it under OnPlayerDisconnect or OnPlayerConnect, both will work %100. Niether of them have more efficiency than the other.
__________________
Walsh is offline   Reply With Quote
Old 03/03/2012, 04:26 PM   #10
PawnoQ
Huge Clucker
 
Join Date: Nov 2011
Posts: 375
Reputation: 7
Default Re: variable reset? +rep!

if its so then thx +rep
PawnoQ is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
warning 219: local variable "PlayerName" shadows a variable at a preceding level [DC] Scripting Help 2 02/01/2012 06:29 PM
Variable reset baske007 Help Archive 4 24/07/2010 12:18 PM
TextDraws as server variable?? How to i change to Player Variable? DarrenReeder Help Archive 2 06/04/2010 07:02 AM
local variable "KillsName" shadows a variable at a preceding level (weird) ғαιιοцт Help Archive 40 14/10/2009 07:04 PM
warning 219: local variable "timecounter" shadows a variable at a preceding leve PKRanger Help Archive 3 08/08/2009 04:04 PM


All times are GMT. The time now is 05:17 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.