OnPlayerCommandReceived (/pm problem)
#1

Hello guys,
i use OnPlayerCommandReceived when i need to stop player from sending commands.
But i want to make exceptions for some commands like /pm .. Well i use this:

Код:
public OnPlayerCommandReceived(playerid, cmdtext[])
{
if(PlayerIsAFK[playerid] == true)
	{
         if(!strcmp(cmdtext,"/afk") || !strcmp(cmdtext,"/pm"))) return 1;
	//some code...
         return 0;
	}
	return 1;
}
The problem is that player CAN use /pm but only "/pm" !!! Not "/pm id text" so player cant send pm anyway ..
Any idea?
Reply
#2

A quick solution would be using strfind instead of strcmp, like this:

PHP код:
!strfind(cmdtext,"/afk"
Reply
#3

Quote:
Originally Posted by iKarim
Посмотреть сообщение
A quick solution would be using strfind instead of strcmp, like this:

PHP код:
!strfind(cmdtext,"/afk"
/afk works perfectely, /pm works too but the real command is /pm id text ... Not only /pm like /afk
Reply
#4

Quote:
Originally Posted by ThomasEvil
Посмотреть сообщение
/afk works perfectely, /pm works too but the real command is /pm id text ... Not only /pm like /afk
It should also work in this case, strcmp compares the entire strings while strfind returns the index where the substring (/pm) is found in the command (/pm id message) (which should be 0, hence the ! on the condition)
Reply
#5

Well it does not work .. When i use "/pm" it sends me message "Use /pm id text" which is normal on my /pm command. But when i use "/pm id text" in this case it call return 0; from the function ...
Reply
#6

Code?
Reply
#7

What code do you need? You have it in main post.
U dont need anything else. My /pm command work very well.
Do not need to post there.
I have explained the problem.
Reply
#8

I can barely understand what you are saying, but what I said works fine and if you can't get it to work but don't want to post the code, then I doubt anyone could help you.

This prints 0 0 as expected, so it's obvious you aren't using it right.
PHP код:
printf("%i %i"strfind("/pm 15 hey this is test""/pm"), strfind("/pm""/pm")); 
Reply
#9

Quote:
Originally Posted by iKarim
Посмотреть сообщение
A quick solution would be using strfind instead of strcmp, like this:

PHP код:
!strfind(cmdtext,"/afk"
I'am sorry this works well!

I just made mistake with admin rights ..
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)