
Here's the code i have:
Code: Select all
local hasGenerated = false;
local hasTransformed = false; --if we've transformed an egg or not
local ran;
local frameCount = 0;
local pnpc = API.load("pnpc"); --init pnpc.lua API
function onTick()
for _, n in pairs(NPC.get(40, -1)) do
n.id = 172
end
end
function onTick() --run the code every tick (a unit of time); most logic for NPCs, etc. is performed in this event
for _, v in pairs(NPC.get(39)) do
local birdo = pnpc.wrap(v);
for _, w in pairs(NPC.getIntersecting(v.x, v.y, v.x + v.width, v.y + v.height)) do --iterate over all NPCs that are intersecting with its hitbox
if w.id == 40 then --if the NPC is an egg
birdo.data.megg = pnpc.wrap(w).uid; --get the unique identifier of the hammer and save it to the Hammer Bro's data table
w.friendly = true;
w:transform(172);
end
end
end
for _, x in pairs(NPC.get(172)) do --iterate over all SMB1 green shells
local shellID = pnpc.wrap(x).uid; --get the unique identifier of the shell
local intersects = false; --a variable that will be set to true if the shell is still intersecting with the Hammer Bro that threw it
for _, y in pairs(NPC.getIntersecting(x.x, x.y, x.x + x.width, x.y + x.height)) do --iterate over all NPCs that are intersecting with the shell
if (y.id == 40) and (pnpc.wrap(y).data.megg == shellID) then --if the NPC is a Hammer Bro and its data table reference for "mHammer" is the shell's uid
intersects = true; --the shell intersects still with the Hammer Bro that threw it, so this variable is set to true
end
end
if not intersects then --if the variable intersects is false
x.friendly = false; --make the shell not be friendly
else --if the variable intersects is true
x.friendly = true; --make the shell be friendly
end
end
end
function onNPCKill(eventObj, killedNPC, killReason) --an event run every time an NPC is killed; makes sure that if a Hammer Bro is killed before the shell it threw is set to not friendly (the shell was intersecting with the bro when it was killed still) that the shell is set to not friendly
if killedNPC.id == 40 then --if the killed NPC is a Hammer Bro
for _, v in pairs(NPC.get(172)) do --iterate over all shells
if pnpc.wrap(killedNPC).data.megg == pnpc.wrap(v).uid then
v.friendly = false;
end
end
end
end