Page 1 of 1

Help with my API

Posted: Sun Oct 09, 2016 1:50 pm
by PlumberGraduate
I'm trying to make an API that allows you to set how many fireballs a Piranha Plant can shoot at once. You should be able to set it from your LunaDLL.lua file. For some reason, it doesn't work at all!

Here is the API code:

Code: Select all

local multiVenusAPI = {};

local pNPC = API.load("pnpc");
local maxFire = 2;
local venusFireAI = 1;

function multiVenusAPI.onInitAPI()
	registerEvent(multiVenusAPI, "onTick", "onTick");
	registerEvent(multiVenusAPI, "onDraw", "onDraw");
	registerEvent(multiVenusAPI, "onNPCKill", "onNPCKill");
end

function multiVenusAPI.maxFireBall(setMax)
    maxFire = setMax;
end

function multiVenusAPI.onTick()
	
	local tableOfVenusFireTrap = NPC.get(245,-1);
	
	for i,npc in ipairs(tableOfVenusFireTrap) do
		if npc.ai1 == 50 then
		    if venusFireAI < maxFire then
			    npc.ai1 = 0;
				venusFireAI = venusFireAI + 1;
		    elseif venusFireAI == maxFire then
				venusFireAI = 1;
			end
		end
	end
end

return multiVenusAPI;
And here is the LunaDLL.lua:

Code: Select all

local multiVenusAPI = API.load("multiFireVenusFireTrap");

function onStart()
    multiVenusAPI.maxFireBall(4);
end

Re: Help with my API

Posted: Sun Oct 09, 2016 2:25 pm
by Emral
venusFireAI should be saved with pnpc (individual for each plant in the level). Also you might wanna check for ai2 == 1 because that's the shooting state.

Re: Help with my API

Posted: Sun Oct 09, 2016 2:35 pm
by PixelPest
Instead of having a function to set the variable, you could just do:

Code: Select all

multiVenusAPI.maxFire = 2; 
To make it accessible just like the function when the API is loaded

Re: Help with my API

Posted: Mon Oct 10, 2016 9:25 am
by PlumberGraduate
Thanks for help. I got it working.