Need help customizing NPCs

Need help with any SMBX game-related issues? Ask your questions here.
User avatar
Animebryan
Snifit
Snifit
Posts: 225
Joined: Fri Jun 03, 2016 5:40 pm
Flair: Need help!
Contact:

Need help customizing NPCs

Postby Animebryan » Fri Mar 05, 2021 3:17 pm

I'm trying to customize 2 npcs. The first is the Fire Bros. They don't spit fireballs as often as they should & I was wondering if there's a way to increase their firing rate (to be similar to how often regular Hammer Bros. throw their hammers). They also jump too damn much & their movement is awkward (Read: too unpredictable)

The second npc is the Red Panser. I just wanted to change it's SMB2 Fireball into Lightning Bolts resprited to look like SMB2 fireball & only fire 1 at a time. I used the template lua file to change it's projectile ID & reduced the shots= to 1 instead of 2. The problem is, when it fires the new projectile, it rapid fires them several times per second & fires them downward at an angle instead of an arc like the SMB2 Fireball.

Image
Spoiler: show
npc-346

Code: Select all

local npcManager = require("npcManager")
local panserAI = require("npcs/ai/pansers")

local panser = {}

local npcID = NPC_ID

npcManager.setNpcSettings({
	id = npcID,
	gfxheight=32,
	gfxwidth=32,
	width=28,
	height=28,
	frames=3,
	framestyle=0,
	jumphurt=true,
	spinjumpsafe=true,
	noblockcollision=false,
	nofireball=true,
	speedx=0,
	shotspeedx=1,
	shotspeedy=9,
	turntime=2,
	reloadtime=65,
	firetime=15,
    shots=1,
    projectileid = 361
})

npcManager.registerHarmTypes(npcID,
	{
		HARM_TYPE_FROMBELOW,
		HARM_TYPE_NPC,
		HARM_TYPE_HELD,
		HARM_TYPE_TAIL,
		HARM_TYPE_PROJECTILE_USED,
		HARM_TYPE_SWORD,
		HARM_TYPE_LAVA
	}, 
	{
		[HARM_TYPE_FROMBELOW]=178,
		[HARM_TYPE_NPC]=178,
		[HARM_TYPE_HELD]=178,
		[HARM_TYPE_TAIL]=178,
		[HARM_TYPE_PROJECTILE_USED]=178,
		[HARM_TYPE_LAVA]={id=13, xoffset=0.5, xoffsetBack = 0, yoffset=1, yoffsetBack = 1.5}
	}
);

panserAI.register(npcID)
return panser
Image
Spoiler: show
npc-361.lua

Code: Select all

local lightning = {}

local npcManager = require("npcManager")

local npcID = NPC_ID

npcManager.setNpcSettings({
	id = npcID,
	gfxoffsetx = 0,
	gfxoffsety = 0,
	gfxwidth = 32, 
	gfxheight = 32, 
	width = 32,
	height = 32,
	frames = 3,
	harmlessgrab=false,
	ignorethrownnpcs = true,
	framespeed = 8,
	framestyle = 1,
	nofireball=1,
	noiceball=-1,
	noyoshi=1,
	ishot = true,
	nohurt=0,
	speed=1,
	nogravity=-1,
	noblockcollision=-1,
	jumphurt = 1,
	nowaterphysics=true,
	spinjumpsafe = false,
	lightradius=32,
	lightbrightness=1,
	lightcolor=Color.white,

	spawnid = 362
})

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

local function initFire(v, f, dir)
	f.data._basegame = {}
	f.data._basegame.dir = dir
	f.data._basegame.spread = v.data._basegame.spread - 1
	f.data._basegame.wasThrown = v.data._basegame.wasThrown or false
	if v.data._basegame.friendly ~= nil then
		f.friendly = v.data._basegame.friendly
	else
		f.friendly = v.friendly
	end
	f.layerName = "Spawned NPCs"
	return f
end

function lightning.onTickNPC(v)
	if Defines.levelFreeze
		or v.isHidden
		or v:mem(0x12C, FIELD_WORD) > 0
		or v:mem(0x138, FIELD_WORD) > 0
		or v:mem(0x12A, FIELD_WORD) <= 0 then return end

	local data = v.data._basegame
	
	if data.feet == nil then
		data.feet = Colliders.Box(0,0,v.width,1)
		data.lastFrameCollision = true
	end
	
	if v:mem(0x136, FIELD_BOOL) == false then
		v.speedY = NPC.config[npcID].speed * 7
	else
		v.speedY = v.speedY + Defines.npc_grav
		data.wasThrown = data.wasThrown or v:mem(0x132, FIELD_WORD) > 0
	end

	if v.speedY > 0 then
		data.feet.x = v.x
		data.feet.y = v.y + v.height
		local collidesWithSolid = false
		local footCollisions = Colliders.getColliding{
		
			a=	data.feet,
			b=	Block.SOLID ..
				Block.PLAYER ..
				Block.SEMISOLID,
			btype = Colliders.BLOCK,
			filter= function(other)
				if (not collidesWithSolid and not other.isHidden and other:mem(0x5A, FIELD_WORD) == 0) then
					if Block.SOLID_MAP[other.id] or Block.PLAYER_MAP[other.id] then
						return true
					end
					if data.feet.y <= other.y + 8 then
						return true
					end
				end
				return false
			end
			
		}
		
		if #footCollisions > 0 then
			collidesWithSolid = true
			
			if not data.lastFrameCollision then
				local id = NPC.config[v.id].spawnid
				local f = NPC.spawn(id, v.x + 0.5 * v.width, footCollisions[1].y - 0.5 * NPC.config[id].height, v:mem(0x146, FIELD_WORD), false, true)
				if NPC.config[id].spread then
					data.spread = NPC.config[id].spread + 1
					initFire(v, f, 0)
				end
				SFX.play(42)
				v:kill(9)
				return
			end
		end
		data.lastFrameCollision = collidesWithSolid
	end
end

return lightning
npc-361.ini
[npc]
name = "Blazing Fireball"
group = "Super Mario Bros. 2"
category = "Projectile"
image = "npc-361.png"
description = "A SMB2 Fireball that generates flame pillars."
gfx-offset-x = 0
gfx-offset-y = 0
gfx-width = 32
gfx-height = 32
physical-width = 32
physical-height = 32
grid = 32
grid-offset-x = 0
grid-offset-y = 0
frame-style = 1
frames = 3
frame-delay = 128
foreground = 0
animation-direction = 0
animation-bidirectional = 0
custom-animation = 0
container = 0
contents-id = 0
have-special = 0

npc-361.txt
frames=3
framestyle=1
framespeed=8
Need serious help with Lua based features :(

Return to “Help and Support”

Who is online

Users browsing this forum: LunarCatUSA and 10 guests