Mob level script help

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

Status
Not open for further replies.
Jun 11, 2020
14
0
1
57
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.
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%}
 
Im not sure about the designing part, but you could use custom NBT's (Im pretty sure entities are holders)

Code:
set {_level} to random integer between x and y
set nbt of event-entity to "{name:%{_level}%}"
 
Status
Not open for further replies.