I am looking to make a script that assigns mobs with a "Level". Then it assigns the mob a hologram, that displays the level. I am having trouble with de-assigning the hologram when the mob despawns/gets killed.
Have a look for yourself.
Have a look for yourself.
Code:
#goal: when a mob spawns, it assingns the mob a random "level". The hologram has to despawn when the mob despawns.
#dependancies: skRayFall, HolographicDisplays
on spawn:
if event-entity is a zombie, a skeleton, a drowned, a evoker, a vindicator, a zombie villager, a stray, a husk or a pillager: # if the spawned mob is (one of) a specific type of mob
set {entities::%event-entity%} to a random integer between 1 and 65535 # give the mob a random, unique tag.
create bound holo object "&aLevel: 3" with id "%event-entity%:%{entities::%event-entity%}%" to event-entity offset by 0, 2.25, 0 # create a hologram
broadcast "New Entity spawned: %event-entity%:%{entities::%event-entity%}%" # debug that mob has spawned
on death:
if event-entity is a zombie, a skeleton, a drowned, a evoker, a vindicator, a zombie villager, a stray, a husk or a pillager: # if the killed mob is (one of) a specific type of mob
broadcast "Entity despawned: %event-entity%:%{entities::%event-entity%}%" # debug that mob has died
delete holo object "%event-entity%:%{entities::%event-entity%}%" # delete the hologram
delete {entities::%event-entity%} # delete the entity's tag
# here is the part that DOES NOT work
# the flaw with the code above is that it cannot detect mobs despawning naturally.
# if the mob gets despawned, the hologram and the tag will not be deleted.
# the following code tries to fix this issue, but it immediately deletes the variable, but not the hologram, even though the mob is still alive
# every 10 ticks:
# loop {entities::*}:
# if loop-index parsed as a entity is not alive:
# broadcast "&cEntity despawned: %loop-index parsed as an entity%:%{entities::%loop-index%}%"
# delete holo object "%loop-index parsed as an entity%:%{entities::%loop-index%}%"
# delete {entities::%loop-index%}