OnPlayerCommandReceived -
ajwar - 09.03.2015
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;
}
}
Re: OnPlayerCommandReceived -
CalvinC - 09.03.2015
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.");
AW: OnPlayerCommandReceived -
Kaliber - 09.03.2015
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
Re: OnPlayerCommandReceived -
ajwar - 09.03.2015
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.
Re: AW: OnPlayerCommandReceived -
ajwar - 09.03.2015
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 ?
AW: Re: AW: OnPlayerCommandReceived -
Kaliber - 09.03.2015
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
Re: AW: OnPlayerCommandReceived -
Gammix - 09.03.2015
Код:
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.
AW: Re: AW: OnPlayerCommandReceived -
Kaliber - 09.03.2015
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
Re: OnPlayerCommandReceived -
ReshiramZekrom - 09.03.2015
He is wright, because if someone write a command such as "/kill /a", the command will be processed anyway..
AW: Re: OnPlayerCommandReceived -
Kaliber - 09.03.2015
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(playerid, cmdtext[]) return print(!strcmp(cmdtext,"/a")?(!"You're right!"):(!"I'm right!"));
You can test it..i am right dude