Detect player crouching
#1

How to detect player crouching, but NOT standing up? Is there a way?
pawn Code:
if( PRESSED(KEY_CROUCH) ) // CROUCH
{
    if( GetPlayerSpecialAction(playerid) == SPECIAL_ACTION_DUCK )
    {
        SCM(playerid, COL_CMDHELP, "Duckd!");
    }
}
Prints "Duckd!" when ducking, and when standing up aswell. That's not what I need exactly.
Reply
#2

try searchin in here:
https://sampwiki.blast.hk/wiki/OnPlayerK...heck_for_a_key
Reply
#3

Quote:
Originally Posted by Mike_Peterson
View Post
Err.. it detects key just fine. It also detects when player crouches just fine.
But when I stand up from crouching, it also detects it as "crouching"... which is not needed.
Reply
#4

Then do a variable check. Set true when crouching and set false when standing up from crouching.
Reply
#5

Quote:
Originally Posted by Zh3r0
View Post
Then do a variable check. Set true when crouching and set false when standing up from crouching.
Tried that. Worked for 1-3 times, but got easily messed up to be other way around.
ATM I got it working with timer (again )

In 500ms the player has time to stand up / crouch, and the GetPlayerSpecialAction returns the value I need.
So:
pawn Code:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    #define RELEASED(%0) \
    (((newkeys & (%0)) != (%0)) && ((oldkeys & (%0)) == (%0)))
   
    #define PRESSED(%0) \
    (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))

    #define HOLDING(%0) \
    ((newkeys & (%0)) == (%0))

    if( PRESSED(KEY_CROUCH) ) // CROUCH
    {
        CheckCrouch(playerid);
    }
    return 1;
}
Delay:CheckCrouch[500, i](playerid)
{
    if( GetPlayerSpecialAction(playerid) == SPECIAL_ACTION_DUCK )
    {
        //stuff
    }
}
And actually in this case I don't mind the slight delay.
Reply
#6

you want to get the state when croching? thats already built-in:
https://sampwiki.blast.hk/wiki/GetPlayerSpecialAction
pay attention to the https://sampwiki.blast.hk/wiki/SpecialActions ...
Code:
1 - SPECIAL_ACTION_DUCK *             - Detect if the player is crouching.
Notes (*) These Special Actions cannot be set.
Reply
#7

Try to use GetPlayerAnimationIndex - It can detect the crouch animation and standing animation aswell
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)