Reserve System for Peach and Toad

Description: Official subforum for LunaLua - an extension framework for SMBX Engine Version 1.3 (which a core of SMBX 2.0). Share your creations that require the use of LunaLUA. You may also share info/tutorials on how to use LunaLUA.
Moderator: Moderators

yoshiegg
Topic author, Passerby
Passerby
yoshiegg
Topic author, Passerby
Passerby
Reputation: 0
Posts: 3
Joined: 5 Jun 2017

Post #1by yoshiegg » 6 Jun 2017, 15:03

Hey Guys.
I've tried to write a code for a reserve box item system for Peach and Toad which includes 2 apis and looks like the following:
remark: for reasons of facility for me, I neither took screenshots of the game nor of my Hud folder cause I think you can imagine the issue from my description and the folders are filled with all necessary resources.If any of these screens are needed or appreciated, let me know and I'll add them

Code: Select all

local peach = {};

function peach.onInitAPI()
   registerEvent(peach, "onTick", "onTick", false)
   registerEvent(peach, "onNPCKill", "onNPCKill", false)

if (player.character == CHARACTER_PEACH or player.character == CHARACTER_TOAD) then
function peach.onNPCKill(killObj, killedNPC, killReason)

                if player.powerup == 2 then
if killReason == 9 and (killedNPC.id == 9 or killedNPC.id == 184 or killedNPC.id == 185 or killedNPC.id == 249 or killedNPC.id == 250 or killedNPC.id == 14 or killedNPC.id == 182 or killedNPC.id == 183 or killedNPC.id == 34 or killedNPC.id == 169 or killedNPC.id == 170 or killedNPC.id == 264 or killedNPC.id == 277) then
         player.reservePowerup = 9

                if player.powerup == 3 then
if killReason == 9 and (killedNPC.id == 9 or killedNPC.id == 184 or killedNPC.id == 185 or killedNPC.id == 249 or killedNPC.id == 250 or killedNPC.id == 14 or killedNPC.id == 182 or killedNPC.id == 183 or killedNPC.id == 34 or killedNPC.id == 169 or killedNPC.id == 170 or killedNPC.id == 264 or killedNPC.id == 277) then
                        player.reservePowerup = 14

                if player.powerup == 4 then
if killReason == 9 and (killedNPC.id == 9 or killedNPC.id == 184 or killedNPC.id == 185 or killedNPC.id == 249 or killedNPC.id == 250 or killedNPC.id == 14 or killedNPC.id == 182 or killedNPC.id == 183 or killedNPC.id == 34 or killedNPC.id == 169 or killedNPC.id == 170 or killedNPC.id == 264 or killedNPC.id == 277) then
                        player.reservePowerup = 34

      if player.powerup == 5 then
if killReason == 9 and (killedNPC.id == 9 or killedNPC.id == 184 or killedNPC.id == 185 or killedNPC.id == 249 or killedNPC.id == 250 or killedNPC.id == 14 or killedNPC.id == 182 or killedNPC.id == 183 or killedNPC.id == 34 or killedNPC.id == 169 or killedNPC.id == 170 or killedNPC.id == 264 or killedNPC.id == 277) then
                        player.reservePowerup = 169

      if player.powerup == 6 then
if killReason == 9 and (killedNPC.id == 9 or killedNPC.id == 184 or killedNPC.id == 185 or killedNPC.id == 249 or killedNPC.id == 250 or killedNPC.id == 14 or killedNPC.id == 182 or killedNPC.id == 183 or killedNPC.id == 34 or killedNPC.id == 169 or killedNPC.id == 170 or killedNPC.id == 264 or killedNPC.id == 277) then
                        player.reservePowerup = 170

      if player.powerup == 7 then
if killReason == 9 and (killedNPC.id == 9 or killedNPC.id == 184 or killedNPC.id == 185 or killedNPC.id == 249 or killedNPC.id == 250 or killedNPC.id == 14 or killedNPC.id == 182 or killedNPC.id == 183 or killedNPC.id == 34 or killedNPC.id == 169 or killedNPC.id == 170 or killedNPC.id == 264 or killedNPC.id == 277) then
                        player.reservePowerup = 264

                if killedNPC.id == 248 then
                        player.reservepowerup = 248
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end

return peach

the second api that follows now is originally by love Bodhi and just edited by me to add NSMB style and Peach and Toad reserve.

Code: Select all

local modernhud = {}

local timelimitOn = false

local timerApi = API.load("leveltimer")

