NamelessDude77 Posted February 20, 2018 Share Posted February 20, 2018 I'm trying to modify the local function setflowertype inside flower.lua to be able to choose which type will be planted I want to do all the stuff in modmain.lua but I can't find where this function gets attached (idk if it's really supposed to) so I'd be able to do something like: local old_setflowertype = inst.somewhere.something.setflowertype What I wish I could do: Quote local function MyStuff(inst) local name = someName local names = {"f1","f2","f3","f4","f5","f6","f7","f8","f9","f10"} local ROSE_CHANCE = someNumber local old_setflowertype = inst.somewhere.something.setflowertype inst.somewhere.something.setflowertype = function(inst, etc) if name == "random" then inst.animname = math.random() < ROSE_CHANCE and "rose" or names[math.random(#names)] else inst.animname = name end end end AddPrefabPostInit("flower", MyStuff) Is it even possible? I also don't understand what animname is. I've spent so many days trying to figure out how to do this with no luck. Any help appreciated, thanks! Link to comment https://forums.kleientertainment.com/forums/topic/87863-help-cant-find-a-way-to-modify-prefab-function/ Share on other sites More sharing options...
Aquaterion Posted February 20, 2018 Share Posted February 20, 2018 setflowertype is local to that file, so it can't be modified. inst.animname stores the animation name of the flower that was chosen, so it can be saved and loaded for next sessions. Link to comment https://forums.kleientertainment.com/forums/topic/87863-help-cant-find-a-way-to-modify-prefab-function/#findComment-1006955 Share on other sites More sharing options...
NamelessDude77 Posted February 20, 2018 Author Share Posted February 20, 2018 (edited) Thanks for your reply, Aquaterion! I see, well after reading @rezecib's post I thought it would be possible somehow though It seems there's no way to change rose chance without modding that function, but would it be possible to do what I want by using inst.animname only? Edited February 20, 2018 by Threnke Link to comment https://forums.kleientertainment.com/forums/topic/87863-help-cant-find-a-way-to-modify-prefab-function/#findComment-1006970 Share on other sites More sharing options...
Aquaterion Posted February 20, 2018 Share Posted February 20, 2018 You could just copy the setflowertype function with some alterations and make it rerun in the AddPrefabPostInit on the flower. That should work just fine other than having a bit of redundancy. AddPrefabPostInit("flower", function(inst) inst:DoTaskInTime(0 function()--delay a bit to make sure it runs AFTER the original function setflowertype(inst, inst.animname) end) end) Link to comment https://forums.kleientertainment.com/forums/topic/87863-help-cant-find-a-way-to-modify-prefab-function/#findComment-1006980 Share on other sites More sharing options...
NamelessDude77 Posted February 21, 2018 Author Share Posted February 21, 2018 (edited) It worked thanks! With a few changes I got it working the way I wanted. No delay needed, tested it. I think it's not necessary since the postinit function execute after the prefab loads, correct me if I'm wrong. I had to change the prefab name from "flower" to "planted_flower" because it was turning all the flowers in the world into the one I chose. Here's how it looks like: AddPrefabPostInit("planted_flower", function(inst) local name = "rose" local function setflowertype(inst, name) inst.animname = name inst.AnimState:PlayAnimation(inst.animname) end if name ~= "random" then setflowertype(inst, name) end end) Now I'll see if I can make the buttons work... Thanks a lot Edit: If there's something to be concerned about this code, please let me know Edited February 21, 2018 by Threnke Link to comment https://forums.kleientertainment.com/forums/topic/87863-help-cant-find-a-way-to-modify-prefab-function/#findComment-1007123 Share on other sites More sharing options...
Aquaterion Posted February 21, 2018 Share Posted February 21, 2018 what is if name ~= "random" then suppose to be doing? because all your flowers change because that statement is always true Link to comment https://forums.kleientertainment.com/forums/topic/87863-help-cant-find-a-way-to-modify-prefab-function/#findComment-1007190 Share on other sites More sharing options...
NamelessDude77 Posted February 21, 2018 Author Share Posted February 21, 2018 It's incomplete, the variable local name will get the data from the selected button, if "random" button is selected then don't call that function and keeps the default random behaviour Link to comment https://forums.kleientertainment.com/forums/topic/87863-help-cant-find-a-way-to-modify-prefab-function/#findComment-1007226 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