Which public to use - 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: Which public to use (
/showthread.php?tid=619403)
Which public to use -
NeXoR - 17.10.2016
Hey guys, I am scripting an Anti Ammo Hacking and I was wondering what should I do
I can't detect non-bullet weapons being shot using OnPlayerWeaponShot, I have to use OnPlayerKeyStateChange or OnPlayerUpdate, now I don't know which one to use to reduce ammo from the variable
My question is, how can I do that while the player is holding a button it will do something ?
This way ?
PHP код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
while(HOLDING(KEY_FIRE))
{
}
return 1;
}
Re: Which public to use -
Vince - 17.10.2016
That doesn't work. A key is held from the time it is pressed to the time it is released. That constitutes (at least) two function calls. To do anything while the key is being held you need a timer. Set the timer when the key is first pressed, kill the timer when it is released.
Re: Which public to use -
NeXoR - 17.10.2016
Quote:
Originally Posted by Vince
That doesn't work. A key is held from the time it is pressed to the time it is released. That constitutes (at least) two function calls. To do anything while the key is being held you need a timer. Set the timer when the key is first pressed, kill the timer when it is released.
|
If I get you right, set the timer on repeating on X interval when it's being pressed, kill it when it's released.
If, for example I would like to do it on a Flamethrower, I don't think it's possible to reduce 1 ammo because it's being reduced from GetPlayerAmmo in a rate of like 100 per second or something like that
Same as Spraycan/Fire Ex.
Re: Which public to use -
Dayrion - 17.10.2016
I did smth like that to know how long time the player pressed a specific key:
PHP код:
new timea[MAX_PLAYERS],
bool:holding[MAX_PLAYERS];
#define HOLDING(%0) \ //wiki
((newkeys & (%0)) == (%0))
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
SCMF(playerid, RED, "newkeys: %i | oldkeys : %i", newkeys, oldkeys);
if(HOLDING(KEY_FIRE) && !holding[playerid])
{
SCM(playerid, GOLD, "Hoooolding");
timea[playerid] = gettime();
holding[playerid] = true;
}
else if((oldkeys & KEY_FIRE) && holding[playerid])
{
SCMF(playerid, GOLD, "You pressed the key during %is", gettime() - timea[playerid]);
holding[playerid] = false;
}
return 1;
}
Re: Which public to use -
SickAttack - 17.10.2016
There is a RELEASED macro, use it. No need for a timer. Take a look at:
https://github.com/Kevin-Reinke/Play..._detection.pwn