PM command
#1

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
Reply
#2

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.
Reply
#3

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!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)