developer_center:developer_editor:hp_icon
Table of Contents
HP Bar (Icon)
Finished Product
UI Design
Script
local UI_ID = nil local HEART_TEXT_ID = nil local FULL_HEART = "◆" local EMPTY_HEART = "◇" local function UpdateHeartText(e) local pid = e.eventobjid local attr = e.playerattr if attr == PLAYERATTR.CUR_HP then local _, cur = Player:getAttr(pid, PLAYERATTR.CUR_HP) local _, max = Player:getAttr(pid, PLAYERATTR.MAX_HP) if max <= 0 then max = 1 end local percent = cur / max local hearts = math.floor(percent * 10 + 0.0001) local text = "" for i = 1, 10 do if i <= hearts then text = text .. FULL_HEART else text = text .. EMPTY_HEART end end Customui:setText(pid, UI_ID, HEART_TEXT_ID, text) end end ScriptSupportEvent:registerEvent("Game.AnyPlayer.EnterGame", UpdateHeartText) ScriptSupportEvent:registerEvent("Player.ChangeAttr", UpdateHeartText)
Explanation
developer_center/developer_editor/hp_icon.txt · Last modified: 2025/07/18 11:09 by don