Zeklo Posted February 15, 2015 Share Posted February 15, 2015 So I recently began modding and I'm wondering how do I make an item constantly check for something. In this case player health. I have the code working fine except that it only checks for the players health once they equip the item. This is because I have it in the onequip part. So where do I need to put it to constantly check? This is the code that checks if the player health is below 100 and if so will then freeze enemies that hit them.if owner.components.health.currenthealth < 100 then inst.freezefn = function(attacked, data) if data and data.attacker and data.attacker.components.freezable then data.attacker.components.freezable:AddColdness(12.0) data.attacker.components.freezable:SpawnShatterFX() end endend Link to comment https://forums.kleientertainment.com/forums/topic/51019-how-to-make-and-item-constantly-check-for/ Share on other sites More sharing options...
Corrosive Posted February 16, 2015 Share Posted February 16, 2015 The key to most object oriented environments is to avoid 'constantly' doing anything, as you want to keep those cpu cycles free for whatever else needs to be done. As a general rule of thumb, you want to be hooking into events as much as possible to accomplish this type of task. A "healthdelta" event gets pushed whenever health changes: components/health.lua: self.inst:PushEvent("healthdelta", {oldpercent = old_percent, newpercent = self:GetPercent(), overtime=overtime, cause=cause})You need to register an event listener for this event. You can see that it pushes an object containing several values of interest to you. oldpercent you will want to make sure was equal to 100. newpercent you will want to make sure is below 100, and cause you will want to make sure was an attacker(I would probably start by checking this, so the others dont need to be checked every time your health changes for any reason). Link to comment https://forums.kleientertainment.com/forums/topic/51019-how-to-make-and-item-constantly-check-for/#findComment-613485 Share on other sites More sharing options...
Mobbstar Posted February 16, 2015 Share Posted February 16, 2015 If the above fails at some point, usually because there isn't an event, you can use inst:DoPeriodicTask(period,function,initial_delay,[further arguments]) too. Link to comment https://forums.kleientertainment.com/forums/topic/51019-how-to-make-and-item-constantly-check-for/#findComment-613629 Share on other sites More sharing options...
Zeklo Posted February 16, 2015 Author Share Posted February 16, 2015 (edited) I'll see what I can do. Thanks for the response. EDIT: How can I check for what season it is? I know its WorldState but how can I do this with an equipable?This is in the onequip section. It crashes because TheWorld is not defined or something along those lines.if TheWorld.state.issummer then inst.freezefn = function(attacked, data) if data and data.attacker and data.attacker.components.freezable then data.attacker.components.freezable:AddColdness(12.0) data.attacker.components.freezable:SpawnShatterFX() end end end Edited February 16, 2015 by Zeklo Link to comment https://forums.kleientertainment.com/forums/topic/51019-how-to-make-and-item-constantly-check-for/#findComment-613642 Share on other sites More sharing options...
Mobbstar Posted February 16, 2015 Share Posted February 16, 2015 I'll see what I can do. Thanks for the response. EDIT: How can I check for what season it is? I know its WorldState but how can I do this with an equipable?This is in the onequip section. It crashes because TheWorld is not defined or something along those lines.if TheWorld.state.issummer then inst.freezefn = function(attacked, data) if data and data.attacker and data.attacker.components.freezable then data.attacker.components.freezable:AddColdness(12.0) data.attacker.components.freezable:SpawnShatterFX() end end end GetWorld() == TheWorld Link to comment https://forums.kleientertainment.com/forums/topic/51019-how-to-make-and-item-constantly-check-for/#findComment-613697 Share on other sites More sharing options...
Zeklo Posted February 16, 2015 Author Share Posted February 16, 2015 (edited) GetWorld() == TheWorld That does fix the crash, but now the game just freezes on the menu. Edited February 17, 2015 by Zeklo Link to comment https://forums.kleientertainment.com/forums/topic/51019-how-to-make-and-item-constantly-check-for/#findComment-613745 Share on other sites More sharing options...
Corrosive Posted February 17, 2015 Share Posted February 17, 2015 @Zeklo, Check near the bottom of your log file. documents\klei\donotstarve\log.txt Link to comment https://forums.kleientertainment.com/forums/topic/51019-how-to-make-and-item-constantly-check-for/#findComment-613808 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