SA-MP Forums Archive
Members online - 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: Members online (/showthread.php?tid=627845)



Members online - AdzeeH - 02.02.2017

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:


Re: Members online - Eoussama - 02.02.2017

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 



Re: Members online - BiosMarcel - 02.02.2017

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


Re: Members online - Eoussama - 02.02.2017

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


Re: Members online - AndreiWow - 02.02.2017

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


Re: Members online - BiosMarcel - 02.02.2017

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)


Re: Members online - AdzeeH - 02.02.2017

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:


Re: Members online - GangstaSunny. - 02.02.2017

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.