how to rewrite this -
Zeus666 - 19.04.2018
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(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[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(str, sizeof(str),"%s: %s - %s", GetRankName(i), PlayerName(i), DUTY_STR);
SendClientMessage(playerid, COLOR, str);
counter++;
}
} }
return 1;
}
Re: how to rewrite this -
AdamsLT - 19.04.2018
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.
Re: how to rewrite this -
GTLS - 20.04.2018
PHP 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[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(str, sizeof(str),"%s: %s - %s", GetRankName(i), PlayerName(i), DUTY_STR);
SendClientMessage(playerid, COLOR, str);
counter++;
}
} }
return 1;
}
Re: how to rewrite this -
Twixxx - 20.04.2018
PHP Code:
CMD:factionon(playerid, params[])
{
if(pInfo[playerid][pRank] < 1)
return SendClientMessage(playerid, -1, !"You are not in any faction.");
new
string[128];
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(0 == IsPlayerConnected(i))
continue;
if(pInfo[i][pFaction] != pInfo[playerid][pFaction])
continue;
format(string, sizeof(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;
}
Re: how to rewrite this -
Zeus666 - 20.04.2018
PHP Code:
CMD:factionon(playerid, params[])
{
new str[128], DUTY_STR[24], COLOR, counter = 0;
SendClientMessage(playerid, -1, " - Membrii online - ");
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][pPoliceDuty])
{
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;
}
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?
Re: how to rewrite this -
Fairuz - 20.04.2018
Don't check if player is in faction inside of loop,place it outside.
Re: how to rewrite this -
FnZ - 20.04.2018
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;
}
Re: how to rewrite this -
TheLeech - 20.04.2018
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;
}
Re: how to rewrite this -
Kraeror - 20.04.2018
Here you are, it should works:
PHP Code:
CMD:factionon(playerid, params[])
{
new str[128], DUTY_STR[24], COLOR, counter = 0;
SendClientMessage(playerid, -1, " - Online members - ");
if((pInfo[playerid][pRank] < 1)) return SendClientMessage(playerid, -1, "You are not from any faction");
for(new i = 0; i < MAX_PLAYERS; i++)
{
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(str, sizeof(str),"%s: %s - %s", GetRankName(i), PlayerName(i), DUTY_STR);
counter++;
}
}
}
SendClientMessage(playerid, COLOR, str);
return 1;
}
I don't recommend to put SCM into a loop! And check the difference between this code and yours!
Re: how to rewrite this -
Logic_ - 20.04.2018
Quote:
Originally Posted by Kraeror
...!
|
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.