local char1 = {Graphics.loadImage(Misc.resolveFile("Hud/SMB1/Char1.png")),Graphics.loadImage(Misc.resolveFile("Hud/SMB2/Char1.png")),Graphics.loadImage(Misc.resolveFile("Hud/SMB3/Char1.png")),Graphics.loadImage(Misc.resolveFile("Hud/SMW/Char1.png")),Graphics.loadImage(Misc.resolveFile("Hud/NSMB/Char1.png"))}
local char2 = {Graphics.loadImage(Misc.resolveFile("Hud/SMB1/Char2.png")),Graphics.loadImage(Misc.resolveFile("Hud/SMB2/Char2.png")),Graphics.loadImage(Misc.resolveFile("Hud/SMB3/Char2.png")),Graphics.loadImage(Misc.resolveFile("Hud/SMW/Char2.png")),Graphics.loadImage(Misc.resolveFile("Hud/NSMB/Char2.png"))}
local char3 = {Graphics.loadImage(Misc.resolveFile("Hud/SMB1/Char3.png")),Graphics.loadImage(Misc.resolveFile("Hud/SMB2/Char3.png")),Graphics.loadImage(Misc.resolveFile("Hud/SMB3/Char3.png")),Graphics.loadImage(Misc.resolveFile("Hud/SMW/Char3.png")),Graphics.loadImage(Misc.resolveFile("Hud/NSMB/Char3.png"))}
local char4 = {Graphics.loadImage(Misc.resolveFile("Hud/SMB1/Char4.png")),Graphics.loadImage(Misc.resolveFile("Hud/SMB2/Char4.png")),Graphics.loadImage(Misc.resolveFile("Hud/SMB3/Char4.png")),Graphics.loadImage(Misc.resolveFile("Hud/SMW/Char4.png")),Graphics.loadImage(Misc.resolveFile("Hud/NSMB/Char4.png"))}
local char5 = {Graphics.loadImage(Misc.resolveFile("Hud/SMB1/Char5.png")),Graphics.loadImage(Misc.resolveFile("Hud/SMB2/Char5.png")),Graphics.loadImage(Misc.resolveFile("Hud/SMB3/Char5.png")),Graphics.loadImage(Misc.resolveFile("Hud/SMW/Char5.png")),Graphics.loadImage(Misc.resolveFile("Hud/NSMB/Char5.png"))}
local coincounter = {Graphics.loadImage(Misc.resolveFile("Hud/SMB1/Coin.png")),Graphics.loadImage(Misc.resolveFile("Hud/SMB2/Coin.png")),Graphics.loadImage(Misc.resolveFile("Hud/SMB3/Coin.png")),Graphics.loadImage(Misc.resolveFile("Hud/SMW/Coin.png")),Graphics.loadImage(Misc.resolveFile("Hud/NSMB/Coin.png"))}
local starcounter = {Graphics.loadImage(Misc.resolveFile("Hud/SMB1/Star.png")),Graphics.loadImage(Misc.resolveFile("Hud/SMB2/Star.png")),Graphics.loadImage(Misc.resolveFile("Hud/SMB3/Star.png")),Graphics.loadImage(Misc.resolveFile("Hud/SMW/Star.png")),Graphics.loadImage(Misc.resolveFile("Hud/NSMB/Star.png"))}
local multiplier = {Graphics.loadImage(Misc.resolveFile("Hud/SMB1/Multiplier.png")),Graphics.loadImage(Misc.resolveFile("Hud/SMB2/Multiplier.png")),Graphics.loadImage(Misc.resolveFile("Hud/SMB3/Multiplier.png")),Graphics.loadImage(Misc.resolveFile("Hud/SMW/Multiplier.png")),Graphics.loadImage(Misc.resolveFile("Hud/NSMB/Multiplier.png"))}
local reserveboxM = {Graphics.loadImage(Misc.resolveFile("Hud/SMB1/ReserveBoxM.png")),Graphics.loadImage(Misc.resolveFile("Hud/SMB2/ReserveBoxM.png")),Graphics.loadImage(Misc.resolveFile("Hud/SMB3/ReserveBoxM.png")),Graphics.loadImage(Misc.resolveFile("Hud/SMW/ReserveBoxM.png")),Graphics.loadImage(Misc.resolveFile("Hud/NSMB/ReserveBoxM.png"))}
local reserveboxL = {Graphics.loadImage(Misc.resolveFile("Hud/SMB1/ReserveBoxL.png")),Graphics.loadImage(Misc.resolveFile("Hud/SMB2/ReserveBoxL.png")),Graphics.loadImage(Misc.resolveFile("Hud/SMB3/ReserveBoxL.png")),Graphics.loadImage(Misc.resolveFile("Hud/SMW/ReserveBoxL.png")),Graphics.loadImage(Misc.resolveFile("Hud/NSMB/ReserveBoxL.png"))}
local reserveboxP = {Graphics.loadImage(Misc.resolveFile("Hud/SMB1/ReserveBoxP.png")),Graphics.loadImage(Misc.resolveFile("Hud/SMB2/ReserveBoxP.png")),Graphics.loadImage(Misc.resolveFile("Hud/SMB3/ReserveBoxP.png")),Graphics.loadImage(Misc.resolveFile("Hud/SMW/ReserveBoxP.png")),Graphics.loadImage(Misc.resolveFile("Hud/NSMB/ReserveBoxP.png"))}
local reserveboxT = {Graphics.loadImage(Misc.resolveFile("Hud/SMB1/ReserveBoxT.png")),Graphics.loadImage(Misc.resolveFile("Hud/SMB2/ReserveBoxT.png")),Graphics.loadImage(Misc.resolveFile("Hud/SMB3/ReserveBoxT.png")),Graphics.loadImage(Misc.resolveFile("Hud/SMW/ReserveBoxT.png")),Graphics.loadImage(Misc.resolveFile("Hud/NSMB/ReserveBoxT.png"))}

