Transforming an NPC to another?

Post here for help and support regarding LunaLua and SMBX2's libraries and features.

Moderator: Userbase Moderators

LunarCatUSA
Monty Mole
Monty Mole
Posts: 115
Joined: Sat Mar 06, 2021 9:56 am
Flair: Soda-Butler

Transforming an NPC to another?

Postby LunarCatUSA » Sat May 22, 2021 4:50 pm

If I wanted an NPC, let’s say ID:1 (goomba), to be transformed to another NPC, let’s say ID: 4 (green koopa), what’s the code I would go about using? [I thought it was something among the lines of npc.transform() or something like that]

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

Re: Transforming an NPC to another?

Postby Emral » Sat May 22, 2021 4:55 pm


LunarCatUSA
Monty Mole
Monty Mole
Posts: 115
Joined: Sat Mar 06, 2021 9:56 am
Flair: Soda-Butler

Re: Transforming an NPC to another?

Postby LunarCatUSA » Sat May 22, 2021 5:07 pm

Well I was right about the code,

So what, it’s like:
myNPC = NPC.get(1, player.section)
myNPC:transform(4)

Something like that?

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

Re: Transforming an NPC to another?

Postby Emral » Sat May 22, 2021 5:59 pm

LunarCatUSA wrote:
Sat May 22, 2021 5:07 pm
Well I was right about the code,

So what, it’s like:
myNPC = NPC.get(1, player.section)
myNPC:transform(4)

Something like that?
NPC.get returns a table of NPCs. You need to iterate over it to get to the individual npcs. It'd be like:

Code: Select all

for k,v in ipairs(NPC.get(1, player.section) do
	v:transform(4)
end

LunarCatUSA
Monty Mole
Monty Mole
Posts: 115
Joined: Sat Mar 06, 2021 9:56 am
Flair: Soda-Butler

Re: Transforming an NPC to another?

Postby LunarCatUSA » Sun May 23, 2021 11:42 pm

So now, how would I make the NPC’s speed 0? The NPC seems to be still in motion when it transforms, I intend for it to stop.

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

Re: Transforming an NPC to another?

Postby Emral » Mon May 24, 2021 12:53 am

LunarCatUSA wrote:
Sun May 23, 2021 11:42 pm
So now, how would I make the NPC’s speed 0? The NPC seems to be still in motion when it transforms, I intend for it to stop.
Setting myNPC.speedX = 0 right below should work, unless the new npc is a walker type.

LunarCatUSA
Monty Mole
Monty Mole
Posts: 115
Joined: Sat Mar 06, 2021 9:56 am
Flair: Soda-Butler

Re: Transforming an NPC to another?

Postby LunarCatUSA » Mon May 24, 2021 10:07 am

That’s not working, if I wanted to just despawn the npc by removing it via layers, how would I go about spawning a new npc at it’s position? When I type myNPC.x = posX and myNPC.y = posY, I get an error message saying “can’t convert nil to double”

Added in 6 minutes 51 seconds:
Oh nevermind, I found a way

Added in 25 seconds:
Just had to set the motion in line with the tick function, not immediately after the event.


Return to “LunaLua Help”

Who is online

Users browsing this forum: No registered users and 1 guest

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari