Page 1 of 1

Request: Lua code to stop Super Mushroom going left

Posted: Wed Feb 12, 2020 11:17 am
by JustInPassing
Hi, so I'm making a SMB1-themed level. I was wondering if there is any Lua code to stop the Super Mushroom going left when emerging from its ? block if you're facing right?

Thank you for reading.

Re: Request: Lua code to stop Super Mushroom going left

Posted: Wed Feb 12, 2020 12:49 pm
by Murphmario
You could probably call something when a Super Mushroom is spawned to force it to go right.

Re: Request: Lua code to stop Super Mushroom going left

Posted: Wed Feb 12, 2020 12:56 pm
by Cedur
So you always want to make it go right, or you don't want it to move at all? (the latter is trivial without Lua)

Re: Request: Lua code to stop Super Mushroom going left

Posted: Wed Feb 12, 2020 12:58 pm
by JustInPassing
Cedur wrote:
Wed Feb 12, 2020 12:56 pm
So you always want to make it go right, or you don't want it to move at all? (the latter is trivial without Lua)
The former i.e. always go right.

Re: Request: Lua code to stop Super Mushroom going left

Posted: Wed Feb 12, 2020 1:11 pm
by Cedur
Would it be a problem to just place an invisible block left to it?

Re: Request: Lua code to stop Super Mushroom going left

Posted: Thu Feb 13, 2020 12:24 am
by JustInPassing
Cedur wrote:
Wed Feb 12, 2020 1:11 pm
Would it be a problem to just place an invisible block left to it?
I've tried, and unless I'm doing something wrong, it would be a problem.

Re: Request: Lua code to stop Super Mushroom going left

Posted: Thu Feb 13, 2020 1:18 am
by Hammerless Penguin
Try this out.

Make a New layer for the block that contains the mushroom
Then make an event that triggers an invisible block to spawn on the left side for a short second when the block is hit.
When the event is finished go to options of the block that contains the mushroom and make sure the event is activated when Mario hits it. If the mushroom still moves to the left then make sure the time that the invisible block spawns is set to be longer.

It should work, if not then perhaps the only solution is to find out something with Luna lua or even a more simple solution is to just edit the configuration of the mushroom and set the speed to 0. The mushroom won’t move at all though.

Re: Request: Lua code to stop Super Mushroom going left

Posted: Thu Feb 13, 2020 2:50 am
by JustInPassing
Hammerless Penguin wrote:
Thu Feb 13, 2020 1:18 am
Try this out.

Make a New layer for the block that contains the mushroom
Then make an event that triggers an invisible block to spawn on the left side for a short second when the block is hit.
When the event is finished go to options of the block that contains the mushroom and make sure the event is activated when Mario hits it. If the mushroom still moves to the left then make sure the time that the invisible block spawns is set to be longer.

It should work, if not then perhaps the only solution is to find out something with Luna lua or even a more simple solution is to just edit the configuration of the mushroom and set the speed to 0. The mushroom won’t move at all though.
Thanks, I got it to work with your help. Here is what I did, for future prosperity.

1) Create a Layer called "Invisible Blocks" (the name doesn't really matter, but makes things clear).
2) Create an Event called "Power-Ups - Hit" (again, name doesn't really matter but makes things clear).
3) In the Layers window, select "Invisible Blocks" and place the invisible block left of where the power-up will spawn.
4) In the Events window, select "Level - Start", select "Layer visibility" and hide the "Invisible Blocks" layer. Preferably, check "Disable smoke transition".
5) Select "Power-Ups - Hit" in the Events window, select "Layer visibility and show the "Invisible Blocks" layer. "Disable smoke transition" is preferable here too.
6) With "Power-Ups - Hit" selected in the Events window, select "Trigger Event" and select "Level - Start" with a minimum delay of 0.5 (0.4 or less will make the invisible blocks disappear before the Super/1-up Mushroom fully spawns).
7) Finally, place your power-up ? Block with the "Power-Ups - Hit" selected as a hit event in the ? Block's properties.

Do you want to hear what I said again?

Re: Request: Lua code to stop Super Mushroom going left

Posted: Thu Feb 13, 2020 3:51 am
by Cedur
Hammerless Penguin wrote:
Thu Feb 13, 2020 1:18 am
Try this out.

Make a New layer for the block that contains the mushroom
Then make an event that triggers an invisible block to spawn on the left side for a short second when the block is hit.
When the event is finished go to options of the block that contains the mushroom and make sure the event is activated when Mario hits it. If the mushroom still moves to the left then make sure the time that the invisible block spawns is set to be longer.

It should work, if not then perhaps the only solution is to find out something with Luna lua or even a more simple solution is to just edit the configuration of the mushroom and set the speed to 0. The mushroom won’t move at all though.

Well, now that I think of it, that's quite smart.

Re: Request: Lua code to stop Super Mushroom going left

Posted: Thu Feb 13, 2020 5:52 am
by IAmPlayer
I looked through my codes, and sure enough, I have it. Someone asked this before to me, so you can reuse this.

Code: Select all

local mushroom = {9, 184, 185}

function onTick()
    for k,v in ipairs(NPC.get(mushroom)) do
        if v:mem(0x138, FIELD_WORD) == 1 then
            v.direction = DIR_RIGHT
        end
    end
end