Need help with lua? - LunaLua General Help

Post here for help and support regarding LunaLua and SMBX2's libraries and features.
User avatar
cato
Bit
Bit
Posts: 135
Joined: Thu Aug 24, 2017 3:06 am
Current Project: My episode
Chat Username: Cato
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.

User avatar
Enjl
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 7511
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Orphion Egamalenitar Osmos IV, Esq.

Re: Need help with lua? - LunaLua General Help

Postby Enjl » 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)
ImageImageImageImage
ImageImageImageImageImageImage

User avatar
cato
Bit
Bit
Posts: 135
Joined: Thu Aug 24, 2017 3:06 am
Current Project: My episode
Chat Username: Cato
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.

User avatar
Enjl
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 7511
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Orphion Egamalenitar Osmos IV, Esq.

Re: Need help with lua? - LunaLua General Help

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

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

User avatar
Wiimeiser
Spiny
Spiny
Posts: 56
Joined: Mon Jun 24, 2019 4:36 am
Flair: What?
Chat Username: Wiimeiser

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...

User avatar
Enjl
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 7511
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Orphion Egamalenitar Osmos IV, Esq.

Re: Need help with lua? - LunaLua General Help

Postby Enjl » 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.
ImageImageImageImage
ImageImageImageImageImageImage

User avatar
Wiimeiser
Spiny
Spiny
Posts: 56
Joined: Mon Jun 24, 2019 4:36 am
Flair: What?
Chat Username: Wiimeiser

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...

User avatar
Enjl
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 7511
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Orphion Egamalenitar Osmos IV, Esq.

Re: Need help with lua? - LunaLua General Help

Postby Enjl » 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)
ImageImageImageImage
ImageImageImageImageImageImage

User avatar
Wiimeiser
Spiny
Spiny
Posts: 56
Joined: Mon Jun 24, 2019 4:36 am
Flair: What?
Chat Username: Wiimeiser

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...

User avatar
Enjl
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 7511
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Orphion Egamalenitar Osmos IV, Esq.

Re: Need help with lua? - LunaLua General Help

Postby Enjl » 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
ImageImageImageImage
ImageImageImageImageImageImage

User avatar
Wiimeiser
Spiny
Spiny
Posts: 56
Joined: Mon Jun 24, 2019 4:36 am
Flair: What?
Chat Username: Wiimeiser

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...

User avatar
Enjl
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 7511
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Orphion Egamalenitar Osmos IV, Esq.

Re: Need help with lua? - LunaLua General Help

Postby Enjl » 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.
ImageImageImageImage
ImageImageImageImageImageImage

User avatar
Wiimeiser
Spiny
Spiny
Posts: 56
Joined: Mon Jun 24, 2019 4:36 am
Flair: What?
Chat Username: Wiimeiser

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.

User avatar
cato
Bit
Bit
Posts: 135
Joined: Thu Aug 24, 2017 3:06 am
Current Project: My episode
Chat Username: Cato
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.

User avatar
RudeGuy
Luigi
Luigi
Posts: 4970
Joined: Fri Dec 27, 2013 7:36 am
Flair: help
Current Project: a random smw hack
Chat Username: rudeguy

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?
im bored

User avatar
Daring Tombstone
Rex
Rex
Posts: 96
Joined: Mon Aug 28, 2017 10:57 pm
Flair: Sad I didn't fight Jirachi
Current Project: Something Maybe
Chat Username: Chaperone

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?
Accurate representation of me after seeing the new SMBX version right after posting my new episode.
Image
Check out my completed episode
Spoiler: show
Image

User avatar
Enjl
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 7511
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Orphion Egamalenitar Osmos IV, Esq.

Re: Need help with lua? - LunaLua General Help

Postby Enjl » 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.
ImageImageImageImage
ImageImageImageImageImageImage


Return to “LunaLua Help”

Who is online

Users browsing this forum: No registered users and 0 guests