Detect when player shooting with OnPlayerKeyStateChange ?
#1

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 ?
Reply
#2

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))
{
    
//.....

Reply
#3

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


Forum Jump:


Users browsing this thread: 1 Guest(s)