Jump to content

Recommended Posts

@Pianobeats

Rabbits become beardlings through the local BecomeBeardling function.

It's called by the local CheckTransformState function, which is then called by two other instance-children functions (ondropfn and OnWake). They can be modified through the inst variable.

-- To access global variables_G = GLOBALGetPlayer = _G.GetPlayerTUNING = _G.TUNINGlocal function rabbit_postinit(inst)	local function beardling_loot(inst)		-- Modify the loot of beardlings here		-- inst refers to the instance of the beardling		inst.components.lootdropper:SetLoot{}		inst.components.lootdropper:AddRandomLoot("beardhair", .5)		inst.components.lootdropper:AddRandomLoot("monstermeat", 1)		inst.components.lootdropper:AddRandomLoot("nightmarefuel", 1)		inst.components.lootdropper.numrandomloot = 1	end	-- Check if the rabbit became a beardling	-- Partially copied from rabbit.lua CheckTransformState fn	local function check_beardling(inst)		if not inst.components.health:IsDead() then			if GetPlayer().components.sanity:GetPercent() > TUNING.BEARDLING_SANITY then			-- Not beardling			else				-- Beardling				-- Run the function to modify loot				beardling_loot(inst)			end		end	end	-- Save old drop fn	local old_ondropfn = inst.components.inventoryitem.ondropfn	-- Then replace it with a new one	inst.components.inventoryitem.ondropfn = function(inst)		old_ondropfn(inst) -- Run the old one first		-- Then run our own check		-- Needs to execute AFTER old_ondropfn to replace values set by original function		check_beardling(inst)	end	-- Same idea as drop fn above	local old_OnWake = inst.OnEntityWake	inst.OnEntityWake = function(inst)		old_OnWake(inst)		check_beardling(inst)	endend-- Runs the above function after rabbit is initializedAddPrefabPostInit("rabbit", rabbit_postinit)

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...