How to count how much players in a faction
#1

And to print it, I need something simple, just to print statistics about specific faction (for Head of Faction-RP server)
Reply
#2

Depends on how you save the players' factions.
Reply
#3

Just access the data itself where ever it's stored and then print it or something.

How to count the players, use something like:
pawn Код:
#define MAX_FACTIONS 10 //See GetMemberCountInFaction for information regarding this.

new Ply_FactionID[MAX_PLAYERS]; //Something like this where their Current Faction ID is stored.



stock GetMemberCountInFaction(factionid){

    if(factionid > (MAX_FACTIONS - 1) || factionid < 0)
        return -1; /*We don't want to even run the loop to get an out of bounds error if the factionid is invalid.
        Return -1 so that you'll know the faction ID is invalid and not that the faction is invalid and there just aren't
        any players in it.
        */

       

    new mcount;
    for(new i = 0, x = GetPlayerPoolSize(); i <= x; i++){ //Loop through all of the players.

        if(!IsPlayerConnected(i)) continue; //If they're not connected, skip them.

        if(Ply_FactionID[i] == factionid) mcount ++; //If their faction matches the requested, add them to the count.
    }

    return mcount;
}
Reply
#4

You could also create a variable and increase/decrease its value when a faction member logs in or disconnects.
Reply
#5

new count = 0;

foreach(Player, i)
{
if(PlayerData[i][pFaction] == factionid)
{
count++;
}
}
Reply
#6

nvm....
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)