Detect player crouching - 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Detect player crouching (
/showthread.php?tid=192662)
Detect player crouching -
TheXIII - 23.11.2010
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.
Re: Detect player crouching -
Mike_Peterson - 23.11.2010
try searchin in here:
https://sampwiki.blast.hk/wiki/OnPlayerK...heck_for_a_key
Re: Detect player crouching -
TheXIII - 23.11.2010
Quote:
Originally Posted by Mike_Peterson
|
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.
Re: Detect player crouching -
Zh3r0 - 23.11.2010
Then do a variable check. Set
true when crouching and set
false when standing up from crouching.
Re: Detect player crouching -
TheXIII - 23.11.2010
Quote:
Originally Posted by Zh3r0
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.
Re: Detect player crouching -
Babul - 23.11.2010
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.
Re: Detect player crouching -
armyoftwo - 23.11.2010
Try to use GetPlayerAnimationIndex - It can detect the crouch animation and standing animation aswell