Rixi's lua draft collection

Share and discuss custom LunaLua code and content packs for SMBX2.

Moderator: Userbase Moderators

Rixitic
Spike
Spike
Posts: 275
Joined: Sat Dec 12, 2015 1:00 am
Contact:

Rixi's lua draft collection

Postby Rixitic » Fri Jul 19, 2024 3:22 am

Occasionally I'll write something for a project that I realize could be useful as a standalone library, but then I never actually get it to a release-worthy state with all the necessary preparations -- writing documentation, cleaning up the comments and debug calls, preparing a sample level and sample code, etc.

At some point, it's better to just put the code out there in its current state than keep sitting on them, right? So, as I did with the Terraria NPC pack, here's three lua libraries I'm releasing in their current state! I'll post more whenever they happen.

Everything in this thread comes as-is with no guarantees of support or updates, but they worked the last time I checked and if there are any issues they shouldn't need much work to fix up. And if someone wants to finish and package up any of these as proper releases, go for it!


shuffledQueues.lua
A library for managing randomly-shuffled lists with additional handling for avoiding repeated values. Good for boss attack queues, card decks... I guess if you want to make a roguelike in SMBX you could use it for that too?


cgfxBridge.lua
You know how you can use a folders.ini file to tell the editor which subfolders your episode's custom graphics and config files are in? Well, you can override that file for individual levels. Doing so can make assets show up properly in the editor even if they're not in the level's resource folder, but those graphics and configs still won't be applied when playing the level.

cgfxBridge fixes that to an extent by comparing the episode and level folders.ini files, loading images and txt files from any unique paths listed, and applying them to Graphics.sprites.npc, Block.config, etc. This means that if you have a tileset you'll be using in multiple levels but don't want to make all of those assets episode-wide resprites, you can just store them in one place and have those levels share them! As of version 0.4, it also supports replacements for SMBX 1.3 sound effects (the ones in this list here.)

Note that this only changes things on the in-game side, the current limits of folders.ini still apply within the editor; you'll still need to include, for example, copies of any custom tileset inis in the level's resource folder.

Older versions:
0.4
0.3.5


customAssetHelper.lua
Say you want to set up a type of custom asset used in your episode, like hats or inventory items. You could just store the assets' data as hardcoded nested tables, but you'd prefer to set it up within SMBX's file-and-folder workflow so that things are a bit more collaboration-friendly.

This library lets you define custom asset types that work similarly to costumes, with each asset of that type getting its own folder and specific files to check for within that folder; so, for example, your episode might look something like this:

  • ExampleEpisode
    • danielcraig
      • danielcraig.png
      • luna.lua
    • danielcraig.lvlx
    • FINALBOSS
    • FINALBOSS.lvlx
    • hats
      • ribbon
        • config.json
        • above.png
        • below.png
        • icon.png
      • beret
        • config.json
        • above.png
        • below.png
        • icon.png
      • aviator
        • config.json
        • above.png
        • below.png
        • icon.png
    • luna.lua

Then in your code you can do this:

Code: Select all

local customAssetHelper = require("customAssetHelper")

local hatData = customAssetHelper.importAssets{
        folder = "hats",
        prefix = "Hat",
        images = {"above","below","icon"}
}

function onStart()
        Misc.dialog(HAT_AVIATOR, HAT_RIBBON, "", hatData)
end

delightfulSoundTest.lua
Someone on Discord asked for help with making a sound test, so I threw together this library from the one I made for Delightful Enhanced.

Here's footage of the original in action, which doesn't want to work with the youtube tag for some reason.


respawnDoors.lua
Fair warning, as of writing this I haven't tested this library at all!

Today I tried to help someone set up reset doors only to find that the reset doors library listed on the assets index is outdated to the point of being unusable in Beta 5. Then I realized that a modern library for the functionality could just piggyback off of respawnRooms.lua, so I threw this together. Then it turned out the person I was trying to help just needed to respawn a koopa so I recommended they just keep it simple and use an egg-plant.

But yeah, this library requires respawnRooms. Once you've got both set up in your episode/level, you should be able to just set up the rooms like normal and add this to your level's code:

Code: Select all

local respawnDoors = require("respawnDoors")
respawnDoors.registerIDs{2,7,16} --replace with the warp ID(s) you want to work as reset doors

