I’d like to introduce new overworld mechanics in my game, but I don’t know how to add a new control.
Say I want there to be a temporary dash move that happens when you press the Z key. How can I make the Z key execute something that I’ve evented in? I also would like to be able to change the functionality of that key when a different character is being played as.
On a similar note, how can I make sure that these buttons will be pressable on a controller rather than just a keyboard?
From my understanding the keyboard and controller mapping in MZ lives in two objects in rmmz_core.js, Input.keyMapper and Input.gamepadMapper. Each one just maps a key code or button index to an action name like “ok” or “shift”. One thing to keep in mind is Z is already the confirm button by default (key code 90 → “ok”), so if you point it at a dash you’d lose your OK button. Maybe pick a key that isn’t taken, or you could keep Z if you’re fine with that tradeoff.
The way I think I would do it is a tiny plugin file in js/plugins that adds the new action to both maps, something like this:
Input.keyMapper[67] = "dash"; // C key
Input.gamepadMapper[6] = "dash"; // button 6, usually a trigger, 0 to 5 and 12 to 15 are already used
Then make a Common Event set to Parallel with a Conditional Branch → Script tab → Input.isTriggered("dash") and put your dash eventing inside that branch. For the per character part, I’d probably nest another conditional inside that checks who’s leading the party, either a switch you flip when you swap characters or a script check like $gameParty.leader().actorId() === 2, and run a different set of eventing for each one.
Controller support comes for free once it’s in gamepadMapper, since Input.isTriggered doesn’t care whether the press came from a key or a button.
I don’t know if I totally understand but I will try. I just said Dash as an example for an action I could do.
I want there to be 4 buttons the player can press, and each one do a different action.
I understand the Parallel Process+Conditional Branch+If Button Pressed part.
I’d like my buttons to be Z X A S on a keyboard, and Z(OK) and X(Menu) won’t matter in this case since you can’t open the menu when on the corresponding map.
What I’m struggling with is how to actually define a new button that I can then put into the conditional branch.
There isn’t a place in the editor to define one, the name is just a string you make up in a plugin file. Anything that isn’t already in Input.keyMapper is free to use.
For your four keys:
Input.keyMapper[90] = "action1"; // Z
Input.keyMapper[88] = "action2"; // X
Input.keyMapper[65] = "action3"; // A
Input.keyMapper[83] = "action4"; // S
Save that as a .js in js/plugins and turn it on in the Plugin Manager. A and S aren’t mapped to anything by default. Z and X are “ok” and “escape”, so pointing them at your own names takes those away, but Enter and Space still cover ok and Esc still covers escape, so your menus keep working.
In the Conditional Branch, the Button dropdown only lists the engine’s own names, so your new ones go in the Script tab instead:
Input.isTriggered("action1")
Then swap the name per branch. isTriggered is a single press, and Input.isPressed if you want it to keep firing while the key is held.
at the end of the Common Event that sends the player away from the 4-button map.
So putting those script commands in means that action1 and action2, as well as ok and escape, can coexist as separate functionalities as long as the player is on the map that specifies it?
Pretty much. A key code only holds one name at a time, so while the player is on that map Z is action1 and nothing else. What keeps ok and escape working over there is that they sit on other keys too, Enter and Space for ok, Esc and Insert and numpad 0 for escape. Those never got touched.
The thing I’d watch out for is saving. keyMapper isn’t part of the save file, so if the player saves while on the 4 button map and loads that file later, Z and X come back as ok and escape and the common event isn’t running to set them again.
What I’d probably do for that is move the first half into a Parallel Process event placed on the map itself:
Followed with an Erase Event right after it so it only fires once. Erase Event wears off when the map is left and set up again, so it runs on every fresh load of that map, a loaded save included. Your exit common event can stay exactly as you have it.
If your conditional branches are sitting in that same event, the Erase Event stops the whole thing before it reaches them, so the keys get set and then nothing is left running to check them.
The other one is my mistake from the last post. Erased events do come back when you leave the map and return, but the erased state is part of the save file, so if the player saves while on that map the event is still erased when they load. That’s the exact case I was trying to cover with it.
So drop the Erase Event and let one parallel event do both jobs:
then your four conditional branches underneath it in that same event. Parallel events run their whole list every frame, so the mapping gets reapplied constantly, which costs nothing. Leave Input.clear() out of this one though, it wipes the current press, so running it every frame would eat the input before the branches see it.
Your exit common event can stay exactly as it is.
One thing to check, if the plugin file still has 90 and 88 in it, pull those two lines out. Otherwise Z and X are action1 and action2 from boot rather than only on that map.
The Conditional Branches that define the buttons were in their own Parallel Process event separate from the action1-4 Setters, but at your prompting I’ve put the Setters into the top of the Button Defining event and they’re all combined now. (minus the Input.clear())
Since the branches were already in their own parallel event, the Erase Event wasn’t what was blocking them, so combining the two may not change anything by itself. Test it first, and if it still doesn’t fire, run through these:
Make sure the Erase Event didn’t come along when you moved the setters. If it’s anywhere in the combined event, it ends the whole thing before the branches run.
Temporarily change one branch’s script to Input.isTriggered("ok") and press Enter while standing on the map. If the text box shows, the event and the Show Text are fine and the problem is on the key name side. If nothing shows even for ok, the event isn’t running at all, so check the page trigger is Parallel Process, the page conditions are all unchecked, and the event is on the map you’re actually standing on.
During playtest on that map, press F8, click the Console tab, type Input.keyMapper[90] and hit Enter. It should print action1. If it prints ok, the setter isn’t taking effect.
Post the exact text of one branch’s script line. The name in the setter and the name in the check have to match exactly, same case, no spaces.
A screenshot of the event page would help too. Once I can see those I can point at something specific.
Sorry this is such a slow process with me here, I try to be really thorough to make sure I understand everything, if you want to move to discord or somewhere I can give you it.
No worries, the forum is fine and it means the next person can find this. Two of those tests need a second pass.
For #2, Z isn’t ok anymore, it’s action1, so pressing Z with the script set to ok wouldn’t show anything either way. Press Enter or Space for that one.
For #3, if the plugin file is still enabled it sets action1 at boot, so the console prints action1 whether or not the map event is running. Is the plugin still on?
Both of those come back to the same question, whether that event is running at all. So also, is it a map event or a Common Event? A Common Event set to Parallel only runs while its switch is on, and a map event needs its trigger on Parallel Process with nothing ticked in the page conditions.
If you want the cleanest test, drop a brand new event on the map, Parallel Process, one Conditional Branch with Script Input.isTriggered("ok") and a Show Text inside, nothing else. Press Enter. If that one shows text and yours doesn’t, it’s something in the page settings, and a screenshot of the top of your event editor (trigger and conditions) is what I’d want to see next.
I made the currently not working parallel button definer set to action button so it doesnt activate atm.
I made that new event exactly as you said it, and it did indeed show text upon pressing Z, Space and Enter.
With this realization, I was able to identify the reason why it was working here and not there, and in the end i was able to get it working! There was a variable I had forgotten to set that wasn’t allowing the process to work. Thanks for all your help though, it’s working now, and I’ll ask you if i have any more questions!