ualreadyknowme Posted February 28 Share Posted February 28 Hello! I want roses to drop rose petals instead of usual petals. (I already made rose petals as an item and it works as intended). I tried several options, but they either work only for newly spawned roses or don't work at all. The code I currently have: AddComponentPostInit(function(inst) local function PickUpRosePetals(inst) if not inst.components.pickable then return end if inst.components.pickable then inst.components.pickable:SetUp("rose_petals", 1) --change the item it gives when picked inst:RemoveEventCallback("picked", PickUpRosePetals) --stops listening to event end end -- rose was picked if inst.prefab == "flower_rose" then --ListenForEvent inst:ListenForEvent("picked", PickUpRosePetals) end end) What can I do to make this work? Any help is appreciated. Link to comment https://forums.kleientertainment.com/forums/topic/169927-roses-drop-rose-petals-change-item-drop-when-picked/ Share on other sites More sharing options...
Baguettes Posted March 1 Share Posted March 1 (edited) Component postinit requires the first argument to be a component name, second being the function. Either way, you're better off using AddPrefabPostInit if it's only for the rose. AddPrefabPostInit("flower_rose", function(inst) -- Uncomment this ONLY IF your mod is tagged "all_clients_require_mod". Leave as is if it's "server_only_mod" -- if not GLOBAL.TheWorld.ismastersim then -- return -- end if inst.components.pickable then inst.components.pickable:ChangeProduct("rose_petals") end end) ChangeProduct simply just changes the product and doesn't do anything else, as such it'll leave the petals given number too. Edited March 1 by Baguettes forgot GLOBAL.TheWorld is a wee bit more complicated than that, so I'd rather not give that advice since I don't remember fully. Link to comment https://forums.kleientertainment.com/forums/topic/169927-roses-drop-rose-petals-change-item-drop-when-picked/#findComment-1852784 Share on other sites More sharing options...
ualreadyknowme Posted March 1 Author Share Posted March 1 1 hour ago, Baguettes said: Component postinit requires the first argument to be a component name, second being the function. Either way, you're better off using AddPrefabPostInit if it's only for the rose. AddPrefabPostInit("flower_rose", function(inst) -- Uncomment this ONLY IF your mod is tagged "all_clients_require_mod". Leave as is if it's "server_only_mod" -- if not GLOBAL.TheWorld.ismastersim then -- return -- end if inst.components.pickable then inst.components.pickable:ChangeProduct("rose_petals") end end) ChangeProduct simply just changes the product and doesn't do anything else, as such it'll leave the petals given number too. Thank you for the reply, but this code has the same problem - it works only for the newly spawned roses. So if i re-enter the world nothing works anymore... Link to comment https://forums.kleientertainment.com/forums/topic/169927-roses-drop-rose-petals-change-item-drop-when-picked/#findComment-1852789 Share on other sites More sharing options...
Baguettes Posted March 1 Share Posted March 1 7 hours ago, ualreadyknowme said: Thank you for the reply, but this code has the same problem - it works only for the newly spawned roses. So if i re-enter the world nothing works anymore... Huh. I swear PrefabPostInit works for everything, even existing ones after reloading. Odd... does your mod happen to have anything else concerning roses? Just curious. Link to comment https://forums.kleientertainment.com/forums/topic/169927-roses-drop-rose-petals-change-item-drop-when-picked/#findComment-1852812 Share on other sites More sharing options...
ualreadyknowme Posted March 1 Author Share Posted March 1 2 hours ago, Baguettes said: Huh. I swear PrefabPostInit works for everything, even existing ones after reloading. Odd... does your mod happen to have anything else concerning roses? Just curious. This is supposed to be the only part of the code that alters roses. I'm making a character, but currently it's just esctemplate with graphics. And rose petals item I've added is basically a copy and paste of in-game petals prefab. I plan to make character's skills based around roses, but i'm stuck My modmain.lua - Extended Sample Character base code + addPrefabPostInit that you suggested. Rose_petals prefab has nothing in it that involves roses but I attached it just in case. Could any of these be the problem? What can I do? rose_petals.lua Link to comment https://forums.kleientertainment.com/forums/topic/169927-roses-drop-rose-petals-change-item-drop-when-picked/#findComment-1852818 Share on other sites More sharing options...
Baguettes Posted March 2 Share Posted March 2 1 hour ago, ualreadyknowme said: snip I don't see an issue in there. Just the usual prefab file. Huh........... now that just confuses me even more. Maybe send modmain too if you're comfortable. Link to comment https://forums.kleientertainment.com/forums/topic/169927-roses-drop-rose-petals-change-item-drop-when-picked/#findComment-1852828 Share on other sites More sharing options...
ualreadyknowme Posted March 2 Author Share Posted March 2 9 hours ago, Baguettes said: Maybe send modmain too if you're comfortable. Sure! here is modmain.lua I also attached a zip file, this is a separate mod (no character, nothing else but changing the rose drop to log, so no modded items are involved). And it still only works on new roses... This way I tried to check myself if anything in my initial code affects it, seems like no. modmain.lua Rose_Petals_Separate_Mod.zip Link to comment https://forums.kleientertainment.com/forums/topic/169927-roses-drop-rose-petals-change-item-drop-when-picked/#findComment-1852860 Share on other sites More sharing options...
Baguettes Posted March 3 Share Posted March 3 I'm a wee bit stumped. Only thing I see not right since it's a character mod is the world mastersim check, but even then I don't see other issues that would be more related. Link to comment https://forums.kleientertainment.com/forums/topic/169927-roses-drop-rose-petals-change-item-drop-when-picked/#findComment-1852956 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