(shouting)

LunaDLL/LunaLUA help thread

The second SMBX collab!
User avatar
Alice
Posts: 2367
Joined: 12 years ago
Pronouns: Girl person
Location: Wonderland

Re: LunaDLL help thread

Post by Alice »

WestonSmith wrote:I know LunaDLL can shut out the jump button, but is it possible to stop the player from jumping while still allowing Kood to float?

Example: Kood walks of the cliff. He can hold the jump button to float to the next ledge. However, at no point does he gain any vertical motion.

Odd question, and I doubt this one is doable, but thought I'd check in with an expert.
I don't know if there's a better way of doing it since I haven't messed with LunaDLL or LunaLua a whole lot yet but isn't there a block collision checking function? You could just have it check if the player is colliding with any blocks below them and disable the jump button if that's true.
User avatar
WestonSmith
Bunny
Posts: 191
Joined: 11 years ago

Re: LunaDLL help thread

Post by WestonSmith »

Thank you! Code works perfect.
User avatar
Sturg
Gets his freak on with VGM
Posts: 710
Joined: 13 years ago
First name: sturgyman
Location: - :noiƚɒɔo⅃
Contact:

Re: LunaDLL help thread

Post by Sturg »

I've suddenly been getting this error repetitively trying to open smbx but to no avail:
Image
ImageImage
Image ImageImage
RIP FISH NIPPLE BANNER
User avatar
Hoeloe
A2XT person
Posts: 1022
Joined: 12 years ago
Pronouns: she/her
Location: Spaaace

Re: LunaDLL help thread

Post by Hoeloe »

Sturg wrote:I've suddenly been getting this error repetitively trying to open smbx but to no avail:
Image
Try a fresh install?
Image
Image
Image
Image
Image
User avatar
7NameSam
hey
Posts: 248
Joined: 9 years ago
Pronouns: they/them

Re: LunaDLL help thread

Post by 7NameSam »

Hey, How can I make things loop from the bottom of the screen to the top of the screen using luna?
Putting down a bunch of warps is too much work.
User avatar
Rednaxela
Maker of Shenanigans
Posts: 897
Joined: 10 years ago
Pronouns: they/them
https://rednaxela.talkhaus.com

Re: LunaDLL help thread

Post by Rednaxela »

7NameSam wrote:Hey, How can I make things loop from the bottom of the screen to the top of the screen using luna?
Putting down a bunch of warps is too much work.
Well, it's a matter of checking if the y-coordinate is above a certain number, and if so moving them up.
To do so for the player only, for all sections, would be something like:

Code: Select all

function onLoop()
	local sectBottom = player.sectionObj.boundary.bottom
	local sectTop = player.sectionObj.boundary.top
	-- If the top of the player is below the bottom of the section...
	if (player.y > sectBottom ) then
		-- Move the (top of the) player 48px above the top of the screen
		player.y = sectTop - 48
	end
end
Test level attached.
Attachments
FallingForever.zip
(1.08 KiB) Downloaded 66 times
User avatar
7NameSam
hey
Posts: 248
Joined: 9 years ago
Pronouns: they/them

Re: LunaDLL help thread

Post by 7NameSam »

Yep works like a charm!
thanks for that.
also, is it possible to do it the other way around? (move through top of screen, and come out the bottom of it)
Edit: and is it possible to do both at the same time?
Last edited by 7NameSam 8 years ago, edited 1 time in total.
User avatar
Rednaxela
Maker of Shenanigans
Posts: 897
Joined: 10 years ago
Pronouns: they/them
https://rednaxela.talkhaus.com

Re: LunaDLL help thread

Post by Rednaxela »

7NameSam wrote:also, is it possible to do it the other way around? (move through top of screen, and come out the bottom of it)
Just reverse top/bottom handling there. So replace "player.y > sectBottom" with "player.y < sectTop - 48", and "player.y = sectTop - 48" with "player.y = sectBottom"
User avatar
7NameSam
hey
Posts: 248
Joined: 9 years ago
Pronouns: they/them

Re: LunaDLL help thread

Post by 7NameSam »

How do you do Autoscrolling with Luna?
User avatar
SAJewers
ASMBXT Level Wrangler/A2XT Project Coordinator /AAT Level Designer
Posts: 4219
Joined: 12 years ago
Location: Nova Scotia

Re: LunaDLL help thread

Post by SAJewers »

is there a way to make all NPCs not move when powering up or down? I'm made part of a level, but it's a bit difficult because NPCs like the crab will continue to move when the powerup/down animation occurs.
ImageImageImageImageImage | Image | Image
Sharenite | RetroAchievements | NameMC | IGDB
User avatar
Rednaxela
Maker of Shenanigans
Posts: 897
Joined: 10 years ago
Pronouns: they/them
https://rednaxela.talkhaus.com

Re: LunaDLL help thread

Post by Rednaxela »

SAJewers wrote:is there a way to make all NPCs not move when powering up or down? I'm made part of a level, but it's a bit difficult because NPCs like the crab will continue to move when the powerup/down animation occurs.
So, took a little new research about offset 0x128, but think I got something:

