Quote:
Originally Posted by Pottus
How do you expect that work correctly without checking the times between presses? No resetting of the variable either.
The best thing to do would be to create your own system that allows defining custom key combo detection.
|
PHP код:
#include <a_samp>
#define PRESSED(%0) \
(((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
new timesJump[MAX_PLAYERS];
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if(!IsPlayerInAnyVehicle(playerid))
{
new firstjumpTime;
if(PRESSED(KEY_JUMP))
{
timesJump[playerid]++;
if(timesJump[playerid] == 1)
{
firstjumpTime = gettime()+4500;
return 1;
}
if(timesJump[playerid] > 3)
{
timesJump[playerid] = 0;
if(firstjumpTime < gettime())
{
OnPlayerJumpThreeTimes(playerid);
}
}
return 1;
}
}
return 1;
}
forward public OnPlayerJumpThreeTimes(playerid);
public OnPlayerJumpThreeTimes(playerid)
{
SendClientMessage(playerid, -1, "detected jumping 3 times within timespan of 4.5 seconds");
// the code when the player jumps three times
ApplyAnimation(playerid, "GYMNASIUM", "gym_tread_falloff", 4.1, 0, 1, 1, 0, 1500, 1);
timesJump[playerid] = 0;
return 1;
}
here's what i've come up with.
to the op:
it uses timestamps. it gets the current time + 4.5 seconds so for example if the time is 12:50:30 (hh mm ss) it will store 12:50:34 in the variable.
if the player has jumped 3 times while the time is less than 12:50:34 (time span of 4 seconds) it will detect and reset the variable for the jump counter.
(technically timestamp is in seconds so 199999 would be 200003 if 4 seconds were added to it).
this code may be bad practice, but it is an idea of what you want.
i can confirm that my method works.
alternatively, you could use ziggi's
GetTickDiff function and check the interval in ms of each jump, so this way, when people spam the jump key and they do it within below a specific value, you can apply an animation to make them trip or what not.