Heldlayer.lua: Layer only moves when you hold an item! (V 1.2)

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

Moderator: Userbase Moderators

MarioChallengerX2
Buster Beetle
Buster Beetle
Posts: 89
Joined: Sat Dec 31, 2022 4:34 pm
Pronouns: he/him

Heldlayer.lua: Layer only moves when you hold an item! (V 1.2)

Postby MarioChallengerX2 » Wed Sep 27, 2023 9:55 pm

From Send Your Regrets to the Czar:


https://youtu.be/ksMHt293O3A?si=gmdH8RieTwcIyJLz&t=575

I don't know if MiracleWater made this ASM originally or if someone else made it.

BEFORE YOU CONTINUE:
Spoiler: show
This is a part of a project I'm working on, the Layertoy project! The Layertoy project is a series of libraries dedicated to niche layer movement scripting. Most of the Layertoy scripts I develop will be based on Layer 2 mechanics from SMW and SMW ROM Hacks! Or some custom ideas, if anyone would like to see an idea!

NOTE ABOUT REQUESTS: I will put them on my list but I won't do the code immediately right away, unless it's urgent and really easy to develop. You can check what Layertoy projects I'll be developing on my forum signature!!
https://imgur.com/a/uU94ivY
Anyway, what's this? This is a library that lets you control the movement of a layer whenever you're holding a specific item.

How to use the library:
Spoiler: show
Create a layer in the level named riselayer and put this line of code in your luna.lua file:

Code: Select all

local heldlayer = require("heldlayer
Variables:
holdlayer.tickspeed: The total amount of ticks that the layer can move for.

Code: Select all

holdlayer.layerspeeds = {
    [1] = 1, -- rising 
    [-1] = -1 -- falling
}
Change those values that are not in brackets to set the speed. They need to be the same value for the movement to be synchronized.


holdlayer.triggertable: If you've read or used Stickykeys.lua before, it works the exact same way here. This is a table where you can register NPC ids that when you hold them, they affect the layer.

Registering an NPC is simple:

Code: Select all

holdlayer.triggertable[114] = true -- registers the red koopa shell
holdlayer.setverticalorder(newvalue)

A function for inverting the negative y and positive y movement of the layer without changing the values manually.

For example, holding an item when it's set to true will make the layer go up.

But if it's set to false, the layer will go down.

In order to avoid any weird edge case or issues with this variable, you can't invert the layer direction until it's back to its origin point.

NOTE ABOUT TIMERS:

Since layers have no definition of position, a timer that increments every tick and variables with a positive and negative value that is the same is used here in order to mimick a definition of position.


And the download link is right here!
https://drive.google.com/file/d/1mpX4-5 ... sp=sharing

Added in 25 minutes 36 seconds:
Version 1.1! A quick update that fixes a bug:

Bug in question was the ticktimer wouldn't change if you're holding an item not registered in the triggertable. But it's fixed now to work properly.

Version 1.1.1 is here! Help from Emral in order to make this code more readable! (TYSM and huge props to him!)
Also changed the layerspeeds variable!

MarioChallengerX2
Buster Beetle
Buster Beetle
Posts: 89
Joined: Sat Dec 31, 2022 4:34 pm
Pronouns: he/him

Re: Heldlayer.lua: Layer only moves when you hold an item! (V 1.2)

Postby MarioChallengerX2 » Thu Sep 28, 2023 11:15 am

UPDATE AGAIN:
V 1.2 is here!

-holdlayer.verticalorder is now a function that you can use to invert negative y speed and positive y speed without changing the values manually.

Also, this fixes a desynchronization issue if you edited the value while the layer was moving.


Return to “LunaLua”

Who is online

Users browsing this forum: No registered users and 0 guests

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari