rooms.lua - Quick respawn & Celeste-styled rooms (v1.2 update)

Share and discuss custom LunaLua code and content packs for SMBX2.
User avatar
MrDoubleA
Bit
Bit
Posts: 134
Joined: Mon Aug 20, 2018 7:02 am
Contact:

rooms.lua - Quick respawn & Celeste-styled rooms (v1.2 update)

Postby MrDoubleA » Fri Feb 21, 2020 9:54 am

This is a library which lets you have quick respawn and Celeste-styled rooms. You can even have no rooms for only quick respawn, if you so please.
Gifs & Screenshots: show
NPC reset
Image
Room transition + block reset
Image
Event timer reset + star coins reset + "diamond sweep" respawn effect
Image

In PGE
Image
Options
Image
Download & Installation: show
You can download it here.

To load it in, put this in your luna.lua file:

Code: Select all

local rooms = require("rooms")
To create a room in the editor, make a layer named "Rooms" and put some bits of quicksand liquid which are the size of the rooms you want. In-game, they'll act as the actual rooms.

At the bottom of the rooms.lua file, there are a bunch of settings for you to tweak.

There are also two global events that you can use: onRoomEnter(roomIdx), and onReset(fromRespawn).
Older Versions: show
The current version of rooms.lua is v1.2, but here are some older download links.
rooms.lua v1.1.1
rooms.lua v1.1
rooms.lua v1.0
Have fun, but please give credit if you use it!
Last edited by MrDoubleA on Mon Mar 30, 2020 10:09 am, edited 5 times in total.
Hi. I'm not very active on the forums.
(MrDoubleA#3124 on Discord)

rooms.lua - Quick respawn & Celeste-styled rooms
simpleLayerMovement.lua - For all your custom layer movement needs!
MrDoubleA's NPC Pack
Are you a mouse?
I support: show
Image
Image
Image
Image

Enjl
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 8873
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Orphion Egamalenitar Osmos IV, Esq.

Re: rooms.lua - Quick respawn & Celeste-styled rooms

Postby Enjl » Fri Feb 21, 2020 10:11 am

Does it invoke a custom lua event when a reset occurs or a room is entered? Would be helpful if people wanna reset their lua routines too. Sadly moving layers will always be a NIGHTMARE.
Look into registerCustomEvent if you wanna provide onEnter and onReset events.
Ideas are useless if you can't make them real.
Image

All my assets from packs and episodes are free to use for non-Novaverse levels and projects, as long as proper credit is given.

User avatar
MrDoubleA
Bit
Bit
Posts: 134
Joined: Mon Aug 20, 2018 7:02 am
Contact:

Re: rooms.lua - Quick respawn & Celeste-styled rooms

Postby MrDoubleA » Fri Feb 21, 2020 10:14 am

Enjl wrote:
Fri Feb 21, 2020 10:11 am
Does it invoke a custom lua event when a reset occurs or a room is entered? Would be helpful if people wanna reset their lua routines too. Sadly moving layers will always be a NIGHTMARE.
Look into registerCustomEvent if you wanna provide onEnter and onReset events.
I didn't know about registerCustomEvent, thanks! The makeshift solution I used is that there's a bunch of tables that you can put your functions in. I'll update it soon.

Edit: The download link's been updated. Adds two events (onRoomEnter(roomIdx) and onRespawnReset()), adds a new option, and fixes the transition between rooms that are in different sections.
Hi. I'm not very active on the forums.
(MrDoubleA#3124 on Discord)

rooms.lua - Quick respawn & Celeste-styled rooms
simpleLayerMovement.lua - For all your custom layer movement needs!
MrDoubleA's NPC Pack
Are you a mouse?
I support: show
Image
Image
Image
Image

User avatar
Locus
Cheep-Cheep
Cheep-Cheep
Posts: 17
Joined: Sun Mar 17, 2019 12:47 pm
Flair: Procrastination

Re: rooms.lua - Quick respawn & Celeste-styled rooms

Postby Locus » Fri Feb 21, 2020 3:02 pm

If I define the rooms with quicksand regions the quicksand physics still work and don't actually make me move as I would when I'm not stuck in it.
edit: I apologize I wasn't paying careful attention and forgot to name the layer
edit 2: I don't know if this happens for others but once you respawn the music stops. If a P-switch is pressed though it resets.

User avatar
MrDoubleA
Bit
Bit
Posts: 134
Joined: Mon Aug 20, 2018 7:02 am
Contact:

Re: rooms.lua - Quick respawn & Celeste-styled rooms

Postby MrDoubleA » Mon Mar 02, 2020 3:35 pm

Locus wrote:
Fri Feb 21, 2020 3:02 pm
If I define the rooms with quicksand regions the quicksand physics still work and don't actually make me move as I would when I'm not stuck in it.
edit: I apologize I wasn't paying careful attention and forgot to name the layer
edit 2: I don't know if this happens for others but once you respawn the music stops. If a P-switch is pressed though it resets.
About the last bit: you need to play music through lua if you want it not to stop after dying. Here's a bit of code to play the section music through lua. I may include a built-in fix in the next version, though!
Hi. I'm not very active on the forums.
(MrDoubleA#3124 on Discord)

rooms.lua - Quick respawn & Celeste-styled rooms
simpleLayerMovement.lua - For all your custom layer movement needs!
MrDoubleA's NPC Pack
Are you a mouse?
I support: show
Image
Image
Image
Image

User avatar
thegameseum
Mega Mole
Mega Mole
Posts: 282
Joined: Fri Aug 10, 2018 11:26 am
Flair: non binary (they, them)
Contact:

Re: rooms.lua - Quick respawn & Celeste-styled rooms

Postby thegameseum » Mon Mar 02, 2020 10:03 pm

Don't have my pc with me now, but if you collect a checkpoint, will it automatically start respawning you there?
Image Image
walker guy

I believe and I accept Jesus Christ as my Lord and Savior. If you do, put this in your signature.

(GENERATION 30: The first time you see this, copy it into your sig on any forum and add 1 to the generation. Social experiment.)

I support:
Spoiler: show
ImageImage
Image

User avatar
Chipss
Rex
Rex
Posts: 84
Joined: Fri Jul 25, 2014 9:47 pm
Contact:

Re: rooms.lua - Quick respawn & Celeste-styled rooms

Postby Chipss » Tue Mar 03, 2020 12:58 am

thegameseum wrote:
Mon Mar 02, 2020 10:03 pm
Don't have my pc with me now, but if you collect a checkpoint, will it automatically start respawning you there?
Yes
Best way to contact me: Chipss#9594 on Discord

Check out my project: viewtopic.php?f=90&t=25639

User avatar
Wiimeiser
Bit
Bit
Posts: 149
Joined: Mon Jun 24, 2019 4:36 am
Flair: What?

Re: rooms.lua - Quick respawn & Celeste-styled rooms

Postby Wiimeiser » Thu Mar 05, 2020 7:49 am

Transitions don't work, the game spams nil value errors and the camera doesn't respect the room boundaries. The respawning does work, but rooms are inoperable unless I set rooms.transitionType = rooms.TRANSITION_TYPE_NONE. It appears to be a conflict, but this is the only custom LUA I'm using in this test episode, so if that's true, then it's with something in the base game.

This is the line the error points to:
if rooms.transitionType ~= rooms.TRANSITION_TYPE_NONE and rooms.rooms[collided].section == rooms.rooms[rooms.currentRoomIndex].section then
It's probably just me but that's very weirdly worded. What exactly is it trying to do? To me it looks like it's redirecting the other two transition types to a conditional branch that tries to pull the room ID out of thin air and since non-integers can't be converted to integers it throws an error. Also, if I try to put a function involving onRoomEnter() and don't have it exactly as I posted, it errors on startup and completely breaks all custom LUA. If I put a number there it expects <name> or ... near the number, if I put a ... there it says the number is malformed.

Also, function onRespawnReset is also broken. If I use the following code:
function onRespawnReset
player:transform(CHARACTER_BOWSER);
player.speedX = -1
end
it expects a colon between "player" and the colon, but if I do that, it says "unexpected symbol". So I have to conclude that this code is incompatible with LunaLUA itself. Someone please send me a sample level so I can see what I'm dong wrong...

Enjl
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 8873
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Orphion Egamalenitar Osmos IV, Esq.

Re: rooms.lua - Quick respawn & Celeste-styled rooms

Postby Enjl » Thu Mar 05, 2020 8:55 am

Of course that code is incompatible with lua. You haven't written proper lua, after all. Remember that, to define a function, you need to put the parentheses afterwards. Some examples:
function onTick()
function onRespawnReset()

Your other issues also sound like syntax errors on your end. It would help greatly if you could post your entire code instead of snippits.
Ideas are useless if you can't make them real.
Image

All my assets from packs and episodes are free to use for non-Novaverse levels and projects, as long as proper credit is given.

User avatar
MrDoubleA
Bit
Bit
Posts: 134
Joined: Mon Aug 20, 2018 7:02 am
Contact:

Re: rooms.lua - Quick respawn & Celeste-styled rooms

Postby MrDoubleA » Thu Mar 05, 2020 9:32 am

Wiimeiser wrote:
Thu Mar 05, 2020 7:49 am
Transitions don't work, the game spams nil value errors and the camera doesn't respect the room boundaries. The respawning does work, but rooms are inoperable unless I set rooms.transitionType = rooms.TRANSITION_TYPE_NONE. It appears to be a conflict, but this is the only custom LUA I'm using in this test episode, so if that's true, then it's with something in the base game.

This is the line the error points to:
if rooms.transitionType ~= rooms.TRANSITION_TYPE_NONE and rooms.rooms[collided].section == rooms.rooms[rooms.currentRoomIndex].section then
It's probably just me but that's very weirdly worded. What exactly is it trying to do? To me it looks like it's redirecting the other two transition types to a conditional branch that tries to pull the room ID out of thin air and since non-integers can't be converted to integers it throws an error. Also, if I try to put a function involving onRoomEnter() and don't have it exactly as I posted, it errors on startup and completely breaks all custom LUA. If I put a number there it expects <name> or ... near the number, if I put a ... there it says the number is malformed.

Also, function onRespawnReset is also broken. If I use the following code:
function onRespawnReset
player:transform(CHARACTER_BOWSER);
player.speedX = -1
end
it expects a colon between "player" and the colon, but if I do that, it says "unexpected symbol". So I have to conclude that this code is incompatible with LunaLUA itself. Someone please send me a sample level so I can see what I'm dong wrong...
About the first error: are you going from an area with no room and then entering a room? If so, I'll fix that in the next version. If not, please show the actual error.
Hi. I'm not very active on the forums.
(MrDoubleA#3124 on Discord)

rooms.lua - Quick respawn & Celeste-styled rooms
simpleLayerMovement.lua - For all your custom layer movement needs!
MrDoubleA's NPC Pack
Are you a mouse?
I support: show
Image
Image
Image
Image

User avatar
Wiimeiser
Bit
Bit
Posts: 149
Joined: Mon Jun 24, 2019 4:36 am
Flair: What?

Re: rooms.lua - Quick respawn & Celeste-styled rooms

Postby Wiimeiser » Thu Mar 05, 2020 4:24 pm

I'm starting in section 0, which has no rooms, then going to section 4, which does. Is that the problem?

The second error still concerns me, though...

User avatar
MrDoubleA
Bit
Bit
Posts: 134
Joined: Mon Aug 20, 2018 7:02 am
Contact:

Re: rooms.lua - Quick respawn & Celeste-styled rooms

Postby MrDoubleA » Fri Mar 06, 2020 1:37 pm

Wiimeiser wrote:
Thu Mar 05, 2020 4:24 pm
I'm starting in section 0, which has no rooms, then going to section 4, which does. Is that the problem?

The second error still concerns me, though...
That is the problem (and it'll be fixed in the next update), and the second issue was already fixed by Enjl:
Enjl wrote:
Thu Mar 05, 2020 8:55 am
Of course that code is incompatible with lua. You haven't written proper lua, after all. Remember that, to define a function, you need to put the parentheses afterwards. Some examples:
function onTick()
function onRespawnReset()

Your other issues also sound like syntax errors on your end. It would help greatly if you could post your entire code instead of snippits.
Hi. I'm not very active on the forums.
(MrDoubleA#3124 on Discord)

rooms.lua - Quick respawn & Celeste-styled rooms
simpleLayerMovement.lua - For all your custom layer movement needs!
MrDoubleA's NPC Pack
Are you a mouse?
I support: show
Image
Image
Image
Image

User avatar
Wiimeiser
Bit
Bit
Posts: 149
Joined: Mon Jun 24, 2019 4:36 am
Flair: What?

Re: rooms.lua - Quick respawn & Celeste-styled rooms

Postby Wiimeiser » Fri Mar 06, 2020 4:57 pm

Starting in the four-rooms test where the four rooms are does work, so I can now confirm that's what I need to do.

Regarding the code snippet where I tried to turn the player into Bowser, that was the entire code I was trying to run. Adding the parentheses made it work, so I was stupid there. But I can't figure out what I'm doing wrong the onRoomEnter part. If I set it to "function onRoomEnter()" it works but triggers for every room.

If you want the test luna.lua for the test level, here it is:
local rooms = require("rooms")

function onRespawnReset()
player:transform(CHARACTER_BOWSER);
player.speedX = -1
end

function onRoomEnter()
player:transform(CHARACTER_SNAKE);
end

User avatar
MrDoubleA
Bit
Bit
Posts: 134
Joined: Mon Aug 20, 2018 7:02 am
Contact:

Re: rooms.lua - Quick respawn & Celeste-styled rooms

Postby MrDoubleA » Fri Mar 06, 2020 7:12 pm

Yes, onRoomEnter triggers when entering any room. That is what it's supposed to do, after all. If you want to make it only happening when entering a certain room, you can do something like this:
function onRoomEnter(roomIdx)
if roomIdx == X then
Y
end
end
Where X is the index of the room and Y is the code to be run. (Note that you don't replace roomIdx at all)
Hi. I'm not very active on the forums.
(MrDoubleA#3124 on Discord)

rooms.lua - Quick respawn & Celeste-styled rooms
simpleLayerMovement.lua - For all your custom layer movement needs!
MrDoubleA's NPC Pack
Are you a mouse?
I support: show
Image
Image
Image
Image

User avatar
Wiimeiser
Bit
Bit
Posts: 149
Joined: Mon Jun 24, 2019 4:36 am
Flair: What?

Re: rooms.lua - Quick respawn & Celeste-styled rooms

Postby Wiimeiser » Fri Mar 06, 2020 9:46 pm

Okay, that does work. Now whenever I enter room 3 I turn into Snake, and whenever I die and respawn I turn into Bowser.

User avatar
MrDoubleA
Bit
Bit
Posts: 134
Joined: Mon Aug 20, 2018 7:02 am
Contact:

Re: rooms.lua - Quick respawn & Celeste-styled rooms (v1.1 update)

Postby MrDoubleA » Wed Mar 11, 2020 5:24 pm

Version 1.1 has been released, and there's been a ton of under the hood changes (the entire respawn reset system has been overhauled, meaning a bunch of jank has been fixed), but there a few changes that'll hopefully help the people using this. Here's a little "change log", even if it is by no means complete:
Change Log: show
- A bunch of massive behind the scenes changes
- Music will no longer stop on dying
- P-Switches now work properly on resetting (and no longer completely destroys levels)
- Mega mushrooms and starmans now reset properly
- Cross-section respawning now works properly
- Added an option to create a pseudo "checkpoint" on entering a section
- Added an option to reset unsaved star coins
- Added support for timer.lua
Hi. I'm not very active on the forums.
(MrDoubleA#3124 on Discord)

rooms.lua - Quick respawn & Celeste-styled rooms
simpleLayerMovement.lua - For all your custom layer movement needs!
MrDoubleA's NPC Pack
Are you a mouse?
I support: show
Image
Image
Image
Image

User avatar
Wiimeiser
Bit
Bit
Posts: 149
Joined: Mon Jun 24, 2019 4:36 am
Flair: What?

Re: rooms.lua - Quick respawn & Celeste-styled rooms (v1.1 update)

Postby Wiimeiser » Thu Mar 12, 2020 3:08 am

Two further things are broken:
-The check for the music.ini file causes an error on startup. The section is "Get music paths for vanilla music" and the line it points to is:
vanillaMusicPaths[w._header] = v.. "\\".. w.file
I've had to comment out the entire thing there to stop the error appearing, but I don't know if that will break anything...

-Enabling this breaks the reserve box blocks (737 and 739) with an error about the game trying to compare a nil with a number on line 13, which is on this line:
if item < 1000 and item > 0 then return end
Then the block just spawns the NPC like a regular block does, instead of putting it in the reserve box like it's supposed to. This seems to suggest NPC IDs are being converted to nil values by the rooms script somewhere...

User avatar
MrDoubleA
Bit
Bit
Posts: 134
Joined: Mon Aug 20, 2018 7:02 am
Contact:

Re: rooms.lua - Quick respawn & Celeste-styled rooms (v1.1.1 update)

Postby MrDoubleA » Fri Mar 13, 2020 7:00 pm

Sorry for the hiccups! The download link has been updated to fix all the bugs that have been reported to me.
Hi. I'm not very active on the forums.
(MrDoubleA#3124 on Discord)

rooms.lua - Quick respawn & Celeste-styled rooms
simpleLayerMovement.lua - For all your custom layer movement needs!
MrDoubleA's NPC Pack
Are you a mouse?
I support: show
Image
Image
Image
Image

MarioBrosCreeper
Goomba
Goomba
Posts: 4
Joined: Sat May 06, 2017 6:15 am

Re: rooms.lua - Quick respawn & Celeste-styled rooms (v1.1.1 update)

Postby MarioBrosCreeper » Wed Mar 18, 2020 5:52 pm

I love the quick respawn feature! It's great to create Kaizo-like levels! :D
However, some things don't reset. Quick respawn does not reset unlocked doors, blocks moved with an event and Event-timers don't work properly.
When I make an event activate another event in 3 seconds and die after 2 seconds, when respawning the new event gets triggered at 1 second.
Conveyor Belts don't reset as well when changed direction and sometimes NPCs such as keys, carryable blocks or disco shells just despawn.
Also, Parakoopas are janky. Their movement is completely different on the first try.

User avatar
MrDoubleA
Bit
Bit
Posts: 134
Joined: Mon Aug 20, 2018 7:02 am
Contact:

Re: rooms.lua - Quick respawn & Celeste-styled rooms (v1.1.1 update)

Postby MrDoubleA » Fri Mar 20, 2020 9:31 am

MarioBrosCreeper wrote:
Wed Mar 18, 2020 5:52 pm
I love the quick respawn feature! It's great to create Kaizo-like levels! :D
However, some things don't reset. Quick respawn does not reset unlocked doors, blocks moved with an event and Event-timers don't work properly.
When I make an event activate another event in 3 seconds and die after 2 seconds, when respawning the new event gets triggered at 1 second.
Conveyor Belts don't reset as well when changed direction and sometimes NPCs such as keys, carryable blocks or disco shells just despawn.
Also, Parakoopas are janky. Their movement is completely different on the first try.
Alright, so let's explain all these: unfortunately, there's not much that can be done to make layers moved through events reset at the moment, so if you want moving layers you'll just have to do it through lua. Thanks for the report on locked doors and conveyor belts not resetting, and blocks should reset (are you sure you're using the latest version?). And, yes, NPCs and blocks reset when changing rooms, so they will disappear if being held.
Hi. I'm not very active on the forums.
(MrDoubleA#3124 on Discord)

rooms.lua - Quick respawn & Celeste-styled rooms
simpleLayerMovement.lua - For all your custom layer movement needs!
MrDoubleA's NPC Pack
Are you a mouse?
I support: show
Image
Image
Image
Image


Return to “LunaLua”

Who is online

Users browsing this forum: Dragon0307 and 1 guest