Jump to content

DST Merm King Badge


Recommended Posts

I created a new badge i want to use to track mermking hunger, but I'm struggling to figure out why mermkingmanager is always nil in the badge code

 

my badge (i'm temporarily using wolfgang animation):

local Badge = require "widgets/badge"

local TINT = { 120 / 255, 127 / 255, 86 / 255, 1 }

local MermKingBadge = Class(Badge, function(self, owner)
    Badge._ctor(self, nil, owner, TINT, "status_mermking", nil, nil, true)

    self.circleframe:GetAnimState():SetBank("status_wolfgang")
    self.circleframe:GetAnimState():SetBuild("status_wolfgang")
    self.dont_animate_circleframe = true
end)

function MermKingBadge:SetPercent(val)

    local original_val = val
    local max = 200

    if self.circular_meter ~= nil then
        self.circular_meter:GetAnimState():SetPercent("meter", val)
    else
        self.anim:GetAnimState():SetPercent("anim", 1 - val)
        if self.circleframe ~= nil and not self.dont_animate_circleframe then
            self.circleframe:GetAnimState():SetPercent("frame", 1 - val)
        end
    end

    self.num:SetString(tostring(math.ceil(original_val * max)))
    self.percent = val
end

return MermKingBadge

 

my modmain.lua

local MermKingBadge = require("widgets/mermkingbadge")

AddPrefabPostInit("mermking", function(inst)
    local function onHungerDelta(_, data)
        GLOBAL.TheWorld:PushEvent("onmermkinghungerchanged", { hunger = data.newpercent })
    end
    inst:ListenForEvent("hungerdelta", function(_, data)
        onHungerDelta(inst, data)
    end)
end)

AddClassPostConstruct("widgets/statusdisplays", function(self)
    if not self.owner or self.owner.prefab ~= "wurt" then
        return
    end
    function self:HungerDelta(data)
        if (data.hunger ~= nil) then
            self.mermkingbadge:SetPercent(data.hunger, 200)
        elseif (GLOBAL.TheWorld.components.mermkingmanager ~= nil) then
            self.mermkingbadge:SetPercent(GLOBAL.TheWorld.components.mermkingmanager.hunger.current)
        end
    end
    self.mermkingbadge = self:AddChild(MermKingBadge(self.owner, true))
    self.mermkingbadge:SetPosition(-124, -52)
    self.mermkingbadge:SetPercent(1, 200)
    self.inst:ListenForEvent("onmermkinghungerchanged", function(data)
        self:HungerDelta(data)
    end, GLOBAL.TheWorld)
end)

 

I push a new event "onmermkinghungerchanged" which is correctly captured by ListenForEvent in the AddClassPostConstruct. The problem is I got both nil here "data.hunger" and here "GLOBAL.TheWorld.components.mermkingmanager"

Any tips on how retrieve mermking hunger?

<3

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...