KeyStateChange update - 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: KeyStateChange update (
/showthread.php?tid=571162)
KeyStateChange update -
arjanforgames - 16.04.2015
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?
Re: KeyStateChange update -
Misiur - 16.04.2015
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.
Re: KeyStateChange update -
arjanforgames - 16.04.2015
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.
Re: KeyStateChange update -
Misiur - 16.04.2015
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.