Jump to content

Digging a rabbit hole gives morsel


Doomgoat

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!

Link to comment
Share on other sites

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)
Link to comment
Share on other sites

@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)
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
×
  • Create New...