[NPC/lua pack] Piranha Plants Ultimate (v1.3)

Share and discuss custom LunaLua code and content packs for SMBX2.

Moderator: Userbase Moderators

marioSuper21
Spiny
Spiny
Posts: 28
Joined: Thu Jul 31, 2025 8:43 am
Pronouns: he

[NPC/lua pack] Piranha Plants Ultimate (v1.3)

Postby marioSuper21 » Fri Aug 01, 2025 3:51 pm

What i did was just combine the piranhaPlant.lua from MrDoubleA and the Grounded Piranha Plant.lua from MegaDood and add improvements to it.
Spoiler: show
Piranha Plant:
Image
Grounded Piranha Plant:
Image
Fire Piranha Plant:
Image
Grounded Fire Piranha Plant:
Image
Changelog:
[1.0] - Initial release.
[1.1] - Modified the rotation of the piranha's head to move towards the player smoothly, with the addition of a move function to control the speed of the piranha plant to be equal to the speed of the first piranha plant.
[1.3] - Add Horizontal Piranha Plant and Fire Piranha Plant.

Credits:
piranhaPlant.lua script by MrDoubleA in SMBX2b5
Grounded Piranha Plant.lua script by MegaDood

future:
Spoiler: show
Horizontal Piranha Plant -- done
Fire Piranha Plant -- done
Jumping Piranha Plant -- coming soon
Ice Piranha Plant -- coming soon
Thank for:
mariobrigade2018 for Fireballs Update.
MrDoubleA for piranhaPlant.lua in SMBX2b5.
MegaDood for Grounded Piranha Plant.lua.

Download
Last edited by marioSuper21 on Tue Aug 19, 2025 5:00 pm, edited 5 times in total.

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

Re: [NPC/lua pack] Piranha Plants Ultimate (v1.0)

Postby mariobrigade2018 » Fri Aug 01, 2025 4:00 pm

Cool, but like, what’s the difference between this and the aforementioned stuff?

marioSuper21
Spiny
Spiny
Posts: 28
Joined: Thu Jul 31, 2025 8:43 am
Pronouns: he

Re: [NPC/lua pack] Piranha Plants Ultimate (v1.0)

Postby marioSuper21 » Fri Aug 01, 2025 4:17 pm

mariobrigade2018 wrote:
Fri Aug 01, 2025 4:00 pm
Cool, but like, what’s the difference between this and the aforementioned stuff?
Thank you! :D
Excellent question indeed!
The main difference is that the Piranha Plants Ultimate pack focuses on variety and expansion.
It currently includes the Normal and Grounded types, but I'll be working on adding Fire, Jumping, and others in the future—all with a unified and organized visual style.
The goal is for the pack to be comprehensive, cohesive, and easily expandable in the future.

Shaktool
2025 Egg Hunter
2025 Egg Hunter
Posts: 529
Joined: Thu Jul 25, 2024 5:34 am
Flair: zip zoom
Pronouns: male

Re: [NPC/lua pack] Piranha Plants Ultimate (v1.0)

Postby Shaktool » Sat Aug 02, 2025 6:09 am

mariobrigade2018 wrote:
Fri Aug 01, 2025 4:00 pm
Cool, but like, what’s the difference between this and the aforementioned stuff?
they're combined?

marioSuper21
Spiny
Spiny
Posts: 28
Joined: Thu Jul 31, 2025 8:43 am
Pronouns: he

Re: [NPC/lua pack] Piranha Plants Ultimate (v1.0)

Postby marioSuper21 » Sat Aug 02, 2025 7:15 am

Yes, that's one of the pack's goals: to bring together all Piranha Plant species into one organized project, unified in form, behavior, and aesthetics.
Instead of having them scattered across various sources, I've put them all in one place.
This isn't meant as an insult to other packs; without them, this pack wouldn't exist in the first place!

ShineBlaster
Buster Beetle
Buster Beetle
Posts: 92
Joined: Sat Jun 28, 2025 8:27 pm
Flair: Quiet and beginner level designer
Pronouns: He/Him

Re: [NPC/lua pack] Piranha Plants Ultimate (v1.0)

Postby ShineBlaster » Sat Aug 02, 2025 8:34 am

That's awesome my friend! I'm looking forward to the extra stuff you'll add in the future. Keep it up!

marioSuper21
Spiny
Spiny
Posts: 28
Joined: Thu Jul 31, 2025 8:43 am
Pronouns: he

Re: [NPC/lua pack] Piranha Plants Ultimate (v1.1)

Postby marioSuper21 » Mon Aug 04, 2025 6:57 am

In this version: The piranha's head rotation has been updated to smoothly move toward the player instead of jumping directly to the target angle.
And new move function has also been added to match the speed of the original piranha plant.

marioSuper21
Spiny
Spiny
Posts: 28
Joined: Thu Jul 31, 2025 8:43 am
Pronouns: he

Re: [NPC/lua pack] Piranha Plants Ultimate (v1.1)

Postby marioSuper21 » Wed Aug 06, 2025 7:40 pm

Get ready guys, Horizontal Piranha Plant and Fire Piranha Plant are coming soon!

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

Re: [NPC/lua pack] Piranha Plants Ultimate (v1.1)

Postby mariobrigade2018 » Wed Aug 06, 2025 10:33 pm

marioSuper21 wrote:
Wed Aug 06, 2025 7:40 pm
Get ready guys, Horizontal Piranha Plant and Fire Piranha Plant are coming soon!
Yay

marioSuper21
Spiny
Spiny
Posts: 28
Joined: Thu Jul 31, 2025 8:43 am
Pronouns: he

Re: [NPC/lua pack] Piranha Plants Ultimate (v1.3)

Postby marioSuper21 » Sat Aug 09, 2025 3:39 pm

Horizontal Piranha Plant and Fire Piranha Plant are here in v1.3.

NOTE: There's a problem with the Fire Piranha Plant in the PiranhaPlant code. When standing next to or in the middle of an NPC in idle mode, it jumps directly to hide mode (try this and you'll see). Please have someone try to fix it. If you do, please write the corrected code in the comments. Thank you for your efforts.

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

Re: [NPC/lua pack] Piranha Plants Ultimate (v1.3)

Postby mariobrigade2018 » Sun Aug 10, 2025 3:59 am

ok so I wasn't able to fix the plants, but I was able to improve the collision of the fireball. It'll be in the spoiler tab below:
Code: show

Code: Select all

local npcManager = require("npcManager")

local fireball = {}
local npcID = NPC_ID

local fireballSettings = {
	id = npcID,
	
	gfxwidth = 18,
	gfxheight = 18,

	gfxoffsetx = 0,
	gfxoffsety = 0,
	
	width = 18,
	height = 18,
	
	frames = 4,
	framestyle = 0,
	framespeed = 4,
	
	speed = 1,
	
	npcblock = false,
	npcblocktop = false, --Misnomer, affects whether thrown NPCs bounce off the NPC.
	playerblock = false,
	playerblocktop = false, --Also handles other NPCs walking atop this NPC.

	nohurt = false,
	nogravity = true,
	noblockcollision = false,
	nofireball = false,
	noiceball = false,
	noyoshi = true,
	nowaterphysics = false,
	
	jumphurt = true,
	spinjumpsafe = false,
	harmlessgrab = false,
	harmlessthrown = false,

	ignorethrownnpcs = true,
	linkshieldable = true,
	lightradius=32,
	lightbrightness=1,
	lightcolor=Color.orange,

	ishot = true,
	durability = 2,

}

npcManager.setNpcSettings(fireballSettings)
npcManager.registerHarmTypes(npcID,{HARM_TYPE_OFFSCREEN},{[HARM_TYPE_OFFSCREEN] = 10})

local function overlappingsolid(v) -- code from the bomb cannonball
	-- if there are no blocks overlapping
	local blocks = Colliders.getColliding{a = v,b = Block.SOLID .. Block.PLAYER,btype = Colliders.BLOCK,collisionGroup = v.collisionGroup}
	if #blocks == 0 then
		-- check for npcs overlapping
		for _, hit in ipairs(Colliders.getColliding{a = v, b = NPC.ALL, btype = Colliders.NPC,collisionGroup = v.collisionGroup}) do
			-- only care about npcs flagged as npcblock
			if NPC.config[hit.id].npcblock then
				-- overlapping an npc
				return true
			end
		end
	else
		-- overlapping a block
		return true
	end
	-- overlapping nothing
	return false
end

function fireball.onInitAPI()
	npcManager.registerEvent(npcID, fireball, "onTickNPC")
end

function fireball.onTickNPC(v)
	if Defines.levelFreeze then return end

	local data = v.data

	if v.despawnTimer <= 0 then
		data.initialized = false
		return
	end

	if not data.initialized then
		data.initialized = true
		data.inBlock = overlappingsolid(v)
		data.originalSpeedX,data.originalSpeedY = v.speedX,v.speedY
		if v.collisionGroup == "" then
			v.collisionGroup = "npc-" .. npcID
		end
	end

	if not overlappingsolid(v) and data.inBlock == true then
		data.inBlock = false
	end

	if not data.inBlock then
		v.noblockcollision = false
	end

	if lunatime.tick() % 3 == 0 then
		local effect = Effect.spawn(265, math.random(v.x, v.x + v.width), math.random(v.y, v.y + v.height))
		effect.x = effect.x - effect.width/2
		effect.y = effect.y - effect.height/2
		effect.priority = -44
	end

	if v.speedX ~= data.originalSpeedX then
		v.speedX = data.originalSpeedX
	end
	if v.speedY ~= data.originalSpeedY then
		v.speedY = data.originalSpeedY
	end

	if v:mem(0x120, FIELD_BOOL) then
		v:mem(0x120, FIELD_BOOL, false)
	end

	if not data.inBlock and (v.collidesBlockBottom or v.collidesBlockRight or v.collidesBlockUp or v.collidesBlockLeft) then
		v:kill(HARM_TYPE_OFFSCREEN)
	end
end

return fireball

marioSuper21
Spiny
Spiny
Posts: 28
Joined: Thu Jul 31, 2025 8:43 am
Pronouns: he

Re: [NPC/lua pack] Piranha Plants Ultimate (v1.3)

Postby marioSuper21 » Sun Aug 10, 2025 11:02 am

Oh! Thanks so much for the fireball update and sorry for bothering you with this.

dulushich_ViiU
Koopa
Koopa
Posts: 17
Joined: Sun Aug 27, 2023 8:08 am
Pronouns: them

Re: [NPC/lua pack] Piranha Plants Ultimate (v1.3)

Postby dulushich_ViiU » Mon Aug 18, 2025 8:34 pm

how to fix it?
Image

this happens when I level the piranha plant, but when I level the grounded piranha plant, everything is fine

(I'm sorry if you didn't understand me, I'm just sitting with a translator.)

marioSuper21
Spiny
Spiny
Posts: 28
Joined: Thu Jul 31, 2025 8:43 am
Pronouns: he

Re: [NPC/lua pack] Piranha Plants Ultimate (v1.3)

Postby marioSuper21 » Mon Aug 18, 2025 9:43 pm

Sorry for the problem, the mistake was my fault. I forgot to change config.isHorizontal to NPC.config[v.id].isHorizontal. Now change it or download the file again.

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

Re: [NPC/lua pack] Piranha Plants Ultimate (v1.3)

Postby mariobrigade2018 » Mon Aug 18, 2025 10:24 pm

marioSuper21 wrote:
Mon Aug 18, 2025 9:43 pm
Sorry for the problem, the mistake was my fault. I forgot to change config.isHorizontal to NPC.config[v.id].isHorizontal. Now change it or download the file again.
Has the fire piranha plant not working while next to it has been fixed?

Shaktool
2025 Egg Hunter
2025 Egg Hunter
Posts: 529
Joined: Thu Jul 25, 2024 5:34 am
Flair: zip zoom
Pronouns: male

Re: [NPC/lua pack] Piranha Plants Ultimate (v1.3)

Postby Shaktool » Tue Aug 19, 2025 1:36 pm

i wonder if Ice piranha plants can be implemented aswell, like Fire piranhas?

marioSuper21
Spiny
Spiny
Posts: 28
Joined: Thu Jul 31, 2025 8:43 am
Pronouns: he

Re: [NPC/lua pack] Piranha Plants Ultimate (v1.3)

Postby marioSuper21 » Tue Aug 19, 2025 4:57 pm

mariobrigade2018 wrote:
Mon Aug 18, 2025 10:24 pm
marioSuper21 wrote:
Mon Aug 18, 2025 9:43 pm
Sorry for the problem, the mistake was my fault. I forgot to change config.isHorizontal to NPC.config[v.id].isHorizontal. Now change it or download the file again.
Has the fire piranha plant not working while next to it has been fixed?
Not yet but I'm not sure if I can fix it
Shaktool wrote: i wonder if Ice piranha plants can be implemented aswell, like Fire piranhas?
You know what, dude, you reminded me of that. I'm going to work on that in the future with the jumping piranha plant.


Return to “LunaLua”

Who is online

Users browsing this forum: No registered users and 0 guests

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari