SM64 coin stars and coin value mod(Help me a bit!)

This is the place for discussion and support for LunaLua and related modifications and libraries.
Forum rules
Before you make a topic/post, consider the following:
-Is there a topic for this already?
-Is your post on topic/appropriate?
-Are you posting in the right forum/following the forum rules?
yoshiegg
Hoopster
Hoopster
Posts: 122
Joined: Mon Jan 25, 2016 9:20 am

SM64 coin stars and coin value mod(Help me a bit!)

Postby yoshiegg » Thu Sep 28, 2017 2:12 pm

Hey guys,

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
However, it neither displays my coin image nor the amount of coins I currently have and I wonder why so I need a little help.

The0x539
Eerie
Eerie
Posts: 751
Joined: Fri Jan 22, 2016 8:02 pm

Re: SM64 coin stars and coin value mod(Help me a bit!)

Postby The0x539 » Thu Sep 28, 2017 2:16 pm

onHUDDraw

Also, for your onNPCKill, look into doing a lookup table, so you can do:

Code: Select all

if coinValues[killedNPC.id] then
    coins = coins + coinValues[killedNPC.id]
end


Return to “LunaLua”

Who is online

Users browsing this forum: No registered users and 1 guest

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari