Jump to content

Recommended Posts

I am trying to create a mod that will have rabbit holes drop a morsel instead of a rabbit. This is my first mod and I think after I get help with this, I will be able to branch off to more advanced ideas. The only problem I am having is with my modmain.lua file, I can't seem to create a working function that will add the loot item to a dug up rabbit hole. Please help!

local function dig_up(inst, chopper)
if inst.components.spawner:IsOccupied() then
inst.components.lootdropper:SpawnLootPrefab("rabbit")
inst.components.lootdropper:SpawnLootPrefab("manrabbit_tail")
else
inst.components.lootdropper:SpawnLootPrefab("manrabbit_tail")
 
end
inst:Remove()
end
 
AddPrefabPostInit("rabbithole", dig_up)

local function dig_up(inst, chopper)
if inst.components.spawner:IsOccupied() then
inst.components.lootdropper:SpawnLootPrefab("rabbit")
inst.components.lootdropper:SpawnLootPrefab("manrabbit_tail")
else
inst.components.lootdropper:SpawnLootPrefab("manrabbit_tail")
 
end
inst:Remove()
end
 
AddPrefabPostInit("rabbithole", dig_up)

local function dig_up(inst, chopper)
if inst.components.spawner:IsOccupied() then
inst.components.lootdropper:SpawnLootPrefab("rabbit")
inst.components.lootdropper:SpawnLootPrefab("manrabbit_tail")
else
inst.components.lootdropper:SpawnLootPrefab("manrabbit_tail")
 
end
inst:Remove()
end
 
AddPrefabPostInit("rabbithole", dig_up)

@Doomgoat,

 

Someone else had a similar issue earlier.

 

AddPrefabPostInit does not add your function as a callable child to the prefab. It simply executes that function once after initializing the prefab. Hence the "post init".

 

You can not access or modify the local "dig_up" function in the rabbithole prefab. You must define your own, and replace the original using "inst.components.workable:SetOnFinishCallback(new_fn)"

-- This will execute once after rabbithole initializeslocal function rabbithole_postinit(inst)    -- local dig_up function    local function dig_up(inst, chopper)        -- do stuff here    end    -- This replaces the old dig_up function with the new one above    inst.components.workable:SetOnFinishCallback(dig_up)end-- Adds the above function to be executed after rabbithole is initializedAddPrefabPostInit("rabbithole", rabbithole_postinit)
Edited by Blueberrys

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...