how to rewrite this
#1

Hi, this command shows online faction members, but I want to make it if playerid is in faction 1, to show only faction 1 members.


PHP Code:
CMD:factionon(playeridparams[])
{
    new 
str[128], DUTY_STR[24], COLORcounter 0;
    
SendClientMessage(playerid, -1" - Online members - ");
    for(new 
0MAX_PLAYERSi++)
    {
        if((
pInfo[i][pRank] < 1)) return SendClientMessage(playerid, -1"You are not from any faction");
        if(
IsPlayerConnected(i))
        {
            if(
pInfo[i][pFaction] == pInfo[i][pFaction]) /// there  i dont know what to do
            
{
                    if(!
pInfo[i][pFactionDuty])
                {
                    
DUTY_STR "Off Duty";
                    
COLOR COLOR_WHITE;
                }
                else
                {
                    
DUTY_STR "ON DUTY";
                    
COLOR COLOR_RED;
                }
                
format(strsizeof(str),"%s: %s - %s",  GetRankName(i), PlayerName(i), DUTY_STR);
                
SendClientMessage(playeridCOLORstr);
                
counter++;
            }
        }    }
    return 
1;

Reply
#2

You are almost there, just one small change.

pInfo[i][pFaction] == pInfo[i][pFaction]

This part in your code compares if the person in this loop iteration has the same faction as himself, if yes - then continues. In your post you say that you only want to do this with people that have the same job as the playerid player.

So, all you have to do is change one i to the word playerid and you're good.

if(pInfo[playerid][pFaction] == pInfo[i][pFaction])

This will compare the faction ids of the person who wrote the command (playerid) and the people that are online (i) and only add those that match to the list.
Reply
#3

PHP Code:
CMD:factionon(playeridparams[]) 

    new 
str[128], DUTY_STR[24], COLORcounter 0
    
SendClientMessage(playerid, -1" - Online members - "); 
    for(new 
0MAX_PLAYERSi++) 
    { 
        if((
pInfo[i][pRank] < 1)) return SendClientMessage(playerid, -1"You are not from any faction"); 
        if(
IsPlayerConnected(i)) 
        { 
            if(
pInfo[i][pFaction] == pInfo[playerid][pFaction]) /// Use Playerid as first index in any one of them.
            

                    if(!
pInfo[i][pFactionDuty]) 
                { 
                    
DUTY_STR "Off Duty"
                    
COLOR COLOR_WHITE
                } 
                else 
                { 
                    
DUTY_STR "ON DUTY"
                    
COLOR COLOR_RED
                } 
                
format(strsizeof(str),"%s: %s - %s",  GetRankName(i), PlayerName(i), DUTY_STR); 
                
SendClientMessage(playeridCOLORstr); 
                
counter++; 
            } 
        }    } 
    return 
1

Reply
#4

