How to create NPCs with basegame behavior?

Post here for help and support regarding LunaLua and SMBX2's libraries and features.
Donkdonker124
Bob-Omb
Bob-Omb
Posts: 20
Joined: Wed Mar 27, 2024 10:31 am
Flair: Fictionally stronger than man
Pronouns: he/him
Contact:

How to create NPCs with basegame behavior?

Postby Donkdonker124 » Mon Apr 22, 2024 4:30 pm

I decided to start working on an NPC pack that just adds things I thought are neat, and I'm currently trying to work on a Para-Goombrat that functions like a para-koopa. How do I do that?

I also would want to figure out how to make a red variant.

Just_Thomas
Spike
Spike
Posts: 263
Joined: Sat Dec 16, 2023 3:32 am
Pronouns: he/him

Re: How to create NPCs with basegame behavior?

Postby Just_Thomas » Tue Apr 23, 2024 2:49 am

I think this might be good example here:

Code: Select all

local npcManager = require("npcManager")

local porcupo = {}

local npcID = NPC_ID

local config = npcManager.setNpcSettings({
	id = npcID,
	gfxheight = 32,
	gfxwidth = 32,
	gfxoffsetx = 0,
	gfxoffsety = 0,
	width = 32, 
	height = 32,
	frames = 2,
	framestyle = 1,
	cliffturn = 1,
	jumphurt = true,
	nofireball = true,
	noiceball = false,
	noyoshi = false,
	nohurt = false,
	jumphurt = true,
	spinjumpsafe = true,
	iswalker = true
})

local harmTypes = {
	[HARM_TYPE_PROJECTILE_USED] = 877,
	[HARM_TYPE_NPC]      = 877,
	[HARM_TYPE_HELD]     = 877,
	[HARM_TYPE_TAIL]     = 877,
	[HARM_TYPE_SWORD]    = 10,
	[HARM_TYPE_FROMBELOW]= 877,
	[HARM_TYPE_LAVA]     = {id = 13, xoffset = 0.5, xoffsetBack = 0, yoffset = 1, yoffsetBack = 1.5}
}

npcManager.registerHarmTypes(npcID, table.unmap(harmTypes), harmTypes)

return porcupo
You should actually be able to fumble your way through most of it.
Source:
[NPC Pack] Chilly's NPCs: v1.1.4 Beta Update
by: Chilly14
viewtopic.php?t=24406
(As I am NOT a coder I can not really write in the normal expected "trade language"or "lingo")
Here are just a few impressions and comments on my part, as you can see, "local porcupo = {}" is used at the beginning, only to end the whole process with "return porcupo"...!
In the case of "[HARM_TYPE_NPC] = 877", for example, the number is actually only there for the own effect ID,
I don't know if you could have done this here with "NPC_ID" instead,
"[HARM_TYPE_SWORD] = 10" is a standard effect and should probably differ accordingly (that's the way it should be and it makes sense).
Otherwise, I have linked important Wiki pages here, where you may find some additional information.

https://docs.codehaus.moe/#/constants/enemy-harm-types
https://docs.codehaus.moe/#/features/npc-config
Last edited by Just_Thomas on Tue Apr 23, 2024 3:01 am, edited 2 times in total.

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

Re: How to create NPCs with basegame behavior?

Postby mariobrigade2018 » Tue Apr 23, 2024 2:55 am

Just_Thomas wrote:
Tue Apr 23, 2024 2:49 am
I think this might be good example here:

Code: Select all

local npcManager = require("npcManager")

local porcupo = {}

local npcID = NPC_ID

local config = npcManager.setNpcSettings({
	id = npcID,
	gfxheight = 32,
	gfxwidth = 32,
	gfxoffsetx = 0,
	gfxoffsety = 0,
	width = 32, 
	height = 32,
	frames = 2,
	framestyle = 1,
	cliffturn = 1,
	jumphurt = true,
	nofireball = true,
	noiceball = false,
	noyoshi = false,
	nohurt = false,
	jumphurt = true,
	spinjumpsafe = true,
	iswalker = true
})

local harmTypes = {
	[HARM_TYPE_PROJECTILE_USED] = 877,
	[HARM_TYPE_NPC]      = 877,
	[HARM_TYPE_HELD]     = 877,
	[HARM_TYPE_TAIL]     = 877,
	[HARM_TYPE_SWORD]    = 10,
	[HARM_TYPE_FROMBELOW]= 877,
	[HARM_TYPE_LAVA]     = {id = 13, xoffset = 0.5, xoffsetBack = 0, yoffset = 1, yoffsetBack = 1.5}
}

npcManager.registerHarmTypes(npcID, table.unmap(harmTypes), harmTypes)

return porcupo
You should actually be able to fumble your way through most of it.
Source:
[NPC Pack] Chilly's NPCs: v1.1.4 Beta Update
by: Chilly14
viewtopic.php?t=24406
https://docs.codehaus.moe/#/constants/enemy-harm-types
https://docs.codehaus.moe/#/features/npc-config
I think he’s talking about 1.3 npc...

Donkdonker124
Bob-Omb
Bob-Omb
Posts: 20
Joined: Wed Mar 27, 2024 10:31 am
Flair: Fictionally stronger than man
Pronouns: he/him
Contact:

Re: How to create NPCs with basegame behavior?

Postby Donkdonker124 » Tue Apr 23, 2024 2:56 pm

mariobrigade2018 wrote:I think he's talking about 1.3 npc...
Yup. That's what I mean.

Just_Thomas
Spike
Spike
Posts: 263
Joined: Sat Dec 16, 2023 3:32 am
Pronouns: he/him

Re: How to create NPCs with basegame behavior?

Postby Just_Thomas » Tue Apr 23, 2024 3:32 pm

Well, Luna Lua involves scripting and I understood your post accordingly (as you posted here).

So you can change existing NPCs by creating a npc-X.txt in your project folder with the new parameters as shown here (like for example: npc-165.txt for the SMW galoomba):
https://docs.codehaus.moe/#/features/npc-config

Normally, people don't publish such things on their own (anymore), but only in combination with their own projects, where the npcs are then used in a modified form. Fortunately, the 1.3. times are over, where you were so restricted.

Also check out the invasion 2 project folder within your SMBX installation. It has some of these mentioned cases if you search for "npc-*.txt".

Donkdonker124
Bob-Omb
Bob-Omb
Posts: 20
Joined: Wed Mar 27, 2024 10:31 am
Flair: Fictionally stronger than man
Pronouns: he/him
Contact:

Re: How to create NPCs with basegame behavior?

Postby Donkdonker124 » Tue Apr 23, 2024 4:51 pm

That's not what I'm looking for. I want to know how to recreate basegame behavior in lunaLua specifically, like the para-goomba, for example.

I mean, if you're not able to code in lua, that's fine. None of us are perfect at it. But I want to keep basegame NPCs intact.

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

Re: How to create NPCs with basegame behavior?

Postby Emral » Wed Apr 24, 2024 2:40 am

The flying npc movement patterns are the isflying npc config:
https://docs.codehaus.moe/#/features/npc-config

To make the enemy turn into another enemy when stomped, you can use onNPCHarm

Code: Select all

function myNPC.onPostNPCHarm(event, v, rsn, culprit) -- replace myNPC with the name of the library table in your npc-n.lua file
	if v.id == NPC_ID and rsn == 1 then
		event.cancelled = true
		v:transform(NEW_ID) -- replace NEW_ID with the ID of the NPC after losing its wings
	end
end
Put the two together and you got yourself a paragoomba/parakoopa.

Just_Thomas
Spike
Spike
Posts: 263
Joined: Sat Dec 16, 2023 3:32 am
Pronouns: he/him

Re: How to create NPCs with basegame behavior?

Postby Just_Thomas » Wed Apr 24, 2024 3:20 am

Donkdonker124 wrote:
Tue Apr 23, 2024 4:51 pm
That's not what I'm looking for. I want to know how to recreate basegame behavior in lunaLua specifically, like the para-goomba, for example.

I mean, if you're not able to code in lua, that's fine. None of us are perfect at it. But I want to keep basegame NPCs intact.
Well .. I managed to misunderstand you twice in a row. But the good thing about such "debates" is that someone who knows better usually appears (at least that's how it often seems to me).
Emral wrote:
Wed Apr 24, 2024 2:40 am
The flying npc movement patterns are the isflying npc config:
https://docs.codehaus.moe/#/features/npc-config

To make the enemy turn into another enemy when stomped, you can use onNPCHarm

Code: Select all

function myNPC.onPostNPCHarm(event, v, rsn, culprit) -- replace myNPC with the name of the library table in your npc-n.lua file
	if v.id == NPC_ID and rsn == 1 then
		event.cancelled = true
		v:transform(NEW_ID) -- replace NEW_ID with the ID of the NPC after losing its wings
	end
end
Put the two together and you got yourself a paragoomba/parakoopa.
I just remembered about that one
"\MegaDood's NPC Pack\Accurate and Expanded Basegame NPCs\Para-Galoomba"
viewtopic.php?t=27285
In the original Super Mario World, paragaloombas would turn to face the player every so often.
They don't do this in SMBX2, so this bit of code adds that back to the enemy.
If you want to apply this to your levels, for more accuracy to SMW, just drag the lua file into your level folder.
I don't know whether this might also be of interest. At least the SMW behavior should be imitated here.
If not, then well.. maybe it is of interest to someone.

Donkdonker124
Bob-Omb
Bob-Omb
Posts: 20
Joined: Wed Mar 27, 2024 10:31 am
Flair: Fictionally stronger than man
Pronouns: he/him
Contact:

Re: How to create NPCs with basegame behavior?

Postby Donkdonker124 » Wed Apr 24, 2024 2:30 pm

Splendid! But there's just one problem.

I can't seem to get either the different AI modes or the transforming to work.

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

Re: How to create NPCs with basegame behavior?

Postby Emral » Wed Apr 24, 2024 6:23 pm

Donkdonker124 wrote:
Wed Apr 24, 2024 2:30 pm
Splendid! But there's just one problem.

I can't seem to get either the different AI modes or the transforming to work.
Could you share more details about how you are doing this?
Are you following this guide?

Donkdonker124
Bob-Omb
Bob-Omb
Posts: 20
Joined: Wed Mar 27, 2024 10:31 am
Flair: Fictionally stronger than man
Pronouns: he/him
Contact:

Re: How to create NPCs with basegame behavior?

Postby Donkdonker124 » Wed Apr 24, 2024 6:38 pm

Emral wrote:
Wed Apr 24, 2024 6:23 pm
Donkdonker124 wrote:
Wed Apr 24, 2024 2:30 pm
Splendid! But there's just one problem.

I can't seem to get either the different AI modes or the transforming to work.
Could you share more details about how you are doing this?
Are you following this guide?
I am trying to create a custom NPC that is a para-goombrat which behaves like the paragoomba. So far, I managed to get it to fly towards the player, but It doesn't support the other behaviors, nor does it transform into a goombrat (in this case ID 753). I tried using your code, seen here:

Code: Select all

function myNPC.onPostNPCHarm(event, v, rsn, culprit) -- replace myNPC with the name of the library table in your npc-n.lua file
	if v.id == NPC_ID and rsn == 1 then
		event.cancelled = true
		v:transform(NEW_ID) -- replace NEW_ID with the ID of the NPC after losing its wings
	end
end
I used this to try and get the enemy to transform upon being stomped, but that didn't seem to work, and it just dies with nothing else happening.
As for the extra behaviors, I thought it was working fine until I changed it from the "Chase" behavior (not to be confused with Chase 2), where it was always using this same behavior.

As of typing this, I have the guide open, and it seems like this concept is on the bottom of the list for "Practice Examples."

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

Re: How to create NPCs with basegame behavior?

Postby mariobrigade2018 » Wed Apr 24, 2024 7:57 pm

Donkdonker124 wrote:
Wed Apr 24, 2024 6:38 pm
Emral wrote:
Wed Apr 24, 2024 6:23 pm
Donkdonker124 wrote:
Wed Apr 24, 2024 2:30 pm
Splendid! But there's just one problem.

I can't seem to get either the different AI modes or the transforming to work.
Could you share more details about how you are doing this?
Are you following this guide?
I am trying to create a custom NPC that is a para-goombrat which behaves like the paragoomba. So far, I managed to get it to fly towards the player, but It doesn't support the other behaviors, nor does it transform into a goombrat (in this case ID 753). I tried using your code, seen here:

Code: Select all

function myNPC.onPostNPCHarm(event, v, rsn, culprit) -- replace myNPC with the name of the library table in your npc-n.lua file
	if v.id == NPC_ID and rsn == 1 then
		event.cancelled = true
		v:transform(NEW_ID) -- replace NEW_ID with the ID of the NPC after losing its wings
	end
end
I used this to try and get the enemy to transform upon being stomped, but that didn't seem to work, and it just dies with nothing else happening.
As for the extra behaviors, I thought it was working fine until I changed it from the "Chase" behavior (not to be confused with Chase 2), where it was always using this same behavior.

As of typing this, I have the guide open, and it seems like this concept is on the bottom of the list for "Practice Examples."
Can we see the code?

Donkdonker124
Bob-Omb
Bob-Omb
Posts: 20
Joined: Wed Mar 27, 2024 10:31 am
Flair: Fictionally stronger than man
Pronouns: he/him
Contact:

Re: How to create NPCs with basegame behavior?

Postby Donkdonker124 » Wed Apr 24, 2024 8:10 pm

Right here.
Spoiler: show

Code: Select all

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

--Create the library table
local paraGoombrat = {}
--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 paraGoombratSettings = {
	id = npcID,
	gfxheight = 48,
	gfxwidth = 40,
	gfxoffsetx = 0,
	gfxoffsety = 0,
	width = 32, 
	height = 32,
	frames = 4,
	framestyle = 0,
	framespeed = 4,
	isflying = true,
}

--Applies NPC settings
npcManager.setNpcSettings(paraGoombratSettings)

--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]=753,
		[HARM_TYPE_FROMBELOW]=754,
		[HARM_TYPE_NPC]=754,
		[HARM_TYPE_PROJECTILE_USED]=754,
		[HARM_TYPE_LAVA]={id=13, xoffset=0.5, xoffsetBack = 0, yoffset=1, yoffsetBack = 1.5},
		[HARM_TYPE_HELD]=754,
		[HARM_TYPE_TAIL]=754,
		[HARM_TYPE_SPINJUMP]=10,
		[HARM_TYPE_OFFSCREEN]=10,
		[HARM_TYPE_SWORD]=10,
	}
);

function paraGoombrat.onPostNPCHarm(event, v, rsn, culprit)
	if v.id == NPC_ID and rsn == 1 then
		event.cancelled = true
		v:transform(npcID - 1)
	end
end


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

return paraGoombrat

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

Re: How to create NPCs with basegame behavior?

Postby mariobrigade2018 » Wed Apr 24, 2024 9:15 pm

Donkdonker124 wrote:
Wed Apr 24, 2024 8:10 pm
Right here.
Spoiler: show

Code: Select all

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

--Create the library table
local paraGoombrat = {}
--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 paraGoombratSettings = {
	id = npcID,
	gfxheight = 48,
	gfxwidth = 40,
	gfxoffsetx = 0,
	gfxoffsety = 0,
	width = 32, 
	height = 32,
	frames = 4,
	framestyle = 0,
	framespeed = 4,
	isflying = true,
}

--Applies NPC settings
npcManager.setNpcSettings(paraGoombratSettings)

--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]=753,
		[HARM_TYPE_FROMBELOW]=754,
		[HARM_TYPE_NPC]=754,
		[HARM_TYPE_PROJECTILE_USED]=754,
		[HARM_TYPE_LAVA]={id=13, xoffset=0.5, xoffsetBack = 0, yoffset=1, yoffsetBack = 1.5},
		[HARM_TYPE_HELD]=754,
		[HARM_TYPE_TAIL]=754,
		[HARM_TYPE_SPINJUMP]=10,
		[HARM_TYPE_OFFSCREEN]=10,
		[HARM_TYPE_SWORD]=10,
	}
);

function paraGoombrat.onPostNPCHarm(event, v, rsn, culprit)
	if v.id == NPC_ID and rsn == 1 then
		event.cancelled = true
		v:transform(npcID - 1)
	end
end


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

return paraGoombrat
Looks like you didn't register onPostNPCHarm. Try replacing onTickNPC with onPostNPCHarm and see if it works.

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

Re: How to create NPCs with basegame behavior?

Postby Emral » Thu Apr 25, 2024 6:18 am

It doesn't support the other behaviors
This is something that just requires the proper UI to show up in the editor. In other words, it is controlled by the ini files.
You should make sure that the INI for your para enemy has this section, copied from npc-242.ini in data/pge/configs/smbx2/items/npc

Code: Select all

have-special = 1
special-name = "Paratroopa Algorithm"
special-type = 0
special-combobox-size = 9
special-option-0 = "Chase"
special-option-1 = "High Jump"
special-option-2 = "Fly & Turn Horizontal"
special-option-3 = "Fly & Turn Vertical"
special-option-4 = "Chase 2"
special-option-5 = "Low Jump"
special-option-6 = "Fly Horizontal"
special-option-7 = "Fly Vertical"
special-option-8 = "Hover In Place"

Donkdonker124
Bob-Omb
Bob-Omb
Posts: 20
Joined: Wed Mar 27, 2024 10:31 am
Flair: Fictionally stronger than man
Pronouns: he/him
Contact:

Re: How to create NPCs with basegame behavior?

Postby Donkdonker124 » Fri Apr 26, 2024 2:34 pm

mariobrigade2018 wrote:
Wed Apr 24, 2024 9:15 pm
Donkdonker124 wrote:
Wed Apr 24, 2024 8:10 pm
Right here.
Spoiler: show

Code: Select all

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

--Create the library table
local paraGoombrat = {}
--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 paraGoombratSettings = {
	id = npcID,
	gfxheight = 48,
	gfxwidth = 40,
	gfxoffsetx = 0,
	gfxoffsety = 0,
	width = 32, 
	height = 32,
	frames = 4,
	framestyle = 0,
	framespeed = 4,
	isflying = true,
}

--Applies NPC settings
npcManager.setNpcSettings(paraGoombratSettings)

--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]=753,
		[HARM_TYPE_FROMBELOW]=754,
		[HARM_TYPE_NPC]=754,
		[HARM_TYPE_PROJECTILE_USED]=754,
		[HARM_TYPE_LAVA]={id=13, xoffset=0.5, xoffsetBack = 0, yoffset=1, yoffsetBack = 1.5},
		[HARM_TYPE_HELD]=754,
		[HARM_TYPE_TAIL]=754,
		[HARM_TYPE_SPINJUMP]=10,
		[HARM_TYPE_OFFSCREEN]=10,
		[HARM_TYPE_SWORD]=10,
	}
);

function paraGoombrat.onPostNPCHarm(event, v, rsn, culprit)
	if v.id == NPC_ID and rsn == 1 then
		event.cancelled = true
		v:transform(npcID - 1)
	end
end


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

return paraGoombrat
Looks like you didn't register onPostNPCHarm. Try replacing onTickNPC with onPostNPCHarm and see if it works.
I tried that, and it just threw up this error.

Image

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

Re: How to create NPCs with basegame behavior?

Postby mariobrigade2018 » Fri Apr 26, 2024 2:42 pm

Donkdonker124 wrote:
Fri Apr 26, 2024 2:34 pm
mariobrigade2018 wrote:
Wed Apr 24, 2024 9:15 pm
Donkdonker124 wrote:
Wed Apr 24, 2024 8:10 pm
Right here.
Spoiler: show

Code: Select all

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

--Create the library table
local paraGoombrat = {}
--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 paraGoombratSettings = {
	id = npcID,
	gfxheight = 48,
	gfxwidth = 40,
	gfxoffsetx = 0,
	gfxoffsety = 0,
	width = 32, 
	height = 32,
	frames = 4,
	framestyle = 0,
	framespeed = 4,
	isflying = true,
}

--Applies NPC settings
npcManager.setNpcSettings(paraGoombratSettings)

--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]=753,
		[HARM_TYPE_FROMBELOW]=754,
		[HARM_TYPE_NPC]=754,
		[HARM_TYPE_PROJECTILE_USED]=754,
		[HARM_TYPE_LAVA]={id=13, xoffset=0.5, xoffsetBack = 0, yoffset=1, yoffsetBack = 1.5},
		[HARM_TYPE_HELD]=754,
		[HARM_TYPE_TAIL]=754,
		[HARM_TYPE_SPINJUMP]=10,
		[HARM_TYPE_OFFSCREEN]=10,
		[HARM_TYPE_SWORD]=10,
	}
);

function paraGoombrat.onPostNPCHarm(event, v, rsn, culprit)
	if v.id == NPC_ID and rsn == 1 then
		event.cancelled = true
		v:transform(npcID - 1)
	end
end


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

return paraGoombrat
Looks like you didn't register onPostNPCHarm. Try replacing onTickNPC with onPostNPCHarm and see if it works.
I tried that, and it just threw up this error.

Image
Shoot. Try replacing that line with this:

Code: Select all

registerEvent(paraGoombrat, "onPostNPCHarm")
At least the thing noticed the code...

Donkdonker124
Bob-Omb
Bob-Omb
Posts: 20
Joined: Wed Mar 27, 2024 10:31 am
Flair: Fictionally stronger than man
Pronouns: he/him
Contact:

Re: How to create NPCs with basegame behavior?

Postby Donkdonker124 » Sun Apr 28, 2024 8:16 pm

mariobrigade2018 wrote:
Fri Apr 26, 2024 2:42 pm

Shoot. Try replacing that line with this:

Code: Select all

registerEvent(paraGoombrat, "onPostNPCHarm")
At least the thing noticed the code...
This gave another error, but I'm trying to edit the code to try and fix it.
Image

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

Re: How to create NPCs with basegame behavior?

Postby mariobrigade2018 » Sun Apr 28, 2024 8:40 pm

Donkdonker124 wrote:
Sun Apr 28, 2024 8:16 pm
mariobrigade2018 wrote:
Fri Apr 26, 2024 2:42 pm

Shoot. Try replacing that line with this:

Code: Select all

registerEvent(paraGoombrat, "onPostNPCHarm")
At least the thing noticed the code...
This gave another error, but I'm trying to edit the code to try and fix it.
Image
Yeah, I don’t remember how to call in onPostNPCHarm, but I think that should be the last step.

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

Re: How to create NPCs with basegame behavior?

Postby Emral » Mon Apr 29, 2024 7:43 am

Donkdonker124 wrote:
Sun Apr 28, 2024 8:16 pm
mariobrigade2018 wrote:
Fri Apr 26, 2024 2:42 pm

Shoot. Try replacing that line with this:

Code: Select all

registerEvent(paraGoombrat, "onPostNPCHarm")
At least the thing noticed the code...
This gave another error, but I'm trying to edit the code to try and fix it.
Image
Could you show the current code, for reference? That error message wouldn't appear with the code mariobrigade gave you.


Return to “LunaLua Help”

Who is online

Users browsing this forum: No registered users and 0 guests

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari