Help with my API

This is the place for discussion and support for LunaLua and related modifications and libraries.

Moderator: Userbase Moderators

Forum rules
Before you make a topic/post, consider the following:
-Is there a topic for this already?
-Is your post on topic/appropriate?
-Are you posting in the right forum/following the forum rules?
PlumberGraduate
Fighter Fly
Fighter Fly
Posts: 38
Joined: Sat Jun 14, 2014 11:39 am

Help with my API

Postby PlumberGraduate » Sun Oct 09, 2016 1:50 pm

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

Emral
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 9891
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Phoenix

Re: Help with my API

Postby Emral » Sun Oct 09, 2016 2:25 pm

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.

PixelPest
Link
Link
Posts: 7111
Joined: Sun Jul 12, 2015 5:38 pm
Flair: Tamer of Boom Booms
Contact:

Re: Help with my API

Postby PixelPest » Sun Oct 09, 2016 2:35 pm

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

PlumberGraduate
Fighter Fly
Fighter Fly
Posts: 38
Joined: Sat Jun 14, 2014 11:39 am

Re: Help with my API

Postby PlumberGraduate » Mon Oct 10, 2016 9:25 am

Thanks for help. I got it working.


Return to “LunaLua”

Who is online

Users browsing this forum: No registered users and 1 guest

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari