Key Combos

A lib for adding actions when certain keys are pressed in order.

Developer Tools

Download (10 KB)

How do I install this?

This mod gives you a few functions for easily adding a call for when a sequence of keys are pressed in order.

This is helpful mainly for the reason that there are very few possible inputs by default, and if you want a lot of accessible player actions requring only the use of the default controls.

Another reason this might be nice, is if you want it to be a 'skill' to do certain actions (make the execution of an action difficult). for example, say you want to make a mod where you have a gun that you can reload, but you want the reloading process to be something of an aquired skill. Simple. You could then make a 'combo' using this mod's handy functions for this sort of case.

Register Combo

The main function (most likely) that you will use is this:

key_combos.register_key_combo(name, combo_list, function(player))

it works like this:

key_combos.register_key_combo("fly", {{'jump', 'down', 'up'}}, function(player)
    player:add_velocity(vector.multiply(player:get_look_dir(), 50))

This creates a combo that when you press "jump", "down", and "up" in order, it will send you flying in the direction you are facing. You may cleverly notice the double curly braces '{}' around the list of controls set to preform the combo. The reason for this is that when you want a combo to be able to be called using different input patterns, you can simply add another list after the first inside of the outer set of curly braces. Like so:

key_combos.register_key_combo("fly", {{'jump', 'left', 'right', 'up'}, {'jump', 'right', 'left', 'up'}}, function(player)
    player:add_velocity(vector.multiply(player:get_look_dir(), 50))

Now you can preform this combo in two different ways... but wait, this also means that now, if you press "Jump" then mash "Left+Right" then press "Up" it will still trigger. Keep this in mind if you want to do a double key mash.

Allow and Disallow player use

Now with your "fly" combo created EVERY player will be able to preform it anytime. This however may not be desirable. Maybe you only want it available for one player. Maybe you want one player excluded from the use of it.. whatever you need a way to disable this combo subjectively, I got you. Automaticly when a combo is created it is available to every player, but the use of the function:

key_combos.disallow_key_combo(combo_name, player_name)

will disable it. it is used like so:

key_combos.disallow_key_combo('fly', 'singleplayer')

Alternitively, if you have many combos and you want this player to not be able to use any of them, you can use the special string, 'all' in place of the combo_name.

key_combos.disallow_key_combo('fly', 'singleplayer')

the same goes for re-allowing combos:

key_combos.allow_key_combo(combo_name, player_name)


key_combos.allow_key_combo('fly', 'singleplayer')

key_combos.allow_key_combo('all', 'singleplayer')

How to help

If you have any questions or bugs you may have found please ask, or report in the repository on github.

That's it, enjoy!



Do you recommend this mod?

  • No reviews, yet.