Commander.lua (Merge of command and commando)

Share and discuss custom LunaLua code and content packs for SMBX2.
User avatar
Yoshi021
Gold Yoshi Egg
Gold Yoshi Egg
Posts: 636
Joined: Thu Jan 21, 2016 9:06 pm
Flair: :)

Commander.lua (Merge of command and commando)

Postby Yoshi021 » Sun Jun 28, 2020 10:52 pm

Hello! Commander.lua is a library aim at helping you read inputs and organize the information easily and conveniently to use!

Documentation
As of now, commander can read inputs from player inputs and keyboard inputs.

Creating a command key
To create a command key, you simply use the commmander.register function. You must supply a table like this:

Code: Select all

local command = require("command")

-- Register your keys
command.register{
  [1] = { -- This represents the command keys for input 1
    up ={ID = 1, name = "up"},  -- You can now access this input by doing commander[1].up
    down = {ID = 1, name = "down"},    
    left = {ID = 1, name = "left"},
    right = {ID = 1, name = "right"},
    jump = {ID = 1, name = "jump"},  
    dash = {ID = 1, name = "run"},   -- You can now access this input by doing commander[1].dash. Note how its inputs are based off the run key.
    pause = 32,  -- 32 is the vk code for the space key
    },
    [2] = {  -- This represents the command keys for input 2
      up = {ID = 2, name = "up"},  -- You can now access this input by doing commander[2].up
      down = {ID = 2, name = "down"},    
      left = {ID = 2, name = "left"},
      right = {ID = 2, name = "right"},
      jump = {ID = 2, name = "jump"},
      dash = {ID = 2, name = "run"},
      pause = 20,  -- 20 is the vk code for the caps lock key    
    },
}
How to register a player key

Code: Select all

  -- name has to be "up", "down", "left", "right", "run", "altRun", "jump", "altJump", "dropItem", "pause"
  myKey = {name = "up"}  -- This is the bare minimum for a player key. It will assume player 1 inputs
  myKey = {name = "up, ID = 1}  -- Use the ID field to specify which player you want the inputs from. Use 1 for players, and 2 for player 2
  myKey = {name = "up", ID = 1, mode = "keys"} -- By default mode is "rawKeys". Set the mode to "keys if you want to. The difference is that keys is affected when disabling player inputs and note that run is activated most of the time when pressing altRun.
  myKey = {name = "up", ID = 1, mode = "keys", type = commander.TYPE_PLAYERKEY} -- You can use type to specify that its a player me, but by default its assumed to be.
How to register a keyboard key

Code: Select all

  myKey = 32  -- Just putting a number will make the script assume its a keyboard key
  myKey = {ID= 32, type= TYPE_KEYBOARD}  -- You can also specify a keyboard key like this
Using a commander key
A commander key has four different keys you can access.
state To be used with KEYS_PRESSED, KEYS_RELEASED, KEYS_DOWN, KEYS_UP.
time Measures how long a key has been held or released. Counts up when pressed, and counts down when released. Gets set to 1 or -1 when a key is pressed or released respectively. Example:

Code: Select all

  local v = commander[1].myCustomKey.time
  v == 30  -- if the key is held for exactly 30 frames
  v > 30  -- if the key is held for longer 30 frames
  v == -30  -- if the key is not held for exactly 30 frames
  v < -30  -- if the key is not held for longer 30 frames
  v == 1   -- Equivalent to checking if a key is KEYS_PRESSED
  v == -1  -- Equivalent to checking if a key is KEYS_RELEASED
prevstate The state of the key in the previous frame
time The time in the previous frame



Download
Commander.lua



TL;DR this library allows you to get standard SMBX inputs, give it a nickname and get the state, and how long the key was held and released.
Please report any bugs you find and feel free to leave suggestions!
Last edited by Yoshi021 on Thu Jul 02, 2020 10:16 am, edited 1 time in total.
"Going to University is FUN!"
DOWNLOAD THE SMBX LEVEL PLAYER
CHECK OUT MY NPC PACK

Join the SMBX Episode Project Discord Server
Image

Join the SMBX 38A Discord!
Image

Join the CodeHaus Discord!
Image
Image

User avatar
arhi998
Cheep-Cheep
Cheep-Cheep
Posts: 10
Joined: Sun Oct 21, 2018 5:00 am
Flair: Hi everyone! i'm just a normal dude playing smbx.

Re: Command.lua and Commando.lua

Postby arhi998 » Mon Jun 29, 2020 3:03 am

Nice! Could be very useful for beginners too. (like me)
Spoiler: show
Image
Image
Image
Image

User avatar
Taycamgame
Gold Yoshi Egg
Gold Yoshi Egg
Posts: 1392
Joined: Mon Jun 19, 2017 11:35 am
Flair: Stargard
Contact:

Re: Command.lua and Commando.lua

Postby Taycamgame » Mon Jun 29, 2020 7:19 am

These are both certainly going to be useful, though I wouldn't be surprised if people typically make more use of Commando due to the added functionality of allowing any key to be an input!
Official Level Reviewer (My Gold Yoshi Egg rank replaced the level reviewer icon, but i am still a level reviewer).
Image
Image
Image
Image
Check out the World Map Service that i host:
viewtopic.php?p=316733#p316733
Check out the projects i support:
Spoiler: show
ImageImage
Image
Image
Quotes: show
xDestroy wrote:
Wellington Games wrote:Taycamgame, I know how to take screenshots in the SMBX.
https://nsmbx.proboards.com/
------
Tower Mario Bros.

User avatar
Novarender
Bit
Bit
Posts: 132
Joined: Sat Aug 06, 2016 6:59 pm
Flair: Whoa

Re: Command.lua and Commando.lua

Postby Novarender » Mon Jun 29, 2020 10:55 am

So did you fix the issue of not being able to detect key releases from non-player inputs?
I believe and I accept Jesus Christ as my Lord and Savior. If you do, put this in your signature.

Hagrid: "You're a wizard, Harry!"
Harry: "You're a hairy wizard!"

The FitnessGram Pacer Test is a multistage aerobic capacity test that progressively gets more difficult as it continues. The 20 meter pacer test will begin in 30 seconds. Line up at the start. The running speed starts slowly but gets faster each minute after you hear this signal bodeboop.

FYRENOVA IS A FAKE!

User avatar
Yoshi021
Gold Yoshi Egg
Gold Yoshi Egg
Posts: 636
Joined: Thu Jan 21, 2016 9:06 pm
Flair: :)

Re: Command.lua and Commando.lua

Postby Yoshi021 » Mon Jun 29, 2020 12:16 pm

Yes!
"Going to University is FUN!"
DOWNLOAD THE SMBX LEVEL PLAYER
CHECK OUT MY NPC PACK

Join the SMBX Episode Project Discord Server
Image

Join the SMBX 38A Discord!
Image

Join the CodeHaus Discord!
Image
Image

User avatar
Yoshi021
Gold Yoshi Egg
Gold Yoshi Egg
Posts: 636
Joined: Thu Jan 21, 2016 9:06 pm
Flair: :)

Re: Commander.lua (Merge of command and commando)

Postby Yoshi021 » Thu Jul 02, 2020 10:16 am

I merged both libraries into one. Now you don't have to pick one over the other!
"Going to University is FUN!"
DOWNLOAD THE SMBX LEVEL PLAYER
CHECK OUT MY NPC PACK

Join the SMBX Episode Project Discord Server
Image

Join the SMBX 38A Discord!
Image

Join the CodeHaus Discord!
Image
Image


Return to “LunaLua”

Who is online

Users browsing this forum: Eclipsed and 2 guests