SA-MP Forums Archive
OnPlayerCommandReceived (/pm problem) - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: OnPlayerCommandReceived (/pm problem) (/showthread.php?tid=651344)



OnPlayerCommandReceived (/pm problem) - ThomasEvil - 18.03.2018

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?


Re: OnPlayerCommandReceived (/pm problem) - iKarim - 18.03.2018

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

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



Re: OnPlayerCommandReceived (/pm problem) - ThomasEvil - 18.03.2018

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


Re: OnPlayerCommandReceived (/pm problem) - iKarim - 18.03.2018

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)


Re: OnPlayerCommandReceived (/pm problem) - ThomasEvil - 18.03.2018

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 ...


Re: OnPlayerCommandReceived (/pm problem) - iKarim - 18.03.2018

Code?


Re: OnPlayerCommandReceived (/pm problem) - ThomasEvil - 18.03.2018

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.


Re: OnPlayerCommandReceived (/pm problem) - iKarim - 18.03.2018

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")); 



Re: OnPlayerCommandReceived (/pm problem) - ThomasEvil - 18.03.2018

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 ..