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 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 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 Share on other sites More sharing options...
Blueberrys Posted January 27, 2015 Share Posted January 27, 2015 @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 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 Share on other sites More sharing options...
Recommended Posts
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.