OnPlayerKeyStateChange help -
Richie© - 13.09.2013
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.
Re: OnPlayerKeyStateChange help -
Richie© - 14.09.2013
Bump
Re: OnPlayerKeyStateChange help -
Pottus - 14.09.2013
anti c-bug ?
Re: OnPlayerKeyStateChange help -
ThePhenix - 14.09.2013
What about something like this:
PHP код:
new PressedFire[MAX_PLAYERS];
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if(PRESSED(KEY_FIRE))
{
PressedFire[playerid] = 1;
}
if(PRESSED(KEY_CROUCH && PressedFire[playerid] == 1))
{
//Do something
}
return 1;
}
Re: OnPlayerKeyStateChange help -
Dragonsaurus - 14.09.2013
Try this:
pawn Код:
if ((newkeys & (KEY_FIRE | KEY_CROUCH)) == (KEY_FIRE | KEY_CROUCH) && (oldkeys & (KEY_FIRE | KEY_CROUCH)) != (KEY_FIRE | KEY_CROUCH))
Re: OnPlayerKeyStateChange help -
Richie© - 14.09.2013
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 :/
Re: OnPlayerKeyStateChange help -
ThePhenix - 14.09.2013
Did you try it?
PHP код:
new PressedFire[MAX_PLAYERS];
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if(PRESSED(KEY_FIRE))
{
PressedFire[playerid] = 1;
}
if(PRESSED(KEY_CROUCH && PressedFire[playerid] == 1))
{
//Do something
}
return 1;
}
Re: OnPlayerKeyStateChange help -
Richie© - 14.09.2013
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.
Re: OnPlayerKeyStateChange help -
ThePhenix - 14.09.2013
Once they press both, you can reset the variable back to 0:
PHP код:
new PressedFire[MAX_PLAYERS];
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
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;
}
Re: OnPlayerKeyStateChange help -
Richie© - 15.09.2013
But still player can press fire button and a while later press crouch and anti glitch code is executed.