PDA

View Full Version : Jail chat


Symon
18/06/2019, 01:52 PM
I have a problem by creating the jail chat. It sends double messages in chat. The first with/without accent and the second the [JAILED] message.

I wanna send just the jailed message if player is jailed, so other and ONLY jailed players can read it. What's wrong?


if(!strcmp(Player[playerid][Accent], "None", true))
{
format(string, sizeof(string), "{%06x}%s says: "WHITE"%s", GetPlayerColor(playerid) >>> 8, RpName(playerid), text);
}
else
{
format(string, sizeof(string), "[%s]{%06x} %s says: "WHITE"%s", Player[playerid][Accent], GetPlayerColor(playerid) >>> 8, RpName(playerid), text);
}
SendNearByMessage(playerid, -1, string, 10.0);

foreach(new i : Player)
{
format(jailchat, sizeof(jailchat), "[JAILED] %s: %s", RpName(playerid), text);

if(Player[i][JailTime]) SCMEX(i, COLOR_PICK, jailchat);
}


I have return 0 on OnPlayerText.

Leaky
18/06/2019, 05:16 PM
I have a problem by creating the jail chat. It sends double messages in chat. The first with/without accent and the second the [JAILED] message.

I wanna send just the jailed message if player is jailed, so other and ONLY jailed players can read it. What's wrong?


if(!strcmp(Player[playerid][Accent], "None", true))
{
format(string, sizeof(string), "{%06x}%s says: "WHITE"%s", GetPlayerColor(playerid) >>> 8, RpName(playerid), text);
}
else
{
format(string, sizeof(string), "[%s]{%06x} %s says: "WHITE"%s", Player[playerid][Accent], GetPlayerColor(playerid) >>> 8, RpName(playerid), text);
}
SendNearByMessage(playerid, -1, string, 10.0);

foreach(new i : Player)
{
format(jailchat, sizeof(jailchat), "[JAILED] %s: %s", RpName(playerid), text);

if(Player[i][JailTime]) SCMEX(i, COLOR_PICK, jailchat);
}


I have return 0 on OnPlayerText.

Assuming that this line SCMEX(i, COLOR_PICK, jailchat); of code is used to send the message, it will be sending it as many times as the number of players in the server because you wrapped it inside the foreach loop

The correction

foreach(new i : Player)
{
if(Player[i][JailTime] > 0)
{
format(jailchat, sizeof(jailchat), "[JAILED] %s: %s", RpName(playerid), text);

}
SCMEX(i, COLOR_PICK, jailchat);
}

Symon
18/06/2019, 07:36 PM
Same problem, it sends twice.

SiaReyes
18/06/2019, 08:33 PM
foreach(new i : Player)
{
if(Player[i][JailTime] > 0)
{
format(jailchat, sizeof(jailchat), "[JAILED] %s: %s", RpName(playerid), text);

}
SCMEX(i, COLOR_PICK, jailchat);
}


Actually, SCMEX is out of if statement and inside foreach, so it will send the message to all players.



if(Player[playerid][JailTime] < 0) // if playe is not in jail!
{
if(!strcmp(Player[playerid][Accent], "None", true))
{
format(string, sizeof(string), "{%06x}%s says: "WHITE"%s", GetPlayerColor(playerid) >>> 8, RpName(playerid), text);
}
else
{
format(string, sizeof(string), "[%s]{%06x} %s says: "WHITE"%s", Player[playerid][Accent], GetPlayerColor(playerid) >>> 8, RpName(playerid), text);
}
SendNearByMessage(playerid, -1, string, 10.0);
}
else if(Player[playerid][JailTime] > 0) // if player is in jail!
{
format(jailchat, sizeof(jailchat), "[JAILED] %s: %s", RpName(playerid), text);
foreach(new i : Player) if(Player[i][JailTime] > 0) // loop through all players and get players who are in jail
{
SCMEX(i, COLOR_PICK, jailchat);
}
}
// So now If the player is not in jail, the Accent msg will be sent, if the player is in jail, the [jailed] msg will be shown to all players who are in jail!

Try this

Symon
20/06/2019, 09:03 AM
It sends both.

Hunud
20/06/2019, 04:53 PM
Maybe the problem is in SCMEX function.

Symon
20/06/2019, 07:06 PM
No that's not the problem. I'm using it for many and many messages.

khRamin78
21/06/2019, 02:36 AM
/*
if you want to send jailed players message to the jailed players only
*/
if(!strcmp(Player[playerid][Accent], "None", true))
{
format(string, sizeof(string), "{%06x}%s says: "WHITE"%s", GetPlayerColor(playerid) >>> 8, RpName(playerid), text);
}
else
{
format(string, sizeof(string), "[%s]{%06x} %s says: "WHITE"%s", Player[playerid][Accent], GetPlayerColor(playerid) >>> 8, RpName(playerid), text);
}
if(Player[playerid][JailTime] > 0)
{
foreach(new i : Player)
{
format(jailchat, sizeof(jailchat), "[JAILED] %s: %s", RpName(playerid), text);

if(Player[i][JailTime]) SCMEX(i, COLOR_PICK, jailchat);
}
}
else
{
SendNearByMessage(playerid, -1, string, 10.0);
}


Use this method instead of your own method