Basically your code would look something like what I've shown below. You can change the delay and maxN variables as you wish to suit your needs.
Code: Select all
local pnpc = API.load("pnpc"); --load the pnpc library which allows us to give variables to specific instances of NPCs, such as Wart
local delay = 55; --set how long it takes in ticks between bubbles (you can change this!)
local maxN = 3; --set how many bubbles wart should shoot (you can change this!)
function onTick() --every tick (unit of time in SMBX)
for _, v in pairs(NPC.get(201)) do --for each of the Warts in the level assign them to v one at a time so we can do stuff to all of them
local wart = pnpc.wrap(v); --wrap our Wart using the pnpc library to give us the ability to give it variables specific to that Wart
if wart.data.counter == nil then --if there wasn't been a value set for the counter within our Wart's data table (of variables)
wart.data.counter = 0; --set the counter to 0 (this variable will be used to make sure we don't exceed the max number of bubbles we have selected being shot each attack phase)
wart.data.reloops = 0; --set our reloops variable to 0 (this variable will be used to make the delay occur)
end
if v.ai1 == 1 then --if the Wart is shooting bubbles (for AI #1: 0 - Idle, 1 - Bubbles, 2 - Hit, 3 - Death)
if v.ai3 == 9 then --if our Wart is about to shoot a bubble on the next tick (shoots a bubble when AI #3 is a multiple of 10)
if wart.data.reloops > 0 then --if our reloops variable is more than zero
wart.data.reloops = wart.data.reloops - 1; --subtract one from the reloops variable
v.ai3 = 8; --lower the AI #3 field to 8 so we can check it again on the next tick when it has increases to 9 between ticks
end
elseif v.ai3 == 10 then --if the AI #3 field equals 10 (which is when our Wart shoots a bubble)
wart.data.counter = wart.data.counter + 1; --add one to the counter which counts how many bubbles our Wart has shot
if wart.data.counter == maxN then --if the number of bubbles our Wart has shot is equal to our max number allowed per attack phase
v.ai3 = 130; --set the AI #3 field to 130 which ends the attack phase for Wart's AI in general (but not others)
wart.data.counter = 0; --set the number of bubbles our Wart has shot to zero so that this variable is ready for the next time we use it
else --if the number of bubbles our wart has shot is not equal to our max number allowed per attack phase (it will be less and mean that our Wart should still be shooting bubbles)
wart.data.reloops = delay; --set the reloops variable to the value of our delay variable
v.ai3 = 8; --set the AI #3 field to 8
end
end
end
end
end
Here's a .gif of what the code above does with the way the variables are set rn:
