Need help with lua? - LunaLua General Help

Post here for help and support regarding LunaLua and SMBX2's libraries and features.

Moderator: Userbase Moderators

cato
Volcano Lotus
Volcano Lotus
Posts: 564
Joined: Thu Aug 24, 2017 3:06 am
Flair: Koishi enjoyer
Contact:

Re: Need help with lua? - LunaLua General Help

Postby cato » Thu Sep 26, 2019 9:32 am

I was trying to give the player more chances to attack a moving horizontal boss if the player misses the stomp, by making the section level warp during an event with Lua.
Here is my code:

Code: Select all

function onEvent(eventName)
    if  eventName == "attack" then
        Section.isLevelWarp	= true
    end
    if  eventName == "defeat"
        Section.isLevelWarp	= false
    end
end
This doesn't work, I think that the event didn't change the section setting though.

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

Re: Need help with lua? - LunaLua General Help

Postby Emral » Thu Sep 26, 2019 10:35 am

cato wrote:
Thu Sep 26, 2019 9:32 am
I was trying to give the player more chances to attack a moving horizontal boss if the player misses the stomp, by making the section level warp during an event with Lua.
Here is my code:

Code: Select all

function onEvent(eventName)
    if  eventName == "attack" then
        Section.isLevelWarp	= true
    end
    if  eventName == "defeat"
        Section.isLevelWarp	= false
    end
end
This doesn't work, I think that the event didn't change the section setting though.
https://wohlsoft.ru/pgewiki/Section_(class)
Section is a class, much like NPC. You wouldn't do NPC.x = player.x and expect a single npc to move to the player position, right? Gotta get the correct section first. local playersection = Section(player.section)

cato
Volcano Lotus
Volcano Lotus
Posts: 564
Joined: Thu Aug 24, 2017 3:06 am
Flair: Koishi enjoyer
Contact:

Re: Need help with lua? - LunaLua General Help

Postby cato » Fri Sep 27, 2019 7:01 am

Thanks. I fixed it by making that section exactly 27 blocks wide. Probably because of the screen scrolls.

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

Re: Need help with lua? - LunaLua General Help

Postby Emral » Fri Sep 27, 2019 7:25 am

1) One screen is 25 blocks wide.
2) Setting level wrap works regardless of section width.

Wiimeiser
Snifit
Snifit
Posts: 215
Joined: Mon Jun 24, 2019 4:36 am
Flair: What?

Re: Need help with lua? - LunaLua General Help

Postby Wiimeiser » Sat Sep 28, 2019 5:43 am

How would I get the Fuzzy effect to always be active in a level? The wavy effect that goes away after a while, not the pixel effect that occurs on impact, that would make the level unplayable. I think I have to copy or reference some code somewhere, but I'm not sure how or where...

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

Re: Need help with lua? - LunaLua General Help

Postby Emral » Sat Sep 28, 2019 7:38 am

Wiimeiser wrote:
Sat Sep 28, 2019 5:43 am
How would I get the Fuzzy effect to always be active in a level? The wavy effect that goes away after a while, not the pixel effect that occurs on impact, that would make the level unplayable. I think I have to copy or reference some code somewhere, but I'm not sure how or where...
Make a local copy of the fuzzy npc in the custom npc-n range and remove the line in onTick that decrements dizzy, then NPC.spawn one on top of the player in onStart in your luna.lua.

Wiimeiser
Snifit
Snifit
Posts: 215
Joined: Mon Jun 24, 2019 4:36 am
Flair: What?

Re: Need help with lua? - LunaLua General Help

Postby Wiimeiser » Sat Sep 28, 2019 11:58 pm

Enjl wrote:
Sat Sep 28, 2019 7:38 am
Wiimeiser wrote:
Sat Sep 28, 2019 5:43 am
How would I get the Fuzzy effect to always be active in a level? The wavy effect that goes away after a while, not the pixel effect that occurs on impact, that would make the level unplayable. I think I have to copy or reference some code somewhere, but I'm not sure how or where...
Make a local copy of the fuzzy npc in the custom npc-n range and remove the line in onTick that decrements dizzy, then NPC.spawn one on top of the player in onStart in your luna.lua.
Okay, I copied fuzzy.lua over, renamed it, and deleted the line in question, though I don't know if it will work yet. I'm not sure how to NPC.spawn one in luna.lua. I can't find it in the handbook...

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

Re: Need help with lua? - LunaLua General Help

Postby Emral » Sun Sep 29, 2019 5:46 am

Wiimeiser wrote:
Sat Sep 28, 2019 11:58 pm
Enjl wrote:
Sat Sep 28, 2019 7:38 am
Wiimeiser wrote:
Sat Sep 28, 2019 5:43 am
How would I get the Fuzzy effect to always be active in a level? The wavy effect that goes away after a while, not the pixel effect that occurs on impact, that would make the level unplayable. I think I have to copy or reference some code somewhere, but I'm not sure how or where...
Make a local copy of the fuzzy npc in the custom npc-n range and remove the line in onTick that decrements dizzy, then NPC.spawn one on top of the player in onStart in your luna.lua.
Okay, I copied fuzzy.lua over, renamed it, and deleted the line in question, though I don't know if it will work yet. I'm not sure how to NPC.spawn one in luna.lua. I can't find it in the handbook...
Remember to also change fuzzy.id to instead refer to the constant NPC_ID, which changes depending on the file name.

As for NPC.spawn documentation... https://wohlsoft.ru/pgewiki/NPC_(class)

Wiimeiser
Snifit
Snifit
Posts: 215
Joined: Mon Jun 24, 2019 4:36 am
Flair: What?

Re: Need help with lua? - LunaLua General Help

Postby Wiimeiser » Sun Sep 29, 2019 7:49 am

I really don't know any LunaLUA... How would I just spawn NPC 999? Also, is this right?

Code: Select all

fuzzy.id = 999

local npcManager = require("npcManager")

fuzzy.settings = npcManager.setNpcSettings{
	id = 999,
	
I don't know what I need to change here...

EDIT: Changed the ID to 999 to avoid any potential conflicts. I tried putting NPC.spawn(999, 67, 69, 1, 0) in my luna.lua but it just throws an error on startup ("No matching overload", whatever that means), what do I actually need to contain it in? The handbook isn't helping me at all... Maybe I'm getting in way over my head and need to use only NPCs with no lua requirement...

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

Re: Need help with lua? - LunaLua General Help

Postby Emral » Sun Sep 29, 2019 8:37 am

The handbook is just for stuff that wasn't on the wiki already, since we're planning on building a new, complete documentation from scratch. The link I provided has all the info.

Overloards for NPC.spawn are:
NPC.spawn(id, x, y, section)
NPC.spawn(id, x, y, section, shouldRespawn?)
NPC.spawn(id, x, y, section, shouldRespawn?, centered?)

The types of each argument are (number, number, number, number, boolean, boolean)
In your line you put NPC.spawn(number, number, number, number, number)
So it complains because it expected true or false for "shouldRespawn?".
ShouldRespawn and centered both default to "false".
Removing the ", 0" should fix it.
That said, you're unlikely to see any changes afterwards. Since the coordinates and section you spawn at seem kinda suspicious. You're spawning at coordinates 67,69 in section 1 (the 2nd section). That's usually where section 10 is situated. Here's an image of how the sections in SMBX are laid out:
Spoiler: show
Image
(not entirely accurate since section 10's top left corner is 0,0)
To spawn the fuzzy on top of the player, you can spawn it at the coordinates player.x, player.y.
To ensure you spawn it in the player's section, you can spawn it in the section player.section.
So your call would look like this:
function onStart()
NPC.spawn(999, player.x, player.y, player.section)
end

Wiimeiser
Snifit
Snifit
Posts: 215
Joined: Mon Jun 24, 2019 4:36 am
Flair: What?

Re: Need help with lua? - LunaLua General Help

Postby Wiimeiser » Sun Sep 29, 2019 8:56 am

Okay, thanks for that. Turns out function onStart() was what I was missing. Now it works, except it gets stuck on the pixellation making the level unplayable. I removed the dizzy = dizzy - 1 in the NPC lua file, was I not supposed to? If I put it back, it goes away after a while. So I'm not sure what I'm supposed to do to get it to stay at a specific point...

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

Re: Need help with lua? - LunaLua General Help

Postby Emral » Sun Sep 29, 2019 9:04 am

Turns out I misread the code.
Make the line like this:
dizzy = math.max(dizzy - 1, (dizziness/2) - 1)
I think that should do it.

Wiimeiser
Snifit
Snifit
Posts: 215
Joined: Mon Jun 24, 2019 4:36 am
Flair: What?

Re: Need help with lua? - LunaLua General Help

Postby Wiimeiser » Sun Sep 29, 2019 9:43 am

Yes, thanks, it's working as intended now.

cato
Volcano Lotus
Volcano Lotus
Posts: 564
Joined: Thu Aug 24, 2017 3:06 am
Flair: Koishi enjoyer
Contact:

Re: Need help with lua? - LunaLua General Help

Postby cato » Sat Oct 05, 2019 2:50 am

How I fix the effect with Lua?
I mean when I attack an NPC when it is moving left, everything is ok.
But when I attack the NPC when it is moving right, the effect is broken.

RudeGuy
Bowser
Bowser
Posts: 4994
Joined: Fri Dec 27, 2013 7:36 am
Flair: local guy

Re: Need help with lua? - LunaLua General Help

Postby RudeGuy » Sat Oct 05, 2019 6:54 am

cato wrote:
Sat Oct 05, 2019 2:50 am
How I fix the effect with Lua?
I mean when I attack an NPC when it is moving left, everything is ok.
But when I attack the NPC when it is moving right, the effect is broken.
can you please post the npc and effect graphics?

Daring Tombstone
Blooper
Blooper
Posts: 160
Joined: Mon Aug 28, 2017 10:57 pm
Flair: What? Not 1000 posts? That means I suck right?

Re: Need help with lua? - LunaLua General Help

Postby Daring Tombstone » Fri Oct 11, 2019 7:26 pm

How would I go about to set a check if the player has harmed an npc? (Specifically NPC-209, Mother brain)
I wanted to set "local Hit" from false to true if Mother Brain has been hit by a link sword slash. I've messed around with the NPC(class) here "https://wohlsoft.ru/pgewiki/NPC_(class)#Offsets" but I can't figure it out. If it's no trouble could I get an example code?

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

Re: Need help with lua? - LunaLua General Help

Postby Emral » Sat Oct 12, 2019 5:46 am

If you notice that 0x148 has increased compared to last frame, Mother Brain took damage. You can also check for changes in mother brain's ai1 value, or a nonzero number in 0x156.

SPEEDIE
Flurry
Flurry
Posts: 180
Joined: Sat Nov 03, 2018 6:22 pm
Flair: u fucking wot
Pronouns: he/him
Contact:

Cheats with LunaLua

Postby SPEEDIE » Sat Oct 26, 2019 3:01 pm

So I want to activate the "imtiredofallthiswalking" cheat at the first time you reach the world map, I added Misc.cheatBuffer("imtiredofallthiswalking") to map.lua (SMBX2 PAL) but it doesn't activate, but if I use for example Misc.cheatBuffer("liveforever"), the cheat code activates and gives me 99 lives.

When I enter the imtiredofallthiswalking inside the pause menu, it all works, I want all the paths to be open and the player to have 99 lives like VLDC!

Murphmario
2025 Egg Hunter
2025 Egg Hunter
Posts: 2389
Joined: Fri Dec 20, 2013 7:07 pm
Pronouns: he/him

Re: Need help with lua? - LunaLua General Help

Postby Murphmario » Sat Oct 26, 2019 4:07 pm

Question: How do I make it so that if an NPC config equals something, then it does something?

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

Re: Cheats with LunaLua

Postby Hoeloe » Sat Oct 26, 2019 6:34 pm

SPEEDIE wrote:
Sat Oct 26, 2019 3:01 pm
So I want to activate the "imtiredofallthiswalking" cheat at the first time you reach the world map, I added Misc.cheatBuffer("imtiredofallthiswalking") to map.lua (SMBX2 PAL) but it doesn't activate, but if I use for example Misc.cheatBuffer("liveforever"), the cheat code activates and gives me 99 lives.

When I enter the imtiredofallthiswalking inside the pause menu, it all works, I want all the paths to be open and the player to have 99 lives like VLDC!
This is a bug caused by Redigit being weird. It'll work properly in new versions of the engine, I think. For now, try Misc.cheatBuffer(" imtiredofallthiswalking") (note the extra space).


Return to “LunaLua Help”

Who is online

Users browsing this forum: No registered users and 2 guests

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari