OnPlayerText
#1

Hi there, this code works fine until someone is actually muted, it will then ignore all the code and return messages as normal as if there was no code under OnPlayerText at all. I want muted players to get the message "You are currently muted and cannot type in the chatbox." and nothing else.

pawn Код:
public OnPlayerText(playerid, text[])
{
    if(Muted[playerid] == 1)
        return SendClientMessage(playerid, COLOR_ERROR, "You are currently muted and cannot type in the chatbox.");

    else if(Muted[playerid] == 0)
    {
        new string[128], playername[MAX_PLAYER_NAME];
        new PlayerColor = GetPlayerColor(playerid);
        GetPlayerName(playerid, playername, sizeof(playername));
        format(string, sizeof(string), "%s[%d]: {FFFFFF}%s", playername, playerid, text);
        SendClientMessageToAll(PlayerColor, string);
    }
    return 0;
}
Any one got an idea?
Reply
#2

I am not sure if this works. But I suggest you to add the muted at the Admin's enum.
It's easier to use it.
pawn Код:
public OnPlayerText(playerid, text[])
{
    if(Muted[playerid] == 1) return SendClientMessage(playerid, COLOR_ERROR, "You are currently muted and cannot type in the chatbox.");
    else {
        new
            string[128],
            playername[MAX_PLAYER_NAME],
            PlayerColor = GetPlayerColor(playerid);
        GetPlayerName(playerid, playername, sizeof(playername));
        format(string, sizeof(string), "%s[%d]: {FFFFFF}%s", playername, playerid, text);
        SendClientMessageToAll(PlayerColor, string);
    }
    return 0;
}
Reply
#3

maybe
return SendClientMessage(playerid, COLOR_ERROR, "You are currently muted and cannot type in the chatbox."),false;
Reply
#4

pawn Код:
public OnPlayerText(playerid, text[])
{
    if(Muted[playerid] == 1) return SendClientMessage(playerid, COLOR_ERROR, "You are currently muted and cannot type in the chatbox.");

    new string[128], playername[MAX_PLAYER_NAME];
    new PlayerColor = GetPlayerColor(playerid);
    GetPlayerName(playerid, playername, sizeof(playername));
    format(string, sizeof(string), "%s[%d]: {FFFFFF}%s", playername, playerid, text);
    SendClientMessageToAll(PlayerColor, string);

    return 0;
}
Is enough.
Reply
#5

Why would you need another if/else ?
lol....
if(Muted[playerid] == 1) return SendClientMessage(playerid, COLOR_ERROR, "You are currently muted and cannot type in the chatbox.");

EDIT


Quote:
Originally Posted by Kingunit
Посмотреть сообщение
pawn Код:
public OnPlayerText(playerid, text[])
{
    if(Muted[playerid] == 1) return SendClientMessage(playerid, COLOR_ERROR, "You are currently muted and cannot type in the chatbox.");

    new string[128], playername[MAX_PLAYER_NAME];
    new PlayerColor = GetPlayerColor(playerid);
    GetPlayerName(playerid, playername, sizeof(playername));
    format(string, sizeof(string), "%s[%d]: {FFFFFF}%s", playername, playerid, text);
    SendClientMessageToAll(PlayerColor, string);

    return 0;
}
Is enough.
IS RIGHT
Reply
#6

Quote:
Originally Posted by ElkaBlazer
Посмотреть сообщение
Why would you need another if/else ?
lol....
Both of ways works. Kingunit's code is more shortly
Reply
#7

Thanks for all the replies guys but my problem still exists using the code below.

pawn Код:
public OnPlayerText(playerid, text[])
{
    if(Muted[playerid] == 1) return SendClientMessage(playerid, COLOR_ERROR, "You are currently muted and cannot type in the chatbox.");

    new string[128], playername[MAX_PLAYER_NAME];
    new PlayerColor = GetPlayerColor(playerid);
    GetPlayerName(playerid, playername, sizeof(playername));
    format(string, sizeof(string), "%s[%d]: {FFFFFF}%s", playername, playerid, text);
    SendClientMessageToAll(PlayerColor, string);
    return 0;
}
I just need to stop the default text from displaying when a player is muted, it works fine until 'Muted' is set to '1'. After that it allows the chat messages to carry on displaying.
Reply
#8

Replace this:
pawn Код:
if(Muted[playerid] == 1) return SendClientMessage(playerid, COLOR_ERROR, "You are currently muted and cannot type in the chatbox.");
With this (notice the 0 at the end):
pawn Код:
if(Muted[playerid] == 1) return SendClientMessage(playerid, COLOR_ERROR, "You are currently muted and cannot type in the chatbox."), 0;
You people need to learn what return values are for. SendClientMessage returns 1 at all times (or so I assume), and when anything other than 0 is returned in OnPlayerText it will send the text through.
Reply
#9

Thanks Vince, never really had a problem with returns until now so lesson learnt lol.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)