Shared chat between 2 factions.
#1

I have tried creating a dept radio system which includes two factions, but the problem is the following thing, the first faction which is the police one can use the command and receive messages from the other faction, but the second faction doesn't see what they type in the shared chat and can not receive any messages from the second faction. This is the code.

PHP код:
 #define SendSplitMessageF(%1,%2,%3) SendSplitMessage(%1, %2, (format(sgstr, sizeof(sgstr), %3), sgstr))
new sgstr[256];
if(
strcmp(cmd"/dept"true) == || strcmp(cmd"/dr"true) == 0)
    {
    new 
length strlen(cmdtext);
      new 
name[24], string[256];
          new 
DeptName[10];
        
GetPlayerName(playeridnamesizeof(name));
        while ((
idx length) && (cmdtext[idx] <= ' ')){idx++;}
        new 
offset idx,result[64];
        while ((
idx length) && ((idx offset) < (sizeof(result) - 1))){result[idx offset] = cmdtext[idx];idx++;}
        
result[idx offset] = EOS;
        if(!
strlen(result))return SendClientMessage(playeridred"USAGE: /dr [text]");
        if(
gTeam[playerid] == POLICEDeptName "SASP";
        else if(
gTeam[playerid] == APDeptName "SACFD";
        for(new 
0MAX_PLAYERSi++)
        {
             if(
IsPlayerConnected(i))
            {
             if(
gTeam[i] == POLICE)
              
SendSplitMessageF(iCOLOR_ORANGE"[%s] %s says: %s"DeptNamenameresult);
            continue;
              }
            if(
gTeam[i] == AP)
            {
            
SendSplitMessageF(iCOLOR_ORANGE"[%s] %s says: %s"DeptNamenameresult);
            continue;
            }
            
format(gstrsizeof(gstr), "%s says (dept. radio): %s"nameresult);
            
ProxDetector(15.0playeridgstrCOLOR_FADE1COLOR_FADE2COLOR_FADE3COLOR_FADE4COLOR_FADE5);
            return 
1;
        }
    }
stock SendSplitMessage(playeridcolormsg[])
{
    new 
ml 115result[160], len strlen(msg), repeat;
    if(
len ml)
    {
        
repeat = (len ml);
        for(new 
0<= repeati++)
        {
            
result[0] = 0;
            if(
len - (ml) > ml)
            {
                
strmid(resultmsgml iml * (i+1));
                
format(resultsizeof(result), "%s"result);
            }
            else
            {
                
strmid(resultmsgml ilen);
                
format(resultsizeof(result), "%s"result);
            }
            
SendClientMessage(playeridcolorresult);
        }
    }
    else
    {
        
SendClientMessage(playeridcolormsg);
    }
    return 
true;

I ran out of any ideas on what could be the problem so if possible, help me out.
Edit 1: Seems like the third faction which is not even included here can see the chat too.
Reply
#2

Remove the return 1; in the loop.
Reply
#3

Ugh, that code is fucking horrible.
Reply
#4

Example (not tested in game)
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);
            }
        }
    }
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)