Page 8 of 13

Re: Need help with lua? - LunaLua General Help

Posted: Thu Sep 26, 2019 9:32 am
by cato
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.

Re: Need help with lua? - LunaLua General Help

Posted: Thu Sep 26, 2019 10:35 am
by Enjl
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)

Re: Need help with lua? - LunaLua General Help

Posted: Fri Sep 27, 2019 7:01 am
by cato
Thanks. I fixed it by making that section exactly 27 blocks wide. Probably because of the screen scrolls.

Re: Need help with lua? - LunaLua General Help

Posted: Fri Sep 27, 2019 7:25 am
by Enjl
1) One screen is 25 blocks wide.
2) Setting level wrap works regardless of section width.

Re: Need help with lua? - LunaLua General Help

Posted: Sat Sep 28, 2019 5:43 am
by Wiimeiser
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...

Re: Need help with lua? - LunaLua General Help

Posted: Sat Sep 28, 2019 7:38 am
by Enjl
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.

Re: Need help with lua? - LunaLua General Help

Posted: Sat Sep 28, 2019 11:58 pm
by Wiimeiser
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...

Re: Need help with lua? - LunaLua General Help

Posted: Sun Sep 29, 2019 5:46 am
by Enjl
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)

Re: Need help with lua? - LunaLua General Help

Posted: Sun Sep 29, 2019 7:49 am
by Wiimeiser
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...

Re: Need help with lua? - LunaLua General Help

Posted: Sun Sep 29, 2019 8:37 am
by Enjl
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

Re: Need help with lua? - LunaLua General Help

Posted: Sun Sep 29, 2019 8:56 am
by Wiimeiser
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...

Re: Need help with lua? - LunaLua General Help

Posted: Sun Sep 29, 2019 9:04 am
by Enjl
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.

Re: Need help with lua? - LunaLua General Help

Posted: Sun Sep 29, 2019 9:43 am
by Wiimeiser
Yes, thanks, it's working as intended now.

Re: Need help with lua? - LunaLua General Help

Posted: Sat Oct 05, 2019 2:50 am
by cato
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.

Re: Need help with lua? - LunaLua General Help

Posted: Sat Oct 05, 2019 6:54 am
by RudeGuy
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?

Re: Need help with lua? - LunaLua General Help

Posted: Fri Oct 11, 2019 7:26 pm
by Daring Tombstone
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?

Re: Need help with lua? - LunaLua General Help

Posted: Sat Oct 12, 2019 5:46 am
by Enjl
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.

Cheats with LunaLua

Posted: Sat Oct 26, 2019 3:01 pm
by SPEEDIE
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!

Re: Need help with lua? - LunaLua General Help

Posted: Sat Oct 26, 2019 4:07 pm
by Murphmario
Question: How do I make it so that if an NPC config equals something, then it does something?

Re: Cheats with LunaLua

Posted: Sat Oct 26, 2019 6:34 pm
by Hoeloe
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).