- Joined
- Sep 30, 2009
- Messages
- 1,326
keywords: logic_compare, math_counter, func_button
Okay, well I got bored so I decided to write a tutorial for those of you that do not know how to use math_counter's or logic_compare's and guess what? It's going to be for a 9-button keypad! There aren't many good tutorials out there, so enjoy!
Let's start with the keypad, you can make your own out of 1x1 or whatever size boxes you want OR you can use the "models/props_lab/keypad.mdl" model (prop_dynamic).
The only problem with using the keypad model is that the buttons for it are really close together and you will end up with the buttons in the corners being 1x1, the button in the middle being 2x2, and the other ones being 2x1. Which is fine, you just have to be paying attention when you press the buttons and sometimes you will hit the wrong button without even knowing it. But enough about that, lets get to part you started reading this for!
# Make 9 func_buttons, you choose the variables, but leave the output alone for now. You don't have to name the buttons unless you want to be able to lock/unlock them. Leave the name blank unless you want it, less clutter on the entity list.
# Make 4 math_counter (point entities) and give them the following names:
keypad_pressed
keypad_multiply (The initial value MUST BE 1 for this one to work)
keypad_output
keypad_count
If you want the keypad to ONLY work ONCE then you do not need the keypad_count entity. All it is used for is to count the number of pressed buttons and reset the keypad for new input.
# Make 2 logic_compare (point entities) and give them the following names:
keypad_case1
keypad_case_reset
Again, if you only want the keypad to work only one time no matter if the input was correct or incorrect leave the keypad_case_reset entity out.
Now on to some outputs!
Go back to your func_buttons and give each and everyone of them this:
# OnPressed, keypad_pressed, SetValueNoFire, #, 0.00 (where # is the corresponding number of the button, ie: 1-9)
# OnPressed, keypad_multiply, Multiply, 10, 0.00
* OnPressed, keypad_count, Add, 1, 0.00
Now let's work with keypad_pressed:
# OutValue, keypad_output, Add, <none>, 0.00
Now keypad_multiply:
# OutValue, keypad_pressed, Multiply, <none>, 0.00
Now keypad_count:
* OutValue, keypad_case_reset, SetValueCompare, <none>, 0.00
Now to keypad_output:
# OutValue, keypad_case1, SetValueCompare, <none>, 0.00
You can add as many logic_compare's as you wish, just make sure you add an output to the keypad_output as specified above for them to work!
And last but not least, the logic_compare's!
On keypad_case_reset it doesn't matter what the "initial value" is, but make sure you set the "compare value" to the length of your input. All codes entered in this keypad should be the same length, a good length is 4-5 digits.
On the outputs for keypad_case_reset:
# OnEqualTo, keypad_pressed, SetValueNoFire, 0, 2.00
# OnEqualTo, keypad_multiply, SetValueNoFire, 1, 2.00
# OnEqualTo, keypad_output, SetValueNoFire, 0, 2.00
# OnEqualTo, keypad_count, SetValueNoFire, 0, 2.00
The delay is so that the keypad has enough time to finish it's computations and send the output. I tested using a delay of 0.00 and never got the output.
Also, copy & paste the OnEqualTo's and change them to OnGreaterThan's in-case someone presses to many buttons. You can also have it play a sound or do something else as well if you want.
On the keypad_case1 you will set the code that will perform the outputs!
For this example let's say we are using a 4 digit code and that code is 1234. Now we need to put it in the logic_compare's "compare value" field, BUT WAIT!! In order for it to work you have to reverse the code and add a 0 (zero) to the end. So in the "compare value" field our code would look like: 43210, but in the game we would press 1234.
The next part is fun, on keypad_case1's outputs DO WHATEVER YOU WANT!
example:
# OnEqualTo, some_door, Unlock, 0.00
# OnGreaterThan, some_killzone, Enable, 0.00
I think that's everything, have fun tinkering!
P.S. If you were wondering about how the math works:
you press button #1, keypad_output's value is now 10
you press button #2, keypad_output's value is now 210
you press button #3, keypad_output's value is now 3210
you press button #4, keypad_output's value is now 43210 and you get the outputs from keypad_case1.
Okay, well I got bored so I decided to write a tutorial for those of you that do not know how to use math_counter's or logic_compare's and guess what? It's going to be for a 9-button keypad! There aren't many good tutorials out there, so enjoy!
Let's start with the keypad, you can make your own out of 1x1 or whatever size boxes you want OR you can use the "models/props_lab/keypad.mdl" model (prop_dynamic).
The only problem with using the keypad model is that the buttons for it are really close together and you will end up with the buttons in the corners being 1x1, the button in the middle being 2x2, and the other ones being 2x1. Which is fine, you just have to be paying attention when you press the buttons and sometimes you will hit the wrong button without even knowing it. But enough about that, lets get to part you started reading this for!
# Make 9 func_buttons, you choose the variables, but leave the output alone for now. You don't have to name the buttons unless you want to be able to lock/unlock them. Leave the name blank unless you want it, less clutter on the entity list.
# Make 4 math_counter (point entities) and give them the following names:
keypad_pressed
keypad_multiply (The initial value MUST BE 1 for this one to work)
keypad_output
keypad_count
If you want the keypad to ONLY work ONCE then you do not need the keypad_count entity. All it is used for is to count the number of pressed buttons and reset the keypad for new input.
# Make 2 logic_compare (point entities) and give them the following names:
keypad_case1
keypad_case_reset
Again, if you only want the keypad to work only one time no matter if the input was correct or incorrect leave the keypad_case_reset entity out.
Now on to some outputs!
Go back to your func_buttons and give each and everyone of them this:
# OnPressed, keypad_pressed, SetValueNoFire, #, 0.00 (where # is the corresponding number of the button, ie: 1-9)
# OnPressed, keypad_multiply, Multiply, 10, 0.00
* OnPressed, keypad_count, Add, 1, 0.00
Now let's work with keypad_pressed:
# OutValue, keypad_output, Add, <none>, 0.00
Now keypad_multiply:
# OutValue, keypad_pressed, Multiply, <none>, 0.00
Now keypad_count:
* OutValue, keypad_case_reset, SetValueCompare, <none>, 0.00
Now to keypad_output:
# OutValue, keypad_case1, SetValueCompare, <none>, 0.00
You can add as many logic_compare's as you wish, just make sure you add an output to the keypad_output as specified above for them to work!
And last but not least, the logic_compare's!
On keypad_case_reset it doesn't matter what the "initial value" is, but make sure you set the "compare value" to the length of your input. All codes entered in this keypad should be the same length, a good length is 4-5 digits.
On the outputs for keypad_case_reset:
# OnEqualTo, keypad_pressed, SetValueNoFire, 0, 2.00
# OnEqualTo, keypad_multiply, SetValueNoFire, 1, 2.00
# OnEqualTo, keypad_output, SetValueNoFire, 0, 2.00
# OnEqualTo, keypad_count, SetValueNoFire, 0, 2.00
The delay is so that the keypad has enough time to finish it's computations and send the output. I tested using a delay of 0.00 and never got the output.
Also, copy & paste the OnEqualTo's and change them to OnGreaterThan's in-case someone presses to many buttons. You can also have it play a sound or do something else as well if you want.
On the keypad_case1 you will set the code that will perform the outputs!
For this example let's say we are using a 4 digit code and that code is 1234. Now we need to put it in the logic_compare's "compare value" field, BUT WAIT!! In order for it to work you have to reverse the code and add a 0 (zero) to the end. So in the "compare value" field our code would look like: 43210, but in the game we would press 1234.
The next part is fun, on keypad_case1's outputs DO WHATEVER YOU WANT!
example:
# OnEqualTo, some_door, Unlock, 0.00
# OnGreaterThan, some_killzone, Enable, 0.00
I think that's everything, have fun tinkering!
P.S. If you were wondering about how the math works:
you press button #1, keypad_output's value is now 10
you press button #2, keypad_output's value is now 210
you press button #3, keypad_output's value is now 3210
you press button #4, keypad_output's value is now 43210 and you get the outputs from keypad_case1.

















