My New code in Progresss
Posted: Thu Jan 06, 2022 3:22 pm
Hi, I'm working on a level where pressing alt run clones an NPC but I have a problem when the NPC dies out of the camera the alt run button doesn't work.

Here's the Code:
Ummm I need a bit of help pls

Here's the Code:
Code: Select all
local cloningdespawn = true
local advent = false
adventimer = 0
function onKeyDown(keycode)
if keycode == KEY_RUN and cloningdespawn == true then
local clonation = NPC.spawn(19,player.x + 0.5 * player.width, player.y + 0.5 * player.height + 8, player.section, false, true)
clonation.speedX = 1 * player.direction
SFX.play(9)
advent = true
end
if cloningdespawn == false and keycode == KEY_RUN then
for _,eso in ipairs(NPC.get(19, player.section)) do
eso:kill(8)
advent = false
end
end
end
function onTick()
if advent == true then
adventimer = adventimer + 1
if adventimer > 2 then
adventimer = 0
cloningdespawn = false
end
else
adventimer = adventimer + 1
if adventimer > 2 then
adventimer = 0
cloningdespawn = true
end
end
end
function onNPCKill(eventObj, killedNPC, killReason)
if killedNPC.id == 19 then
cloningdespawn = true
end
end