OnPlayerSprint? - 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)
+--- Thread: OnPlayerSprint? (
/showthread.php?tid=598864)
OnPlayerSprint? -
Lirbo - 17.01.2016
how can i detect when a player is sprinting?
Re: OnPlayerSprint? -
PrO.GameR - 17.01.2016
A combination of SPRINT key press and animation check maybe ?
Re: OnPlayerSprint? -
Lirbo - 17.01.2016
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
Re: OnPlayerSprint? -
Pottus - 17.01.2016
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.
Re: OnPlayerSprint? -
-CaRRoT - 17.01.2016
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.
Re: OnPlayerSprint? -
d1git - 17.01.2016
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(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;
}
Pretty simple really - but I would use the method Pottus explained.
EDIT: Typo.
EDIT2: Just tested this in-game, it does work.
Re: OnPlayerSprint? -
Lirbo - 17.01.2016
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(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;
}
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
Re: OnPlayerSprint? -
d1git - 17.01.2016
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(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;
}
Re: OnPlayerSprint? -
Lirbo - 17.01.2016
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(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;
}
|
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?
Re: OnPlayerSprint? -
d1git - 17.01.2016
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.