Tesumoto Posted March 27, 2018 Share Posted March 27, 2018 Hello everyone! I have a specific function. I need it to work for objects with defined prefabs, but for the rest it was not used. Someone can tell me how to implement this? AddComponentPostInit("burnable", function(self) local _StartWildfire = self.StartWildfire self.StartWildfire = function(self) end end) Thank you for attention! Link to comment Share on other sites More sharing options...
IronHunter Posted March 31, 2018 Share Posted March 31, 2018 (edited) --you could make a table for your specific prefabs local burnables = { grass = true, sapling = true, reeds = true, } AddComponentPostInit("burnable", function(self) local _StartWildfire = self.StartWildfire self.StartWildfire = function(self) if burnables[self.inst.prefab] then _StartWildfire(self) end end end) I don't have time to test this atm, but its what I assume you are asking for Edited March 31, 2018 by IronHunter Link to comment Share on other sites More sharing options...
Tesumoto Posted April 1, 2018 Author Share Posted April 1, 2018 On 31.03.2018 at 9:35 AM, IronHunter said: --you could make a table for your specific prefabs local burnables = { grass = true, sapling = true, reeds = true, } AddComponentPostInit("burnable", function(self) local _StartWildfire = self.StartWildfire self.StartWildfire = function(self) if burnables[self.inst.prefab] then _StartWildfire(self) end end end) I don't have time to test this atm, but its what I assume you are asking for Thanks you very much, this code works without errors. But is it possible to do the opposite, so that function works only for specific prefabs? Or is it too difficult? Link to comment Share on other sites More sharing options...
IronHunter Posted April 1, 2018 Share Posted April 1, 2018 If you want to exclude specific prefabs you could put a not in front of burnables[self.inst.prefab] I am not sure what function you are refering to. But you could also do elseif or else for additional precision on what you want it to do. Link to comment Share on other sites More sharing options...
Tesumoto Posted April 1, 2018 Author Share Posted April 1, 2018 20 minutes ago, IronHunter said: If you want to exclude specific prefabs you could put a not in front of burnables[self.inst.prefab] I am not sure what function you are refering to. But you could also do elseif or else for additional precision on what you want it to do. AddComponentPostInit("burnable", function(self) local _StartWildfire = self.StartWildfire self.StartWildfire = function(self) end end) I tried to change the code, but I did not succeed. I want this function to work only for special prefabs. And for everything else, it was ignored. Link to comment Share on other sites More sharing options...
IronHunter Posted April 1, 2018 Share Posted April 1, 2018 The code I provided is suppose to do that. It enables wildfires for specific prefabs in the table, anything not in your list is excluded automatically. Just change the prefabs in the table to your custom ones. I just populated it with vanilla ones as an example. Link to comment Share on other sites More sharing options...
Tesumoto Posted April 1, 2018 Author Share Posted April 1, 2018 10 minutes ago, IronHunter said: The code I provided is suppose to do that. It enables wildfires for specific prefabs in the table, anything not in your list is excluded automatically. Just change the prefabs in the table to your custom ones. I just populated it with vanilla ones as an example. I need other effect. I want that the things specified in the prefabs are protected from fires, and everything else is burnt. Is this code difficult to write? Link to comment Share on other sites More sharing options...
IronHunter Posted April 1, 2018 Share Posted April 1, 2018 Use not to exclude those prefabs like I mentioned in earlier post. If not burnables[self.inst.prefab] then etc. Link to comment Share on other sites More sharing options...
Tesumoto Posted April 2, 2018 Author Share Posted April 2, 2018 11 hours ago, IronHunter said: Use not to exclude those prefabs like I mentioned in earlier post. If not burnables[self.inst.prefab] then etc. Hmm... This it was very easy. It was necessary to add only "not" =) local burnables = { sapling = true, grass = true, } AddComponentPostInit("burnable", function(self) local _StartWildfire = self.StartWildfire self.StartWildfire = function(self) if not burnables[self.inst.prefab] then _StartWildfire(self) end end end) Thanks you for help, I hope now my mod will become even more useful. Link to comment 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