SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 18/06/2019, 01:52 PM   #1
KeyOfKey
Huge Clucker
 
KeyOfKey's Avatar
 
Join Date: Apr 2019
Posts: 235
Reputation: 12
Default Jail chat

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?

pawn Code:
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.
KeyOfKey is offline   Reply With Quote
Old 18/06/2019, 05:16 PM   #2
Leaky
Big Clucker
 
Join Date: Jul 2018
Posts: 58
Reputation: 12
Default Re: Jail chat

Quote:
Originally Posted by KeyOfKey View Post
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?

pawn Code:
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
PHP Code:
foreach(new Player)
{
       if(
Player[i][JailTime] > 0
       {
               
format(jailchatsizeof(jailchat), "[JAILED] %s: %s"RpName(playerid), text);

       }
       
SCMEX(iCOLOR_PICKjailchat);

__________________
Leaky is offline   Reply With Quote
Old 18/06/2019, 07:36 PM   #3
KeyOfKey
Huge Clucker
 
KeyOfKey's Avatar
 
Join Date: Apr 2019
Posts: 235
Reputation: 12
Default Re: Jail chat

Same problem, it sends twice.
KeyOfKey is offline   Reply With Quote
Old 18/06/2019, 08:33 PM   #4
SiaReyes
Big Clucker
 
SiaReyes's Avatar
 
Join Date: Mar 2019
Location: Coordinates X,Y,Z
Posts: 164
Reputation: 15
Default Re: Jail chat

Quote:
Originally Posted by Leaky View Post
PHP Code:
foreach(new Player)
{
       if(
Player[i][JailTime] > 0
       {
               
format(jailchatsizeof(jailchat), "[JAILED] %s: %s"RpName(playerid), text);

       }
       
SCMEX(iCOLOR_PICKjailchat);

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

pawn Code:
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
__________________
Piwzeeees
SiaReyes is online now   Reply With Quote
Old 20/06/2019, 09:03 AM   #5
KeyOfKey
Huge Clucker
 
KeyOfKey's Avatar
 
Join Date: Apr 2019
Posts: 235
Reputation: 12
Default Re: Jail chat

It sends both.
KeyOfKey is offline   Reply With Quote
Old 20/06/2019, 04:53 PM   #6
Hunud
Gangsta
 
Hunud's Avatar
 
Join Date: Jun 2016
Location: Right here.
Posts: 605
Reputation: 53
Default Re: Jail chat

Maybe the problem is in SCMEX function.
__________________
SE Community

Hunud is offline   Reply With Quote
Old 20/06/2019, 07:06 PM   #7
KeyOfKey
Huge Clucker
 
KeyOfKey's Avatar
 
Join Date: Apr 2019
Posts: 235
Reputation: 12
Default Re: Jail chat

No that's not the problem. I'm using it for many and many messages.
KeyOfKey is offline   Reply With Quote
Old 21/06/2019, 02:36 AM   #8
khRamin78
Huge Clucker
 
Join Date: Jun 2015
Posts: 314
Reputation: 30
Default Re: Jail chat

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

        if(
Player[i][JailTime]) SCMEX(iCOLOR_PICKjailchat);
    }
}
else
{
    
SendNearByMessage(playerid, -1string10.0);

Use this method instead of your own method
khRamin78 is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
admin chat and advisor chat avaible without /aduty /cduty Acres Scripting Help 2 09/01/2015 01:13 PM
Help with jail time, and jail save Breilid Scripting Help 1 14/12/2012 10:17 AM
Help with jail timer and when connecting will check if in jail PaulDinam Scripting Help 9 01/07/2012 11:45 AM
Admin Chat < Admins can't see chat or my text, but I can see their chat Andy_McKinley Help Archive 37 17/05/2011 08:26 PM
[FilterScript] [FS] Jail area and Jail command PinkFloydLover Filterscripts 13 05/08/2009 06:11 AM


All times are GMT. The time now is 06:34 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.