Jump to content

Custom Health Badge


Thomas Die
 Share

Recommended Posts

How to make Custom Badges For Health/maybe others

The Code To Do This:

Spoiler

Assets = {Asset("ANIM", "anim/custom_meter.zip")}

local function CustomHealthBar(class)
if GLOBAL.ThePlayer.prefab == "Your_Prefab_Name" then
		if class.heart.circleframe then
		   class.heart.circleframe:GetAnimState():OverrideSymbol("icon", "anim_build", "icon")
		   class.heart.anim:GetAnimState():SetMultColour( 1, 1, 1, 1 )--default white: works in RGB
		   class.heart.backing:GetAnimState():SetMultColour( 1, 1, 1, 1 )--default white: works in RGB
		else print("bruh")
	end end
end
AddClassPostConstruct("widgets/statusdisplays", CustomHealthBar)

--for hunger instead of heart do stomach
--for sanity instead of heart do brain
--these two should wokr the same but eh

 

class.heart.backing is the the very back of the badge
class.heart.anim is the colour of the meter itself

this goes in your modmain


The Assets To Do This:
custom_meter.rar

Little Showcase:

image.png.3ab865c1e742513a0fac4fcf1c01d62b.png

  • Like 1
  • Thanks 2
Link to comment
Share on other sites

18 hours ago, Welx said:

The health icon won't appear for the badge. Is there a way to fix that?

can you send me the code or the file?

Off the top of my head i can say that it could be:
    > Spriter build name wasn't changed
    > class.heart.circleframe:GetAnimState():OverrideSymbol("icon", "anim_build", "icon"):
            The anim_build wasn't changed
    > my code sucks

  • Thanks 1
Link to comment
Share on other sites

13 hours ago, thomas4846 said:

can you send me the code or the file?

Off the top of my head i can say that it could be:
    > Spriter build name wasn't changed
    > class.heart.circleframe:GetAnimState():OverrideSymbol("icon", "anim_build", "icon"):
            The anim_build wasn't changed
    > my code sucks

Big dumbo move on my part
I changed my Spriter build name but forgot to change the anim_build to the build name, lol
I changed that and now it works. Thanks for pointing that out!

  • GL Happy 1
Link to comment
Share on other sites

Shot in the dark, but is there any way this widget could be modified to not be tied to health? I made a thread here about it but have not gotten a single reply aside from myself.

Here's my entire mod so that one can see if everything's organized correctly and see how all my files are coded, things are named properly, etc.

Thanks in advance!

Garamonde.rar

Link to comment
Share on other sites

2 hours ago, Garamonde said:

 

I'll give a brief explanation what i know:
P.S i use to use other people's code it doesn't work that well

You're trying to make a new meter so you'll need to know how the widgets and net-vars work:

All of the meters are compiled inside of scripts\widgets\statusdisplay 
so to access and import you should use:
(statusdisplays is where all the icons/huds reside)

AddClassPostConstruct("widgets/statusdisplays", function (self)
 --code
end)

The cool people at klei have decided to make another widget called badge to simplify the process for creating the widget to importing some data,
you can use my assets as a template for your icons

This is somethings just to make the code more manageable throughout coding it first:
and below is the code used to create the badge\meter.
 

local require = GLOBAL.require

local Badge = require "widgets/badge"
local UIAnim = require "widgets/uianim"
local Text = require "widgets/text"
--this is so that the code uses the in items in widgets for us to use
AddClassPostConstruct("widgets/statusdisplays", function (self)
  --local Badge = Class(Widget, function(self, anim, owner, tint, iconbuild, circular_meter, use_clear_bg)
  self.custom_meter = self:AddChild(Badge(nil, self.owner, { 1, 1, 1, 1 }, "iconbuild"))
      self.custom_meter:SetClickable(true)
	  self.custom_meter:SetPosition(x, y, z)
      --position could be anything but i use  x, y, z = 0, -85, 0
end)

to import data is to use netvars personally i use something more simpler but that's for you to figure out.

some of the code from my tutorial can be used for reference in regard to some of the things here, sorry but anything more is gonna drain me good luck on your code.

  • Thanks 1
Link to comment
Share on other sites

On 1/4/2021 at 4:20 PM, Thomas Die said:

How to make Custom Badges For Health/maybe others

The Code To Do This:

  Reveal hidden contents


Assets = {Asset("ANIM", "anim/custom_meter.zip")}

local function CustomHealthBar(class)
if GLOBAL.ThePlayer.prefab == "Your_Prefab_Name" then
		if class.heart.circleframe then
		   class.heart.circleframe:GetAnimState():OverrideSymbol("icon", "anim_build", "icon")
		   class.heart.anim:GetAnimState():SetMultColour( 1, 1, 1, 1 )--default white: works in RGB
		   class.heart.backing:GetAnimState():SetMultColour( 1, 1, 1, 1 )--default white: works in RGB
		else print("bruh")
	end end
end
AddClassPostConstruct("widgets/statusdisplays", CustomHealthBar)

--for hunger instead of heart do stomach
--for sanity instead of heart do brain
--these two should wokr the same but eh

 

class.heart.backing is the the very back of the badge
class.heart.anim is the colour of the meter itself

this goes in your modmain


The Assets To Do This:
custom_meter.rar 82.14 kB · 15 downloads

Little Showcase:

image.png.3ab865c1e742513a0fac4fcf1c01d62b.png

Will this just change the HP meter, or will it be able to add a new meter, like Time or Might?

Link to comment
Share on other sites

49 minutes ago, ScrewdriverLad said:

Will this just change the HP meter, or will it be able to add a new meter, like Time or Might?

Just the health meter. Time is also just a replaced health meter like this. If you want to make another meter for your mod, I'd suggest look into Wigfrid's inspiration meter or the new Might meter for guidance.

Link to comment
Share on other sites

2 minutes ago, TheSkylarr said:

Just the health meter. Time is also just a replaced health meter like this. If you want to make another meter for your mod, I'd suggest look into Wigfrid's inspiration meter or the new Might meter for guidance.

Alright, that was my plan. Thank you very much for the quick reply!

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