Solved Different color of entity's name depends on it's health

  • Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the comminuty!

    Now, what are you waiting for? Join the community now!

  • LOOKING FOR A VERSION OF SKRIPT?

    You can always check out skUnity Downloads for downloads and any other information about Skript!

SandBoxer011

New Member
Feb 9, 2024
6
1
3
20
Hello, can someone help me with a script, please?
I started using skript recently and I don't know is that possible.
I want to make an entity's name that changes color if it's health is low.

Here's my script:
on spawn of cow:
set max health of event-entity to 25
set health of event-entity to 25
set event-entity's name to "&fDummy Cow &7[&a%event-entity's health%&7/&a%event-entity's max health%&7]"
on damage:
wait 1 tick
if victim is a cow:
if {%victim's health%} <= {%victim's max health%}*0.9:
set name of victim to "&fDummy Cow &7[&e%victim's health%&7/&a%victim's max health%&7]"
if {%victim's health%} <= {%victim's max health%}*0.5:
set name of victim to "&fDummy Cow &7[&c%victim's health%&7/&a%victim's max health%&7]"
else:
set name of victim to "&fDummy Cow &7[&a%victim's health%&7/&a%victim's max health%&7]"
on death of cow:
cancel drops of items
drop 1 Beef

(It doesn't change the color)
 
nvm find the solution by myself
script:
on spawn of cow:
set max health of event-entity to 25
set health of event-entity to 25
set event-entity's name to "&fDummy Cow &7[&a%event-entity's health%&7/&a%event-entity's max health%&7]"
on damage:
wait 1 tick
if victim is a cow:
if {%victim's health%} >= 20:
set name of victim to "&fDummy Cow &7[&a%victim's health%&7/&a%victim's max health%&7]"
else:
if {%victim's health%} >= 5:
set name of victim to "&fDummy Cow &7[&e%victim's health%&7/&a%victim's max health%&7]"
else:
set name of victim to "&fDummy Cow &7[&c%victim's health%&7/&a%victim's max health%&7]"
on death of cow:
cancel drops of items
drop 1 Beef