Keys State Help
#5

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(playeridnewkeysoldkeys)
{
    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.1011015001);
    
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.
Reply


Messages In This Thread
Keys State Help - by Istrator - 29.04.2018, 15:10
Re: Keys State Help - by RedRex - 29.04.2018, 15:14
Re: Keys State Help - by Loinal - 29.04.2018, 15:16
Re: Keys State Help - by Pottus - 29.04.2018, 16:34
Re: Keys State Help - by git - 29.04.2018, 19:05
Re: Keys State Help - by Istrator - 30.04.2018, 11:43
Re: Keys State Help - by jasperschellekens - 30.04.2018, 14:21
Re: Keys State Help - by git - 30.04.2018, 14:43

Forum Jump:


Users browsing this thread: 2 Guest(s)