KeyStateChange update
#1

Hello,

So I have a script with a fire extinguisher and a variable.
Now I created a function that will mimic the ammo of the fire ex. in the variable. But here is the problem:
The variable gets updated when I release the fire key, although I want it to be updated every second or so while holding the fire key.

Any ideas?
Reply
#2

Yup, you need timer though

1. When key gets pressed, start a (repeating) timer to decrease amount of "ammo" left
2. When it gets released, or there is no ammo left, stop the timer.
Reply
#3

Quote:
Originally Posted by Misiur
Посмотреть сообщение
Yup, you need timer though

1. When key gets pressed, start a (repeating) timer to decrease amount of "ammo" left
2. When it gets released, or there is no ammo left, stop the timer.
Could you elaborate on this? As the script inside the function seems to get executed when you release the keys.
Reply
#4

pawn Код:
static
    PlayerExtinguisherAmmo[MAX_PLAYERS],
    PlayerExtinguisherTimer[MAX_PLAYERS]
;
//...
forward ExtinguisherAmmoTimer(playerid);
public ExtinguisherAmmoTimer(playerid)
{
    if (--PlayerExtinguisherAmmo <= 0) {
        KillTimer(PlayerExtinguisherTimer);
        //eventually change weapon to something else so he can't use extinguisher anymore
    }
    return 1;
}
Now, OnPlayerKeyStateChange when fire button is pressed start this timer on repeat, and on button release kill it as well. Recharge the ammo when you deem it should be recharged.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)