Help with killing named entities

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

Cupcaeke

Member
Jun 16, 2022
1
0
1
122
Hi there! This is my first post here so apologies if I don't have the rules quite under my belt yet.

I am making a kit in a 1.8.9 kitpvp server that summons named wolves with a bone, and I wanna make it so the wolves are killed :emoji_slight_smile:<) when the player dies or has their inventory cleared (I have it so selecting another kit also clears the inventory of a player). I have the spawning of the wolves down, but I just can't figure out how to kill them. I have tried a bunch of different things, but to no avail so far. Here is what I currently have:

Code (Script):

-on rightclick with a bone:
- name of player's tool is "&rDog Whistle"
- spawn a wolf 1 meter above the targeted block
- tame last spawned wolf to player
- heal last spawned wolf
- set the last spawned wolf's name to "&a%player%'s Wolf"
- spawn a wolf 1 meter above the targeted block
- tame last spawned wolf to player
- heal last spawned wolf
- set the last spawned wolf's name to "&a%player%'s Wolf"
- spawn a wolf 1 meter above the targeted block
- tame last spawned wolf to player
- heal last spawned wolf
- set the last spawned wolf's name to "&a%player%'s Wolf"

-on death:
- if name of a wolf is "&a%player%'s Wolf"
- kill wolf

-on command "/cleareverything":
- if name of a wolf is "&a%player%'s Wolf"
- kill wolf
 
You can prob add them to a list when you spawn them and when the player dies kill everything in the list then remove/delete the list
 
As my predecessor said
Keep in mind saving entities in lists is not recommended as the variables will be wiped when the server restarts.
What you could do instead is save an entity's uuid and parse it as an entity type and then work with that.

add this under your on rightclick event
Code:
set {_x} to uuid of last spawned wolf parsed as entity
add {_x} to {wolf::%player%::*}


replace this
Code:
if name of a wolf is "&a%player%'s Wolf"
kill wolf


with this

Code:
on death:
    loop {wolf::%victim%::*}:
        kill loop-value

You can't use wolf under command or damage related events, use victim (damage receiver or killed entity) and attacker (damage dealer or the killer) for on damage: and on death:.
Since only players and the console can execute commands, you can't use entities inside command related events either: instead you'll most of the time have to work with loops as shown below.


Code:
on command "/cleareverything":
    loop {wolf::%player%::*}: #this is the loop we used before
        kill loop-value


or without the loop

Code:
on command "/cleareverything":
    loop all wolves:
        if name of loop-entity = "&a%player%'s Wolf":
            kill loop-entity