local mushroompwr1 = Graphics.loadImage(Misc.resolveFile("Hud/Powerup/mushroom.png"))
local mushroompwr2 = Graphics.loadImage(Misc.resolveFile("Hud/Powerup/mushroom2.png"))
local mushroompwr3 = Graphics.loadImage(Misc.resolveFile("Hud/Powerup/mushroom3.png"))
local mushroompwr4 = Graphics.loadImage(Misc.resolveFile("Hud/Powerup/mushroom4.png"))
local firepwr1 = Graphics.loadImage(Misc.resolveFile("Hud/Powerup/flower.png"))
local firepwr2 = Graphics.loadImage(Misc.resolveFile("Hud/Powerup/flower2.png"))
local firepwr3 = Graphics.loadImage(Misc.resolveFile("Hud/Powerup/flower3.png"))
local firepwr4 = Graphics.loadImage(Misc.resolveFile("Hud/Powerup/flower4.png"))
local leafpwr = Graphics.loadImage(Misc.resolveFile("Hud/Powerup/leaf.png"))
local leafpwr2 = Graphics.loadImage(Misc.resolveFile("Hud/Powerup/leaf2.png"))
local tanookipwr = Graphics.loadImage(Misc.resolveFile("Hud/Powerup/tanooki.png"))
local tanookipwr2 = Graphics.loadImage(Misc.resolveFile("Hud/Powerup/tanooki2.png"))
local hammerpwr = Graphics.loadImage(Misc.resolveFile("Hud/Powerup/hammer.png"))
local hammerpwr2 = Graphics.loadImage(Misc.resolveFile("Hud/Powerup/hammer2.png"))
local icepwr1 = Graphics.loadImage(Misc.resolveFile("Hud/Powerup/ice.png"))
local icepwr2 = Graphics.loadImage(Misc.resolveFile("Hud/Powerup/ice2.png"))
local icepwr3 = Graphics.loadImage(Misc.resolveFile("Hud/Powerup/ice3.png"))
local stopwatchpwr = Graphics.loadImage(Misc.resolveFile("Hud/Powerup/clock.png"))

local heartbg = {Graphics.loadImage(Misc.resolveFile("Hud/SMB1/HeartBG.png")),Graphics.loadImage(Misc.resolveFile("Hud/SMB2/HeartBG.png")),Graphics.loadImage(Misc.resolveFile("Hud/SMB3/HeartBG.png")),Graphics.loadImage(Misc.resolveFile("Hud/SMW/HeartBG.png")),Graphics.loadImage(Misc.resolveFile("Hud/NSMB/HeartBG.png"))}
local heartfill = {Graphics.loadImage(Misc.resolveFile("Hud/SMB1/HeartFill.png")),Graphics.loadImage(Misc.resolveFile("Hud/SMB2/HeartFill.png")),Graphics.loadImage(Misc.resolveFile("Hud/SMB3/HeartFill.png")),Graphics.loadImage(Misc.resolveFile("Hud/SMW/HeartFill.png")),Graphics.loadImage(Misc.resolveFile("Hud/NSMB/HeartFill.png"))}

modernhud.style = 5
modernhud.timecounter = 400
modernhud.usereserve = true

function modernhud.onInitAPI()
registerEvent(modernhud,"onStart","onStart",true)
registerEvent(modernhud,"onTick","onTick",true)
registerEvent(modernhud,"onHUDDraw","onHUDDraw",true)
registerEvent(modernhud,"timelimit","timelimit",true)
end

function modernhud.onStart()
timerApi.GUIPosition_NoStars = {x = 658, y = 47}
timerApi.GUIPosition_Stars = {x = 658, y = 47}
Graphics.activateHud(false)
end

function modernhud.onTick()
if timelimitOn then
modernhud.timelimit()
end
if not modernhud.usereserve then
player.reservePowerup = 0
end
end

