How do I make Piranha Plants take multiple hits to be defeated?

Post here for help and support regarding LunaLua and SMBX2's libraries and features.
mariobrigade2018
Spike
Spike
Posts: 299
Joined: Wed May 24, 2023 7:00 pm
Flair: Normie in coding who dreams of making a Mario game
Pronouns: he/him

How do I make Piranha Plants take multiple hits to be defeated?

Postby mariobrigade2018 » Wed Apr 24, 2024 1:04 pm

I discovered that the modern iteration of the Giant Piranha Plants makes them die on 3 hits. How would I add that to the Piranha Plants?

Cat king
Koopa
Koopa
Posts: 18
Joined: Thu Feb 29, 2024 1:04 pm
Flair: Mario kart wii is #1
Pronouns: he/him

Re: How do I make Piranha Plants take multiple hits to be defeated?

Postby Cat king » Thu Apr 25, 2024 11:51 am

I'm fairly certain that you can use NPC Config to change the number of hits it takes to defeat. But that might be just for bosses, I've never tried otherwise. in that case then you'll just have to make a script.

mariobrigade2018
Spike
Spike
Posts: 299
Joined: Wed May 24, 2023 7:00 pm
Flair: Normie in coding who dreams of making a Mario game
Pronouns: he/him

Re: How do I make Piranha Plants take multiple hits to be defeated?

Postby mariobrigade2018 » Thu Apr 25, 2024 2:51 pm

Cat king wrote:
Thu Apr 25, 2024 11:51 am
I'm fairly certain that you can use NPC Config to change the number of hits it takes to defeat. But that might be just for bosses, I've never tried otherwise. in that case then you'll just have to make a script.
That’s the problem. Health only works with boss enemies and CNPCs with that sort of code written in it. And I don’t know what to put there so that it works.

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

Re: How do I make Piranha Plants take multiple hits to be defeated?

Postby Emral » Thu Apr 25, 2024 7:03 pm

"Modern iteration" of giant piranha plants? SMBX2 uses Redigit's Big Piranha Plants which take6 hits from fireballs, 2 hits from other npcs and 3 hits from link's stab, so this code which roughly translates to this in a npc-n.lua:

Code: Select all

local multihit = {}

function multihit.onNPCHarm(e, v, r, c)
	if v.id == NPC_ID then
		if r ~= 1 and r ~= 2 and r ~= 6 then
			v.data.hits = v.data.hits or 0
               		if v.ai3 <= lunatime.tick() then -- invulnerability frames
                    		if r == 3 then -- npc hit
                        		if c and c.isValid and type(c) == "NPC" and c.id == 13 then
                            			SFX.play(39)
                            			v.data.hits = v.data.hits + 1
                           			v.ai3 = lunatime.tick() + 10
                           			if v.ai2 == 2 then v.ai1 = 50 end -- this is for retracting into the pipe. the current basegame plants might use a different variable for this
                        		else
                            			v.data.hits = v.data.hits + 3
                            			SFX.play(39)
                           			v.ai3 = lunatime.tick() + 30
                           			if v.ai2 == 2 then v.ai1 = 50 end -- this is for retracting into the pipe. the current basegame plants might use a different variable for this
                        		end
                   		elseif r == 10 then -- link stab
                        		v.data.hits = v.data.hits + 2
                           		v.ai3 = lunatime.tick() + 10
                           		if v.ai2 == 2 then v.ai1 = 50 end -- this is for retracting into the pipe. the current basegame plants might use a different variable for this
                    		end
               		end
                	If v.data.hits < 6 then e.cancelled = true end
		end
	end
end

registerEvent(multihit, "onNPCHarm")

return multihit

mariobrigade2018
Spike
Spike
Posts: 299
Joined: Wed May 24, 2023 7:00 pm
Flair: Normie in coding who dreams of making a Mario game
Pronouns: he/him

Re: How do I make Piranha Plants take multiple hits to be defeated?

Postby mariobrigade2018 » Thu Apr 25, 2024 10:15 pm

Emral wrote:
Thu Apr 25, 2024 7:03 pm
"Modern iteration" of giant piranha plants? SMBX2 uses Redigit's Big Piranha Plants which take 6 hits from fireballs, 2 hits from other npcs and 3 hits from link's stab, so this code which roughly translates to this in a npc-n.lua:

Code: Select all

local multihit = {}

function multihit.onNPCHarm(e, v, r, c)
	if v.id == NPC_ID then
		if r ~= 1 and r ~= 2 and r ~= 6 then
			v.data.hits = v.data.hits or 0
               		if v.ai3 <= lunatime.tick() then -- invulnerability frames
                    		if r == 3 then -- npc hit
                        		if c and c.isValid and type(c) == "NPC" and c.id == 13 then
                            			SFX.play(39)
                            			v.data.hits = v.data.hits + 1
                           			v.ai3 = lunatime.tick() + 10
                           			if v.ai2 == 2 then v.ai1 = 50 end -- this is for retracting into the pipe. the current basegame plants might use a different variable for this
                        		else
                            			v.data.hits = v.data.hits + 3
                            			SFX.play(39)
                           			v.ai3 = lunatime.tick() + 30
                           			if v.ai2 == 2 then v.ai1 = 50 end -- this is for retracting into the pipe. the current basegame plants might use a different variable for this
                        		end
                   		elseif r == 10 then -- link stab
                        		v.data.hits = v.data.hits + 2
                           		v.ai3 = lunatime.tick() + 10
                           		if v.ai2 == 2 then v.ai1 = 50 end -- this is for retracting into the pipe. the current basegame plants might use a different variable for this
                    		end
               		end
                	If v.data.hits < 6 then e.cancelled = true end
		end
	end
end

registerEvent(multihit, "onNPCHarm")

return multihit
I was referring to the ones that showed up in NSMBU, where they would take 3 fireballs to be defeated, but die in one to everything else that they can die to. They were shown in NSMBU. (Can't find the video at the moment) I can work with this though, and it can be used to Lua-fy the Redigit Plants. Thanks!

Also the code that you linked gave me a heart attack. Damn you, Redigit.


Return to “LunaLua Help”

Who is online

Users browsing this forum: No registered users and 0 guests

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari