SA-MP Forums Archive
How to count how much players in a faction - 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)
+--- Thread: How to count how much players in a faction (/showthread.php?tid=607721)



How to count how much players in a faction - DemME - 22.05.2016

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


Re: How to count how much players in a faction - Stinged - 23.05.2016

Depends on how you save the players' factions.


Re: How to count how much players in a faction - Banana_Ghost - 23.05.2016

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;
}



Re: How to count how much players in a faction - Abagail - 23.05.2016

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


Re: How to count how much players in a faction - Nin9r - 23.05.2016

new count = 0;

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


Re: How to count how much players in a faction - DemME - 23.05.2016

nvm....