Heya, so I went and improved this as in making it work with Beta 4.
Most of the original code and stuff is the same, I just made it not error.
Code: Select all
local colliders = loadAPI("colliders")
local function loadCustomPowerupGraphics(path)
local tableOfImg = {}
tableOfImg.mario = Graphics.loadImage(Misc.resolveFile(path .. "\\mario.png"))
tableOfImg.luigi = Graphics.loadImage(Misc.resolveFile(path .. "\\luigi.png"))
tableOfImg.peach = Graphics.loadImage(Misc.resolveFile(path .. "\\peach.png"))
tableOfImg.toad = Graphics.loadImage(Misc.resolveFile(path .. "\\toad.png"))
tableOfImg.link = Graphics.loadImage(Misc.resolveFile(path .. "\\link.png"))
return tableOfImg
end
local powerupNpcs = {0, 9, 14, 34, 169, 170, 264}
local customPlayerPowerups = {}
customPlayerPowerups["beetroot"] = {graphics = loadCustomPowerupGraphics("lunaimg\\cpowerup-beetroot"), triggerNPC = 92}
local playerDefaultGraphics = {}
local activeCustomPowerup = {nil, nil}
local beetrootCount = 0
local runPressed = 0
local attackFrame = 0
local pchar = 0
local bspd = 0
local nbpsd = 0
local hittable = {1, 2, 3, 4, 5, 6, 7, 8, 12, 15, 17, 18, 19, 20, 23, 24, 25, 27, 28, 29, 36, 37, 38, 39, 40, 42, 43, 44, 45, 47, 48, 51, 52, 53, 54, 55, 59, 61, 63, 65, 71, 72, 73, 74, 76, 77, 86, 89, 93, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 161, 162, 163, 164, 165, 166, 167, 168, 172, 173, 174, 175, 176, 177, 180, 189, 194, 199, 200, 201, 203, 204, 205, 206, 207, 210, 229, 230, 231, 232, 233, 234, 235, 236, 242, 243, 244, 245, 247, 256, 257, 261, 262, 267, 268, 270, 271, 272, 275, 280, 281, 283, 284, 285, 286, 294, 295, 296, 297, 298, 299}
local explodeTimer = 0
local beetrootDisabled = 0
local slashed = 0
local linkBeet = 0
local playerCount = 1
Cheats.register("needabeetroot",{
onActivate = (function()
Audio.playSFX(12)
if player.character == 1 or player.character == 2 then
player.reservePowerup = 92
else
NPC.spawn(92,player.x,player.y,player.section)
end
return true
end),
})
function onStart()
playerDefaultGraphics[1] = Graphics.sprites.mario[2].img
playerDefaultGraphics[2] = Graphics.sprites.luigi[2].img
playerDefaultGraphics[3] = Graphics.sprites.peach[2].img
playerDefaultGraphics[4] = Graphics.sprites.toad[2].img
playerDefaultGraphics[5] = Graphics.sprites.link[2].img
end
function onTick()
local thePlayer = Player.get()[playerIndex];
for playerIndex, thePlayer in pairs(Player.get()) do
for k, customPower in pairs(customPlayerPowerups) do
for k1, veggie in pairs(NPC.get(customPower.triggerNPC, thePlayer.section)) do
veggie.friendly = true;
if(colliders.collide(thePlayer, veggie)) then
local spriteOverride;
local sheet;
runPressed = 1
if(thePlayer.character == 1) then
spriteOverride = Graphics.sprites.mario;
sheet = customPower.graphics.mario;
elseif(thePlayer.character == 2) then
spriteOverride = Graphics.sprites.luigi;
sheet = customPower.graphics.luigi;
elseif(thePlayer.character == 3) then
spriteOverride = Graphics.sprites.peach;
sheet = customPower.graphics.peach;
elseif(thePlayer.character == 4) then
spriteOverride = Graphics.sprites.toad;
sheet = customPower.graphics.toad;
else
spriteOverride = Graphics.sprites.link;
sheet = customPower.graphics.link;
linkBeet = 1;
end
spriteOverride[2].img = sheet;
if(activeCustomPowerup[playerIndex] == nil) then
if(thePlayer.powerup ~= 1) then
thePlayer.reservePowerup = powerupNpcs[thePlayer.powerup]
end
else
thePlayer.reservePowerup = customPlayerPowerups[activeCustomPowerup[playerIndex]].triggerNPC;
end
thePlayer.Hearts = thePlayer.Hearts + 1;
veggie:kill(7);
thePlayer.powerup = 2;
if(activeCustomPowerup[playerIndex] ~= k) then
thePlayer.BlinkTimer = 60;
playSFX(34);
else
playSFX(12);
end
activeCustomPowerup[playerIndex] = k;
end
end
end
if(thePlayer.ForcedAnimationState == 1 or
thePlayer.ForcedAnimationState == 2 or
thePlayer.ForcedAnimationState == 4 or
thePlayer.ForcedAnimationState == 5 or
thePlayer.ForcedAnimationState == 11 or
thePlayer.ForcedAnimationState == 12 or
thePlayer.ForcedAnimationState == 41) then
local spriteOverride;
if(thePlayer.character == 1) then
spriteOverride = Graphics.sprites.mario;
elseif(thePlayer.character == 2) then
spriteOverride = Graphics.sprites.luigi;
elseif(thePlayer.character == 3) then
spriteOverride = Graphics.sprites.peach;
elseif(thePlayer.character == 4) then
spriteOverride = Graphics.sprites.toad;
else
spriteOverride = Graphics.sprites.link;
end
spriteOverride[2].img = playerDefaultGraphics[thePlayer.character];
if(activeCustomPowerup[playerIndex] ~= nil and thePlayer.ForcedAnimationState ~= 2) then
thePlayer.reservePowerup = customPlayerPowerups[activeCustomPowerup[playerIndex]].triggerNPC;
end
activeCustomPowerup[playerIndex] = nil;
end
if player.character == 5
and thePlayer.hearts == 1 then
linkBeet = 0
end
end
if beetrootCount >= 2 then
player:mem(0x160,FIELD_WORD,2)
end
if not player.runKeyPressing
and beetrootCount ~= 2 then
runPressed = 0
end
if attackFrame > 0 then
attackFrame = attackFrame - 1
end
if explodeTimer > 0 then
explodeTimer = explodeTimer - 1
end
for _,v in pairs(NPC.get(154,-1)) do
local pchar = player.character
local pdir = player:mem(0x106,FIELD_WORD)
for _,h in pairs(NPC.get(hittable, -1)) do
if(colliders.collide(v,h))
and not h.friendly
and explodeTimer == 0 then
Misc.doBombExplosion(v.x,v.y,0,player)
explodeTimer = 21,6
end
end
if v.data.started ~= 1 then
if player.character ~= 5 then
beetrootCount = beetrootCount + 1
end
v.data.bounces = 0
if pchar == 1 or pchar == 3 then
v.speedX = 4*pdir
v.speedY = -6
elseif pchar == 2 then
v.speedX = 3*pdir
v.speedY = -7
elseif pchar == 4 then
v.speedX = 5*pdir
v.speedY = -5
end
if(player.upKeyPressing) then
v.speedY = v.speedY - 1
v.speedX = v.speedX - 1*pdir
end
v.data.direction = -1*pdir
v.data.started = 1
end
if v:mem(0x128,FIELD_WORD) == -1 then
beetrootCount = beetrootCount - 1
v.data.bounces = 0
v:kill()
end
if ((v.collidesBlockBottom) or (v.collidesBlockLeft) or (v.collidesBlockRight) or (v.collidesBlockUp)) then
if player.character ~= 5 then
Misc.doBombExplosion(v.x + 5,v.y + 5,0,player)
Misc.doBombExplosion(v.x - 5,v.y - 5,0,player)
Misc.doBombExplosion(v.x + 5,v.y - 5,0,player)
Misc.doBombExplosion(v.x - 5,v.y + 5,0,player)
Audio.playSFX(39)
v.data.bounces = v.data.bounces + 1
if pchar == 1 or pchar == 3 then
v.speedY = -6
bspd = 4
elseif pchar == 2 then
v.speedY = -7
bspd = 3
elseif pchar == 4 then
v.speedY = -5
bspd = 5
end
nbspd = bspd*-1
if v.data.bounces == 1 then
v.speedX = bspd*v.data.direction
elseif v.data.bounces == 2 then
v.speedX = nbspd*v.data.direction
elseif v.data.bounces == 3 then
if pchar == 3 then
v.speedX = bspd*v.data.direction
else
beetrootCount = beetrootCount - 1
v.data.bounces = 0
v:kill()
end
elseif v.data.bounces == 4 then
beetrootCount = beetrootCount - 1
v.data.bounces = 0
v:kill()
end
else
Misc.doBombExplosion(v.x + 8,v.y + 8,0,player)
Misc.doBombExplosion(v.x,v.y + 12,0,player)
Misc.doBombExplosion(v.x - 8,v.y + 8,0,player)
Misc.doBombExplosion(v.x - 12,v.y,0,player)
Misc.doBombExplosion(v.x - 8,v.y - 8,0,player)
Misc.doBombExplosion(v.x,v.y - 12,0,player)
Misc.doBombExplosion(v.x + 8,v.y - 8,0,player)
Misc.doBombExplosion(v.x + 12,v.y,0,player)
v:kill()
end
end
end
if player.powerup ~= 2
and player.character == 5 then
linkBeet = 0
end
playerCount = mem(0x00B2595E,FIELD_WORD)
end
function onDraw()
for playerIndex, thePlayer in pairs (Player.get()) do
if(activeCustomPowerup[playerIndex] == "beetroot")
and(player.runKeyPressing or player:mem(0x50,FIELD_WORD) == -1)
and (player:mem(0x12E,FIELD_BOOL) == false or player.character == 5)
and player:mem(0x40,FIELD_WORD) ~= 3
and player:mem(0x10C,FIELD_WORD) ~= 1
and player:mem(0x136,FIELD_BOOL) == false
and (player:mem(0x160,FIELD_WORD) or slashed) == 0
and player:mem(0x3C,FIELD_BOOL) == false
and player:mem(0x44,FIELD_BOOL) == false
and player:mem(0x160,FIELD_WORD) == 0
and runPressed == 0 or player.character == 5 then
attackFrame = 9
runPressed = 1
if player:mem(0x106,FIELD_WORD) ~= -1 then
if player.character ~= 5 then
NPC.spawn(154,player.x + 22,player.y + 16,player.section)
player:mem(0x160,FIELD_WORD,12)
Audio.playSFX(18)
elseif slashed == 0
and linkBeet == 1 then
if player:mem(0x114,FIELD_WORD) == 7 then
Misc.doBombExplosion(player.x + 62,player.y + 14,0,player)
elseif player:mem(0x114,FIELD_WORD) == 8 then
Misc.doBombExplosion(player.x + 62,player.y + 26,0,player)
end
slashed = 1
end
else
if player.character ~= 5 then
NPC.spawn(154,player.x - 14,player.y + 16,player.section)
player:mem(0x160,FIELD_WORD,12)
Audio.playSFX(18)
elseif slashed == 0
and linkBeet == 1 then
if player:mem(0x114,FIELD_WORD) == 7 then
Misc.doBombExplosion(player.x - 37,player.y + 14,0,player)
elseif player:mem(0x114,FIELD_WORD) == 8 then
Misc.doBombExplosion(player.x - 37,player.y + 26,0,player)
end
slashed = 1
end
end
end
if player.character ~= 5 then
if attackFrame > 5 then
if player.character ~= 3 then
if player.character ~= 2 then
player:mem(0x114,FIELD_WORD, 12)
else
player:mem(0x114,FIELD_WORD, 11)
end
else
player:mem(0x114,FIELD_WORD, 2)
end
elseif attackFrame > 0 then
if player.character ~= 3 then
if player.character ~= 2 then
player:mem(0x114,FIELD_WORD, 11)
else
player:mem(0x114,FIELD_WORD, 12)
end
else
player:mem(0x114,FIELD_WORD, 3)
end
end
elseif slashed == 1
and player:mem(0x114,FIELD_WORD) ~= 7
and player:mem(0x114,FIELD_WORD) ~= 8 then
slashed = 0
end
if(activeCustomPowerup[playerIndex] == "beetroot")
and player.character == 5
and player.Hearts > 1
and player:mem(0x114,FIELD_WORD) == 6
and player.altRunKeyPressing then
for _,bomb in pairs(NPC.get(134,player.section)) do
bomb.width = 32
bomb.height = 32
if bomb:mem(0x132,FIELD_WORD) == 1 then
bomb.id = 154
end
end
end
end
end