Members command problem
#1

I have problem with command, when i type /members it show me first player rank,then who are the leader.
I want command showing me first who are the leader then which player is rank.

Код:
CMD:members(playerid, params[])
{
	new stringer[213];
	new teamnumber;
	if (PlayerInfo[playerid][pLeader] != 0)
	{
		teamnumber = PlayerInfo[playerid][pLeader];
	}
	else if (PlayerInfo[playerid][pMember] != 0)
	{
		teamnumber = PlayerInfo[playerid][pMember];
	}
	else
	{
		return SendClientMessage(playerid, COLOR_GRAD1, "Вы ни где не состоите!");
	}
	SendClientMessage(playerid, 0x059BD3AA, "Члены организации Online:");
	new countmute = 0;
	foreach(new i : Player)
	{
		if ((PlayerInfo[i][pMember] == teamnumber) && IsPlayerConnected(i))
		{
			format(stringer, sizeof(stringer), "");
			countmute++;
			if (PlayerInfo[i][pLeader] == teamnumber)
			{
				format(stringer, sizeof(stringer), "[%d] %s ранг: Лидер {FFFFFF}", i, NamePlayer[i]);
			}
			else if (PlayerInfo[i][pMember] == teamnumber)
			{
				format(stringer, sizeof(stringer), "[%d] %s ранг: %d {FFFFFF}", i, NamePlayer[i], PlayerInfo[i][pRank]);
			}
			if (strlen(stringer) > 1)
			{
				SendClientMessage(playerid, 0xC0E1EEFF, stringer);
			}
		}
	}
	if (countmute == 0)
	{
		SendClientMessage(playerid, COLOR_GRAY, "Нет игроков");
	}
	else
	{
		SendMes(playerid, COLOR_YELLOW, "Всего: %d человек", countmute);
	}
	return true;
}
Reply
#2

Change:

PHP код:
if (PlayerInfo[i][pLeader] == teamnumber)
            {
                
format(stringersizeof(stringer), "[%d] %s ранг: Лидер {FFFFFF}"iNamePlayer[i]);
            }
            else if (
PlayerInfo[i][pMember] == teamnumber)
            {
                
format(stringersizeof(stringer), "[%d] %s ранг: %d {FFFFFF}"iNamePlayer[i], PlayerInfo[i][pRank]);
            } 
With:

PHP код:
if (PlayerInfo[i][pLeader] == teamnumber)
            {
                
format(stringersizeof(stringer), "%s [%d] ранг: Лидер {FFFFFF}"NamePlayer[i], i);
            }
            else if (
PlayerInfo[i][pMember] == teamnumber)
            {
                
format(stringersizeof(stringer), "%s [%d] ранг: %d {FFFFFF}"NamePlayer[i], iPlayerInfo[i][pRank]);
            } 
Reply
#3

Quote:
Originally Posted by jihadmeneer
Посмотреть сообщение
Change:

PHP код:
if (PlayerInfo[i][pLeader] == teamnumber)
            {
                
format(stringersizeof(stringer), "[%d] %s ранг: Лидер {FFFFFF}"iNamePlayer[i]);
            }
            else if (
PlayerInfo[i][pMember] == teamnumber)
            {
                
format(stringersizeof(stringer), "[%d] %s ранг: %d {FFFFFF}"iNamePlayer[i], PlayerInfo[i][pRank]);
            } 
With:

PHP код:
if (PlayerInfo[i][pLeader] == teamnumber)
            {
                
format(stringersizeof(stringer), "%s [%d] ранг: Лидер {FFFFFF}"NamePlayer[i], i);
            }
            else if (
PlayerInfo[i][pMember] == teamnumber)
            {
                
format(stringersizeof(stringer), "%s [%d] ранг: %d {FFFFFF}"NamePlayer[i], iPlayerInfo[i][pRank]);
            } 
I don't want that.
My command showing like this

