SA-MP Forums Archive
Total Variable Counter Possible? - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Total Variable Counter Possible? (/showthread.php?tid=271907)



Total Variable Counter Possible? - Rolyy - 26.07.2011

I am wondering if it is possible to count the total of a variable[MAX_PLAYERS]
To count the total ammount of numbers of all connected players

Example:
ID 2: variable[playerid] = 20;
ID 7: variable[playerid] = 11
ID 9: variable[playerid] = 37

And if the total (20+11+37=68) can be counted within 1 pawno line.

Thanks in Advance,
Rolyy.


Re: Total Variable Counter Possible? - park4bmx - 26.07.2011

well just do something like this
pawn Код:
new Count;
Count = variable[playerid] + variable2[playerid] + variable3[playerid];



Re: Total Variable Counter Possible? - iPLEOMAX - 26.07.2011

Try this:

pawn Код:
new totalvalue;
for( new i=0; i<MAX_PLAYERS; i++ ) { totalvalue += Variable[i]; }



Re: Total Variable Counter Possible? - Rolyy - 26.07.2011

Quote:
Originally Posted by park4bmx
Посмотреть сообщение
pawn Код:
new Count;
Count = variable[playerid] + variable2[playerid] + variable3[playerid];
This is a bit too much..


Quote:
Originally Posted by iPLEOMAX
Посмотреть сообщение
new totalvalue;
for( new i=0; i<MAX_PLAYERS; i++ ) { totalvalue += Variable[i]; }
[/pawn]
Already tried something like this, but this one doesn't work either..


Re: Total Variable Counter Possible? - iPLEOMAX - 26.07.2011

Can you post the actual part of what you are trying to code?


Re: Total Variable Counter Possible? - Rolyy - 26.07.2011

Quote:
Originally Posted by iPLEOMAX
Посмотреть сообщение
Can you post the actual part of what you are trying to code?
Too many parts then, but lets say it has to do with with IsPlayerAlive[playerid] by 1(yes) or 0(no).
And somehow to count the total ammount of IsPlayerAlive[MAX_PLAYERS]..


AW: Total Variable Counter Possible? - Nero_3D - 26.07.2011

so you want to know how much player are alive

the code iPLEOMAX posted looks fine for me

you said it doesnt worked, than what happend instead, as I am sure that the code compiles


Re: Total Variable Counter Possible? - Rolyy - 26.07.2011

Wait, Something is wrong. This code does work everytime once entering a command.

pawn Код:
for( new i=0; i<MAX_PLAYERS; i++ )
        {
            TotalTeamPlayers += IsPlayerAlive[i];
        }
But if I try to reset the counter every command then it remains on 0.
pawn Код:
for( new i=0; i<MAX_PLAYERS; i++ )
        {
            TotalTeamPlayers = 0; //Also tried these 2 lines opposite.
            TotalTeamPlayers += IsPlayerAlive[i]; //Also tried these 2 lines opposite.
        }
Do you know maybe whats wrong about this?


AW: Total Variable Counter Possible? - Nero_3D - 26.07.2011

if you would do it in the loop it would set the variable each time to 0 and than add the current one

so the last run would look like that

pawn Код:
TotalTeamPlayers = 0;
TotalTeamPlayers += IsPlayerAlive[499];
the result should be clear, only 0 or 1

You need to reset it before the loop

pawn Код:
//
        TotalTeamPlayers = 0;
        for( new i=0; i<MAX_PLAYERS; i++ )
        {
            TotalTeamPlayers += IsPlayerAlive[i];
        }



Re: AW: Total Variable Counter Possible? - Rolyy - 26.07.2011

Quote:
Originally Posted by Nero_3D
Посмотреть сообщение
if you would do it in the loop it would set the variable each time to 0 and than add the current one

so the last run would look like that

pawn Код:
TotalTeamPlayers = 0;
TotalTeamPlayers += IsPlayerAlive[499];
the result should be clear, only 0 or 1

You need to reset it before the loop

pawn Код:
//
        TotalTeamPlayers = 0;
        for( new i=0; i<MAX_PLAYERS; i++ )
        {
            TotalTeamPlayers += IsPlayerAlive[i];
        }
Jezus, its so obvious but why didn't i thought of that >_<.
Lol ahh well, another something that I learned.
Thank you both so much for your effort .