Code: Select all

	-- Check if the player has invincibility frames
	if (player:mem(0x140, FIELD_WORD) ~= 0) or (player:mem(0x128, FIELD_FLOAT) ~= 0) then
		-- If so, freeze time
		mem(0xB2C8B4, FIELD_WORD, -1)
	else
		-- Otherwise, unfreeze time
		mem(0xB2C8B4, FIELD_WORD, 0)
	end
Put this in onLoop. Note that it doesn't co-exist with actual time-freeze green p-switches, if your level uses any of those.
Let me know how that goes :)

7NameSam wrote:How do you do Autoscrolling with Luna?
It's a matter of manipulating the section boundary, which can be done like:

Code: Select all

-- Move the left boundary 5 to the right, and set the right boundary to the left plus 800
local bounds = player.sectionObj.boundary
bounds.left = bounds.left + 5
bounds.right = bounds.left + 800
player.sectionObj.boundary = bounds
This code would go in your onLoop or similar.
Also, right now I'm making a little helper library to make fancier autoscroll effects easier. (Going to use it to clean up some things in the relay level)
User avatar
7NameSam
hey
Posts: 248
Joined: 9 years ago
Pronouns: they/them

Re: LunaDLL help thread

Post by 7NameSam »

Rednaxela wrote:
7NameSam wrote:How do you do Autoscrolling with Luna?
It's a matter of manipulating the section boundary, which can be done like:

Code: Select all

-- Move the left boundary 5 to the right, and set the right boundary to the left plus 800
local bounds = player.sectionObj.boundary
bounds.left = bounds.left + 5
bounds.right = bounds.left + 800
player.sectionObj.boundary = bounds
This code would go in your onLoop or similar.
Also, right now I'm making a little helper library to make fancier autoscroll effects easier. (Going to use it to clean up some things in the relay level)
Is it possible to fix the issue when after a while of scrolling the background does the solitare thing?
User avatar
SAJewers
ASMBXT Level Wrangler/A2XT Project Coordinator /AAT Level Designer
Posts: 4219
Joined: 12 years ago
Location: Nova Scotia

Re: LunaDLL help thread

Post by SAJewers »

While that works, NPCs will stay frozen until the end of invincibility frames, rather than just the duration of the powerup/down animation.
ImageImageImageImageImage | Image | Image
Sharenite | RetroAchievements | NameMC | IGDB
User avatar
Rednaxela
Maker of Shenanigans
Posts: 897
Joined: 10 years ago
Pronouns: they/them
https://rednaxela.talkhaus.com

Re: LunaDLL help thread

Post by Rednaxela »

7NameSam wrote:Is it possible to fix the issue when after a while of scrolling the background does the solitare thing?
Yes, put all that in an "if" statement so that it stops scrolling before you leave the original section boundaries set by the editor, or instead of an "if" statement you could use math.max to set a maximum value for bounds.left to get set to.
SAJewers wrote:While that works, NPCs will stay frozen until the end of invincibility frames, rather than just the duration of the powerup/down animation.
Oh, I thought that's what you wanted.
If you want just the animation without the extra invincibility frames, replace this:

Code: Select all

if (player:mem(0x140, FIELD_WORD) ~= 0) or (player:mem(0x128, FIELD_FLOAT) ~= 0) then
with:

Code: Select all

if (player:mem(0x128, FIELD_FLOAT) ~= 0) then
The float at 0x128 being non-zero represents the powerup/powerdown animation being active, whereas the word at 0x140 being non-zero represents the invincibility frames following that.
EDIT: 0x128 also applies to character change animations.
User avatar
7NameSam
hey
Posts: 248
Joined: 9 years ago
Pronouns: they/them

Re: LunaDLL help thread

Post by 7NameSam »

Rednaxela wrote:
7NameSam wrote:Is it possible to fix the issue when after a while of scrolling the background does the solitare thing?
Yes, put all that in an "if" statement so that it stops scrolling before you leave the original section boundaries set by the editor, or instead of an "if" statement you could use math.max to set a maximum value for bounds.left to get set to.
I don't know lua :oops:
User avatar
Rednaxela
Maker of Shenanigans
Posts: 897
Joined: 10 years ago
Pronouns: they/them
https://rednaxela.talkhaus.com

Re: LunaDLL help thread

Post by Rednaxela »

7NameSam wrote:I don't know lua :oops:
Heh, well... if you want a quick snippet...
This applies to the first section.

Code: Select all

local originalRightEdge = nil
function onLoop()
    if originalRightEdge == nil then
    	local bounds = Section(0).boundary
    	originalRightEdge = bounds.right
    	bounds.right = bounds.left + 800
    end
    
    local bounds = Section(0).boundary
    bounds.right = math.min(bounds.right + 5, originalRightEdge)
    bounds.left = bounds.right - 800
    Section(0).boundary = bounds
end
Untested, but I think it ought to work.
User avatar
7NameSam
hey
Posts: 248
Joined: 9 years ago
Pronouns: they/them

Re: LunaDLL help thread

Post by 7NameSam »

