How to check online players -
MadafakaPro - 11.03.2013
Hello, i have a question how to check how much members are online from group/faction ?
I some to explain me.
I want when players types /mon it will says ex : 4 members online .
Thanks in advance.
Re: How to check online players -
Denying - 11.03.2013
Make a variable to count a faction's online players and loop through all connected players when a player types /mon and check if they're in that faction, if they're raise the variable's value by one, after finishing the loop, format and send the player the desired message.
Re: How to check online players -
MadafakaPro - 11.03.2013
pawn Код:
if(strcmp("/mon", cmdtext, true) == 0)
{
if(PlayerInfo[playerid][playerteam]<1 || PlayerInfo[playerid][playerteam]==CIV || PlayerInfo[playerid][playerteam]==255) return SendClientError(playerid,"You cant use this Command");
SendClientMessage(playerid,COLOR_LIGHTYELLOW,"------[MEMBERS ONLINE]------");
for(new i; i != MAX_PLAYERS; i++)
{
if(PlayerInfo[playerid][playerteam] == PlayerInfo[playerid][playerteam])
{
format(string,sizeof(string),"(RANK:%s )( %s[ID:%d]) ",PlayerInfo[playerid][RankName],PlayerName(playerid),i);
SendClientMessage(playerid,COLOR_WHITE,string);
}
}
return 1;
}
i have /mon cmd which shows the online members with their names but i want to count them and displays them as Number .
Re: How to check online players -
Calabresi - 11.03.2013
Let's say the variable which saves player's faction is PlayerFaction and you want to check for faction ID 8. You gotta create a command as you wish and use that format;
pawn Код:
new count, string[128];
for(new id = 0; id < MAX_PLAYERS; id++)
{
if(PlayerFaction[id] == 8)
{
count++;
}
}
format(string, sizeof(string), "%d members are online from faction 8.", count);
SendClientMessage(playerid, -1, string);
I hope you understood it.
Re: How to check online players -
Denying - 11.03.2013
pawn Код:
new faction = 0, online[128];
if(strcmp("/mon", cmdtext, true) == 0)
{
if(PlayerInfo[playerid][playerteam]<1 || PlayerInfo[playerid][playerteam]==CIV || PlayerInfo[playerid][playerteam]==255) return SendClientError(playerid,"You cant use this Command");
SendClientMessage(playerid,COLOR_LIGHTYELLOW,"------[MEMBERS ONLINE]------");
for(new i; i != MAX_PLAYERS; i++)
{
if(PlayerInfo[playerid][playerteam] == PlayerInfo[playerid][playerteam])
{
faction++;
}
}
format(online, sizeof(online), "%d online members!", faction);
SendClientMessage(playerid, 0xFFFFFFFF, online);
return 1;
}
Put the new faction = 0 and online [128]; and the top of your script.
Re: How to check online players -
MadafakaPro - 11.03.2013
Everytime when i invite myself in different faction its adding +150 members ..
i get this mesage
150 members online etc
Re: How to check online players -
[HK]Ryder[AN] - 11.03.2013
Use this code.
pawn Код:
if(strcmp("/mon", cmdtext, true) == 0)
{
new members, online[128];
if(PlayerInfo[playerid][playerteam]<1 || PlayerInfo[playerid][playerteam]==CIV || PlayerInfo[playerid][playerteam]==255) return SendClientError(playerid,"You cant use this Command");
SendClientMessage(playerid,COLOR_LIGHTYELLOW,"------[MEMBERS ONLINE]------");
for(new i; i != MAX_PLAYERS; i++)
{
if(PlayerInfo[playerid][playerteam] == PlayerInfo[playerid][playerteam])
{
members++;
}
}
format(online, sizeof(online), "%d online members!", members);
SendClientMessage(playerid, 0xFFFFFFFF, online);
return 1;
}
Re: How to check online players -
MadafakaPro - 11.03.2013
It still not works.. its only showining - 150 Members online...
Re: How to check online players -
iRage - 11.03.2013
Ryder is comparing playerid with playerid, use this.
pawn Код:
if(strcmp("/mon", cmdtext, true) == 0)
{
new members, online[128];
if(PlayerInfo[playerid][playerteam]<1 || PlayerInfo[playerid][playerteam]==CIV || PlayerInfo[playerid][playerteam]==255) return SendClientError(playerid,"You cant use this Command");
SendClientMessage(playerid,COLOR_LIGHTYELLOW,"------[MEMBERS ONLINE]------");
for(new i; i < MAX_PLAYERS; i++)
{
if(PlayerInfo[playerid][playerteam] == PlayerInfo[i][playerteam])
{
members++;
}
}
format(online, sizeof(online), "%d online members!", members);
SendClientMessage(playerid, 0xFFFFFFFF, online);
return 1;
}
Re: How to check online players -
iggy1 - 11.03.2013
A better alternative would be to have a variable count how many players are in a team/faction when they join the team/faction. For example when you put a player in the cops team increase the "number_of_cops" var by one. When they log off reduce it by one. Then you always have access to the number of players in a team without looping through all players.