So, umm

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?
PersonNamedUser
Reznor
Reznor
Posts: 2882
Joined: Fri Feb 27, 2015 8:07 pm

So, umm

Postby PersonNamedUser » Tue Jun 06, 2017 12:43 pm

Image

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
Do you know exactly what's going wrong here?

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

Re: So, umm

Postby PixelPest » Tue Jun 06, 2017 9:24 pm

Try loading classExpander.lua

PersonNamedUser
Reznor
Reznor
Posts: 2882
Joined: Fri Feb 27, 2015 8:07 pm

Re: So, umm

Postby PersonNamedUser » Tue Jun 06, 2017 9:30 pm

PixelPest wrote:Try loading classExpander.lua
I don't even usually use 2.0 yet
EDIT:
Do i need to to do this?

The0x539
Eerie
Eerie
Posts: 751
Joined: Fri Jan 22, 2016 8:02 pm

Re: So, umm

Postby The0x539 » Tue Jun 06, 2017 9:41 pm

yes

NPC:transform is a function provided by classExpander

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

Re: So, umm

Postby PixelPest » Tue Jun 06, 2017 10:13 pm

MosaicMario wrote:
PixelPest wrote:Try loading classExpander.lua
I don't even usually use 2.0 yet
EDIT:
Do i need to to do this?
I definitely suggested it because it's a pointless thing to do /sarcasm

You don't need 2.0 to use APIs

TDK
Phanto
Phanto
Posts: 1440
Joined: Wed Nov 11, 2015 12:26 pm
Flair: Retired

Re: So, umm

Postby TDK » Tue Jun 06, 2017 10:33 pm

MosaicMario wrote:
PixelPest wrote:Try loading classExpander.lua
I don't even usually use 2.0 yet
EDIT:
Do i need to to do this?
Now that I think about it, you probably have an outdated version of LunaLua.
What version do you have?

Hoeloe
Phanto
Phanto
Posts: 1465
Joined: Sat Oct 03, 2015 6:18 pm
Flair: The Codehaus Girl
Pronouns: she/her

Re: So, umm

Postby Hoeloe » Wed Jun 07, 2017 4:24 am

Chances are if you're not using 2.0, you don't have the classExpander. At the very least it won't be loaded automatically. I'd suggest just using 2.0. The only reason to use Lua separately is if you really want to make use of a more recent feature and even then you'd be better off waiting for beta 4.

PersonNamedUser
Reznor
Reznor
Posts: 2882
Joined: Fri Feb 27, 2015 8:07 pm

Re: So, umm

Postby PersonNamedUser » Wed Jun 07, 2017 2:07 pm

The code works now, but i ran into another problem, now the birdo hits themselves with the projectile, i don't see what's wrong with the code though.
EDIT:
Nvm, i figured out the problem, now it's working fine.


Return to “LunaLua”

Who is online

Users browsing this forum: No registered users and 3 guests

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari