katursis / Pawn.CMD

🚀 Plugin-powered command processor for SA:MP server
MIT License
119 stars 13 forks source link

OnPlayerCommandPerformed returns -1 even if i type a valid command. #11

Closed UnuAlex closed 6 years ago

UnuAlex commented 6 years ago

I added a custom Unknown command message, and even if i type a valid command that message shows up. Note that this bug occurs only when the command returns a error message(like if i dont type a parameter, or if dont fulfill a statement) .

public OnPlayerCommandPerformed(playerid, cmd[], params[], result, flags)
{
    if(result == -1)
    {
        Text_Send(playerid,$UNKNOWN_COMMAND);
        return 0;
    }
    return 1;
}

This is the code in OnPlayerCommandPerformed. Right now i use y_text to send messages(because i have multi-language system), but even if i use SendClientMessage(in the callback above) its doing the same thing.

After further testing i found out that this is happening because i use y_text(Text_Send) functions to send messages in my commands, if i use SendClientMessage everything functions normally. Here is a screenshot with the texts: https://imgur.com/4MXs9fC

This the line for /movespray that is checking for params: if(sscanf(params,"d",pnsid))return Text_Send(playerid, $COMMAND_MOVESPRAY);

And this is the line for the /armour command: if(sscanf(params,"uf",id,armor))return SCM(playerid,c_ERROR,"Tasteaza:"c_error" /armour[playerid/nume jucator] [armura]","Type:"c_error" /armour[playerid/playerName] [ammount]");

UnuAlex commented 6 years ago

I managed to work around by returning 1 after sending the message, like shown bellow.

if(sscanf(params,"d",pnsid))return Text_Send(playerid, $COMMAND_MOVESPRAY), 1;

Autorojo commented 6 years ago

Hi. That is because the Text_Send function returns -1, so you are sending that -1 to the callback. It's not a plugin bug. Try to return a integer different than -1 in the command and your code will work.

UnuAlex commented 6 years ago

Thanks! I figured that eventually.

Closed!