Page 1 of 1

[Request] A more advanced NPC-147

Posted: Fri Apr 02, 2021 6:40 pm
by timocomsmbx2345
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.

Re: [Request] A more advanced NPC-147

Posted: Sat Apr 03, 2021 3:01 am
by Emral
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

Re: [Request] A more advanced NPC-147

Posted: Sat Apr 03, 2021 7:46 am
by timocomsmbx2345
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