Detect when player presses two buttons
Hi everybody, well i want to prevent something when a player hold the buttons w and a or w and d buttons simultaneously for two seconds, well my question is how i can detect when the players hold this buttons at the same time for two seconds? i want to set hight gravity when this happen but my quesion is just the other, can someone give me an example? ..thx in advance
|
Re: Detect when player presses two buttons
It's not possible to detect keys but it is possible to detect the command. So, if we assume the default key binds, you want to detect the movement commands. You need to find plugins that already check for buttons for an example how to determine the "buttons" (aka the commands sent that are made for keyboard keys). Some of the more common ones that I've seen are the IN_SCORE button.
Once you get the basic methodology for determining the 'buttons' that are being pressed, then you will need to keep track of how long the button has been pressed. Anyways, you should start with the basic detecting the buttons and then go to the 2 seconds thing. Here are some useful posts: https://forums.alliedmods.net/showthread.php?t=198285 https://forums.alliedmods.net/showthread.php?t=214980 https://forums.alliedmods.net/showthread.php?t=231550 |
Re: Detect when player presses two buttons
Thx this help me a lot, just another question how i can make for example if the player holding down the botton for 2 or more seconds i want activate something, how i can do?
code: PHP Code:
|
Re: Detect when player presses two buttons
The XY-problem is making it hard to filter the buttons to your likings. I'll give you 3 examples that you can make fit your purpose.
This will be called every call of CmdStart, if you want it only once you'll have to filter it with a bool. Code:
This will be called once per holding-down-instance. Code:
This will only count if the same 2 keys has been hold down for 2 seconds. Code:
I strongly advice against any of this if there's a better way. |
Re: Detect when player presses two buttons
wow very thx for the examples, so if i want to set gravity when player hold down two keys then give normal gravity when player release the button, in this form is fine?
PHP Code:
|
Re: Detect when player presses two buttons
It's possible that there's another solution for your problem. You might be taking the wrong approach.
Enough of the XY problem, and fully explain why you want this? What is it going to achieve in the end? Does it have something to do with long jumping? |
Re: Detect when player presses two buttons
Yes is something about jump, for example when you stick to the wall and aim to the wall and you hold the keys w and a or w and d at the same time and you jump a lot of time the player gains more speed and is a bit annoying, that's why I'm trying to do this.
|
Re: Detect when player presses two buttons
So you've just come up with the solution yourself - hook Jump() and check for the buttons or for a certain player speed.
See how much more simple things become when you fully explain your problem? |
Re: Detect when player presses two buttons
Ok, just i have another question how i can save correctly the gravity of the players? i mean i use this on zombie plague mod and the zombies and humans have different gravity, i make this but dont work..
PHP Code:
|
Re: Detect when player presses two buttons
You'vs misunderstood, CmdStart is not required.
|
| All times are GMT -4. The time now is 06:04. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.