I have been testing Yanfly's ButtonCommonEvents plugin and I was wondering if it would be possible to create more than just one button common events? For example if pressing "Q" triggers a certain common event, could typing "QA" trigger a different event? This probably won't work just by modifying Yanfly's plugin, since both "Q" and "QA" would require some timing trigger, so that "Q" wouldn't trigger immediately when going for "QA".
MV Button combination for common event
Javascript/Plugin SupportYou could have an event triggered by pressing Q, which checks is A is also pressed and launches one of those two events depending on that.
More specifically:
- Set a switch when pressing Q, and have that switch activate a parallel event
- Have that event check for two things: if Q is not pressed anymore, and if A is pressed
- If A is pressed, turn off the switch and launch the "QA" event
- If Q is no longer pressed, turn off the switch and launch the "Q" event
More specifically:
- Set a switch when pressing Q, and have that switch activate a parallel event
- Have that event check for two things: if Q is not pressed anymore, and if A is pressed
- If A is pressed, turn off the switch and launch the "QA" event
- If Q is no longer pressed, turn off the switch and launch the "Q" event
Sorry, I didn't explain this clearly enough. In this case I wish that typing "QA" would have some effect, instead of holding down both buttons at the same time. An example would be Konami code, where you have to type a specific combination of keys to have something happen.
So I guess instead of waiting for Q to be unpressed you'd simply wait some time the player has to press A, and run the "Q" event if that time passes without an A press.
Yes, exactly.
I do recommend checking to make sure that the "T" key is assigned to a blank common event or at least have it mapped in your system. Yanfly has it set so that keys are mapped only when tied to a common event. In my case, I am using common event 30 (Q Button), 31 (turns on by parallel switch), and 32 (blank common event for T key).
You could use
if you didn't want to use a common event slot. You'll have to save it as a plugin or define it somewhere in your game before use. Probably best to just go the Yanfly route since you are using it there. I think you can assign more than 1 key to the same blank common event so that you can use the key in game for combos.
You could use
Code:
Input.keyMapper[84] = 't'
I tested your example and it works as a combo by pressing both buttons at the same time.
My intention however was to have an effect when you type a certain button combination (e.g Konami code). To clarify further typing only 'Q' would do something, whereas typing 'QUAKE' it would do something different instead. I assume this requires some sort of timer check before activating the effect, so that 'Q' wouldn't activate if you wanted to have the 'QUAKE' effect instead.
You can put in 1 - 6 wait frames at the beginning of the common event it and that would work. You'll have to change the variable from 12 to something else based on your timing. I assumed that the counter would help but it looks like a wait frame is needed or I could have set it to trigger when the value hits one. I'll show you a better example when I get to a computer.
Edit: Here is what was able to work for me - the Q button must be lifted and cannot bleed over. Please use a wait frame if you need it at the beginning or change the counter to fit your needs and experiment.
This one needs a counter of 15 and only triggers after 15 frames for the Q button being triggered. It also checks during those 15 frames if T is triggered and only if Q is not triggered/held.
Edit: I wrapped the "If Script Input.isTriggered..." event command inside of another conditional branch that requires the Counter to be at least 2 or higher so that it doesn't work until the counter gets to that frame (below 15, of course):
I also added an Else clause to close out the switch so it doesn't repeat the sequence if the Q button was pressed more than once within the timeframe.
Hope this helps! I try not to do a wait frame for user input since the timing is so precise. Using a counter really helps and you can add and remove what you need. This version assumes that the player is lifting the key after each input so if it is held on even for a frame, it will not activate. If that feels like it would be an issue, remove the !Input._currentState['q'] and use slightly more time on the counter.
There are many ways to approach this so please test it with your own modifications to fit your needs.
Result (with else statement) - there was one misfire with the program picking up the Q without the T after it that you will see in the video:
Thanks!
Edit: With 1 wait frame (or as needed):
If you are usign YEP_ButtonCommonEvent, I have an idea that you use 3 common events to check the Q or QA input.
Though it is much easier to just use NW.js and keypress event, log your key input into a string, so you can check later for any long combinations like "QUAKE".
Anyway, it is done like this:
Edit*
Well it has a slight bug that if you hold Q, or input QQQQQ very quickly, the 15 frames delay will be reset. Though it can be fixed by adding an extra check in common event Q if it really matters.
Though it is much easier to just use NW.js and keypress event, log your key input into a string, so you can check later for any long combinations like "QUAKE".
Anyway, it is done like this:
Edit*
Well it has a slight bug that if you hold Q, or input QQQQQ very quickly, the 15 frames delay will be reset. Though it can be fixed by adding an extra check in common event Q if it really matters.
Thank you for both of your replies.
I am currently using utunnels suggestion and it seems to work as intended. I'll do a few more tests/adjustments to see if I need any more help with this.
I am currently using utunnels suggestion and it seems to work as intended. I'll do a few more tests/adjustments to see if I need any more help with this.
Original thread: https://forums.rpgmakerweb.com/threads/button-combination-for-common-event.169803/