Total Variable Counter Possible?
#1

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.
Reply
#2

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

Try this:

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

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..
Reply
#5

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

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]..
Reply
#7

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
Reply
#8

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?
Reply
#9

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];
        }
Reply
#10

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 .
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)