Rednaxela wrote:
7NameSam wrote:I don't know lua :oops:
Heh, well... if you want a quick snippet...
This applies to the first section.

Code: Select all

local originalRightEdge = nil
function onLoop()
    if originalRightEdge == nil then
    	local bounds = Section(0).boundary
    	originalRightEdge = bounds.right
    	bounds.right = bounds.left + 800
    end
    
    local bounds = Section(0).boundary
    bounds.right = math.min(bounds.right + 5, originalRightEdge)
    bounds.left = bounds.right - 800
    Section(0).boundary = bounds
end
Untested, but I think it ought to work.
No, it just instantly moves the screen to the end of the section
User avatar
Rednaxela
Maker of Shenanigans
Posts: 897
Joined: 10 years ago
Pronouns: they/them
https://rednaxela.talkhaus.com

Re: LunaDLL help thread

Post by Rednaxela »

7NameSam wrote:No, it just instantly moves the screen to the end of the section
Whoops, add an extra "Section(0).boundary = bounds" right before the first "end" line
User avatar
7NameSam
hey
Posts: 248
Joined: 9 years ago
Pronouns: they/them

Re: LunaDLL help thread

Post by 7NameSam »

Is there some kind of Lua thing you can do so you don't become big when you get a checkpoint?
User avatar
Hoeloe
A2XT person
Posts: 1022
Joined: 12 years ago
Pronouns: she/her
Location: Spaaace

Re: LunaDLL help thread

Post by Hoeloe »

7NameSam wrote:Is there some kind of Lua thing you can do so you don't become big when you get a checkpoint?
Technically yes, but it requires a bit of trickery.

First you need to check if you just collected the checkpoint - searching for all checkpoint NPCs, storing the number you find, and then checking to see if that's decreased, will do that.

Second, you need to cancel the "get big" animation. I forgot the exact memory location, but there's a memory map on the Lua wiki which should point you in the right direction.

If that doesn't solve it, you may also need to set the powerup state to small (if and only if you weren't big before collecting the checkpoint).

That should more or less do what you need.
Image
Image
Image
Image
Image
User avatar
Ignoritus
O◡O
Posts: 207
Joined: 11 years ago
Pronouns: he/him/his
Location: U.S.

Re: LunaDLL help thread

Post by Ignoritus »

So how would I go about setting mother brain's hits using LunaLUA? I'm guessing it involves setting a specific NPC memory address, do we have a reference list that might tell me it?
Image
User avatar
Rednaxela
Maker of Shenanigans
Posts: 897
Joined: 10 years ago
Pronouns: they/them
https://rednaxela.talkhaus.com

Re: LunaDLL help thread

Post by Rednaxela »

Ignoritus wrote:So how would I go about setting mother brain's hits using LunaLUA? I'm guessing it involves setting a specific NPC memory address, do we have a reference list that might tell me it?
Reference list here

In particular offset 0x148 with a type of FIELD_FLOAT
So can play around with things like

Code: Select all

npc:mem(0x148, FIELD_FLOAT, 10)
User avatar
Ignoritus
O◡O
Posts: 207
Joined: 11 years ago
Pronouns: he/him/his
Location: U.S.

Re: LunaDLL help thread

Post by Ignoritus »

Rednaxela wrote:
Ignoritus wrote:So how would I go about setting mother brain's hits using LunaLUA? I'm guessing it involves setting a specific NPC memory address, do we have a reference list that might tell me it?
Reference list here

In particular offset 0x148 with a type of FIELD_FLOAT
So can play around with things like

Code: Select all

npc:mem(0x148, FIELD_FLOAT, 10)
Thanks, now my dreams of making mother brain take three times as many hits can be realized. :D
Image
User avatar
snoruntpyro
cutest girl 2023
Posts: 884
Joined: 9 years ago
Pronouns: she/her
Contact:

Re: LunaDLL help thread

Post by snoruntpyro »

Is there any way to deactivate SMBX's despawning code? In other words, always have all NPCs active?
Image
Image
Image
Image
Image
User avatar
Rednaxela
Maker of Shenanigans
Posts: 897
Joined: 10 years ago
Pronouns: they/them
https://rednaxela.talkhaus.com

Re: LunaDLL help thread

Post by Rednaxela »

Pyro wrote:Is there any way to deactivate SMBX's despawning code? In other words, always have all NPCs active?
Something like the following would work, but note that it may cause slowdown if there are too many NPCs in the level:

Code: Select all

for i,npc in pairs(npcs()) do
    -- Make sure it's not a generator (0x64), and that it is something that's supposed
    -- to respawn were it to despawn (0xDC is the ID something would respawn as,
    -- or 0 if it's meant to disappear permanently when offscreen)
    if (npc:mem(0x64, FIELD_WORD) == 0) and (npc:mem(0xDC, FIELD_WORD) ~= 0) then
        -- 0x12A is the countdown till despawning happens. Keep resetting this timer if the above criteria pass
        npc:mem(0x12A, FIELD_WORD, 120)
    end
end
Put the above in your onLoop
Post Reply