need help with /pm command using zcmd & sscanf
#1

I just converted all my commands to zcmd, before i used the stock
/pm command from the 'base' FS included with the server dowload package,
i found here on the forum this code from Sergei

pawn Code:
CMD:pm(playerid, params[])
{
    new str[128],id,pname[MAX_PLAYER_NAME];
    if(sscanf(params, "us", id, params)) SendClientMessage(playerid, ADMINFS_MESSAGE_COLOR, "Usage: /pm <id> <message>");
    else if(id == INVALID_PLAYER_ID) SendClientMessage(playerid, ADMINFS_MESSAGE_COLOR, "ERROR: Player not connected");
    if(playerid == id) SendClientMessage(playerid, ADMINFS_MESSAGE_COLOR, "ERROR: You cannot pm yourself!");
    else
    {
        GetPlayerName(id, str, 24);
        format(str, sizeof(str), "PM To %s(ID %d): %s", str, id, params);
        GetPlayerName(id, str, 24);
        format(str, sizeof(str), "PM To %s(ID %d): %s", str, id, params);
        SendClientMessage(playerid, 0xFF0000FF, str);
        GetPlayerName(playerid, pname, sizeof(pname));
        format(str, sizeof(str), "PM From %s(ID %d): %s", pname, playerid, params);
        SendClientMessage(id, 0xFF0000FF, str);
    }
    return 1;
}
The problem is when i execute the command ingame with only /pm, it shows me both warning messages,
the USAGE and "you cannot pm yourself", also when i do /pm 0 text, hapens the same but this time
sscanf prints a warning to the logs:
Code:
[20:51:01] sscanf warning: Strings without a length are deprecated, please add a destination size.
Could someone take a look at the script and tell me whats wrong there?
Thanks, regards.
Reply
#2

Anyone please?
Reply
#3

Your problem is that you use params with sscanf ( Just to say, that is not wrong but you'll have to do much more ) you should just make a new array with it's size and put it in sscanf instead of params. And when you use a string in sscanf you NEED to declare it's size.

This is just your code and it should work now.
pawn Code:
COMMAND:pm(playerid, params[])
{
    new str[128],id,pname[MAX_PLAYER_NAME], Message[128];
    if(sscanf(params, "us[128]", id, Message)) SendClientMessage(playerid, ADMINFS_MESSAGE_COLOR, "Usage: /pm <id> <message>");
    else if(id == INVALID_PLAYER_ID) SendClientMessage(playerid, ADMINFS_MESSAGE_COLOR, "ERROR: Player not connected");
    if(playerid == id) SendClientMessage(playerid, ADMINFS_MESSAGE_COLOR, "ERROR: You cannot pm yourself!");
    else
    {
        GetPlayerName(id, str, 24);
        format(str, sizeof(str), "PM To %s(ID %d): %s", str, id, Message);
        GetPlayerName(id, str, 24);
        format(str, sizeof(str), "PM To %s(ID %d): %s", str, id, Message);
        SendClientMessage(playerid, 0xFF0000FF, str);
        GetPlayerName(playerid, pname, sizeof(pname));
        format(str, sizeof(str), "PM From %s(ID %d): %s", pname, playerid, Message);
        SendClientMessage(id, 0xFF0000FF, str);
    }
    return 1;
}
EDIT: Just to say, your code is NOT wrong but can be a little buggy.
Reply
#4

Alright, thanks.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)