how to count players
#1

Hello friends!

I saw a filterscript in forum called last man standing or something like that, but link was dead, so i decided to create someting like that for my server. So i will get to the point. How can i count players who are in that event like if player joins event
pawn Код:
PlayerInfo[playerid][InLM] = 1;
It counts +1
When someone leaves
pawn Код:
PlayerInfo[playerid][InLM] = 0;
it counts -1 and updates in textdraw, i tried in way that doesnt worked for me like when someone joins its counts + and its shows for him in textdraw that its 1/20 but when leaves there still stays 1/20 i hope someone understands me
Thank ya all for answers.
Reply
#2

All you need is a variable. First, create the variable :
pawn Код:
new var = 0;
Then, in the cmd for joining the event, simply change it's value :
pawn Код:
var++;
And then you can check if the player is at the event by checking the variable like that :
pawn Код:
if(var==1)
I think you know what to do from here. If you don't, just post what you don't know.
Reply
#3

make a global variable like new Team1=0;
then every time they join the team do Team1++; and when leave Team1--;

simple
Reply
#4

you just setting the variable to 1 and 0 that's why it won't work.

it must be += 1; if someone leaves, -= 1;
Reply
#5

Quote:
Originally Posted by Romel
Посмотреть сообщение
you just setting the variable to 1 and 0 that's why it won't work.

it must be += 1; if someone leaves, -= 1;
that is his enum variables.
its for to check if the player is in InLM as you can see PlayerInfo[playerid][InLM]
not a counter !
Reply
#6

Use a loop and count all the players where PlayerInfo[i][InLM] > 0

pawn Код:
new total = 0;
for(new i=0; i<MAX_PLAYERS; i++) {
    if(IsPlayerConnected(i)) {
        if(PlayerInfo[i][InLM])
            total++;
    }
}

// total will now contain the total amount of players in Last Man Standing
printf("The total amount of players still in LM is: %d", total);
Reply
#7

Thank ya all!
In a fact i didnt mention it but i have that global variable thingy.
Sinner i will try your way now.
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)