Doomgoat Posted January 27, 2015 Share Posted January 27, 2015 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 https://forums.kleientertainment.com/forums/topic/49796-digging-a-rabbit-hole-gives-morsel/ Share on other sites More sharing options...
Doomgoat Posted January 27, 2015 Author Share Posted January 27, 2015 local function dig_up(inst, chopper)if inst.components.spawner:IsOccupied() theninst.components.lootdropper:SpawnLootPrefab("rabbit")inst.components.lootdropper:SpawnLootPrefab("manrabbit_tail")elseinst.components.lootdropper:SpawnLootPrefab("manrabbit_tail") endinst:Remove()end AddPrefabPostInit("rabbithole", dig_up)local function dig_up(inst, chopper)if inst.components.spawner:IsOccupied() theninst.components.lootdropper:SpawnLootPrefab("rabbit")inst.components.lootdropper:SpawnLootPrefab("manrabbit_tail")elseinst.components.lootdropper:SpawnLootPrefab("manrabbit_tail") endinst:Remove()end AddPrefabPostInit("rabbithole", dig_up)local function dig_up(inst, chopper)if inst.components.spawner:IsOccupied() theninst.components.lootdropper:SpawnLootPrefab("rabbit")inst.components.lootdropper:SpawnLootPrefab("manrabbit_tail")elseinst.components.lootdropper:SpawnLootPrefab("manrabbit_tail") endinst:Remove()end AddPrefabPostInit("rabbithole", dig_up) Link to comment https://forums.kleientertainment.com/forums/topic/49796-digging-a-rabbit-hole-gives-morsel/#findComment-606403 Share on other sites More sharing options...
Doomgoat Posted January 27, 2015 Author Share Posted January 27, 2015 It seems that the page froze when I submitted this post and I clicked to post it multiple times thinking that it was not working... sorry about that, and I decided to change it from morsels to bunny puffs. Link to comment https://forums.kleientertainment.com/forums/topic/49796-digging-a-rabbit-hole-gives-morsel/#findComment-606404 Share on other sites More sharing options...
Blueberrys Posted January 27, 2015 Share Posted January 27, 2015 (edited) @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 January 27, 2015 by Blueberrys Link to comment https://forums.kleientertainment.com/forums/topic/49796-digging-a-rabbit-hole-gives-morsel/#findComment-606417 Share on other sites More sharing options...
Doomgoat Posted January 28, 2015 Author Share Posted January 28, 2015 @Blueberrys Thank you so much! My mod works now!! Many many many thanks Link to comment https://forums.kleientertainment.com/forums/topic/49796-digging-a-rabbit-hole-gives-morsel/#findComment-606779 Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now