[Request] A more advanced NPC-147

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

Moderator: Userbase Moderators

timocomsmbx2345
Foo
Foo
Posts: 853
Joined: Sat Feb 06, 2016 1:44 pm
Contact:

[Request] A more advanced NPC-147

Postby timocomsmbx2345 » Fri Apr 02, 2021 6:40 pm

Ok, so uh, so like, a blank npc that turns into any random npc in a given range. I'm just shocked that there is no npc randomizer yet.

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

Re: [Request] A more advanced NPC-147

Postby Emral » Sat Apr 03, 2021 3:01 am

Well yeah cause it's really trivial.

Put this into your npc-n.lua and bind onTickEndNPC:

Code: Select all

-- Replace the numbers with your preferred IDs to turn into.
local ids = {1,2,3,4,5,6,7,8,9}

-- replace myNPC with the name of the library table
function myNPC.onTickEndNPC(v)
	v:transform(RNG.irandomEntry(ids))
end

timocomsmbx2345
Foo
Foo
Posts: 853
Joined: Sat Feb 06, 2016 1:44 pm
Contact:

Re: [Request] A more advanced NPC-147

Postby timocomsmbx2345 » Sat Apr 03, 2021 7:46 am

Enjl wrote:
Sat Apr 03, 2021 3:01 am
Well yeah cause it's really trivial.

Put this into your npc-n.lua and bind onTickEndNPC:

Code: Select all

-- Replace the numbers with your preferred IDs to turn into.
local ids = {1,2,3,4,5,6,7,8,9}

-- replace myNPC with the name of the library table
function myNPC.onTickEndNPC(v)
	v:transform(RNG.irandomEntry(ids))
end
Interesting, I had my npc use the sample library, and nothing happened.
Actually never mind, I forgot to register the functions, and this is how I solved it:

Code: Select all

function sampleNPC.onInitAPI()
	npcManager.registerEvent(npcID, sampleNPC, "onTickEndNPC")
end
local ids = {92,139,140,141,142,143,144,145,146,933}
function sampleNPC.onTickEndNPC(v)
	v:transform(RNG.irandomEntry(ids))
end


Return to “LunaLua Help”

Who is online

Users browsing this forum: No registered users and 1 guest

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari