at the moment i'm trying to make a star spawn when you collect 100 coins like in SM64 and came up with this code:
Code: Select all
local coin_star = {}
local coins = 0
local coin = Graphics.loadImage(Misc.resolveFile("coin_star/coin.png"))
function coin_star.onInitAPI()
registerEvent(coin_star, "onNPCKill", "onNPCKill", false)
registerEvent(coin_star, "onStart", "onStart", true)
registerEvent(coin_star, "onHUDdraw", "onHUDdraw", false)
registerEvent(coin_star, "onTick", "onTick", false)
end
function coin_star.onStart()
coins = 0
Graphics.activateHud(false)
end
function coin_star.onNPCKill(killObj, killedNPC, killReason)
if killedNPC.id == 10 or killedNPC.id == 33 or killedNPC.id == 88 or killedNPC.id == 138 or killedNPC.id == 251 then
coins = coins + 1
end
if killedNPC.id == 207 then
coins = coins + 2
end
if killedNPC.id == 258 or killedNPC.id == 252 then
coins = coins + 5
end
if coins >= 100 then
NPC.spawn(196,player.x,player.y-24,player.section)
end
end
function coin_star.onHUDdraw()
Text.printWP("coins",1,37,300,5) --coin counter
Graphics.drawImageWP(coin,4,300,5)
end
return coin_star