OnPlayerSprint?
#1

how can i detect when a player is sprinting?
Reply
#2

A combination of SPRINT key press and animation check maybe ?
Reply
#3

Quote:
Originally Posted by PrO.GameR
Посмотреть сообщение
A combination of SPRINT key press and animation check maybe ?
oh right sounds logic, but could you help me by giving me an example? i'm not that good that keystate or w/e it is
Reply
#4

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

Quote:
Originally Posted by Pottus
Посмотреть сообщение
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.
Would be alot easier to use what Pottus suggested, take a look at https://sampwiki.blast.hk/wiki/GetPlayerVelocity and the rest of the velocity functions.
Reply
#6

Could this work?

PHP код:
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))) 
PHP код:
public OnPlayerKeyStateChange(playeridnewkeysoldkeys)
{
    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;

Pretty simple really - but I would use the method Pottus explained.

EDIT: Typo.

EDIT2: Just tested this in-game, it does work.
Reply
#7

Quote:
Originally Posted by d1git
Посмотреть сообщение
Could this work?

PHP код:
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))) 
PHP код:
public OnPlayerKeyStateChange(playeridnewkeysoldkeys)
{
    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;

Pretty simple really - but I would use the method Pottus explained.

EDIT: Typo.

EDIT2: Just tested this in-game, it does work.
giving me an error "undefined symbol PRESSED" also tried to change it to "PRESSING" but still the same error
Reply
#8

I just updated the code, it should work now - typo basically.

PHP код:
new sprint[MAX_PLAYERS]; 
#define PRESSED(%0) \
    
(((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
#define RELEASED(%0) \ 
    
(((newkeys & (%0)) != (%0)) && ((oldkeys & (%0)) == (%0))) 
PHP код:
public OnPlayerKeyStateChange(playeridnewkeysoldkeys

    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

Reply
#9

Quote:
Originally Posted by d1git
Посмотреть сообщение
I just updated the code, it should work now - typo basically.

PHP код:
new sprint[MAX_PLAYERS]; 
#define PRESSED(%0) \
    
(((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
#define RELEASED(%0) \ 
    
(((newkeys & (%0)) != (%0)) && ((oldkeys & (%0)) == (%0))) 
PHP код:
public OnPlayerKeyStateChange(playeridnewkeysoldkeys

    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

So it's currently detecting if the player press on SPACE etc but if he's just standing? how can i make sure it detects when he's running? i've an idea, maybe if he's pressing on the KEY_SPRINT + W or S or A or D. how can i do it?
Reply
#10

The code I presented to you does exactly what you want it to do, it only detects if the player is holding space (sprinting) - if he's standing still, he isn't sprinting (Sprint = 0).

Holding W/A/S/D is not sprinting, if you want to detect if he's running you should probably do what Pottus came up with.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)