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
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.
Edit: as I thought, player.reserve powerup doesn't work for Toad and Peach as they have heart systems by default, I've tried now to spawn an npc in the drawn reserve box with speed x and speed y = 0
and set the speed in the y-direction to 2 if the dropitemkey is pressed so the powerup comes down like it does for Mario and Luigi.But now the powerup doesn't spawn anymore.
And here's my code.This time wiith fixed scopes:
Code: Select all
local peach = {};
function peach.onInitAPI()
registerEvent(peach, "onTick", "onTick", false)
end
function peach.onTick()
if (player.character == CHARACTER_PEACH or player.character == CHARACTER_TOAD) then
for k,v in pairs(NPC.get(248,-1)) do
v.x = 384
v.y = 42
v.speedX = 0
v.speedY = 0
if player.dropitemkeypressing == true then
v.speedY = 2
end
end
if player.powerup == 2 then
for k,v in pairs(NPC.get(9,-1)) do
NPC.id = 9
NPC.x = 384
NPC.y = 42
NPC.speedX = 0
NPC.speedY = 0
if player.dropitemkeypressing == true then
NPC.speedY = 2
end
end
for k,v in pairs(NPC.get(14,-1)) do
NPC.id = 9
NPC.x = 384
NPC.y = 42
NPC.speedX = 0
NPC.speedY = 0
if player.dropitemkeypressing == true then
NPC.speedY = 2
end
end
for k,v in pairs(NPC.get(34,-1)) do
NPC.id = 9
NPC.x = 384
NPC.y = 42
NPC.speedX = 0
NPC.speedY = 0
if player.dropitemkeypressing == true then
NPC.speedY = 2
end
end
for k,v in pairs(NPC.get(182,-1)) do
NPC.id = 9
NPC.x = 384
NPC.y = 42
NPC.speedX = 0
NPC.speedY = 0
if player.dropitemkeypressing == true then
NPC.speedY = 2
end
end
for k,v in pairs(NPC.get(183,-1)) do
NPC.id = 9
NPC.x = 384
NPC.y = 42
NPC.speedX = 0
NPC.speedY = 0
if player.dropitemkeypressing == true then
NPC.speedY = 2
end
end
for k,v in pairs(NPC.get(184,-1)) do
NPC.id = 9
NPC.x = 384
NPC.y = 42
NPC.speedX = 0
NPC.speedY = 0
if player.dropitemkeypressing == true then
NPC.speedY = 2
end
end
for k,v in pairs(NPC.get(185,-1)) do
NPC.id = 9
NPC.x = 384
NPC.y = 42
NPC.speedX = 0
NPC.speedY = 0
if player.dropitemkeypressing == true then
NPC.speedY = 2
end
end
end
if player.powerup == 3 then
if (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
NPC.id = 14
NPC.x = 384
NPC.y = 42
NPC.speedX = 0
NPC.speedY = 0
if player.dropitemkeypressing == true then
NPC.speedY = 2
end
end
if (killedNPC.id == 9 or killedNPC.id == 184 or killedNPC.id == 185 or killedNPC.id == 249 or killedNPC.id == 250) then
NPC.id = 9
NPC.x = 384
NPC.y = 42
NPC.speedX = 0
NPC.speedY = 0
if player.dropitemkeypressing == true then
NPC.speedY = 2
end
end
end
if player.powerup == 4 then
if (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
NPC.id = 34
NPC.x = 384
NPC.y = 42
NPC.speedX = 0
NPC.speedY = 0
if player.dropitemkeypressing == true then
NPC.speedY = 2
end
end
if (killedNPC.id == 9 or killedNPC.id == 184 or killedNPC.id == 185 or killedNPC.id == 249 or killedNPC.id == 250) then
NPC.id = 9
NPC.x = 384
NPC.y = 42
NPC.speedX = 0
NPC.speedY = 0
if player.dropitemkeypressing == true then
NPC.speedY = 2
end
end
end
if player.powerup == 5 then
if (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
NPC.id = 14
NPC.x = 384
NPC.y = 42
NPC.speedX = 0
NPC.speedY = 0
if player.dropitemkeypressing == true then
NPC.speedY = 2
end
end
if (killedNPC.id == 9 or killedNPC.id == 184 or killedNPC.id == 185 or killedNPC.id == 249 or killedNPC.id == 250) then
NPC.id = 9
NPC.x = 384
NPC.y = 42
NPC.speedX = 0
NPC.speedY = 0
if player.dropitemkeypressing == true then
NPC.speedY = 2
end
end
end
if player.powerup == 6 then
if (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
NPC.id = 170
NPC.x = 384
NPC.y = 42
NPC.speedX = 0
NPC.speedY = 0
if player.dropitemkeypressing == true then
NPC.speedY = 2
end
end
if (killedNPC.id == 9 or killedNPC.id == 184 or killedNPC.id == 185 or killedNPC.id == 249 or killedNPC.id == 250) then
NPC.id = 9
NPC.x = 384
NPC.y = 42
NPC.speedX = 0
NPC.speedY = 0
if player.dropitemkeypressing == true then
NPC.speedY = 2
end
end
end
if player.powerup == 7 then
if (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
NPC.id = 264
NPC.x = 384
NPC.y = 42
NPC.speedX = 0
NPC.speedY = 0
if player.dropitemkeypressing == true then
NPC.speedY = 2
end
end
if (killedNPC.id == 9 or killedNPC.id == 184 or killedNPC.id == 185 or killedNPC.id == 249 or killedNPC.id == 250) then
NPC.id = 9
NPC.x = 384
NPC.y = 42
NPC.speedX = 0
NPC.speedY = 0
if player.dropitemkeypressing == true then
NPC.speedY = 2
end
end
end
end
end
return peach