/r(adio) won't work
#1

Hi. Im trying to make a /r(adio) command for players in a PD faction. This is my code:
pawn Код:
[COMMAND:r(playerid, params[])
{
    new msg[128], copname[40], rchat[128];
    if(PlayerInfo[playerid][pFaction] == 0) return SendClientMessage(playerid,COLOR_WHITE," You are not in a faction");
    if(sscanf(params, "s[128]", rchat)) return SendClientMessage(playerid,COLOR_WHITE," Usage: /r [text]");
    GetPlayerName(playerid, copname, sizeof(copname));
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(PlayerInfo[i][pFaction] == PlayerInfo[playerid][pFaction])
        {
        format(msg, sizeof(msg), "%s (%i - %s): %s, over.", copname, PlayerInfo[playerid][pFRank], PlayerInfo[playerid][pFRankName], rchat);
        SendClientMessage(i, COLOR_BLUE, msg);
        return 1;
        }
    }
}
But, when I type /r sometext, nothing shows up on my screen. I don't know about the other's screen, cause I didn't test it on other players and I can't atm.
Reply
#2

try this:
pawn Код:
for(new i; i<MAX_PLAYERS; i++)
if(IsPlayerConnected(i) && PlayerInfo[i][pFaction] == PlayerInfo[playerid][pFaction])
Reply
#3

pawn Код:
[COMMAND:r(playerid, params[])
{
    new msg[128], copname[40], rchat[128];
    if(PlayerInfo[playerid][pFaction] == 0) return SendClientMessage(playerid,COLOR_WHITE," You are not in a faction");
    if(sscanf(params, "s", rchat)) return SendClientMessage(playerid,COLOR_WHITE," Usage: /r [text]");
    GetPlayerName(playerid, copname, sizeof(copname));
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(PlayerInfo[i][pFaction] == PlayerInfo[playerid][pFaction])
        {
        format(msg, sizeof(msg), "%s (%i - %s): %s, over.", copname, PlayerInfo[playerid][pFRank], PlayerInfo[playerid][pFRankName], rchat);
        SendClientMessage(i, COLOR_BLUE, msg);
        }
    }
return 1;
}
Try that one

Do you get any errors, anyway?
Reply
#4

Quote:
Originally Posted by Kyle_Olsen
Посмотреть сообщение
pawn Код:
[COMMAND:r(playerid, params[])
{
    new msg[128], copname[40], rchat[128];
    if(PlayerInfo[playerid][pFaction] == 0) return SendClientMessage(playerid,COLOR_WHITE," You are not in a faction");
    if(sscanf(params, "s", rchat)) return SendClientMessage(playerid,COLOR_WHITE," Usage: /r [text]");
    GetPlayerName(playerid, copname, sizeof(copname));
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(PlayerInfo[i][pFaction] == PlayerInfo[playerid][pFaction])
        {
        format(msg, sizeof(msg), "%s (%i - %s): %s, over.", copname, PlayerInfo[playerid][pFRank], PlayerInfo[playerid][pFRankName], rchat);
        SendClientMessage(i, COLOR_BLUE, msg);
        }
    }
return 1;
}
Try that one

Do you get any errors, anyway?
No errors or warnings. Gonna try yours and Kmitska's solution.

EDIT: Thank you both of you. I got it working. It seemed that the array size of the rchat was too small. I increased it to 200 and it works now.
Reply
#5

You don't need to use sscanf there, it would be slower in this situation. Try doing this;

pawn Код:
COMMAND:r(playerid, params[])
{
    new msg[128], copname[40];
    if(PlayerInfo[playerid][pFaction] == 0) return SendClientMessage(playerid,COLOR_WHITE," You are not in a faction");
    if(isnull(params)) return SendClientMessage(playerid, COLOR_WHITE, "SYNTAX: /®adio [message]");
    GetPlayerName(playerid, copname, sizeof(copname));
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(PlayerInfo[i][pFaction] == PlayerInfo[playerid][pFaction])
        {
            format(msg, sizeof(msg), "%s (%i - %s): %s, over.", copname, PlayerInfo[playerid][pFRank], PlayerInfo[playerid][pFRankName], params);
            SendClientMessage(i, COLOR_BLUE, msg);
        }
    }
    return 1;
}
Reply
#6

Quote:
Originally Posted by RealCop228
Посмотреть сообщение
You don't need to use sscanf there, it would be slower in this situation. Try doing this;

pawn Код:
COMMAND:r(playerid, params[])
{
    new msg[128], copname[40];
    if(PlayerInfo[playerid][pFaction] == 0) return SendClientMessage(playerid,COLOR_WHITE," You are not in a faction");
    if(isnull(params)) return SendClientMessage(playerid, COLOR_WHITE, "SYNTAX: /®adio [message]");
    GetPlayerName(playerid, copname, sizeof(copname));
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(PlayerInfo[i][pFaction] == PlayerInfo[playerid][pFaction])
        {
            format(msg, sizeof(msg), "%s (%i - %s): %s, over.", copname, PlayerInfo[playerid][pFRank], PlayerInfo[playerid][pFRankName], params);
            SendClientMessage(i, COLOR_BLUE, msg);
        }
    }
    return 1;
}
Thanks for that. I edited all my commands simmilar to /r (like /me, /do, /s ...).
Reply
#7

Quote:
Originally Posted by kreso932
Посмотреть сообщение
Thanks for that. I edited all my commands simmilar to /r (like /me, /do, /s ...).
Good luck!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)