Need help with lua? - LunaLua General Help

Post here for help and support regarding LunaLua and SMBX2's libraries and features.
Emral
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 9707
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Phoenix

Re: Need help with lua? - LunaLua General Help

Postby Emral » Mon Mar 27, 2023 4:46 am

Torterra18 wrote:
Fri Feb 17, 2023 4:16 pm
Umm, I'm kinda new to this lua thing, and please I need someone to answer me, how do I make a loot table for the Box NPC? The documentation doesn't talk about that...
There's an example in the extra settings for the crate.
ditditdit wrote:
Mon Mar 27, 2023 1:08 am
noobiest question ever: how do i trigger an event with lua?
triggerEvent("eventname")

Torterra18
Koopa
Koopa
Posts: 19
Joined: Fri Feb 03, 2023 9:43 am
Pronouns: he/him

Re: Need help with lua? - LunaLua General Help

Postby Torterra18 » Mon Mar 27, 2023 10:05 am

Emral wrote:
Mon Mar 27, 2023 4:46 am
Torterra18 wrote:
Fri Feb 17, 2023 4:16 pm
Umm, I'm kinda new to this lua thing, and please I need someone to answer me, how do I make a loot table for the Box NPC? The documentation doesn't talk about that...
There's an example in the extra settings for the crate.
Ok, it's a rather simple one, but how it is done to, like, make the NPC inside have custom settings, or have more than one type of NPC?

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

Re: Need help with lua? - LunaLua General Help

Postby Emral » Mon Mar 27, 2023 10:08 am

Torterra18 wrote:
Mon Mar 27, 2023 10:05 am
Emral wrote:
Mon Mar 27, 2023 4:46 am
Torterra18 wrote:
Fri Feb 17, 2023 4:16 pm
Umm, I'm kinda new to this lua thing, and please I need someone to answer me, how do I make a loot table for the Box NPC? The documentation doesn't talk about that...
There's an example in the extra settings for the crate.
Ok, it's a rather simple one, but how it is done to, like, make the NPC inside have custom settings, or have more than one type of NPC?
Cant really modify the settings but you just do a comma separated list to have more than one type.

ditditdit
Dolphin
Dolphin
Posts: 92
Joined: Sun Jan 02, 2022 4:25 pm
Flair: e
Pronouns: she/they
Contact:

Re: Need help with lua? - LunaLua General Help

Postby ditditdit » Mon Mar 27, 2023 4:26 pm

Emral wrote:
Mon Mar 27, 2023 4:46 am
Torterra18 wrote:
Fri Feb 17, 2023 4:16 pm
Umm, I'm kinda new to this lua thing, and please I need someone to answer me, how do I make a loot table for the Box NPC? The documentation doesn't talk about that...
There's an example in the extra settings for the crate.
ditditdit wrote:
Mon Mar 27, 2023 1:08 am
noobiest question ever: how do i trigger an event with lua?
triggerEvent("eventname")
THANKS SO MUCH! i am currently coding an RPG battle for a collab episode, and had hit a major roadblock, as i doubt TriggerSMBXEvent even works anymore.

Hoeloe
Foo
Foo
Posts: 1463
Joined: Sat Oct 03, 2015 6:18 pm
Flair: The Codehaus Girl
Pronouns: she/her

Re: Need help with lua? - LunaLua General Help

Postby Hoeloe » Tue Mar 28, 2023 6:28 am

ditditdit wrote:
Mon Mar 27, 2023 4:26 pm
THANKS SO MUCH! i am currently coding an RPG battle for a collab episode, and had hit a major roadblock, as i doubt TriggerSMBXEvent even works anymore.
I... don't think TriggerSMBXEvent was ever part of LunaLua. It also wasn't part of LunaDLL's script, before that was replaced with Lua. Are you maybe thinking of SMBX38A's language Teascript-VB? I don't know if it's used there either, but SMBX38A is a completely different program, and has nothing to do with SMBX2.

