Jump to content

[solved] how to access moisturemeter?


Recommended Posts

I would like to access the moisturemeter to set a new tooltip, via the player inst.
Is this possible?

I tried:
inst.HUD.moisturemeter
inst.HUD.controls.moisturemeter
inst.moisturemeter

But it is nothing of it... of course this is just guessing, but I don't know another way. tableprint inst.HUD or simular does not work.

The goal is to change the Tooltip of the moisturemeter to the actual MoistureRate, which is propagated to the client with help of net_float.
 

The only thing that worked so far is:

function MoistureMeterShowRate(self)
    local _SetValue = self.SetValue
    self.SetValue = function(inst,...) 
        self:SetTooltip("+"..round2(self.owner.MRate:value(),3).."/s")
        return _SetValue(inst,...)
    end        
end
AddClassPostConstruct("widgets/moisturemeter", MoistureMeterShowRate)

but the function SetValue is called not often enough , so it updates not often enough =/
That's why I thought I can set the Tooltip directly in the OnDirtyEvent function from the net_float thing...
Also I tried to add DoTaskInTime to the MoistureMeter Class, but self.DoTaskInTime does not work.

Edited by Serpens
Link to comment
Share on other sites

1 hour ago, Serpens said:

I would like to access the moisturemeter to set a new tooltip, via the player inst.
Is this possible?

inst.HUD.controls.status.moisturemeter

 

1 hour ago, Serpens said:

Also I tried to add DoTaskInTime to the MoistureMeter Class, but self.DoTaskInTime does not work.

Because self does not refer to an entity.

For these widgets, you may use self.inst (the entity for the widget). Or self.owner (which refers to the player anchored to the widget).

For example, in status displays:

self.inst:ListenForEvent("moisturedelta", self.onmoisturedelta, self.owner)

self is the widget class.

self.inst is the widget entity.

self.owner is the player (which gets pushed the "moisturedelta" event).

So, for example:

local function MoistureMeterShowRate(self)
	local function OnMoistureRateDirty(owner)
		self.moisturemeter:SetTooltip("+"..round2(owner.MRate:value(),3).."/s")
	end
	self.inst:ListenForEvent("OnMoistureRateDirty", OnMoistureRateDirty, self.owner)
end
AddClassPostConstruct("widgets/statusdisplays", MoistureMeterShowRate)

 

Link to comment
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
 Share

×
  • Create New...