SA-MP Forums Archive
Help Please With PM Command - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Help Please With PM Command (/showthread.php?tid=189482)



Help Please With PM Command - Tim_Ethen - 12.11.2010

Here is my code...
pawn Код:
dcmd_pm(playerid, params[]) {
    new id, message[256];
    if(sscanf(params, "is", id, message)) SendClientMessage(playerid, 0xFFFFFFFF, "USAGE: /pm [playerid] [message]");
    else {
        if(id == playerid) SendClientMessage(playerid, 0xFF0000FF, "You can't send a private message to yourself.");
        else {
            new output1[256], output2[256], name1[MAX_PLAYER_NAME], name2[MAX_PLAYER_NAME];
            GetPlayerName(playerid, name1, sizeof(name1));
            GetPlayerName(id, name2, sizeof(name2));
            format(output1, sizeof(output1), "PM To %s(%i): %s", name2, id, message);
            format(output2, sizeof(output2), "PM From %s(%i): %s", name1, playerid, message);
            SendClientMessage(playerid, 0x00FFFFFF, output1);
            SendClientMessage(id, 0x00FFFFFF , output2);
        }
    }
    return 1;
}
Compiles Fine...
Works Fine...

But... Gives Me This In The Console
Quote:

sscanf warning: Strings without a length are deprecated, please add a destination size.

What Can I Do To Fix This?

Yes I Like Periods


Re: Help Please With PM Command - (SF)Noobanatior - 12.11.2010

like this i belive
pawn Код:
if(sscanf(params, "is[256]", id, message))
might have to play with the size to make it happy but same size at the output string


Re: Help Please With PM Command - Larsey123IsMe - 12.11.2010

Why dosent this work?

pawn Код:
#include <a_samp>
#include <dcmd>

public OnPlayerCommandText(playerid, cmdtext[])
{
    dcmd(pm, 256, cmdtext);
    return 0;
}

dcmd_pm(playerid, params[]) {
    new id, message[256];
    if(sscanf(params, "is[256]", id, message)) SendClientMessage(playerid, 0xFFFFFFFF, "USAGE: /pm [playerid] [message]");
    else {
        if(id == playerid) SendClientMessage(playerid, 0xFF0000FF, "You can't send a private message to yourself.");
        else {
            new output1[256], output2[256], name1[MAX_PLAYER_NAME], name2[MAX_PLAYER_NAME];
            GetPlayerName(playerid, name1, sizeof(name1));
            GetPlayerName(id, name2, sizeof(name2));
            format(output1, sizeof(output1), "PM To %s(%i): %s", name2, id, message);
            format(output2, sizeof(output2), "PM From %s(%i): %s", name1, playerid, message);
            SendClientMessage(playerid, 0x00FFFFFF, output1);
            SendClientMessage(id, 0x00FFFFFF , output2);
        }
    }
    return 1;
}



Re: Help Please With PM Command - Miguel - 12.11.2010

First off, why would you need a 256 cells strings for a PM message? 128 is the max input and you wouldn't even need it, since the message will be shortened by "PM From Name(300): ". You don't need two strings to show two messages, you can format one of them twice.

This should work:
pawn Код:
dcmd_pm(playerid, params[])
{
    new
        id,
        string[128],
        message[94],
        name[2][21];
       
    if(sscanf(params, "rs[93]", id, message)) return SendClientMessage(playerid, 0xFFFFFFFF, "USAGE: /pm [playerid] [message]");
    else if(!IsPlayerConnected(id)) return SendClientMessage(playerid, 0xFFFFFFFF, "That player is not even connected to the server.");
    else if(id == playerid) return SendClientMessage(playerid, 0xFF0000FF, "You can't send a private message to yourself.");
    GetPlayerName(playerid, name[0], 21);
    GetPlayerName(id, name[1], 21);
    format(string, sizeof(string), "PM To %s(%i): %s", name[1], id, message);
    SendClientMessage(playerid, 0x00FFFFFF, string);
    format(string, sizeof(string), "PM From %s(%i): %s", name[0], playerid, message);
    SendClientMessage(id, 0x00FFFFFF, string);
    return 1;
}