(request) code for a functioning boss hp system

Post here for help and support regarding LunaLua and SMBX2's libraries and features.

Moderator: Userbase Moderators

KoolGamer32
Bob-Omb
Bob-Omb
Posts: 24
Joined: Tue Jan 19, 2021 11:35 am
Flair: Life is cool and stuff so yeah!
Pronouns: he/him
Contact:

(request) code for a functioning boss hp system

Postby KoolGamer32 » Mon Aug 30, 2021 10:59 am

I have tried everything and I just cant figure out how to make a custom boss with a fully functioning health system. everything i have tried doesnt work and I get an error and the off time it actually doesnt give me an erro my npc just dies in 1 hit. I also want to know how to give it ai and like where to put the boss hp code in the script and all that
Last edited by KoolGamer32 on Tue Aug 31, 2021 8:49 pm, edited 2 times in total.

wyldstrykr
Buster Beetle
Buster Beetle
Posts: 84
Joined: Mon May 31, 2021 11:20 pm

Re: How do i make a functioning boss hp system

Postby wyldstrykr » Tue Aug 31, 2021 4:44 am

lets say the boss npc is npc-800
what i did is make an amount of health, lets say 10.
on your npc-800.lua file, either do v.ai1=10 other v.ai1 to v.ai6 works or
v.data.health=10.

now how to reduce it??
on your main lua, make onnpcharm event. check the npc if its match (800) then check if the health is not 0. if it isnt. then cancel the event token and reduce its health by one via v.data.health = v.data.health -1 or v.ai1= v.ai1 -1.
that works for me. you can also do the onnpcharm on the npclua instead

KoolGamer32
Bob-Omb
Bob-Omb
Posts: 24
Joined: Tue Jan 19, 2021 11:35 am
Flair: Life is cool and stuff so yeah!
Pronouns: he/him
Contact:

Re: How do i make a functioning boss hp system

Postby KoolGamer32 » Tue Aug 31, 2021 11:14 am

Can you tell me the exact code I need to write for that I know almost nothing about lua

wyldstrykr
Buster Beetle
Buster Beetle
Posts: 84
Joined: Mon May 31, 2021 11:20 pm

Re: (request) code for a functioning boss hp system

Postby wyldstrykr » Tue Aug 31, 2021 10:26 pm

im not at home so please bear with me.
my eXample this time is npc-801. this is the lua of npc-801
Spoiler: show

Code: Select all

--NPCManager is required for setting basic NPC properties
local npcManager = require("npcManager")

--Create the library table
local RabbitW = {}
--NPC_ID is dynamic based on the name of the library file
local npcID = NPC_ID
--Defines NPC config for our NPC. You can remove superfluous definitions.
local RabbitWSettings = {
	id = npcID,
	--Sprite size
	gfxheight = 32,
	gfxwidth = 40,
	--Hitbox size. Bottom-center-bound to sprite size.
	width = 38,
	height = 31,
	--Sprite offset from hitbox for adjusting hitbox anchor on sprite.
	gfxoffsetx = 0,
	gfxoffsety = 0,
	--Frameloop-related
	frames = 5,
	framestyle = 1,
	framespeed = 8, --# frames between frame change
	--Movement speed. Only affects speedX by default.
	
	speed = 1,
	--Collision-related
	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 = false,
	noblockcollision = false,
	nofireball = false,
	noiceball = false,
	noyoshi= false,
	nowaterphysics = false,
	--Various interactions
	jumphurt = false, --If true, spiny-like
	spinjumpsafe = false, --If true, prevents player hurt when spinjumping
	harmlessgrab = false, --Held NPC hurts other NPCs if false
	harmlessthrown = false, --Thrown NPC hurts other NPCs if false

	grabside=false,
	grabtop=false,

	--Identity-related flags. Apply various vanilla AI based on the flag:
	iswalker=true,
	--isbot = false,
	--isvegetable = false,
	--isshoe = false,
	--isyoshi = false,
	--isinteractable = false,
	--iscoin = false,
	--isvine = false,
	--iscollectablegoal = false,
	--isflying = false,
	--iswaternpc = false,
	--isshell = false,

	--Emits light if the Darkness feature is active:
	--lightradius = 100,
	--lightbrightness = 1,
	--lightoffsetx = 0,
	--lightoffsety = 0,
	--lightcolor = Color.white,

	--Define custom properties below
}

--Applies NPC settings
npcManager.setNpcSettings(RabbitWSettings)

--Register the vulnerable harm types for this NPC. The first table defines the harm types the NPC should be affected by, while the second maps an effect to each, if desired.
npcManager.registerHarmTypes(npcID,
	{
		HARM_TYPE_JUMP,
		--HARM_TYPE_FROMBELOW,
		HARM_TYPE_NPC,
		--HARM_TYPE_PROJECTILE_USED,
		HARM_TYPE_LAVA,
		--HARM_TYPE_HELD,
		--HARM_TYPE_TAIL,
		HARM_TYPE_SPINJUMP,
		HARM_TYPE_OFFSCREEN,
		--HARM_TYPE_SWORD
	}, 
	{
		[HARM_TYPE_JUMP]=801,
		--[HARM_TYPE_FROMBELOW]=10,
		[HARM_TYPE_NPC]=10,
		--[HARM_TYPE_PROJECTILE_USED]=10,
		[HARM_TYPE_LAVA]={id=13, xoffset=0.5, xoffsetBack = 0, yoffset=1, yoffsetBack = 1.5},
		--[HARM_TYPE_HELD]=10,
		--[HARM_TYPE_TAIL]=10,
		[HARM_TYPE_SPINJUMP]=801,
		[HARM_TYPE_OFFSCREEN]=10,
		--[HARM_TYPE_SWORD]=10,
	}
);

--Custom local definitions below


--Register events
function RabbitW.onInitAPI()
	npcManager.registerEvent(npcID, RabbitW, "onTickNPC")
	--npcManager.registerEvent(npcID, RabbitW, "onNPCHarm")
	--npcManager.registerEvent(npcID, RabbitW, "onTickEndNPC")
	--npcManager.registerEvent(npcID, RabbitW, "onDrawNPC")
	--registerEvent(RabbitW, "onNPCKill")
end

function RabbitW.onTickNPC(v)
	--Don't act during time freeze
	
	if Defines.levelFreeze then return end
	
	local data = v.data
	
	--If despawned
	if v.despawnTimer <= 0 then
		--Reset our properties, if necessary
		data.initialized = false
		return
	end

	--Initialize
	if not data.initialized then
		--Initialize necessary data.
		data.initialized = true
		v.ai5=10
	end

	--Depending on the NPC, these checks must be handled differently
	if v:mem(0x12C, FIELD_WORD) > 0    --Grabbed
	or v:mem(0x136, FIELD_BOOL)        --Thrown
	or v:mem(0x138, FIELD_WORD) > 0    --Contained within
	then
		--Handling
	end	
end
--Gotta return the library table!
return RabbitW
the only important piece is the v.ai5. set it to the number you like.
then on your main lua, do this:

Code: Select all

function onNPCHarm(eventObj,killedNPC,killReason,culpritOrNil )
	
	if killedNPC.id==801 and killedNPC.ai5>1 then
		eventObj.cancelled = true
		killedNPC.ai5=killedNPC.ai5-1
	end
	
end
or something like that. i cant test it tho do to me being outside

KoolGamer32
Bob-Omb
Bob-Omb
Posts: 24
Joined: Tue Jan 19, 2021 11:35 am
Flair: Life is cool and stuff so yeah!
Pronouns: he/him
Contact:

Re: (request) code for a functioning boss hp system

Postby KoolGamer32 » Tue Aug 31, 2021 11:59 pm

Thanks although I amrgetting a weird warning every tick and I’m pretty sure the code isn’t working because of that so I made a different topic about that error. Regardless thanks for all the help


Return to “LunaLua Help”

Who is online

Users browsing this forum: No registered users and 1 guest

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari