Individual Variables for a Mob

  • 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 community!

    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!

Sep 13, 2023
18
1
3
I'm making a PvE server, and I want to make an individual variable for each mob to show their hp on their nametag. My current code is:

Code:
on right click:
    if name of player's held item is "&2Undead Lure":
        remove 1 green dye named "&2Undead Lure" from player's inventory
        set {zombiespawned::%player%} to 1
        spawn 1 zombie at player
        set max health of last spawned entity to 20
        set health of last spawned entity to 20
        set {zombie_mhp} to max health of last spawned entity
        set {zombie_hp} to health of last spawned entity
        set display name of last spawned mob to "&7[Lv1] &2Zombie &c%{zombie_hp}%&7/&c%{zombie_mhp}%"

on damage of zombie:
    if display name of victim contains "&7[Lv1] &2Zombie":
        set {zombie_mhp} to max health of last spawned entity
        set {zombie_mhp} to round({zombie_mhp})
        set {zombie_hp} to health of last spawned entity
        set {zombie_hp} to round({zombie_hp})
        set display name of last spawned mob to "&7[Lv1] &2Zombie &c%{zombie_hp}%&7/&c%{zombie_mhp}%"

Basically I want a different variable to track the HP of individual mobs because the script I'm using right now makes the HP and MHP variables universal to mobs.
 
I already did this on a different post...

However, the context was quite different, and I don't understand what you are trying to do. Please elaborate further.
 
I'm making a PvE server, and I want to make an individual variable for each mob to show their hp on their nametag. My current code is:

Code:
on right click:
    if name of player's held item is "&2Undead Lure":
        remove 1 green dye named "&2Undead Lure" from player's inventory
        set {zombiespawned::%player%} to 1
        spawn 1 zombie at player
        set max health of last spawned entity to 20
        set health of last spawned entity to 20
        set {zombie_mhp} to max health of last spawned entity
        set {zombie_hp} to health of last spawned entity
        set display name of last spawned mob to "&7[Lv1] &2Zombie &c%{zombie_hp}%&7/&c%{zombie_mhp}%"

on damage of zombie:
    if display name of victim contains "&7[Lv1] &2Zombie":
        set {zombie_mhp} to max health of last spawned entity
        set {zombie_mhp} to round({zombie_mhp})
        set {zombie_hp} to health of last spawned entity
        set {zombie_hp} to round({zombie_hp})
        set display name of last spawned mob to "&7[Lv1] &2Zombie &c%{zombie_hp}%&7/&c%{zombie_mhp}%"

Basically I want a different variable to track the HP of individual mobs because the script I'm using right now makes the HP and MHP variables universal to mobs.
Use nbt tags