SA-MP Forums Archive
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)
+--- Thread: PM command (/showthread.php?tid=612784)



[Solved] PM command - ThatThoseTheThy - 21.07.2016

Hello there,

I am creating a PM command from various links I mash together. For some weird reason when I get in game and pm someone something it does this:




It shows the ID of the player you are sending to and then the message you wanted.

PHP код:
#define FILTERSCRIPT
#include <a_samp>
#include <sscanf>
#include <zcmd>
enum PlayerInfo
{
    
Last,
    
NoPM,
}
new 
pInfo[MAX_PLAYERS][PlayerInfo];
//Usual OnFilterScript things are empty and so on
public OnPlayerConnect(playerid)
{
    
pInfo[playerid][Last] = -1;
    
pInfo[playerid][NoPM] = 0;
    return 
1;
}
public 
OnPlayerDisconnect(playeridreason)
{
    
pInfo[playerid][Last] = -1;
    
pInfo[playerid][NoPM] = 0;
    return 
1;
}
CMD:pm(playeridparams[])
{
    new 
idmsg[128], text[128];
    if(
sscanf(params"s[128]"msg) || sscanf(params"u"id)) return SendClientMessage(playeridRED"[USAGE]: /pm [name/id] [msg]");
    if(!
IsPlayerConnected(id)) return SendClientMessage(playeridRED"Player not found.");
    if(
strlen(msg) < || strlen(msg) > 128) return SendClientMessage(playeridRED"Your message can only contain 1-128 characters.");
    if(
playerid == id) return SendClientMessage(playeridRED"You cannot PM yourself.");
    if(
pInfo[id][NoPM] == 1) return SendClientMessage(playerid,-1,"That player isnt recieving pm's");
    
format(textsizeof(text), "PM To %s : %s"PlayerName(id), msg);
    
SendClientMessage(playeridYELLOWtext);
    
format(textsizeof(text), "PM From %s : %s"PlayerName(playerid), msg);
    
SendClientMessage(idYELLOWtext);
        
        
    
pInfo[id][Last] = playerid;
    return 
true;
}
stock PlayerName(playerid)//Executing function.
{
    new 
pName[MAX_PLAYER_NAME];
    
GetPlayerName(playeridpNamesizeof(pName));
    return 
pName;


Thanks in advance


Re: PM command - Konstantinos - 21.07.2016

You need to "join" the specifiers for sscanf:
pawn Код:
if(sscanf(params, "us[128]", id, msg)) return ...
Player's input cannot exceed 128 characters either so checking the length is pointless. Just a suggestion as well, checking if "id" is INVALID_PLAYER_ID to return an error is much better than calling IsPlayerConnected.


Re: PM command - ThatThoseTheThy - 21.07.2016

INVALID_PLAYER_ID was giving me something weird but for now it works. The issue was the splitting, although I did that because of a different bug which this solved as well. Fucking love you man, thanks a lot!