PM command is bugged
#1

Hello, so i've got this code right here

pawn Код:
CMD:pm(playerid,params[])
{
    new PID,p_Send[24],p_Rec[24],str[128],str2[128],Message[100];
    GetPlayerName(PID,p_Rec,24);
    GetPlayerName(playerid,p_Send,24);
    switch (PM_Enabled[PID])
    {
        case 0: return SendClientMessage(playerid,COLOR_RED,"This player has disabled his pm");
        case 1:
        {
            if(sscanf(params,"us[100]",PID,Message)) return SendClientMessage(playerid,COLOR_GREEN,"USAGE:/pm playerid message");
            if(isnull(params)) return SendClientMessage(playerid,COLOR_RED,"USAGE:/pm playerid message");
            if(PID==playerid) return SendClientMessage(playerid,COLOR_RED,"You can't pm your self.");
            if(!IsPlayerConnected(PID)) return SendClientMessage(playerid,COLOR_RED,"This player is not connected.");
            format(str2,sizeof(str),"Pm To "#COL_GREEN"%s[%d]:%s",p_Rec,PID,Message);
            format(str,sizeof(str2),"Pm From "#COL_GREEN"%s[%d]:%s",p_Send,playerid,Message);
            SendClientMessage(playerid,COLOR_RED,str2);
            SendClientMessage(PID,COLOR_YELLOW,str);
        }
    }
    return 1;
}
And a pm on/off command , they work fine
the problem is , when a player pm's a player who used pmoff, he get's this "This player has disabled his pm "
but still the target id gets the message , how to stop the message from being sent then?
Reply
#2

Here is your fix:
pawn Код:
CMD:pm(playerid, params[])
{
    new sname[MAX_PLAYER_NAME], RID, rname[MAX_PLAYER_NAME], string[128], message[128];
    GetPlayerName(playerid, sname, sizeof(sname));
    GetPlayerName(RID, rname, sizeof(rname));
    if(sscanf(params, "us[128]", RID, message)) return SendClientMessage(playerid, COLOR_GREEN, "USAGE: /pm [playerid] [message]");
    if(PM_Enabled[RID] == 0) return SendClientMessage(playerid, COLOR_RED, "This player has disabled his PM's.");
    if(IsPlayerConnected(RID))
    {
        format(string, sizeof(string), "[PM from %s]: %s", sname, message);
        SendClientMessage(RID, COLOR_YELLOW, string);
        format(string, sizeof(string), "[PM to %s]: %s", rname, message);
        SendClientMessage(playerid, COLOR_RED, string);
    }
    else
    {
        SendClientMessage(playerid, -1, "Invalid player specified.");
        return 1;
    }
    return 1;
}
Reply
#3

Excuse me , but how is this going to fix it?
You just made an if statment at IsPlayerConnected
also , why did u use if statments instead of switch?
Reply
#4

Quote:
Originally Posted by CoDeZ
Посмотреть сообщение
Excuse me , but how is this going to fix it?
You just made an if statment at IsPlayerConnected
also , why did u use if statments instead of switch?
Just use the code and reply back if it works. I will explain later, as I am busy atm.
Reply
#5

Fixed code:

pawn Код:
CMD:pm(playerid, params[])
{
    new sname[MAX_PLAYER_NAME], RID, rname[MAX_PLAYER_NAME], string[128], message[128];
    if(sscanf(params, "us[128]", RID, message)) return SendClientMessage(playerid, COLOR_GREEN, "USAGE: /pm [playerid] [message]");
    GetPlayerName(playerid, sname, sizeof(sname));
    GetPlayerName(RID, rname, sizeof(rname));
    if(PM_Enabled[RID] == 0) return SendClientMessage(playerid, COLOR_RED, "This player has disabled his PM's.");
    else if(!IsPlayerConnected(RID)) return SendClientMessage(playerid, COLOR_RED, "Player not connected!");

    format(string, sizeof(string), "[PM from %s]: %s", sname, message);
    SendClientMessage(RID, COLOR_YELLOW, string);
    format(string, sizeof(string), "[PM to %s]: %s", rname, message);
    SendClientMessage(playerid, COLOR_RED, string);
    return 1;
}
Reply
#6

Quote:
Originally Posted by Dan.
Посмотреть сообщение
Fixed code:

pawn Код:
CMD:pm(playerid, params[])
{
    new sname[MAX_PLAYER_NAME], RID, rname[MAX_PLAYER_NAME], string[128], message[128];
    if(sscanf(params, "us[128]", RID, message)) return SendClientMessage(playerid, COLOR_GREEN, "USAGE: /pm [playerid] [message]");
    GetPlayerName(playerid, sname, sizeof(sname));
    GetPlayerName(RID, rname, sizeof(rname));
    if(PM_Enabled[RID] == 0) return SendClientMessage(playerid, COLOR_RED, "This player has disabled his PM's.");
    else if(!IsPlayerConnected(RID)) return SendClientMessage(playerid, COLOR_RED, "Player not connected!");

    format(string, sizeof(string), "[PM from %s]: %s", sname, message);
    SendClientMessage(RID, COLOR_YELLOW, string);
    format(string, sizeof(string), "[PM to %s]: %s", rname, message);
    SendClientMessage(playerid, COLOR_RED, string);
    return 1;
}
Not trying to kill anything here, but I actually use"GetPlayerName(targetid, targetid, sizeof(targetid));" before ALL of my sscanf lines and everything still works like a charm..


EDIT:

Make the string longer than 128. That's terribly short for a PM....in game it'll cut off badly.
Reply
#7

Yes, I edited my post already. Just that I have always used GetPlayerName after the sscanf line, didn't think that it will work before it. But thanks for pointing it out.
Reply
#8

Quote:
Originally Posted by Steven82
Посмотреть сообщение
Not trying to kill anything here, but I actually use"GetPlayerName(targetid, targetid, sizeof(targetid));" before ALL of my sscanf lines and everything still works like a charm..


EDIT:

Make the string longer than 128. That's terribly short for a PM....in game it'll cut off badly.
Why should he make it bigger than 128? SA:MP chat max input is 128, so no need to make it bigger.

Quote:
Originally Posted by ******
Посмотреть сообщение
The SA:MP chat box has a maximum line length of 128, if someone types something you know it will never be longer than 128 ever. This includes text and commands, so why use a buffer twice that length to process the input?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)