PHP код:
Online Members:
BigBoy81 Rank1
AngeLpiNe 
(Leader
So is the mixed, I do not want to be mixed..

I want to showing first who are leader, then who are members like this

PHP код:
Online Members:
AngeLpiNe (Leader)
BigBoy81 Rank
Reply
#4

PHP код:
CMD:members(playeridparams[])
{
    new 
stringer[213];
    new 
teamnumber;
    if (
PlayerInfo[playerid][pLeader] != 0)
    {
        
teamnumber PlayerInfo[playerid][pLeader];
    }
    else if (
PlayerInfo[playerid][pMember] != 0)
    {
        
teamnumber PlayerInfo[playerid][pMember];
    }
    else
    {
        return 
SendClientMessage(playeridCOLOR_GRAD1"Вы ни где не состоите!");
    }
    
SendClientMessage(playerid0x059BD3AA"Члены организации Online:");
    new 
countmute 0;
    new 
findleader=0;
    foreach(new 
Player)
    {
        if ((
PlayerInfo[i][pMember] == teamnumber) && IsPlayerConnected(i))
        {
            
format(stringersizeof(stringer), "");
            
countmute++;
            if (
PlayerInfo[i][pLeader] == teamnumber&&findleader==0)
            {
                
format(stringersizeof(stringer), "[%d] %s ранг: Лидер {FFFFFF}"iNamePlayer[i]);
                
findleader++;
                
i=0;
            }
            else if (
PlayerInfo[i][pMember] == teamnumber&&findleader!=0)
            {
                
format(stringersizeof(stringer), "[%d] %s ранг: %d {FFFFFF}"iNamePlayer[i], PlayerInfo[i][pRank]);
            }
            if (
strlen(stringer) > 1)
            {
                
SendClientMessage(playerid0xC0E1EEFFstringer);
            }
        }
    }
    if (
countmute == 0)
    {
        
SendClientMessage(playeridCOLOR_GRAY"Нет игроков");
    }
    else
    {
        
SendMes(playeridCOLOR_YELLOW"Всего: %d человек"countmute);
    }
    return 
true;

Haven't really worked with foreach, but this should work, try it.
Reply
#5

Quote:
Originally Posted by PrO.GameR
Посмотреть сообщение
PHP код:
CMD:members(playeridparams[])
{
    new 
stringer[213];
    new 
teamnumber;
    if (
PlayerInfo[playerid][pLeader] != 0)
    {
        
teamnumber PlayerInfo[playerid][pLeader];
    }
    else if (
PlayerInfo[playerid][pMember] != 0)
    {
        
teamnumber PlayerInfo[playerid][pMember];
    }
    else
    {
        return 
SendClientMessage(playeridCOLOR_GRAD1"Вы ни где не состоите!");
    }
    
SendClientMessage(playerid0x059BD3AA"Члены организации Online:");
    new 
countmute 0;
    new 
findleader=0;
    foreach(new 
Player)
    {
        if ((
PlayerInfo[i][pMember] == teamnumber) && IsPlayerConnected(i))
        {
            
format(stringersizeof(stringer), "");
            
countmute++;
            if (
PlayerInfo[i][pLeader] == teamnumber&&findleader==0)
            {
                
format(stringersizeof(stringer), "[%d] %s ранг: Лидер {FFFFFF}"iNamePlayer[i]);
                
findleader++;
                
i=0;
            }
            else if (
PlayerInfo[i][pMember] == teamnumber&&findleader!=0)
            {
                
format(stringersizeof(stringer), "[%d] %s ранг: %d {FFFFFF}"iNamePlayer[i], PlayerInfo[i][pRank]);
            }
            if (
strlen(stringer) > 1)
            {
                
SendClientMessage(playerid0xC0E1EEFFstringer);
            }
        }
    }
    if (
countmute == 0)
    {
        
SendClientMessage(playeridCOLOR_GRAY"Нет игроков");
    }
    else
    {
        
SendMes(playeridCOLOR_YELLOW"Всего: %d человек"countmute);
    }
    return 
true;

Haven't really worked with foreach, but this should work, try it.
No, now doesn't show anything under Online Members:
Reply
#6

Stop expecting someone to do it for you, and copying and pasting answers.

You need to change the order in which you are doing the checks, or the way you are doing the check.

If the Leader will be offline, then that should be stored somewhere so it can be displayed.

Код:
if ((PlayerInfo[i][pMember] == teamnumber) && IsPlayerConnected(i)) 
        { 
            format(stringer, sizeof(stringer), ""); 
            countmute++; 
            if (PlayerInfo[i][pLeader] == teamnumber&&findleader==0) 
            { 
                format(stringer, sizeof(stringer), "[%d] %s ранг: Лидер {FFFFFF}", i, NamePlayer[i]); 
                findleader++; 
                i=0; 
            } 
            else if (PlayerInfo[i][pMember] == teamnumber&&findleader!=0) 
            { 
                format(stringer, sizeof(stringer), "[%d] %s ранг: %d {FFFFFF}", i, NamePlayer[i], PlayerInfo[i][pRank]); 
            } 
            if (strlen(stringer) > 1) 
            { 
                SendClientMessage(playerid, 0xC0E1EEFF, stringer); 
            } 
        }
That code, is simply going through the player list and making output. It doesn't sort it.

If you were the first player on, and you were the leader, and a member joined, it'll display fine. In this case, the member joined, then the leader joined. so it looks wrong.

Again though, stop expecting copy/paste answers... That's not what this section is for. As for those who are pasting... Stop it... It teaches them NOTHING.
Reply
#7

You need to make it sort it out, remove else; and go from there. *hinthint
Reply
#8

Quote:
Originally Posted by Sew_Sumi
Посмотреть сообщение
Stop expecting someone to do it for you, and copying and pasting answers.

You need to change the order in which you are doing the checks, or the way you are doing the check.

If the Leader will be offline, then that should be stored somewhere so it can be displayed.

Код:
if ((PlayerInfo[i][pMember] == teamnumber) && IsPlayerConnected(i)) 
        { 
            format(stringer, sizeof(stringer), ""); 
            countmute++; 
            if (PlayerInfo[i][pLeader] == teamnumber&&findleader==0) 
            { 
                format(stringer, sizeof(stringer), "[%d] %s ранг: Лидер {FFFFFF}", i, NamePlayer[i]); 
                findleader++; 
                i=0; 
            } 
            else if (PlayerInfo[i][pMember] == teamnumber&&findleader!=0) 
            { 
                format(stringer, sizeof(stringer), "[%d] %s ранг: %d {FFFFFF}", i, NamePlayer[i], PlayerInfo[i][pRank]); 
            } 
            if (strlen(stringer) > 1) 
            { 
                SendClientMessage(playerid, 0xC0E1EEFF, stringer); 
            } 
        }
That code, is simply going through the player list and making output. It doesn't sort it.

If you were the first player on, and you were the leader, and a member joined, it'll display fine. In this case, the member joined, then the leader joined. so it looks wrong.

Again though, stop expecting copy/paste answers... That's not what this section is for. As for those who are pasting... Stop it... It teaches them NOTHING.
Actually I was too sleepy and didn't notice he doesn't have a check to see if leader is online, in theory it does exactly what he said, which is show leader first
and btw storing players then sorting them is CPU efficient, I like to do the loop twice, it's ram efficient and it's a matter of personal preference, I don't have experience in foreach, but in a simple for I would simply check on the i=MAX_PLAYERS to see if findleader==0, if it was =0 I would make i=0 again and findleader=1, and tada, problem is fixed.
You can't expect someone to magically learn something unless you either fix their problem this time, or give them a different working example that they can follow, or babble for an hour for them to learn. Whichever you choose thats your choice, and I simply got mine alright ? so instead of crying in every topic, be helpful, either make a well explained answer for them to learn, write a new code for them to follow or just don't answer to that topic alright ?
Reply
#9

I need some example how i can make sort this.
I sort it by rank, but using foreach my names are mixed.
Reply
#10

Quote:
Originally Posted by PrO.GameR
Посмотреть сообщение
Actually I was too sleepy and didn't notice he doesn't have a check to see if leader is online, in theory it does exactly what he said, which is show leader first
and btw storing players then sorting them is CPU efficient, I like to do the loop twice, it's ram efficient and it's a matter of personal preference, I don't have experience in foreach, but in a simple for I would simply check on the i=MAX_PLAYERS to see if findleader==0, if it was =0 I would make i=0 again and findleader=1, and tada, problem is fixed.
You can't expect someone to magically learn something unless you either fix their problem this time, or give them a different working example that they can follow, or babble for an hour for them to learn. Whichever you choose thats your choice, and I simply got mine alright ? so instead of crying in every topic, be helpful, either make a well explained answer for them to learn, write a new code for them to follow or just don't answer to that topic alright ?
Was that directed at me?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)