Welpx Posted December 19, 2016 Share Posted December 19, 2016 I wanted to make a new meter with a world stat instead of player stat. I already found a few topics here that helped me put an actual meter in game (for now it's just a lazy copy of the beaverness badge, I'll change that later). Anyway, I'm still stuck since I have no idea how to actually get a variable and show it there... Here is what I achieved so far: Spoiler -- modmain.lua local sw = GLOBAL.require "widgets/shadowwidget" AddClassPostConstruct("widgets/statusdisplays", function(self) self.shadow = self:AddChild(sw(self.owner)) self.shadow:SetPosition(-117, 20, 0) end) -- shadowwidget.lua local Badge = require "widgets/badge" local UIAnim = require "widgets/uianim" local function OnIsFullMoon(inst, isfullmoon) inst.widget.isfullmoon = isfullmoon inst.widget:UpdateArrow() end local TestBadge = Class(Badge, function(self, owner) Badge._ctor(self, "beaver_meter", owner) self.sanityarrow = self.underNumber:AddChild(UIAnim()) self.sanityarrow:GetAnimState():SetBank("sanity_arrow") self.sanityarrow:GetAnimState():SetBuild("sanity_arrow") self.sanityarrow:SetClickable(false) self.inst:WatchWorldState("isfullmoon", OnIsFullMoon) self.isfullmoon = TheWorld.state.isfullmoon self.val = 100 self.arrowdir = nil self:UpdateArrow() end) function TestBadge:UpdateArrow() local anim = self.isfullmoon and self.val > 0 and "arrow_loop_decrease_most" or "neutral" if self.arrowdir ~= anim then self.arrowdir = anim self.sanityarrow:GetAnimState():PlayAnimation(anim, true) end end function TestBadge:SetPercent(val, max) Badge.SetPercent(self, val, max) self.val = val self:UpdateArrow() end return TestBadge Link to comment Share on other sites More sharing options...
Aquaterion Posted December 19, 2016 Share Posted December 19, 2016 I'm not sure why you're making it update the arrow when a full moon hits, shouldn't you be calling SetPercent? which then calls updatearrow itself? Link to comment Share on other sites More sharing options...
Welpx Posted December 19, 2016 Author Share Posted December 19, 2016 I'm not sure either, I just copied the beaverness bagde because I wasn't able to make one for myself xD I tried to use SetPercent before but it didn't work, I even took a peek at statusdisplay.lua but it's really confusing. Could you or someone else, explain to me how and where should I call SetPercent to update the meter based on a variable? Link to comment Share on other sites More sharing options...
zazabar Posted December 19, 2016 Share Posted December 19, 2016 There are a couple of ways you could do it. Depending on what it is measuring, you can assign a listener for when the value changes, it pushes an event to the clients with the SetPercent function. What exactly are you trying to measure? Link to comment Share on other sites More sharing options...
Welpx Posted December 20, 2016 Author Share Posted December 20, 2016 I want to measure a new player stat, it's supposed to be a meter that keeps draining and the only way to refill it is by killing monsters (the amount is defined by the mob's attack damage, pretty much like wigfrid's perk). Once the meter gets to zero, you die. Link to comment Share on other sites More sharing options...
zazabar Posted December 20, 2016 Share Posted December 20, 2016 Your best bet would be to use the base entity function DoPeriodicTask() for lowering it over time. The arguments it takes are a delta_time, targetFunction, then the required function variables. For the combat portion, you'll need to have your variable use the ListenForEvent function, which will use the "killed" tag. For actually setting it up, Doing a PostInit on another character component wouldn't hurt. For instance, you could add it to health as long as you don't overwrite or change any of the functions associated with it and just use it as a storage place. Link to comment Share on other sites More sharing options...
Welpx Posted December 21, 2016 Author Share Posted December 21, 2016 Thanks for the tips, it finally works now. I was a bit lost about where to put DoPeriodicTask() but taking a look at hunger.lua /sanity;lua gave me a clue. 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