1. 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!

  2. LOOKING FOR A VERSION OF SKRIPT?

    You can always check out our Wiki for downloads and any other information about Skript!

Dismiss Notice
This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Mob level script help

Discussion in 'Skript' started by WilliamPlays0402, Nov 23, 2021.

Thread Status:
Not open for further replies.
  1. WilliamPlays0402

    Joined:
    Jun 11, 2020
    Messages:
    14
    Likes Received:
    0
    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 (Text):
    1. #goal: when a mob spawns, it assingns the mob a random "level". The hologram has to despawn when the mob despawns.
    2. #dependancies: skRayFall, HolographicDisplays
    3. on spawn:
    4.   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
    5.     set {entities::%event-entity%} to a random integer between 1 and 65535 # give the mob a random, unique tag.
    6.     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
    7.     broadcast "New Entity spawned: %event-entity%:%{entities::%event-entity%}%" # debug that mob has spawned
    8.  
    9. on death:
    10.   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
    11.     broadcast "Entity despawned: %event-entity%:%{entities::%event-entity%}%" # debug that mob has died
    12.     delete holo object "%event-entity%:%{entities::%event-entity%}%" # delete the hologram
    13.     delete {entities::%event-entity%} # delete the entity's tag
    14.  
    15. # here is the part that DOES NOT work
    16. # the flaw with the code above is that it cannot detect mobs despawning naturally.
    17. # if the mob gets despawned, the hologram and the tag will not be deleted.
    18. # 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
    19.  
    20. # every 10 ticks:
    21.   # loop {entities::*}:
    22.     # if loop-index parsed as a entity is not alive:
    23.       # broadcast "&cEntity despawned: %loop-index parsed as an entity%:%{entities::%loop-index%}%"
    24.       # delete holo object "%loop-index parsed as an entity%:%{entities::%loop-index%}%"
    25.       # delete {entities::%loop-index%}
    26.      
     
  2. Phuple

    Phuple Member

    Joined:
    Jun 25, 2021
    Messages:
    18
    Likes Received:
    1
    Im not sure about the designing part, but you could use custom NBT's (Im pretty sure entities are holders)

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

Share This Page

Loading...