ditditdit
Dolphin
Dolphin
Posts: 92
Joined: Sun Jan 02, 2022 4:25 pm
Flair: e
Pronouns: she/they
Contact:

Re: Need help with lua? - LunaLua General Help

Postby ditditdit » Tue Mar 28, 2023 7:04 pm

Hoeloe wrote:
Tue Mar 28, 2023 6:28 am
ditditdit wrote:
Mon Mar 27, 2023 4:26 pm
THANKS SO MUCH! i am currently coding an RPG battle for a collab episode, and had hit a major roadblock, as i doubt TriggerSMBXEvent even works anymore.
I... don't think TriggerSMBXEvent was ever part of LunaLua. It also wasn't part of LunaDLL's script, before that was replaced with Lua. Are you maybe thinking of SMBX38A's language Teascript-VB? I don't know if it's used there either, but SMBX38A is a completely different program, and has nothing to do with SMBX2.
https://wohlsoft.ru/pgewiki/TriggerSMBXEvent

oops.

that was dumb.

Hoeloe
Foo
Foo
Posts: 1463
Joined: Sat Oct 03, 2015 6:18 pm
Flair: The Codehaus Girl
Pronouns: she/her

Re: Need help with lua? - LunaLua General Help

Postby Hoeloe » Wed Mar 29, 2023 6:13 am

ditditdit wrote:
Tue Mar 28, 2023 7:04 pm

https://wohlsoft.ru/pgewiki/TriggerSMBXEvent

oops.

