Members online
#1

Hey guys, how do I make it so this command allows you to see how many players are online in each gang?

Here is my code:

Код:
CMD:families(playerid, params[])
{
	new string[128], familyid;

	if(sscanf(params, "d", familyid))
	{
		new number = 0;
		for(new i = 0; i < sizeof(FamilyInfo); i++)
		{
			number ++;
			{
				format(string, sizeof(string), "%d. Name: %s | Leader: %s | Members: %d | Online: %s.",number,FamilyInfo[i][FamilyName],FamilyInfo[i][FamilyLeader],FamilyInfo[i][FamilyMembers]);
			}
			SendClientMessageEx(playerid, COLOR_WHITE, string);
		}
		return 1;
	}
I want it to say, Name of gang: | Leader: | Members in gang: | Members currently online in the gang:
Reply
#2

Suppose you have 3 gangs G1 G2 G3,
you can put it this way
PHP код:
CMD:membersonline(playerid){
new 
Count1//This will store the number of connected players in gang number 1
    
Count2//This will store the number of connected players in gang number 2
    
Count3//This will store the number of connected players in gang number 3
//Now loop through all players
for(new i=0;i<GetPlayerPoolSize();i++){
    if(!
IsPlayerConnected(i)) continue; //If the player is not connected, the following lines won't be executed for that specific player id, so the seleced id will increment
    
if(PlayerGang[i] == G1Gcount1++; //if a player is in gang 1 the GCount1 variable will increment
    
if(PlayerGang[i] == G2GCount2++; //if a player is in gang 2 the GCount2 variable will increment
    
if(PlayerGang[i] == G3GCount3++; //if a player is in gang 3 the GCount3 variable will increment
}
//Now display the results
printf("Connected Members from gang 1: %d",GCount1);
printf("Connected Members from gang 2: %d",GCount2);
printf("Connected Members from gang 3: %d",GCount3);
return 
1;
}
//Replace the PlayerGang[MAX_PLAYERS] array with your own
//This is an example for ZCMD/iZCMD/YCMD... Command processores 
Reply
#3

Quote:
Originally Posted by Eoussama
Посмотреть сообщение
Suppose you have 3 gangs G1 G2 G3,
you can put it this way
PHP код:
new Count1//This will store the number of connected players in gang number 1
    
Count2//This will store the number of connected players in gang number 2
    
Count3//This will store the number of connected players in gang number 3
//Now loop through all players
for(new i=0;i<GetPlayerPoolSize();i++){
    if(!
IsPlayerConnected(i)) continue; //If the player is not connected, the following lines won't be executed for that specific player id, so the seleced id will increment
    
if(PlayerGang[i] == G1Gcount1++; //if a player is in gang 1 the GCount1 variable will increment
    
if(PlayerGang[i] == G2GCount2++; //if a player is in gang 2 the GCount2 variable will increment
    
if(PlayerGang[i] == G3GCount3++; //if a player is in gang 3 the GCount3 variable will increment
}
//Now display the results
printf("Connected Members from gang 1: %d",GCount1);
printf("Connected Members from gang 2: %d",GCount2);
printf("Connected Members from gang 3: %d",GCount3);
//Replace the PlayerGang[MAX_PLAYERS] array with your own 
A little criticism of mine, if you give examples, you might want to consider doing it properly :P
Reply
#4

Quote:
Originally Posted by [Bios]Marcel
Посмотреть сообщение
A little criticism of mine, if you give examples, you might want to consider doing it properly :P
Thanks for the advice, I would like to know tho, what did I do wrong?
Tnx in advance
Reply
#5

Maybe also tell him where to put this code, I don't think he knows.
Reply
#6

Quote:
Originally Posted by Eoussama
Посмотреть сообщение
Thanks for the advice, I would like to know tho, what did I do wrong?
Tnx in advance
unnecessary ifs (use else ifs or switch), calling GetPlayerPoolSize every time instead of once , called the variables at the top: Count(Number), but used GCount(Number)
Reply
#7

I don't want it to be a seperate command though? I just want it like i've set it out to be.

I just want it to be a command doing /families and it tells you the following about the families:

Gang name:
Leader:
Members:
Members online:
Reply
#8

create a new variable called "FamilyInfo[i][FamilyOnline]" (for example).
if a player is connecting set the variable + 1 for his family.
set it minus 1 when he is disconnecting.

easiest solution.
and why do you need the scanff there?
the player is typing a ID but you anyways show him the information of all families.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)