Brain Posted July 24, 2015 Share Posted July 24, 2015 (edited) I need help with something. Although I´m a seasoned programmer, It´s my first time in lua and modding for DS/DST and I´m having a hard time with something. Sorry to bother you guys, I tried really hard but I hit the wall. I want to replace the hunter component, the one that handles all the animal tracks and dirt piles and Koalefant spawning. It is part of the forest prefab. Code is simple and goes like this:function ReplaceHunter (inst) print "replacing hunter component" inst:RemoveComponent("hunter") --inst:AddComponent("betterhunter")endAddPrefabPostInit("forest", ReplaceHunter)So, the RemoveComponent works but the game crashes because the constructor of the hunter component registers a DoTaskInTime:local Hunter = Class(function(self, inst) -- stuffself.inst:DoTaskInTime(0, function(inst) inst.components.hunter:StartCooldown() end)end)The crash comes when the scheduler fires and ".hunter" reference is nil, because I destroyed it 1 frame before. I tried looking at pendingtasks list of Periodic objects so I could Cancel() it but the problem is that once the task is scheduled, I can´t identify from which component it originated, because the GUID that is passed to the scheduler is entities´. I also can´t cancel all of them, because of course that could break half the world and other mods. So, unless someone more knowledgeable has an easy solution, I suppose I will have to inject code into Klei´s hunter.lua (modifying some of its methods) so it stops firing scheduler tasks and instead fires a callback function in modmain.lua that removes the component when it is safe to do so. I thank you all in advance for any better idea! Edited July 24, 2015 by Brain Link to comment Share on other sites More sharing options...
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 account
Already have an account? Sign in here.Sign In Now