OnPlayerCommandReceived
#1

I wan't to let players using /pm [text], /a [text] cmds while they are in jail(Info[playerid][Jailed]==1). How can i do that?

pawn Код:
public OnPlayerCommandReceived(playerid, cmdtext[])
{
    if(Info[playerid][Jailed]==1)
    {

            SendClientMessage(playerid,COLOR_RED,"ERROR, You are in jail.");
            return 0;
     
    }
}
Reply
#2

Just put that in your /pm and /a command in the top.
But using return 0 will make the command not succeed, giving the "Unknown command" message.
You can just do it like this to make it shorter, and it won't display Unknown command.
pawn Код:
if(Info[playerid][Jailed]==1) return SendClientMessage(playerid,COLOR_RED,"ERROR, You are in jail.");
Reply
#3

Or make it like this:

Код:
public OnPlayerCommandReceived(playerid, cmdtext[])
{
    new cmd[32],pos=strfind(cmdtext," ");
    strmid(cmd,cmdtext,0,(pos == -1)?strlen(cmdtext):pos,32);
    if(Info[playerid][Jailed]==1)
    {
        if(!strcmp(cmd,"/pm") || !strcmp(cmd,"/a")) return 1;
        SendClientMessage(playerid,COLOR_RED,"ERROR, You are in jail.");
        return 0;
    }
}
Greekz
Reply
#4

Quote:
Originally Posted by CalvinC
Посмотреть сообщение
Just put that in your /pm and /a command in the top.
But using return 0 will make the command not succeed, giving the "Unknown command" message.
You can just do it like this to make it shorter, and it won't display Unknown command.
pawn Код:
if(Info[playerid][Jailed]==1) return SendClientMessage(playerid,COLOR_RED,"ERROR, You are in jail.");

That is not my problem, my code is blocking all player commands while player is in jail. I wan't to let jailed players use only 2 cmds (/pm [playerid] [text] and /a [text]) while they are in jail.
Reply
#5

Quote:
Originally Posted by Kaliber
Посмотреть сообщение
Or make it like this:

Код:
public OnPlayerCommandReceived(playerid, cmdtext[])
{
    new cmd[32],pos=strfind(cmdtext," ");
    strmid(cmd,cmdtext,0,(pos == -1)?strlen(cmdtext):pos,32);
    if(Info[playerid][Jailed]==1 && strcmp(cmd,"/pm") != 0 && strcmp(cmd,"/a") != 0)
    {
        SendClientMessage(playerid,COLOR_RED,"ERROR, You are in jail.");
        return 0;
    }
}
Greekz
Is it possible to do this with sscanf ?
Reply
#6

Quote:
Originally Posted by ajwar
Посмотреть сообщение
Is it possible to do this with sscanf ?
...not quite sure, it should come to bugs...just use it like this, it's faster anyway
Reply
#7

Код:
public OnPlayerCommandRecieved(playerid, cmdtext[])
{
    if(Info[playerid][Jailed]==1)
    {
        if(!strcmp(cmdtext,"/pm") || !strcmp(cmdtext,"/a")) return 1;

        SendClientMessage(playerid,COLOR_RED,"ERROR, You are in jail.");
        return 0;
    }
    return 1;
}
This code simply dissables all commands except /pm and /a which would bypass the check and work from the main source of the cmd. You dont need to re write the cmd in this callback.
I dont think so you require anything else than this. sscanf dont work as string matching or maybe y_stringhash. Sscanf is just opposite of format.
Reply
#8

Quote:
Originally Posted by Gammix
Посмотреть сообщение
This code simply dissables all commands except /pm and /a which would bypass the check and work from the main source of the cmd. You dont need to re write the cmd in this callback.
Damn dude, look at my Code!

That what you wrote, do not work!!!

Because, when you write this:

/a hi

is cmdtext /a hi...so it doesn't match with strcmp(cmdtext,"/a") ..because it is strcmp(cmdtext,"/a hi")...

Greekz
Reply
#9

He is wright, because if someone write a command such as "/kill /a", the command will be processed anyway..
Reply
#10

Quote:
Originally Posted by ReshiramZekrom
Посмотреть сообщение
He is wright, because if someone write a command such as "/kill /a", the command will be processed anyway..
Dude...when you say something proof it!

PHP код:
#include <a_samp>
main() OnPlayerCommandText(0,"/a hallo");
public 
OnPlayerCommandText(playeridcmdtext[]) return print(!strcmp(cmdtext,"/a")?(!"You're right!"):(!"I'm right!")); 
You can test it..i am right dude
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)