that was dumb.
Huh. I looked at the documentation for LunaDLL (been YEARS since I've used it) and while incomplete, it didn't list TriggerSMBXEvent. Regardless, LunaDLL's Autocode isn't the same thing as LunaLua, and it's never been the intent to copy it for LunaLua's purposes.

Xboy1
Koopa
Koopa
Posts: 18
Joined: Thu Jul 04, 2019 6:15 am
Flair: supah mayrio bruthas

Re: Need help with lua? - LunaLua General Help

Postby Xboy1 » Wed May 17, 2023 3:56 pm

I'm trying to make a Fire Chomp from NSMB, but theres some things it needs that I don't know how to do:
1. How do I change the sprite before an attack? Like hammer bros or boom boom. I tried to use v.animationFrame = v.animationFrame + 4 but it didn't do anything.
2. How do I make a trail? I want to make a trail of fireballs just like in the game but I dont' even know where to start.
3. How do I aim a projectile directly at the player? Just like a venus fly trap.

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 » Sat Jun 10, 2023 12:46 am

Question, why do some enemies not stand still when I set their speed to 0?

Like say,

Code: Select all

if player.direction == -1 then
		status = 1
	elseif player.direction == 1 then
		status = 0
	end
	if status == 0 then
		v.speedx = 0
	end
	if status == 1 then
		Graphics.draw{
				type = RTYPE_IMAGE,
				image = Alert,
				x = v.x-8,
				y = v.y-32,
				priority = 40,
				sceneCoords = true,
			}
	end
	if status == 1 and v.direction == -1 then
		v.speedX = -1
	elseif status == 1 and v.direction == 1 then
		v.speedX = 1
	end
The code works so that the enemy stands still on start (Status 0). When the player faces left, the enemy enters status 1 and starts moving and when the player faces right, the enemy enters status 0 and SHOULD not be moving. The problem is that the enemy continues moving despite the status being 0. Anyone know why they keep moving?

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

Re: Need help with lua? - LunaLua General Help

Postby Emral » Sat Jun 10, 2023 1:42 am

does the npc have "iswalker" set to true in its npc config? examples include koopas, goombas, spinies, etc...
iswalker forces speed like that

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 » Sat Jun 10, 2023 3:31 pm

felt i'd bring my smaller, specific Lua questions over to this thread, that's probably the correct move
two i wanna know about, with no particular rush, are:
1. how can I kill an NPC with an onEvent script?
and 2. how can I check an NPC's health value and use that to trigger an event before they're actually dead, just after taking enough damage?

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 » Sat Jun 10, 2023 5:55 pm

Emral wrote:
Sat Jun 10, 2023 1:42 am
does the npc have "iswalker" set to true in its npc config? examples include koopas, goombas, spinies, etc...
iswalker forces speed like that
Opened up NPC config for it and put
iswalker = 0 and iswalker = 1, both times, nothing changed.

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

Re: Need help with lua? - LunaLua General Help

Postby deice » Sat Jun 10, 2023 7:00 pm

vee_Sleepy wrote:
Sat Jun 10, 2023 3:31 pm
1. how can I kill an NPC with an onEvent script?
this one needs to be a little more specific, because you need to know exactly which npc you want to kill. is it an npc you spawned yourself previously? is it an npc with a specific position/id/property/etc? hard to answer without any of that info
vee_Sleepy wrote: 2. how can I check an NPC's health value and use that to trigger an event before they're actually dead, just after taking enough damage?
some vanilla npcs such as bosses store health at memory offset 148 (but i think the logic depends on the npc itself) whereas custom npcs might have their own health fields, so make sure you know what value you're checking. regardless, you'd probably want to use the onNPCHarm or (if you want to make sure the event hasn't been cancelled) onPostNPCHarm event. the syntax for both can be found on the "lunalua events" doc page

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 » Sat Jun 10, 2023 7:56 pm

deice wrote:
Sat Jun 10, 2023 7:00 pm
vee_Sleepy wrote:
Sat Jun 10, 2023 3:31 pm
1. how can I kill an NPC with an onEvent script?
this one needs to be a little more specific, because you need to know exactly which npc you want to kill. is it an npc you spawned yourself previously? is it an npc with a specific position/id/property/etc? hard to answer without any of that info
it's a custom Mother Brain that i was using for a boss fight. i know, very original.
more specifically, the boss' first form is a custom Mother Brain while the second is a reskinned custom NPC (DRACalgar's Rayquaza), and i'd have the Mother Brain form appear and immediately die as part of a cutscene thing at the end of the fight
deice wrote:
vee_Sleepy wrote: 2. how can I check an NPC's health value and use that to trigger an event before they're actually dead, just after taking enough damage?
some vanilla npcs such as bosses store health at memory offset 148 (but i think the logic depends on the npc itself) whereas custom npcs might have their own health fields, so make sure you know what value you're checking. regardless, you'd probably want to use the onNPCHarm or (if you want to make sure the event hasn't been cancelled) onPostNPCHarm event. the syntax for both can be found on the "lunalua events" doc page
I'm guessing i'll need to find the storage for the Mother Brain HP value. i wanna make the two forms, like, appear multiple times with short intermission attacks, and it just looks weird to make them die over and over in one fight. i want it to be a little more polished than the Good Ol' Days of heavily evented epic boss fights lol

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

Re: Need help with lua? - LunaLua General Help

Postby deice » Sun Jun 11, 2023 7:47 am

vee_Sleepy wrote:
Sat Jun 10, 2023 7:56 pm
it's a custom Mother Brain that i was using for a boss fight. i know, very original.
more specifically, the boss' first form is a custom Mother Brain while the second is a reskinned custom NPC (DRACalgar's Rayquaza), and i'd have the Mother Brain form appear and immediately die as part of a cutscene thing at the end of the fight
i assume it's the only mother brain that's spawned at one given time, so something like this should do the trick:

Code: Select all

function onEvent(eventName)
	if(eventName == "KillMotherBrain") then -- change the event name to suit your needs
		if(NPC.get(209)[1] and NPC.get(209)[1].isValid) then
			(NPC.get(209)[1]):kill()
		end
	end
end
vee_Sleepy wrote:
Sat Jun 10, 2023 7:56 pm
I'm guessing i'll need to find the storage for the Mother Brain HP value. i wanna make the two forms, like, appear multiple times with short intermission attacks, and it just looks weird to make them die over and over in one fight. i want it to be a little more polished than the Good Ol' Days of heavily evented epic boss fights lol
mother brain is a vanilla npc and thus stores its health in the pre-determined memory location

Code: Select all

function onPostNPCHarm(harmedNpc, harmType, culpritOrNil)
	if(harmedNpc.id == 209) then
		local hitsTaken = harmedNpc:mem(0x148, FIELD_FLOAT)
		-- handle logic below this line
	end
end
this code will run whenever a mother brain takes damage, just keep in mind that "hitsTaken" stores what it says it does i.e. the amount of health mother brain has lost as opposed to the amount of health remaining

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

Re: Need help with lua? - LunaLua General Help

Postby Emral » Sun Jun 11, 2023 8:12 am

deice wrote:
Sun Jun 11, 2023 7:47 am

Code: Select all

function onEvent(eventName)
	if(eventName == "KillMotherBrain") then -- change the event name to suit your needs
		if(NPC.get(209)[1] and NPC.get(209)[1].isValid) then
			(NPC.get(209)[1]):kill()
		end
	end
end
Mind this might malfunction if there are 2 mother brain NPCs in the level. It also loops over the list of mother brains 3 times, which is hugely wasteful.
Something like this is more robust.

Code: Select all

function onEvent(eventName)
	if(eventName == "KillMotherBrain") then -- change the event name to suit your needs
		for k,v in NPC.iterate(209) do
			if v.despawnTimer > 0 then
				v:kill()
			end
		end
	end
end

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

Re: Need help with lua? - LunaLua General Help

Postby deice » Sun Jun 11, 2023 12:14 pm

Emral wrote:
Sun Jun 11, 2023 8:12 am
Mind this might malfunction if there are 2 mother brain NPCs in the level. It also loops over the list of mother brains 3 times, which is hugely wasteful.
deice wrote:
Sun Jun 11, 2023 7:47 am
i assume it's the only mother brain that's spawned at one given time, so something like this should do the trick:
the code you posted is better though so if it works for this use case i'd recommend it over mine

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 » Sun Jun 11, 2023 11:10 pm

Emral's code seems to work just fine so far
i gotta test Deice's early NPC erase code, and also retool my code and event list to be more efficient and built around it
another question: what's the code that ends a level? I imported the Milky Way Wishes ending fanfare to play through the code when my boss fight is over, and i don't want to have the SMB3 ending fanfare right after it or anything, that'd just make the ending obnoxiously long lol
EDIT 2: i'm dumb as a brick and it's just under the Misc class in the documentation, so that new question i had is already solved

EDIT (about @Deice code): doesn't seem to be working
i set the Mother Brain NPC config to take more than 3 hits, then i set the "hitsTaken" to 3 and then had it lead into a universal event for a part of the fight being done, which was then redirected to the proper next part with an onEvent chunk
What the onPostNPCHarm part is looking like, just for perfect clarity. i'm not getting errors when i hit F5 to test, or when i hit the boss, so i guess i did that much right here?

Image
Last edited by vee_Sleepy on Mon Jun 12, 2023 12:51 pm, edited 1 time in total.

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

Re: Need help with lua? - LunaLua General Help

Postby Emral » Mon Jun 12, 2023 3:48 am

vee_Sleepy wrote:
Sun Jun 11, 2023 11:10 pm
There's a bit more here that's unknown, which might cause the issue. Please let me know...
1. if you put Misc.dialog(hitsTaken) in a line above the if hitsTaken == 3 check, what does it print?
-- If it prints nothing, this code is not running for some reason
-- If it is printing a number every time, what number sequence is it printing? The expectation is 1, 2, 3, etc...

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.

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 » Mon Jun 12, 2023 12:14 pm

Think I should look at the code for boos on how to stop an enemy in its tracks on at a certain instance?


Return to “LunaLua Help”

Who is online

Users browsing this forum: No registered users and 0 guests

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari