OnPlayerKeyStateChange help
#1

Im trying to detect when players is pressing KEY_FIRE then KEY_CROUCH, this is to block a block a bug where you are stuck in crouch position and can do bad things...
I read the wiki and found the 'PRESSED', i tested this, but it does the exact oposite of what i want it to:
pawn Код:
if(PRESSED( KEY_FIRE | KEY_CROUCH ))
And yeah, i also tried this:
pawn Код:
if(PRESSED( KEY_CROUCH | KEY_FIRE ))
It also detects if KEY_CROUCH is pressed first.
I want it to detect KEY_FIRE, then KEY_CROUCH.
Reply
#2

Bump
Reply
#3

anti c-bug ?
Reply
#4

What about something like this:
PHP код:
new PressedFire[MAX_PLAYERS];
public 
OnPlayerKeyStateChange(playeridnewkeysoldkeys)
{
    if(
PRESSED(KEY_FIRE))
    {
        
PressedFire[playerid] = 1;
    }
    if(
PRESSED(KEY_CROUCH && PressedFire[playerid] == 1))
    {
        
//Do something
    
}
    return 
1;

Reply
#5

Try this:
pawn Код:
if ((newkeys & (KEY_FIRE | KEY_CROUCH)) == (KEY_FIRE | KEY_CROUCH) && (oldkeys & (KEY_FIRE | KEY_CROUCH)) != (KEY_FIRE | KEY_CROUCH))
Reply
#6

Not c-bug, atm this works as anti cbug, but thats not what i wanted.
Its bug where you punch and press crouch twice, then you get stuck in crouch position and can fire unlimited shots from example sawn off shotgun without reload.

Dragonsaurus, i tried out that to, its from the wiki. It did exactly the same as the code i pasted in first post.

I tried searching, but i did not find anything. Wish there could be an include that fixes the weapon bugs, i saw on ******* that there are many more ways to exploit sawn off bugs :/
Reply
#7

Did you try it?
PHP код:
new PressedFire[MAX_PLAYERS];
public 
OnPlayerKeyStateChange(playeridnewkeysoldkeys)
{
    if(
PRESSED(KEY_FIRE))
    {
        
PressedFire[playerid] = 1;
    }
    if(
PRESSED(KEY_CROUCH && PressedFire[playerid] == 1))
    {
        
//Do something
    
}
    return 
1;

Reply
#8

the variable PressedFire needs to be resetted sometime, or player can press crouch 1 hour later and anti bug code will be executed. To reset it i need to create a timer which i really dont want to in a callback that is called as often as OPKSC.
Reply
#9

Once they press both, you can reset the variable back to 0:

PHP код:
new PressedFire[MAX_PLAYERS];
public 
OnPlayerKeyStateChange(playeridnewkeysoldkeys)
{
    if(
PRESSED(KEY_FIRE))
    {
        
PressedFire[playerid] = 1;
    }
    if(
PRESSED(KEY_CROUCH && PressedFire[playerid] == 1))
    {
        
PressedFire[playerid] = 0;//The cycle will repeat again.
        //Do something
    
}
    return 
1;

Reply
#10

But still player can press fire button and a while later press crouch and anti glitch code is executed.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)