WhiteAutumn Posted October 7, 2019 Share Posted October 7, 2019 (edited) How do you invoke (and then later hide) the damage over time overlay that appears when you are starving? Edited October 12, 2019 by WhiteAutumn Link to comment https://forums.kleientertainment.com/forums/topic/112493-how-to-invoke-the-damage-over-time-overlay-solved/ Share on other sites More sharing options...
Ultroman Posted October 7, 2019 Share Posted October 7, 2019 (edited) This code once worked for removing health. Look up for original widget to see what has changed since this code was written, and then you can decide how to manipulate it. Be advised, this controls the entire "losing health"/bloodover widget. You can change the if-statement which controls when it is triggered and untriggered. -- Remove red overlay (losing health) AddClassPostConstruct("widgets/bloodover", function(self) function self:UpdateState() if (freezingHealthPenaltyPercentage > 0 and self.owner.IsFreezing ~= nil and self.owner:IsFreezing()) or (overheatingHealthPenaltyPercentage > 0 and self.owner.IsOverheating ~= nil and self.owner:IsOverheating()) or (self.owner.replica.hunger ~= nil and self.owner.replica.hunger:IsStarving()) or (self.owner.IsBeaverStarving ~= nil and self.owner:IsBeaverStarving()) then self:TurnOn() else self:TurnOff() end end end) Edited October 7, 2019 by Ultroman Link to comment https://forums.kleientertainment.com/forums/topic/112493-how-to-invoke-the-damage-over-time-overlay-solved/#findComment-1269192 Share on other sites More sharing options...
WhiteAutumn Posted October 8, 2019 Author Share Posted October 8, 2019 (edited) Thank you, this appears to work so far however I have run into a little issue. I can't seem to access TheWorld (nil value) while in the context of UpdateState? Sorry if this is a stupid question / problem. -- Modify bloodover widget AddClassPostConstruct("widgets/bloodover", function(self) function self:UpdateState() if (self.owner.IsFreezing ~= nil and self.owner:IsFreezing()) or (self.owner.IsOverheating ~= nil and self.owner:IsOverheating()) or (self.owner.replica.hunger ~= nil and self.owner.replica.hunger:IsStarving()) or TheWorld.state.phase == "day" then print("NOW ON") self:TurnOn() else print("NOW OFF") self:TurnOff() end end end) (this is in modmain.lua) Edited October 8, 2019 by WhiteAutumn Link to comment https://forums.kleientertainment.com/forums/topic/112493-how-to-invoke-the-damage-over-time-overlay-solved/#findComment-1269248 Share on other sites More sharing options...
Ultroman Posted October 8, 2019 Share Posted October 8, 2019 Try GLOBAL.TheWorld instead of TheWorld Link to comment https://forums.kleientertainment.com/forums/topic/112493-how-to-invoke-the-damage-over-time-overlay-solved/#findComment-1269412 Share on other sites More sharing options...
WhiteAutumn Posted October 9, 2019 Author Share Posted October 9, 2019 22 hours ago, Ultroman said: Try GLOBAL.TheWorld instead of TheWorld Thanks that worked! Now my hopefully my final problem and question is about how to trigger UpdateState. Having a look in bloodover.lua we can see when UpdateState gets triggered self.inst:ListenForEvent("badaura", _Flash, owner) self.inst:ListenForEvent("attacked", function(owner, data) if not data.redirected then self:Flash() end end, owner) self.inst:ListenForEvent("damaged", _Flash, owner) -- same as attacked, but for non-combat situations like making a telltale heart self.inst:ListenForEvent("startstarving", _UpdateState, owner) self.inst:ListenForEvent("stopstarving", _UpdateState, owner) self.inst:ListenForEvent("startfreezing", _UpdateState, owner) self.inst:ListenForEvent("stopfreezing", _UpdateState, owner) self.inst:ListenForEvent("startoverheating", _UpdateState, owner) self.inst:ListenForEvent("stopoverheating", _UpdateState, owner) self.inst:DoTaskInTime(0, _UpdateState) However since I need it to update upon changing phase that won't work, is it possible to change UpdateState to be called upon phase change? Link to comment https://forums.kleientertainment.com/forums/topic/112493-how-to-invoke-the-damage-over-time-overlay-solved/#findComment-1269733 Share on other sites More sharing options...
Ultroman Posted October 11, 2019 Share Posted October 11, 2019 First result when searching the game files for the string: "phase" gives the following example: inst:WatchWorldState("phase", OnPhase) So, you simply change your code to be: -- Modify bloodover widget AddClassPostConstruct("widgets/bloodover", function(self) TheWorld:WatchWorldState("phase", self.UpdateState) function self:UpdateState() if (self.owner.IsFreezing ~= nil and self.owner:IsFreezing()) or (self.owner.IsOverheating ~= nil and self.owner:IsOverheating()) or (self.owner.replica.hunger ~= nil and self.owner.replica.hunger:IsStarving()) or TheWorld.state.phase == "day" then print("NOW ON") self:TurnOn() else print("NOW OFF") self:TurnOff() end end end) Link to comment https://forums.kleientertainment.com/forums/topic/112493-how-to-invoke-the-damage-over-time-overlay-solved/#findComment-1270183 Share on other sites More sharing options...
WhiteAutumn Posted October 11, 2019 Author Share Posted October 11, 2019 Wouldn't this add a new listener every time UpdateState is called? eventually resulting in UpdateState being called a lot of times on phase change? Link to comment https://forums.kleientertainment.com/forums/topic/112493-how-to-invoke-the-damage-over-time-overlay-solved/#findComment-1270286 Share on other sites More sharing options...
WhiteAutumn Posted October 11, 2019 Author Share Posted October 11, 2019 (edited) Testing the suggested change leaves the game in an infinite loop upon character load :/ edit: hold on something else seems to be causing that edit: Okay this time I have what actually happens. The game loads fine however on phase change it crashes: Line 70 is this (a part of previous code snippets): if (self.owner.IsFreezing ~= nil and self.owner:IsFreezing()) or Edited October 12, 2019 by WhiteAutumn Link to comment https://forums.kleientertainment.com/forums/topic/112493-how-to-invoke-the-damage-over-time-overlay-solved/#findComment-1270537 Share on other sites More sharing options...
Ultroman Posted October 12, 2019 Share Posted October 12, 2019 Then you have to check whether "owner" actually exists before doing your checks: -- Modify bloodover widget AddClassPostConstruct("widgets/bloodover", function(self) TheWorld:WatchWorldState("phase", self.UpdateState) function self:UpdateState() if (self.owner and (self.owner.IsFreezing ~= nil and self.owner:IsFreezing()) or (self.owner.IsOverheating ~= nil and self.owner:IsOverheating()) or (self.owner.replica.hunger ~= nil and self.owner.replica.hunger:IsStarving())) or TheWorld.state.phase == "day" then print("NOW ON") self:TurnOn() else print("NOW OFF") self:TurnOff() end end end) Here, I have wrapped all the owner-checks in a parenthesis, and slapped on that it should only do those particular checks if the owner variable exists. Otherwise, it just does your day check. Link to comment https://forums.kleientertainment.com/forums/topic/112493-how-to-invoke-the-damage-over-time-overlay-solved/#findComment-1270674 Share on other sites More sharing options...
WhiteAutumn Posted October 12, 2019 Author Share Posted October 12, 2019 (edited) That also crashes but this time at line 45 in bloodover.lua due to owner being nil. It's fine though, i've found a hacky workaround that does work. Turns out there's only one listener for the event "stopstarving" and that listener is the one in bloodover.lua which calls UpdateState so I can just push event stopstarving whenever I want UpdateState called and it works. Edited October 12, 2019 by WhiteAutumn Link to comment https://forums.kleientertainment.com/forums/topic/112493-how-to-invoke-the-damage-over-time-overlay-solved/#findComment-1270690 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