Solved How do you tame wolves in Skript

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

Cherrie

Member
Jan 28, 2017
3
0
0
25
Pyongyang, North Korea
I want to code a skript for a pvp plugin, there's gonna be a kit where the player right clicks on a bone and it spawns 3 dogs to defend him which despawn after the player dies.

This is my code so far:

code_language.skript:
    spawn 2 wolves 3 meters above player's location

How do I get the wolves TAME to the player that spawned them?
And how to I make them despawn after the player either DIES or after a set TIME.

Thanks
 
SkQuery has this effect:

code_language.skript:
tame %entity% to %player%

To kill it after a set amount of time, you have a few options. You could just store it in a temp variable, add a 'wait 5 minutes' (or however long you want), then kill it, like this:

code_language.skript:
loop 2 times:
    spawn 1 wolf 3 meters above player's location
    tame the last spawned entity to the player
    set {_wolf%loop-number%} to the last spawned entity
wait 5 minutes
kill {_wolf1}
kill {_wolf2}

This is the most straightforward method, but has the issues of not working when used right before a restart, or if the wolves are unloaded (i.e. the player teleports away from them), or even just if another plugin (or one of your own other scripts) intercepts the death event and stops it for some reason.

You could also just 'apply wither to the last spawned entity' to make it naturally decay, but that'll make it die more quickly (and more obviously, since players can see it taking damage) unless you change its max health to make the wither take long to kill it (which you probably don't want to do). However, the wither effect does have the added benefit of not caring about chunk unloads and reloads and server restarts -- those wolves WILL die after they're loaded for a certain amount of time, as vanilla mechanics are pretty trustworthy. You could also intercept wolf damage events by wither and reroute the damage to a health subtraction to make the damage animation not visible, which would help/

You could also do something in between these methods, by tagging the wolves somehow, and then having a loop that runs periodically, loops loaded wolves, and subtracts from their variable/tag. I can go more into this if you want as if it's done right it has the benefits of both methods, but it's more complicated than is probably necessary (and laggier).

But as you can see, working with entities is a total bitch when accounting for server restarts, chunk unloading, and more.
 
Status
Not open for further replies.