Shared chat between 2 factions. -
cs_waller - 15.11.2016
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) == 0 || strcmp(cmd, "/dr", true) == 0)
{
new length = strlen(cmdtext);
new name[24], string[256];
new DeptName[10];
GetPlayerName(playerid, name, sizeof(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(playerid, red, "USAGE: /dr [text]");
if(gTeam[playerid] == POLICE) DeptName = "SASP";
else if(gTeam[playerid] == AP) DeptName = "SACFD";
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
if(gTeam[i] == POLICE)
SendSplitMessageF(i, COLOR_ORANGE, "[%s] %s says: %s", DeptName, name, result);
continue;
}
if(gTeam[i] == AP)
{
SendSplitMessageF(i, COLOR_ORANGE, "[%s] %s says: %s", DeptName, name, result);
continue;
}
format(gstr, sizeof(gstr), "%s says (dept. radio): %s", name, result);
ProxDetector(15.0, playerid, gstr, COLOR_FADE1, COLOR_FADE2, COLOR_FADE3, COLOR_FADE4, COLOR_FADE5);
return 1;
}
}
stock SendSplitMessage(playerid, color, msg[])
{
new ml = 115, result[160], len = strlen(msg), repeat;
if(len > ml)
{
repeat = (len / ml);
for(new i = 0; i <= repeat; i++)
{
result[0] = 0;
if(len - (i * ml) > ml)
{
strmid(result, msg, ml * i, ml * (i+1));
format(result, sizeof(result), "%s", result);
}
else
{
strmid(result, msg, ml * i, len);
format(result, sizeof(result), "%s", result);
}
SendClientMessage(playerid, color, result);
}
}
else
{
SendClientMessage(playerid, color, msg);
}
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.
Re: Shared chat between 2 factions. -
justinnater - 15.11.2016
Remove the return 1; in the loop.
Re: Shared chat between 2 factions. -
Luis- - 15.11.2016
Ugh, that code is fucking horrible.
Re: Shared chat between 2 factions. -
TwinkiDaBoss - 16.11.2016
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);
}
}
}
}