PHP Code:
CMD:factionon(playeridparams[])
{
    if(
pInfo[playerid][pRank] < 1)
        return 
SendClientMessage(playerid, -1, !"You are not in any faction.");
    new
        
string[128];
    for(new 
0MAX_PLAYERSi++)
    {
        if(
== IsPlayerConnected(i))
            continue;
        if(
pInfo[i][pFaction] != pInfo[playerid][pFaction])
            continue;
        
format(stringsizeof(string), "%s: %s - %s"GetRankName(i), PlayerName(i), (pInfo[i][pFactionDuty] ? ("Off Duty") : ("ON DUTY")));
        
SendClientMessage(playerid, (pInfo[i][pFactionDuty] ? COLO_RED COLOR_WHITE), string);
    }
    return 
1;

Reply
#5

PHP Code:
CMD:factionon(playeridparams[])
{
    new 
str[128], DUTY_STR[24], COLORcounter 0;
    
SendClientMessage(playerid, -1" - Membrii online - ");
    for(new 
0MAX_PLAYERSi++)
    {
            if((
pInfo[i][pRank] < 1)) return SendClientMessage(playerid, -1"You are not from any faction");
               if(
IsPlayerConnected(i))
        {
            if(
pInfo[playerid][pFaction] == pInfo[i][pFaction])
            {
                if(!
pInfo[i][pPoliceDuty])
                {
                    
DUTY_STR "Off Duty";
                    
COLOR COLOR_WHITE;
                }
                else
                {
                    
DUTY_STR "ON DUTY";
                    
COLOR COLOR_RED;
                }
                
format(strsizeof(str),"%s: %s - %s",  GetRankName(i), PlayerName(i), DUTY_STR);
                
SendClientMessage(playeridCOLORstr);
                
counter++;
            }
        }
    }
    return 
1;

I did this,but everytime I type /factionon, it shows the online members, but it shows that "You are not from any faction" too.

Did I place that IF too late on the code?
Reply
#6

Don't check if player is in faction inside of loop,place it outside.
Reply
#7

Code:
CMD:factionon(playerid, params[]) 
{ 
    new str[128], DUTY_STR[24], COLOR, counter = 0; 
    SendClientMessage(playerid, -1, " - Online members - "); 
    for(new i = 0; i < MAX_PLAYERS; i++) 
    { 
        if((pInfo[i][pRank] < 1)) return SendClientMessage(playerid, -1, "You are not from any faction"); 
        if(IsPlayerConnected(i)) 
        { 
            if(pInfo[playerid][pFaction] == pInfo[i][pFaction])
            { 
                    if(!pInfo[i][pFactionDuty]) 
                { 
                    DUTY_STR = "Off Duty"; 
                    COLOR = COLOR_WHITE; 
                } 
                else 
                { 
                    DUTY_STR = "ON DUTY"; 
                    COLOR = COLOR_RED; 
                } 
                format(str, sizeof(str),"%s: %s - %s",  GetRankName(i), PlayerName(i), DUTY_STR); 
                SendClientMessage(playerid, COLOR, str); 
                counter++; 
            } 
        }  
    return 1; 
}
Reply
#8

its because the i where the sendclient message code is searching all players for the faction id < 1 so sends the message change it to [playerid]

Code:
CMD:factionon(playerid, params[]) 
{ 
    new str[128], DUTY_STR[24], COLOR, counter = 0; 
    SendClientMessage(playerid, -1, " - Online members - "); 
    for(new i = 0; i < MAX_PLAYERS; i++) 
    { 
        //This is where you had the [i] instead of [playerid]
        if((pInfo[playerid][pRank] < 1)) return SendClientMessage(playerid, -1, "You are not from any faction"); 
        if(IsPlayerConnected(i)) 
        { 
            if(pInfo[playerid][pFaction] == pInfo[i][pFaction])
            { 
                    if(!pInfo[i][pFactionDuty]) 
                { 
                    DUTY_STR = "Off Duty"; 
                    COLOR = COLOR_WHITE; 
                } 
                else 
                { 
                    DUTY_STR = "ON DUTY"; 
                    COLOR = COLOR_RED; 
                } 
                format(str, sizeof(str),"%s: %s - %s",  GetRankName(i), PlayerName(i), DUTY_STR); 
                SendClientMessage(playerid, COLOR, str); 
                counter++; 
            } 
        }  
    return 1; 
}
Reply
#9

Here you are, it should works:
PHP Code:
CMD:factionon(playeridparams[])
{
    new 
str[128], DUTY_STR[24], COLORcounter 0;
    
SendClientMessage(playerid, -1" - Online members - ");
    if((
pInfo[playerid][pRank] < 1)) return SendClientMessage(playerid, -1"You are not from any faction");
    for(new 
0MAX_PLAYERSi++)
    {
        if(
IsPlayerConnected(i))
        {
            if(
pInfo[i][pFaction] == pInfo[playerid][pFaction])
            {
                if(!
pInfo[i][pFactionDuty])
                {
                    
DUTY_STR "Off Duty";
                    
COLOR COLOR_WHITE;
                }
                else
                {
                    
DUTY_STR "ON DUTY";
                    
COLOR COLOR_RED;
                }
                
format(strsizeof(str),"%s: %s - %s",  GetRankName(i), PlayerName(i), DUTY_STR);
                
counter++;
            }
        }
    }
    
SendClientMessage(playeridCOLORstr);
    return 
1;

I don't recommend to put SCM into a loop! And check the difference between this code and yours!
Reply
#10

Quote:
Originally Posted by Kraeror
View Post
...!
Hell no. We want to send a list of players not just one player lol. Your code is wrong.

Edit: the only thing right in your code is the first 'if' statement Which checks for rank.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)