SA-MP Forums Archive
Detect when player shooting with OnPlayerKeyStateChange ? - 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: Detect when player shooting with OnPlayerKeyStateChange ? (/showthread.php?tid=599650)



Detect when player shooting with OnPlayerKeyStateChange ? - YouServ - 28.01.2016

Hi,

I want to detect when player shooting (aim or not) with OnPlayerKeyStateChange.

Actually, I have this shit :

Код:
	if(oldkeys == KEY_FIRE)
	{
		SendClientMessage(playerid, -1, "fire");
	}
The problem is : when the player shot without aim, the SCM is showing but when player shoot and aim the SCM don't show.

How to detect when a player AIM+SHOT at the same time ?


Re: Detect when player shooting with OnPlayerKeyStateChange ? - valych - 28.01.2016

It is happening because when player presses multiple keys, variable oldkeys is different from KEY_FIRE. You shouldn't check key pressing in the way you did.
PHP код:
if(oldkeys KEY_FIRE
{
    
// Your code here

For more detailed information see the wiki page (https://sampwiki.blast.hk/wiki/OnPlayerKeyStateChange). You will find a lot of useful advice and functions to check keys pressing.

About "How to check for multiple keys" (from the wiki page):
PHP код:
if ((newkeys KEY_FIRE) && (newkeys KEY_CROUCH))
{
    
//.....




Re: Detect when player shooting with OnPlayerKeyStateChange ? - Gammix - 28.01.2016

pawn Код:
if (newkeys & KEY_FIRE)
{
}
This isn't accurate and not actually meant for detecting weapon shooting, you should use OnPlayerWeaponShot instead if you want to only detect Bullet weapons.