Page 1 of 1

Luigi hitting blocks

Posted: Fri Nov 18, 2022 10:29 am
by Giggs-Chan
For some reason, when you hit a block with a coin in it as Luigi, you don't get the coin right away. You have to jump on top of the block and collect it. Is there any way to fix this and why was this implemented in the first place?

Re: Luigi hitting blocks

Posted: Fri Nov 18, 2022 12:42 pm
by deice
Giggs-Chan wrote:
Fri Nov 18, 2022 10:29 am
For some reason, when you hit a block with a coin in it as Luigi, you don't get the coin right away. You have to jump on top of the block and collect it. Is there any way to fix this and why was this implemented in the first place?
this same effect occurs with blocks that hold multiple coins as well. luigi or link hitting them will make all the coins pop out at once instead of requiring the player to hit it multiple times. it was probably implemented just cause redigit thought it would make for an interesting mechanic.

a way to patch this out could be:

Code: Select all

function onBlockHit(eventObj, hitBlock, fromUpper, playerOrNil)
	if(hitBlock.isValid and hitBlock.contentID < 1000 and playerOrNil and playerOrNil.character == CHARACTER_LUIGI) then
		eventObj.cancelled = true
		playerOrNil.character = CHARACTER_MARIO
		hitBlock:hit(fromUpper, playerOrNil, hitBlock:mem(0x04, FIELD_WORD))
		playerOrNil.character = CHARACTER_LUIGI
	end
end
and while this is kinda hacky, i can't really think of a better solution personally as passing the same character to block:hit() would cause an infinite recursion, crashing the game.

Re: Luigi hitting blocks

Posted: Sun Nov 20, 2022 3:56 pm
by Mushroom King
Worst, Luigi will not have the right amount if it's more than 21 coins, meaning he got less. More precisely, it is impossible for Luigi to get more than 21 coins in one block.

Re: Luigi hitting blocks

Posted: Mon Nov 21, 2022 8:08 am
by Giggs-Chan
Mushroom King wrote:
Sun Nov 20, 2022 3:56 pm
Worst, Luigi will not have the right amount if it's more than 21 coins, meaning he got less. More precisely, it is impossible for Luigi to get more than 21 coins in one block.
Probably cuz 9 plus 10 is 21 LOL

Added in 4 hours 59 minutes 17 seconds:
deice wrote:
Fri Nov 18, 2022 12:42 pm
Giggs-Chan wrote:
Fri Nov 18, 2022 10:29 am
For some reason, when you hit a block with a coin in it as Luigi, you don't get the coin right away. You have to jump on top of the block and collect it. Is there any way to fix this and why was this implemented in the first place?
this same effect occurs with blocks that hold multiple coins as well. luigi or link hitting them will make all the coins pop out at once instead of requiring the player to hit it multiple times. it was probably implemented just cause redigit thought it would make for an interesting mechanic.

a way to patch this out could be:

Code: Select all

function onBlockHit(eventObj, hitBlock, fromUpper, playerOrNil)
	if(hitBlock.isValid and hitBlock.contentID < 1000 and playerOrNil and playerOrNil.character == CHARACTER_LUIGI) then
		eventObj.cancelled = true
		playerOrNil.character = CHARACTER_MARIO
		hitBlock:hit(fromUpper, playerOrNil, hitBlock:mem(0x04, FIELD_WORD))
		playerOrNil.character = CHARACTER_LUIGI
	end
end
and while this is kinda hacky, i can't really think of a better solution personally as passing the same character to block:hit() would cause an infinite recursion, crashing the game.
Could you please post a file with the Luigi coin fix in it?

Re: Luigi hitting blocks

Posted: Tue Nov 22, 2022 12:48 pm
by deice
Giggs-Chan wrote:
Mon Nov 21, 2022 1:07 pm
Could you please post a file with the Luigi coin fix in it?
create a file in your episode folder (the same one that holds your world.wld file) if you want it to apply to your whole episode, or inside a level's custom folder (the one containing custom assets such as graphics) if it's necessary just for one level, name it "luna.lua" (without the quotation marks) and then copy and paste the code i posted inside it.

Re: Luigi hitting blocks

Posted: Tue Nov 22, 2022 1:31 pm
by Giggs-Chan
Alright, Thank you. I'm also waiting for Hatsune Blake to update the minimalist HUD.

Re: Luigi hitting blocks

Posted: Sat Nov 26, 2022 8:27 pm
by Giggs-Chan
Image

Ok, I put the code into the lunalua file, and this happened. What did I do wrong?

Re: Luigi hitting blocks

Posted: Sat Nov 26, 2022 10:23 pm
by Marioman2007
Try changing this line.

Code: Select all

if(hitBlock.isValid and hitBlock.contentID < 1000 and playerOrNil and playerOrNil.character == CHARACTER_LUIGI) then
to

Code: Select all

if(hitBlock.isValid and hitBlock.contentID >= 1 and hitBlock.contentID <= 99 and playerOrNil and playerOrNil.character == CHARACTER_LUIGI) then
The original code checks if a block has no npcs in it, this code checks if the block has coins in it since in this case we only want the coins to be affected.

Re: Luigi hitting blocks

Posted: Sun Nov 27, 2022 1:20 pm
by Giggs-Chan
I also figured out that Toad has the same problem with the blocks except this time, it's worse. It shows SMB2 coins. Do I just copy and paste and replace "LUIGI" with "TOAD"? If so, where?

Re: Luigi hitting blocks

Posted: Sun Nov 27, 2022 2:05 pm
by deice
Giggs-Chan wrote:
Sun Nov 27, 2022 1:20 pm
I also figured out that Toad has the same problem with the blocks except this time, it's worse. It shows SMB2 coins. Do I just copy and paste and replace "LUIGI" with "TOAD"? If so, where?
if you want to prevent this effect completely, regardless of character, you can use the following code instead of the previously posted one:

Code: Select all

function onBlockHit(eventObj, hitBlock, fromUpper, playerOrNil)
	if(hitBlock.isValid and hitBlock.contentID > 0 and hitBlock.contentID < 100 and playerOrNil and (player.character ~= CHARACTER_PEACH and player.character ~= CHARACTER_MARIO)) then
		eventObj.cancelled = true
		local prevChar = player.character
		playerOrNil.character = CHARACTER_MARIO
		hitBlock:hit(fromUpper, playerOrNil, hitBlock:mem(0x04, FIELD_WORD))
		playerOrNil.character = prevChar
	end
end

Re: Luigi hitting blocks

Posted: Sun Nov 27, 2022 9:06 pm
by Marioman2007
deice wrote:
Sun Nov 27, 2022 2:05 pm
if you also want to remove the feature where toad can hit a block multiple times at once, replace

Code: Select all

hitBlock:mem(0x04, FIELD_WORD)
with the number 1.

I think it's better to not specify the hit count, I remember running into a bug when I specified that as 1.
Spoiler: show
Image

Re: Luigi hitting blocks

Posted: Mon Nov 28, 2022 3:08 am
by deice
Marioman2007 wrote:
Sun Nov 27, 2022 9:06 pm
I think it's better to not specify the hit count, I remember running into a bug when I specified that as 1.
actually, (now that i've had time to test the code) it seems that memory offset 0x04 doesn't get updated before onBlockHit, meaning that the code I used already removes the feature by default and there's no need to change anything.