Inputs2.lua

From Moondust Wiki
Revision as of 01:53, 26 January 2016 by Henryrichard (talk | contribs) (Reformatted it.)
Jump to navigation Jump to search

Download Latest Version

Inputs2 is a small library which makes it easier to override the player's input. It is not fully backwards compatable with Inputs, but it doesn't take much effort to update old code.

Installation

Save the above file as inputs2.lua and drop it in the LuaScriptsLib folder.

How to use

To use this api, add this to your lunadll.lua or lunaworld.lua:

local inputs2 = loadAPI("inputs2");

Example

local inputs2 = loadAPI("inputs2");
    
inputs2.locked[1]["altjump"] = true


function onLoop ()
    if  inputs2.state[1]["altjump"] == inputs.PRESS  then
	playSFX(26)
	
	-- Get direction multiplier
	local dirMult = -1
	if  player:mem (0x106, FIELD_WORD) ~= -1  then
	    dirMult = 1
	end
	
	-- Spawn boomerang
	local boomerang = NPC.spawn (292, player.x + (32*dirMult), player.y, 1)
	boomerang.speedX = 12*dirMult + player.speedX
	boomerang:mem (0x110, FIELD_DFLOAT, 1)
    end
end

This will replace spin jumping with a boomerang, but only for player 1. Player 2 will function normally.

Documentation

Constants Description
inputs2.UP Value for a key that is up.
inputs2.PRESS Value for a key that was just pressed.
inputs2.HOLD Value for a key that is currently held down.
inputs2.RELEASE Value for a key that was just released.
Fields Description
inputs2.state[playerIndex][keyname] This field contains the value for a key (one of the above constants). Args:
playerIndex - The player pressing the key. Always 1 or 2.
keyname - a string containing the name of the key. All letters are lowercase.
inputs2.locked[playerIndex][keyname] This field is a boolean that can lock a key if true. Args:
playerIndex - The player pressing the key. Always 1 or 2.
keyname - a string containing the name of the key. All letters are lowercase. Use "all" to lock all keys.
inputs2.debug This field is a boolean that causes all the key states to be drawn to the screen if true.