function modernhud.onHUDDraw()
if (player.character == CHARACTER_MARIO) then
Graphics.drawImageWP(char1[modernhud.style],32,30,5)
end
if (player.character == CHARACTER_LUIGI) then
Graphics.drawImageWP(char2[modernhud.style],32,30,5)
end
if (player.character == CHARACTER_PEACH) then
Graphics.drawImageWP(char3[modernhud.style],32,30,5)
end
if (player.character == CHARACTER_TOAD) then
Graphics.drawImageWP(char4[modernhud.style],32,30,5)
end
if (player.character == CHARACTER_LINK) then
Graphics.drawImageWP(char5[modernhud.style],32,30,5)
end
Text.printWP(string.format("%08d",mem(0x00B2C8E4,FIELD_DWORD)),1,480,48,5)
Text.printWP(mem(0x00B2C5AC,FIELD_FLOAT),1,84,48,5)
Text.printWP(mem(0x00B2C5A8,FIELD_WORD),1,84,86,5)
Text.printWP(mem(0x00B251E0,FIELD_WORD),1,84,124,5)
Graphics.drawImageWP(coincounter[modernhud.style],32,68,5)
Graphics.drawImageWP(starcounter[modernhud.style],32,106,5)
Graphics.drawImageWP(multiplier[modernhud.style],48,30,5)
if modernhud.usereserve and (player.character == CHARACTER_MARIO or player.character == CHARACTER_LUIGI or player.character == CHARACTER_PEACH or player.character == CHARACTER_TOAD) then
if (player.reservePowerup == 9) then
Graphics.drawImageWP(mushroompwr4,384,42,4)
end
if (player.reservePowerup == 14) then
Graphics.drawImageWP(firepwr4,384,42,4)
end
if (player.reservePowerup == 34) then
Graphics.drawImageWP(leafpwr2,384,42,4)
end
if (player.reservePowerup == 169) then
Graphics.drawImageWP(tanookipwr2,384,42,4)
end
if (player.reservePowerup == 170) then
Graphics.drawImageWP(hammerpwr2,384,42,4)
end
if (player.reservePowerup == 182) then
Graphics.drawImageWP(firepwr4,384,42,4)
end
if (player.reservePowerup == 183) then
Graphics.drawImageWP(firepwr4,384,42,4)
end
if (player.reservePowerup == 184) then
Graphics.drawImageWP(mushroompwr4,384,42,4)
end
if (player.reservePowerup == 185) then
Graphics.drawImageWP(mushroompwr4,384,42,4)
end
if (player.reservePowerup == 248) then
Graphics.drawImageWP(stopwatchpwr,384,42,4)
end
if (player.reservePowerup == 264) then
Graphics.drawImageWP(icepwr3,384,42,4)
end
if (player.reservePowerup == 277) then
Graphics.drawImageWP(icepwr3,384,42,4)
end
if (player.character == CHARACTER_MARIO) then
Graphics.drawImageWP(reserveboxM[modernhud.style],372,30,3)
end
if (player.character == CHARACTER_LUIGI) then
Graphics.drawImageWP(reserveboxL[modernhud.style],372,30,3)
end
if (player.character == CHARACTER_PEACH) then
Graphics.drawImageWP(reserveboxP[modernhud.style],372,30,3)
end
if (player.character == CHARACTER_TOAD) then
Graphics.drawImageWP(reserveboxT[modernhud.style],372,30,3)
end
end
if (player.character == CHARACTER_LINK) then
Graphics.drawImageWP(heartbg[modernhud.style],357,38,4)
if (player:mem(0x16,FIELD_WORD)) == 1 then
Graphics.drawImageWP(heartfill[modernhud.style],357,38,5)
elseif (player:mem(0x16,FIELD_WORD)) == 2 then
Graphics.drawImageWP(heartfill[modernhud.style],357,38,5)
Graphics.drawImageWP(heartfill[modernhud.style],389,38,5)
elseif (player:mem(0x16,FIELD_WORD)) == 3 then
Graphics.drawImageWP(heartfill[modernhud.style],357,38,5)
Graphics.drawImageWP(heartfill[modernhud.style],389,38,5)
Graphics.drawImageWP(heartfill[modernhud.style],421,38,5)
end
end
end

function modernhud.timelimitOn()
timerApi.setTimerState(true)
timerApi.setSecondsLeft(modernhud.timecounter)
end

function modernhud.timelimitOff()
timerApi.setTimerState(false)
end

return modernhud

However, this code has the problem that the powerup just flashes in the reserve for a short time and then disappears.
So I have to ask you how this problem could be solved or if it can't because you can't overwrite the default 3HP Heart system without facing big issues or using advanced lua coding.

greetings and thanks for help in advance, yoshiegg.

Return to “LunaLua - Extension Framework”

Who is online (over the past 5 minutes)

Users browsing this forum: 1 guest