Sign in to follow this  
WhiteAutumn

How to invoke the damage over time overlay? [Solved]

Recommended Posts

WhiteAutumn    2
Posted (edited)

How do you invoke (and then later hide) the damage over time overlay that appears when you are starving?
mADeZmr.jpg

Edited by WhiteAutumn

Share this post


Link to post
Share on other sites
Ultroman    552
Posted (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 by Ultroman
  • Like 1

Share this post


Link to post
Share on other sites
WhiteAutumn    2
Posted (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 by WhiteAutumn

Share this post


Link to post
Share on other sites
WhiteAutumn    2
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?
 

 

Share this post


Link to post
Share on other sites
Ultroman    552

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)

 

  • Like 1

Share this post


Link to post
Share on other sites
WhiteAutumn    2

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?

Share this post


Link to post
Share on other sites
WhiteAutumn    2

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:
A2N5d3c.png

Line 70 is this (a part of previous code snippets):

if (self.owner.IsFreezing ~= nil and self.owner:IsFreezing()) or
Edited by WhiteAutumn

Share this post


Link to post
Share on other sites
Ultroman    552

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.

Share this post


Link to post
Share on other sites
WhiteAutumn    2

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 by WhiteAutumn

Share this post


Link to post
Share on other sites

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

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this