16.11.2016, 00:19
Example (not tested in game)
Or if you want dynamic usage of this system
pawn Код:
#define POLICE 1
#define MEDICS 2
CMD:faction(playerid,params[]) {
new text[128];
if(sscanf(params,"s[128]")) return SendClientMessage(playerid,COLOR_RED,"Usage: /faction [text]");
SendFactionMessage(text, POLICE, MEDICS);
return true;
}
stock SendFactionMessage(text[],faction1, faction2) {
for(new i=0; i < MAX_PLAYERS ;i++) {
if(IsPlayerConnected(i)) {
if(gTeam[i] == faction1 || gTeam[i] == faction2) { //if they are part of faction 1 or part of faction 2
SendClientMessage(i,COLOR_RED,text);
}
}
}
}
Or if you want dynamic usage of this system
pawn Код:
#define POLICE 1
#define MEDICS 2
#define NO_FACTION 3
CMD:faction(playerid,params[]) {
new text[128];
if(sscanf(params,"s[128]")) return SendClientMessage(playerid,COLOR_RED,"Usage: /faction [text]");
SendFactionMessage(text, getPlayerFaction(playerid));
return true;
}
stock getPlayerFaction(playerid) return gTeam[playerid];
stock getConnectedFaction(faction) {
switch(faction) {
case POLICE: return MEDICS;
case MEDICS: return POLICE;
default: return NO_FACTION; //if they are not part of the faction above
}
}
stock SendFactionMessage(text[], faction) {
for(new i=0; i < MAX_PLAYERS ;i++) {
if(IsPlayerConnected(i)) {
if(gTeam[i] == faction1 || gTeam[i] == getConnectedFaction(faction)) { //if they are part of faction 1 or part of faction 1 is connected to
SendClientMessage(i,COLOR_RED,text);
}
}
}
}