17.01.2016, 17:30
how can i detect when a player is sprinting?
I am going to suggest thinking about what constitutes sprinting the first method sprint and animation. That could be part of the check but technically a player wouldn't be considered sprinting until the players velocity reaches and surpasses the sprint velocity threshold. The threshold is considered an arbitrary limit which can be fine tuned to your preference.
|
new sprint[MAX_PLAYERS];
// PRESSING(keyVariable, keys)
#define PRESSED(%0) \
(((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
// RELEASED(keys)
#define RELEASED(%0) \
(((newkeys & (%0)) != (%0)) && ((oldkeys & (%0)) == (%0)))
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if(PRESSED(KEY_SPRINT))
{
sprint[playerid] = 1; // Player pressed the sprint key
}
if(RELEASED(KEY_SPRINT))
{
sprint[playerid] = 0; // Player letgo of the sprint key
}
return 1;
}
Could this work?
PHP код:
PHP код:
EDIT: Typo. EDIT2: Just tested this in-game, it does work. |
new sprint[MAX_PLAYERS];
#define PRESSED(%0) \
(((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
#define RELEASED(%0) \
(((newkeys & (%0)) != (%0)) && ((oldkeys & (%0)) == (%0)))
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if(PRESSED(KEY_SPRINT))
{
sprint[playerid] = 1; // Player pressed the sprint key
}
if(RELEASED(KEY_SPRINT))
{
sprint[playerid] = 0; // Player letgo of the sprint key
}
return 1;
}
I just updated the code, it should work now - typo basically.
PHP код:
PHP код:
|