Which public to use
#1

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(playeridnewkeysoldkeys)
{
    while(
HOLDING(KEY_FIRE))
    {
    }
    return 
1;

Reply
#2

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.
Reply
#3

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.
Reply
#4

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(playeridnewkeysoldkeys)
{
    
SCMF(playeridRED"newkeys: %i | oldkeys : %i"newkeysoldkeys);
    if(
HOLDING(KEY_FIRE) && !holding[playerid])
    {
        
SCM(playeridGOLD"Hoooolding");
        
timea[playerid] = gettime();
        
holding[playerid] = true;
    }
    else if((
oldkeys KEY_FIRE) && holding[playerid])
    {
        
SCMF(playeridGOLD"You pressed the key during %is"gettime() - timea[playerid]);
        
holding[playerid] = false;
    }
    return 
1;

Reply
#5

There is a RELEASED macro, use it. No need for a timer. Take a look at:

https://github.com/Kevin-Reinke/Play..._detection.pwn
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)