-- Uncomment both of the following lines to disable respawning on death, in case you want your registered warps to be the only ways to respawn in the level
-- local respawnRooms = require("respawnRooms")
-- respawnRooms.respawnSettings.enabled = false
Last edited by Rixitic on Mon Aug 18, 2025 4:08 am, edited 6 times in total.

Rixitic
Spike
Spike
Posts: 275
Joined: Sat Dec 12, 2015 1:00 am
Contact:

Re: Rixi's lua draft collection

Postby Rixitic » Tue Sep 17, 2024 11:51 am

I've updated cgfxBridge.lua to fix a number of bugs, make the library a bit more configurable, and improve commenting and clarity in some places. It also now needs to be run manually with cgfxBridge.apply() after importing it; see the added instructions at the start of the library for more info. Shout-out to Chipss for the thorough testing and being super patient during the troubleshooting process!

Here's a quick link for convenience, but the link in the OP points to v.0.3.5 as well.

I'll see about writing a docs page for folders.ini in the near(ish?) future.

Rixitic
Spike
Spike
Posts: 275
Joined: Sat Dec 12, 2015 1:00 am
Contact:

Re: Rixi's lua draft collection

Postby Rixitic » Tue May 27, 2025 8:18 pm

Another quick update: I wrote the folders.ini docs entry a while ago and cgfxBridge v0.4, which now properly supports sound effect replacements (at least for the original 91 SMBX 1.3 sounds, not the extended ones.)

Once again, providing those links for convenience but the original post has been updated to include them as well.

Rixitic
Spike
Spike
Posts: 275
Joined: Sat Dec 12, 2015 1:00 am
Contact:

Re: Rixi's lua draft collection

Postby Rixitic » Wed Jun 04, 2025 2:34 pm

New library:

delightfulSoundTest.lua
Someone on Discord asked for help with making a sound test, so I threw together this library from the one I made for Delightful Enhanced.

Here's footage of the original in action, which doesn't want to work with the youtube tag for some reason.

Rixitic
Spike
Spike
Posts: 275
Joined: Sat Dec 12, 2015 1:00 am
Contact:

Re: Rixi's lua draft collection

Postby Rixitic » Sat Aug 02, 2025 4:14 pm

New library:

respawnDoors.lua
Fair warning, as of writing this I haven't tested this library at all!

Today I tried to help someone set up reset doors only to find that the reset doors library listed on the assets index is outdated to the point of being unusable in Beta 5. Then I realized that a modern library for the functionality could just piggyback off of respawnRooms.lua, so I threw this together. Then it turned out the person I was trying to help just needed to respawn a koopa so I recommended they just keep it simple and use an egg-plant.

But yeah, this library requires respawnRooms. Once you've got both set up in your episode/level, you should be able to just set up the rooms like normal and add this to your level's code:

Code: Select all

local respawnDoors = require("respawnDoors")
respawnDoors.registerIDs{2,7,16} --replace with the warp ID(s) you want to work as reset doors

-- Uncomment both of the following lines to disable respawning on death, in case you want your registered warps to be the only ways to respawn in the level
-- local respawnRooms = require("respawnRooms")
-- respawnRooms.respawnSettings.enabled = false

Rixitic
Spike
Spike
Posts: 275
Joined: Sat Dec 12, 2015 1:00 am
Contact:

Re: Rixi's lua draft collection

Postby Rixitic » Mon Aug 18, 2025 3:09 am

cgfxBridge.lua v0.5, because for some reason I never made it account for files in the level's resource folder??? It seemed to support them in most levels in the project I previously used it for, but now the library explicitly gives them top priority over any graphics and configs applied from folders.ini files.

This does have the potential to break things considerably depending on how your project is organized, so I've kept the links to v0.4 and v0.3.5 in the OP just in case.

While I'm here, a quick note about a feature cgfxBridge has had for a while now: the library will load and apply not just the full contents of folders listed in the folders.ini file, but individual filepaths as well. The editor won't do the same, however, so while this feature makes it much easier to selectively apply graphics from a set stored in the same folder, using it will mean the in-editor graphics will no longer reflect the in-game ones. Hopefully in future updates to SMBX2 the editor can be made to support that and/or we'll get a more robust successor to folders.ini that is automatically applied at runtime.

EDIT:
and apparently smbx is case-insensitive but this library wasn't, so 0.5.1


Return to “LunaLua”

Who is online

Users browsing this forum: No registered users and 4 guests

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari