I'm making a custom npc (smbx2)

Post here for help and support regarding LunaLua and SMBX2's libraries and features.
smbx2 level editor
Shy Guy
Shy Guy
Posts: 8
Joined: Thu Oct 01, 2020 7:19 am

I'm making a custom npc (smbx2)

Postby smbx2 level editor » Thu Oct 29, 2020 10:12 pm

I'm making a custom npc, but the custom npc doesn't go back
Now I can walk custom npc
How can I make a custom npc bounce when it hits a wall?
Gfx Pack
Spoiler: show
Soon...

Enjl
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 9075
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Orphion Egamalenitar Osmos IV, Esq.

Re: I'm making a custom npc (smbx2)

Postby Enjl » Fri Oct 30, 2020 2:26 am

That functionality is the default behaviour. To not get it you have to be doing something wrong. Show your code, please.
Ideas are useless if you can't make them real.
Image

All my assets from packs and episodes are free to use for non-Novaverse levels and projects, as long as proper credit is given.

Mirror of all my content and collaborations on IPFS: QmZKzVJAsD6dE2tTHEb58XEmsNLzrW2MVsTtW7HWLAAcCC

smbx2 level editor
Shy Guy
Shy Guy
Posts: 8
Joined: Thu Oct 01, 2020 7:19 am

Re: I'm making a custom npc (smbx2)

Postby smbx2 level editor » Fri Oct 30, 2020 3:03 am

Enjl wrote:
Fri Oct 30, 2020 2:26 am
That functionality is the default behaviour. To not get it you have to be doing something wrong. Show your code, please.

Code: Select all

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

--Create the library table
local sampleNPC = {}
--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 sampleNPCSettings = {
	id = 751,
	--Sprite size
	gfxheight = 64,
	gfxwidth = 64,
	--Hitbox size. Bottom-center-bound to sprite size.
	width = 64,
	height = 64,
	--Sprite offset from hitbox for adjusting hitbox anchor on sprite.
	gfxoffsetx = 0,
	gfxoffsety = 0,
	--Frameloop-related
	frames = 2,
	framestyle = 1,
	framespeed = 8, --# frames between frame change
	--Movement speed. Only affects speedX by default.
	speed = 1,
	--Collision-related
	npcblock = true,
	npcblocktop = true, --Misnomer, affects whether thrown NPCs bounce off the NPC.
	playerblock = false,
	playerblocktop = true, --Also handles other NPCs walking atop this NPC.

	nohurt=false,
	nogravity = false,
	noblockcollision = false,
	nofireball = true,
	noiceball = false,
	noyoshi= true,
	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=true,

	--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(sampleNPCSettings)

--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]=10,
		--[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]=10,
		--[HARM_TYPE_OFFSCREEN]=10,
		--[HARM_TYPE_SWORD]=10,
	}
);

--Custom local definitions below


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

function sampleNPC.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
	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
	
	--Execute main AI. This template just jumps when it touches the ground.
	if v.collidesBlockBottom then
		v.speedX = -0.6
	end
end

--Gotta return the library table!
return sampleNPC
Added in 42 minutes 52 seconds:
I'm making a big shy guy
Gfx Pack
Spoiler: show
Soon...

Enjl
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 9075
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Orphion Egamalenitar Osmos IV, Esq.

Re: I'm making a custom npc (smbx2)

Postby Enjl » Fri Oct 30, 2020 4:21 am

You set speedX to -0.6, which is always left. Try 0.6 * v.direction to make it adapt to facing direction (either -1 or 1).
Ideas are useless if you can't make them real.
Image

All my assets from packs and episodes are free to use for non-Novaverse levels and projects, as long as proper credit is given.

Mirror of all my content and collaborations on IPFS: QmZKzVJAsD6dE2tTHEb58XEmsNLzrW2MVsTtW7HWLAAcCC

smbx2 level editor
Shy Guy
Shy Guy
Posts: 8
Joined: Thu Oct 01, 2020 7:19 am

Re: I'm making a custom npc (smbx2)

Postby smbx2 level editor » Fri Oct 30, 2020 5:29 am

Added in 45 seconds:
Enjl wrote:
Fri Oct 30, 2020 4:21 am
You set speedX to -0.6, which is always left. Try 0.6 * v.direction to make it adapt to facing direction (either -1 or 1).
I didn't walk after adding
How do you use it?
Gfx Pack
Spoiler: show
Soon...

User avatar
Gabriel_2004
Shy Guy
Shy Guy
Posts: 6
Joined: Sat Feb 20, 2021 11:04 am
Pronouns: he/him

Re: I'm making a custom npc (smbx2)

Postby Gabriel_2004 » Tue Feb 23, 2021 8:09 am

smbx2 level editor wrote:
Fri Oct 30, 2020 5:30 am
Added in 45 seconds:
Enjl wrote:
Fri Oct 30, 2020 4:21 am
You set speedX to -0.6, which is always left. Try 0.6 * v.direction to make it adapt to facing direction (either -1 or 1).
I didn't walk after adding
How do you use it?
Did you put it like that?
v.speedX = 0.6 * v.direction
I am here with two goals, meeting people from the Smbx community, and learning about Lunalua to create my own npc packs, (sorry for my English, I am Brazilian)


Return to “LunaLua Help”

Who is online

Users browsing this forum: No registered users and 1 guest