Need help with lua? - LunaLua General Help

Post here for help and support regarding LunaLua and SMBX2's libraries and features.
vee_Sleepy
Fighter Fly
Fighter Fly
Posts: 40
Joined: Tue Nov 29, 2022 7:15 pm
Flair: oh worm?
Pronouns: they/it

Re: Need help with lua? - LunaLua General Help

Postby vee_Sleepy » Mon Jun 12, 2023 12:38 pm

Emral wrote:
Mon Jun 12, 2023 3:48 am
2. Do you have an NPC config file with a health config for Mother Brain?
The reason this is relevant is because the way the 0x148 offset works is a bit weird. It starts at 0, then counts up. If it reaches 10, Mother Brain dies. But it starting at 0 is only true if the health NPC config is unchanged. The goal value is constant because it determines death, so instead, the start value changes with NPC config. So if you were to set Mother Brain's health to 5, the start value would be (death (10) - health (5)) = 5, meaning after 3 hits the 0x148 offset would show 8, instead of 3.
ok, so knowing it starts at 0 and it's relative to the default health value really helps
i just changed it back to the default 10 in the config and changed the code to say 2 and now it all works as intended, thanks :3c

LunarCatUSA
Hoopster
Hoopster
Posts: 115
Joined: Sat Mar 06, 2021 9:56 am
Flair: Soda-Butler

Re: Need help with lua? - LunaLua General Help

Postby LunarCatUSA » Wed Jun 14, 2023 9:58 am

Figured it out,
Just needed to find a way to decelerate the v.speedx when it isn't zero so I make a tick to say v.speedx - 0.1 until it equals zero.

I just saw something like that in the Boos AI so all good now!
Thanks guys.

Tango
Volcano Lotus
Volcano Lotus
Posts: 575
Joined: Fri Apr 25, 2014 12:06 pm
Contact:

Re: Need help with lua? - LunaLua General Help

Postby Tango » Fri Jul 07, 2023 5:18 pm

Hello, I have a simple system in place which triggers a SMBX event when you have collected a specific number of coins. However, I'd like the coins collected to be remembered by the game upon a reset (specifically when you lose a life), so that you are not required to re-collect the same coins again. The way I thought of tackling this would be to assigning each coin in the level some kind of identification, and have the code keep track of each single coin to see if they have been collected or not. However I'm unsure in how I can assign each coin its unique identification, or if this is even the optimal way of achieving this goal.

I'd be thankful to have some light shed on this problem.

mariobrigade2018
Spike
Spike
Posts: 275
Joined: Wed May 24, 2023 7:00 pm
Flair: Normie in coding who dreams of making a Mario game
Pronouns: he/him

Re: Need help with lua? - LunaLua General Help

Postby mariobrigade2018 » Sat Jul 08, 2023 6:40 pm

I'm trying to modify the effects for collecting a star coin, but the image used for it only shows half of it and is stretched.
The image:

Image

And the effect modifier code:

Code: Select all

[1]
import=AI_STARCOIN
gfxwidth=32
gfxheight=32
width=32
height=32
frames = 8
framestyle = 1
framespeed = 8
Not sure what's going on, so getting help as soon as possible would be nice.

deice
Volcano Lotus
Volcano Lotus
Posts: 548
Joined: Fri Jul 23, 2021 7:35 am

Re: Need help with lua? - LunaLua General Help

Postby deice » Sat Jul 08, 2023 6:56 pm

Tango wrote:
Fri Jul 07, 2023 5:18 pm
The way I thought of tackling this would be to assigning each coin in the level some kind of identification, and have the code keep track of each single coin to see if they have been collected or not. However I'm unsure in how I can assign each coin its unique identification, or if this is even the optimal way of achieving this goal.
this should be achievable using an npc settings json file.
mariobrigade2018 wrote: I'm trying to modify the effects for collecting a star coin, but the image used for it only shows half of it and is stretched.
have you tried maybe cutting the frame count in half? the star coin effect is kind of janky if memory serves me right

mariobrigade2018
Spike
Spike
Posts: 275
Joined: Wed May 24, 2023 7:00 pm
Flair: Normie in coding who dreams of making a Mario game
Pronouns: he/him

Re: Need help with lua? - LunaLua General Help

Postby mariobrigade2018 » Sun Jul 09, 2023 12:13 am

Nuh-uh. Nothing. Here's my altered code:

Code: Select all

[1]
import = AI_STARCOIN
gfxwidth=32
gfxheight=32
width=32
height=32
frames = 4
framestyle = 1
framespeed = 8
And the GIF, featuring a glitch:

Image

Emral
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 9722
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Phoenix

Re: Need help with lua? - LunaLua General Help

Postby Emral » Sun Jul 09, 2023 12:21 am

mariobrigade2018 wrote:
Sun Jul 09, 2023 12:13 am
Nuh-uh. Nothing. Here's my altered code:

Code: Select all

[1]
import = AI_STARCOIN
gfxwidth=32
gfxheight=32
width=32
height=32
frames = 4
framestyle = 1
framespeed = 8
And the GIF, featuring a glitch:

Image
Some NPC config specific fields in your effect config here
The defaults for AI_STARCOIN should work fine for you here, for both effect-233 and effect-276.
The only difference I see is framespeed being 8 rather than the default 3.
If you want framespeed at 8, change the file to this:

Code: Select all

[1]
import = AI_STARCOIN
framespeed = 3
If 3 is fine as well, you can delete the file.

The reason only half of it shows is because of framestyle=1, btw. But gfxwidth/gfxheight don't exist for effects, and width/height are auto-set from frames (4 frames being default for AI_STARCOIN).
So doing the math you right now have 4 frames on your sheet, of 32px height. But you set framestyle=1 so it means there are 4 frames in each direction. So each frame is 1/8 of the image, or 1/2 of an actual frame. And then setting height to 32px manually to override that causes the image to stretch.

mariobrigade2018
Spike
Spike
Posts: 275
Joined: Wed May 24, 2023 7:00 pm
Flair: Normie in coding who dreams of making a Mario game
Pronouns: he/him

Re: Need help with lua? - LunaLua General Help

Postby mariobrigade2018 » Sun Jul 09, 2023 1:18 am

Emral wrote:
Sun Jul 09, 2023 12:21 am
Some NPC config specific fields in your effect config here
The defaults for AI_STARCOIN should work fine for you here, for both effect-233 and effect-276.
The only difference I see is framespeed being 8 rather than the default 3.
If you want framespeed at 8, change the file to this:

Code: Select all

[1]
import = AI_STARCOIN
framespeed = 3
If 3 is fine as well, you can delete the file.

The reason only half of it shows is because of framestyle=1, btw. But gfxwidth/gfxheight don't exist for effects, and width/height are auto-set from frames (4 frames being default for AI_STARCOIN).
So doing the math you right now have 4 frames on your sheet, of 32px height. But you set framestyle=1 so it means there are 4 frames in each direction. So each frame is 1/8 of the image, or 1/2 of an actual frame. And then setting height to 32px manually to override that causes the image to stretch.
And removing the txt file fixed the problem. Thanks! :D


Image

Ba bu, ba da daAAAAAAAAAAAA! (SMBX's Star collected SFX)

Tango
Volcano Lotus
Volcano Lotus
Posts: 575
Joined: Fri Apr 25, 2014 12:06 pm
Contact:

Re: Need help with lua? - LunaLua General Help

Postby Tango » Sun Jul 09, 2023 10:11 pm

deice wrote:
Sat Jul 08, 2023 6:56 pm
Tango wrote:
Fri Jul 07, 2023 5:18 pm
The way I thought of tackling this would be to assigning each coin in the level some kind of identification, and have the code keep track of each single coin to see if they have been collected or not. However I'm unsure in how I can assign each coin its unique identification, or if this is even the optimal way of achieving this goal.
this should be achievable using an npc settings json file.
Thank you very much for telling me about json files! Thanks to you (and the help of other users at the discord server), I've been able to get access to each of these single coins in the level with the script. Now I will find a way to make the code keep track of the collected coins, and restoring only the ones that haven't been collected upon level reset, which I intend to find out myself.

Than you once again, hopefully the last time I return to this thread to seek help for this subject!

mariobrigade2018
Spike
Spike
Posts: 275
Joined: Wed May 24, 2023 7:00 pm
Flair: Normie in coding who dreams of making a Mario game
Pronouns: he/him

Re: Need help with lua? - LunaLua General Help

Postby mariobrigade2018 » Mon Jul 10, 2023 3:34 pm

Is there a way to make Luigi's SMA jumps?


Image
(It's this.)

LunarCatUSA
Hoopster
Hoopster
Posts: 115
Joined: Sat Mar 06, 2021 9:56 am
Flair: Soda-Butler

Re: Need help with lua? - LunaLua General Help

Postby LunarCatUSA » Fri Aug 04, 2023 1:14 pm

Image

This is a dummy NPC I'm working on.

I have its general pathing and walking down when mobile, but I want to be able to have my npc be those two idle frames (5,6) for the left direction and the last two idle frames (7,8) for the right direction.

I think I need to have something like v.animationFrame = 5 and then switch to 6 with the time? (Likewise with the other side)

Added in 3 hours 49 minutes 58 seconds:
Okay so I can make the 0 + 1 but the problem is that my NPC is stuck with the first 2 frames for left movement and the next 2 frames for right movement. I don't know how to make it so it looks further down onto the png sprite sheet for the next set of frames.

Goldenemerl64
Rex
Rex
Posts: 38
Joined: Tue Jul 07, 2020 3:50 pm

Re: Need help with lua? - LunaLua General Help

Postby Goldenemerl64 » Wed Aug 09, 2023 2:40 am

Man.. It's been a while since I've been here. But Is there anyway to change a Mount's Hitboxes? and if not, is there a way to make custom mounts?

mariobrigade2018
Spike
Spike
Posts: 275
Joined: Wed May 24, 2023 7:00 pm
Flair: Normie in coding who dreams of making a Mario game
Pronouns: he/him

Re: Need help with lua? - LunaLua General Help

Postby mariobrigade2018 » Fri Aug 11, 2023 1:26 pm

I have added this script here into my episode. viewtopic.php?p=278105&hilit=Super#p278105

Everything works fine except the graphics don't load:

Image

For reference, this is what it's supposed to look like.
Image
(GIF by TDK)

Any ideas why this is happening?

mariobrigade2018
Spike
Spike
Posts: 275
Joined: Wed May 24, 2023 7:00 pm
Flair: Normie in coding who dreams of making a Mario game
Pronouns: he/him

Re: Need help with lua? - LunaLua General Help

Postby mariobrigade2018 » Sun Sep 03, 2023 1:23 pm

I imported Megadood's Giant Buzzy Beetle and move the npc id from 755 to 759 and added custom graphics. But when I load it in, it disappears and gives me this:

Image

Anyone knows why this happens?

MarioChallengerX2
Dolphin
Dolphin
Posts: 80
Joined: Sat Dec 31, 2022 4:34 pm
Pronouns: he/him

Re: Need help with lua? - LunaLua General Help

Postby MarioChallengerX2 » Sun Sep 03, 2023 7:15 pm

mariobrigade2018 wrote:
Sun Sep 03, 2023 1:23 pm
I imported Megadood's Giant Buzzy Beetle and move the npc id from 755 to 759 and added custom graphics. But when I load it in, it disappears and gives me this:

Image

Anyone knows why this happens?
Oh, it has an effect tied to it. You need to rename the effect to whatever number you changed the npc to.

mariobrigade2018
Spike
Spike
Posts: 275
Joined: Wed May 24, 2023 7:00 pm
Flair: Normie in coding who dreams of making a Mario game
Pronouns: he/him

Re: Need help with lua? - LunaLua General Help

Postby mariobrigade2018 » Mon Sep 04, 2023 3:57 am

MarioChallengerX2 wrote:
Sun Sep 03, 2023 7:15 pm
mariobrigade2018 wrote:
Sun Sep 03, 2023 1:23 pm
I imported Megadood's Giant Buzzy Beetle and move the npc id from 755 to 759 and added custom graphics. But when I load it in, it disappears and gives me this:

Image

Anyone knows why this happens?
Oh, it has an effect tied to it. You need to rename the effect to whatever number you changed the npc to.
*Facepalm* ...and I told myself this would never happen. Oh well.

mariobrigade2018
Spike
Spike
Posts: 275
Joined: Wed May 24, 2023 7:00 pm
Flair: Normie in coding who dreams of making a Mario game
Pronouns: he/him

Re: Need help with lua? - LunaLua General Help

Postby mariobrigade2018 » Mon Sep 11, 2023 8:08 pm

How do I make these sprites:

Image

rotate dynamically?

mariobrigade2018
Spike
Spike
Posts: 275
Joined: Wed May 24, 2023 7:00 pm
Flair: Normie in coding who dreams of making a Mario game
Pronouns: he/him

Re: Need help with lua? - LunaLua General Help

Postby mariobrigade2018 » Sun Nov 19, 2023 12:39 pm

Does anyone know how I make this 2-player compatible:

Code: Select all

local allBoomerang = {}

function allBoomerang.onInitAPI()
	registerEvent(allBoomerang, "onTick")
end

local BoomerangLock = 0

function allBoomerang.onTick()
	if player.character == CHARACTER_BOWSER then
	--do nothing
	return end
	if player.powerup == PLAYER_HAMMER then
		if player.character == CHARACTER_MARIO or CHARACTER_LUIGI or CHARACTER_WARIO or CHARACTER_ZELDA then
			if BoomerangLock == 0 then
				if(player.runKeyPressing) then
					for k,v in pairs(NPC.get(171,-1)) do
						v.id = 292
						v.width = 32
						v.height = 32
						v:mem(0x110,FIELD_DFLOAT,1)
						if BoomerangLock == 0 then
							if player:mem(0x106,FIELD_WORD) ~= -1 then
								BoomerangLock = 1
								v.x = v.x + 2
								v.speedX = 25
								v.speedY = -10
							else
								BoomerangLock = 1
								v.x = v.x - 2
								v.speedX = -25
								v.speedY = -10
							
							end
						end
					end
				end
			else
				local BoomerangCheck = NPC.get(292,-1)
				if table.getn(BoomerangCheck) == 0 then
					BoomerangLock = 0
				else
					player:mem(0x160,FIELD_WORD,2)
				end
			end
		end
	end
end

return allBoomerang
I used Tempest's boomerang flower for the code.

mariobrigade2018
Spike
Spike
Posts: 275
Joined: Wed May 24, 2023 7:00 pm
Flair: Normie in coding who dreams of making a Mario game
Pronouns: he/him

Re: Need help with lua? - LunaLua General Help

Postby mariobrigade2018 » Sat Dec 02, 2023 9:51 pm

I've got no clue what this error code is:
Image
Does any know what this error code is?

deice
Volcano Lotus
Volcano Lotus
Posts: 548
Joined: Fri Jul 23, 2021 7:35 am

Re: Need help with lua? - LunaLua General Help

Postby deice » Sun Dec 03, 2023 7:24 am

mariobrigade2018 wrote:
Sat Dec 02, 2023 9:51 pm
Does any know what this error code is?
you've most likely got a malformed npc config txt file. check any txt files in your level/episode folder for typos or other errors


Return to “LunaLua Help”

Who is online

Users browsing this forum: No registered users and 1 guest

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari