Here's said code.
Code: Select all
local npcManager = require("npcManager")
local rng = API.load("rng");
local DAKU_1 = {}
local Units = {}
local npcID = NPC_ID
local DAKU_1_Settings = {
id = npcID,
score = 0,
gfxheight = 74,
gfxwidth = 126,
width = 126,
height = 74,
gfxoffsetx = 0,
gfxoffsety = 0,
frames = 6,
framestyle = 0,
framespeed = 5000,
speed = 2.2,
npcblock = true,
npcblocktop = true,
playerblock = false,
playerblocktop = false,
nohurt = false,
nogravity = false,
noblockcollision = false,
nofireball = true,
noiceball = true,
noyoshi= true,
nowaterphysics = true,
jumphurt = false,
spinjumpsafe = false,
harmlessgrab = false,
harmlessthrown = false,
grabside = false,
grabtop = false,
iswalker = true,
--lightradius = 100,
--lightbrightness = 1,
--lightoffsetx = 0,
--lightoffsety = 0,
--lightcolor = Color.white,
}
npcManager.setNpcSettings(DAKU_1_Settings)
npcManager.registerHarmTypes(npcID,
{
HARM_TYPE_JUMP,
HARM_TYPE_SPINJUMP,
}
);
function DAKU_1.onInitAPI()
npcManager.registerEvent(npcID, DAKU_1, "onTickNPC")
npcManager.registerEvent(npcID, DAKU_1, "onTickEndNPC")
npcManager.registerEvent(npcID, DAKU_1, "onDrawNPC")
registerEvent(DAKU_1, "onNPCKill")
end
function DAKU_1.onTickNPC(v)
if Defines.levelFreeze then return end
local data = v.data
if v.despawnTimer <= 0 then
data.initialized = false
return
end
v.AnimationTimer = 99999999
if not data.initialized and Units[v] == nil then
Units[v] = {
State = "Normal",
AnimationDebounce = 5,
AnimationDebounceAttack = 2,
Health = 5,
AttackTimer = 200,
DebounceTimer = 0,
DefaultDebounceTimer = 75,
}
data.initialized = true
end
end
function DAKU_1.onTickEndNPC(v)
if Defines.levelFreeze then return end
local data = v.data
if v.despawnTimer <= 0 then
data.initialized = false
return
end
v.AnimationTimer = 99999999
if Units[v] then
v.despawnTimer = 100
Table = Units[v]
if Table.State ~= "[DEAD]" then
if Table.State == "Normal" then
v.speed = 2.2
v.speedX = v.direction * 1
Table.AttackTimer = Table.AttackTimer - 1
if Table.AttackTimer <= 0 then
v.speedX = 0
Table.AttackTimer = rng.random(50,300)
Table.DebounceTimer = Table.DefaultDebounceTimer
Table.State = "Charging"
else
if Table.AnimationDebounce > 0 then
Table.AnimationDebounce = Table.AnimationDebounce - 1
else
Table.AnimationDebounce = 5
if v.animationFrame >= 3 then
v.animationFrame = 0
else
v.animationFrame = v.animationFrame + 1
end
end
end
elseif Table.State == "Charging" or Table.State == "Hurt" then
v.speedX = 0
Table.DebounceTimer = Table.DebounceTimer - 1
if Table.DebounceTimer <= 0 then
Table.State = "Normal"
else
if Table.AnimationDebounceAttack > 0 then
Table.AnimationDebounceAttack = Table.AnimationDebounceAttack - 1
else
Table.AnimationDebounceAttack = 3
if v.animationFrame == 4 then
v.animationFrame = 5
else
v.animationFrame = 4
end
end
end
end
else
v.speedX = 0
end
end
if v.collidesBlockBottom then
end
end
function DAKU_1.onNPCKill(eventObj, v, killReason, culprit)
if v.id ~= npcID then return end
eventObj.cancelled = true
if killReason then
if Units[v] then
local Table = Units[v]
if Table.State ~= "Charging" then
player.speedY = -4
SFX.play(2)
else
Table.Health = Table.Health - 1
player.speedY = -6
if Table.Health == 0 then
SFX.play(2)
Table.State = "[DEAD]"
Animation.spawn(267,x,y,player.section,false,true)
v:kill()
else
SFX.play(39)
Table.State = "Hurt"
Table.DebounceTimer = Table.DefaultDebounceTimer
end
end
end
end
end
return DAKU_1