Hey guys kav here and today we’re going to be covering how to detect different damage sources for pvp purposes you could do this on pve as well uh it works you might just have to reverse engineer it a little bit but i’m going to be showing you how to use The hit detection data pack that i put together and kind of modify that to detect damage sources so that i can detect say if a player hits another player with a fireball or if a player hits another player with a sword or if a player hits another player with An arrow so those kind of small details might be necessary to yours and you can also kind of further diversify this to detect if a player hits another player with fireball and that fireball was generated by a player who was using a very certain ability I’m not going to get too in deep into i’m going to get too deep into what i’m working on right now but you can probably guess kind of what it is but if you let’s say i have an ability that shoots a fireball or shoots an arrow but i have Another ability that also shoots a fireball or shoots an arrow it’s going to be important to know the difference between one one type of ability and the other so that it is important to know now one thing to also know is that when it comes to specifically fireballs it’s Not going to be possible to detect with explosion race radiuses red eye only direct impact and that’s because the way the game works is if a player gets hit by an explosion like that where it did not actually hit me the game will not know based on advancements Anything about the source of that damage or where that damage came from even if the owner have even if there is somebody who owns the fireball who created the explosion because there’s no entity when an explosion deals damage to uh go back to and route your way back to the Creator so in order to deal kind of an aoe type damage you can’t use this system and what i actually use is something similar to my snowball writing data pack except i use a marker instead of an area effect cloud but it’s basically the same thing as my snowball Writing down the back so i essentially make an entity right on top of it and then detect when it’s no longer riding and then hit anything nearby so the first thing you’re going to need is the entity hit data pack which i have provided in the description for you It’s a very basic data pack but also very powerful and also very inefficient well it’s not inefficient at what it does it just costs a lot to do what it does because what it’s doing is pretty expensive is pretty incredible in terms of complexity so essentially we have a Couple things so we have some loading and tick functions then we also have some an advancement with on hit unhurt okay we also have uh functions and we also have tags with entity types called targets targets are things that you’re going to detect for hits between and this is actually important to Specify based on your project because you want to minimize the amount of times that this advancement is successful to reduce the amount of commands that it eats up so for us you want to change it to very specific things in my case you want to change it to player And you also want to change it to fireball okay and this will only track the successes for fireballs and players so then the next thing you need to do is you need to note that this data pack is kind of excessive than what it does it Has on hurt and it has on hit both of them are not necessary so you want to use only one of the two so the only one you need is on hurt and the reason for that is when something gets hit by something then you gotta go figure out who hit me If that makes sense i think you can also use on hit to go figure out who did you hit but it’s a little bit more ambiguous because if you do that order then you’re already starting at the player so you won’t be able to find the fireball so you pretty Much need to use onhurt which is i believe the special one that i added to the nph ph whatever so it’s missing one condition which is uh triggering on the target being false but that’s okay because we don’t care if the We only want it to trigger when the target is true anyways so you come down here you see that the reward function is reward one and that means that you can get rid of this guy and you can go into the functions and you can get rid of Anything that doesn’t have a one after it and also has something that’s named the same thing you can also get rid of on hit so you wouldn’t get rid of real tick you wouldn’t get rid of tick because they don’t have something that also is named real tick one so just Anything that doesn’t have a one with it i know i could have made it more um organized by having a hit folder and a hurt folder and maybe i will do that uh and update the pack but uh for now that’s what you got to do So then when you come into reward reward is what you do to check certain things so what this function is going to do is if you hit a target which technically this check doesn’t actually matter so i’m just going to get rid of it anyways because you won’t be able to check if The target is false um but this will look for the original entity that dealt the hurting and this removes the advancement so if we go into find entity that is just a thing that you don’t want to touch because it’ll just figure out who the entity is based on conditions And then if you go into uh on hurt this will do say hits me so it will say fireball hit me like in the chat if a fireball hits you and it actually does a path to the original owner so it’ll say cloud hit me okay It won’t say fireball so if the fireball has an owner that is cloud it’ll say cloud hit me and that’s one thing that will be important here is that when you spawn the fireball you do data modify entity the fireball’s uu owner set from at s uuid when you when you fire the Fireball make sure you copy the uuid of the owner to it so that it knows that it’s your fireball so that when you run this hit me it’ll say your name the name of the original player hit me and this is going to be a little annoying because You can really only test this on multiplayer if you’re intending it for a multiplayer game but this won’t this will not work for non-player entities is just something that i want to clarify here this will only work for pvp uh i don’t know if you can do this for Non-player entities so that’s just something you’ll have to explore yourself with this data pack i just wanted to kind of show you guys how to use this data pack in an interesting way so anyways how do we specify which one it is so we’re in here right this will do Well at this command you will have the person that got hit and at this level you will have the person that dealt the damage or at least the deep level of the owner like the direct owner but how do we know if the thing that hit them was a Fireball well that’s a good question so we actually have to add that into here into the criteria to basically just give some more criteria that can trigger regardless so inside here we’re going to add basically a new criteria so you could copy this one here or you could just Start typing out your own but essentially what you need to make for the fireball is make a new criteria called is fireball and you can put this under you probably want to put this under target or somewhere so we go to the fireball and it is triggered when the entity hurts the Player just like all these other ones and then the conditions for whether this is true will be checking if the damage source entity which would go to the player because it is the damage source entity is whoever owns it so if there is no player that owns it then it’s just Going to be the source entity as the fireball if there is a player that owns it then it is the player now in this case i actually added this tag to the fireball itself because fireball is supposed to deal a set amount of damage regardless of who owns it uh the only Difference here is uh you can use who owns it to make sure that you don’t hurt yourself but this will trigger for whether it’s owned or not in my case but in your case it might be different so essentially if the player who owns the fireball has a Tag of using this specific ability so you could have two of these so you could have fireball and you could have something like uh like epic fireball right or like a fireball that does more damage or it’s like slower i don’t know and you could just change this tag to like epic Fireball and these ones would be would trigger differently okay just keep that in mind so the tag actually makes sure that you have this specific ability and then i just add this type equals projectile this is actually not really necessary it’s just added code you don’t technically need it But anyways the point is what it’s doing is it’s going to the original owner of it and checking what tag they have and if their tag is having the ability and this is assuming that you can’t really switch abilities in between now this is kind of a caveat again of the system or A limitation in the sense that you can only check if they are able to use a finite number of abilities or you’re assuming that the ability is going to be used before or hit something before they use another ability or change abilities you can always work with this however you Want but this is just how you check the mbt okay so now that we know that the entity that is hitting them has a certain tag right then we just need one more thing and we have to add it to the conditions and we just add it here That way this will this this thing will trigger if the either condition is true but the important thing is not that it will trigger if either condition is true if the important thing is that it will just add something we can test okay so i just Throw it in there right all right so one thing that you do have to add and i forgot to add this is you have to add damage into the damage criteria you have to add the type of the direct entity which is the thing dealing the damage is a Fireball and this is important for my case i didn’t include that just because i have a hierarchy so if it can’t detect something else then it just assumes it was a melee damage type but you may not have that kind of hierarchy system so if you want to specifically know if it was A fireball you have to check if it is a fireball the direct entity grant and the source entity refers to the player direct ltd refers to the entity that hit them then back inside here we can go execute if entity as and this is where i can go back Get this back right this is something i actually need kind of so you check if the advancement and then you check the criteria of the advancement and you see is fireball if is fireball is true run say hit by fireball okay so then essentially this will go to The player if you need to do anything with the specific player this will allow you to do stuff with the person who hit them if you want to like to give them a give them a plus one kill because if you know that they were hit by a fireball And then you can do some math beforehand because you know how much damage a fireball is supposed to do and you know how much health the player has so you can figure out hey did i kill them okay i killed them then inside here you could Give them plus one for the kill if you wanted to do something like that and now i guess my video is demonetized for that anyways so that is pretty much everything i want to show you guys now i’ll just show you kind of a proof Of it working on a server i’ll try and get somebody in there to test it with me so now if you’re on a server and you have the test data pack going and you have something that spawns a fireball that has your uuid well first i’ll hit Him and it says hit me cloudwolf hit me but if i hit him with fireball it says node hit by fireball cloud will hit me so you can kind of see that distinction it’s able to discern whether it’s melee or it’s fireball alright guys so That’s it for this video maybe it was a little sloppier than my regular videos but that’s because i haven’t done a video that does tutorials in like a month if you have any tutorials that you specifically want to see let me know i’ll try to get to them But just kind of a big picture if you made it this far is essentially with this data pack which i will include a version of it in the description just because there were so many kind of little minor changes i had to do i’ll include what we worked on today in the Description but uh this data pack lets you detect in pvp scenarios whether a player was hit with melee or say well i guess nothing or no specific thing or if they were hit specifically with a fireball and you can extend this to if they were specifically Hit with an arrow and you can also add some other specifiers using that mbt to detect if they were specifically hit with somebody who is using a fireball of a certain type based on the mbt tags so if you thought that was useful please leave A like let me know what you want to see next and i’ll see you next time peace foreign Video Information
This video, titled ‘Detect Damage Sources For PVP in Minecraft’, was uploaded by Cloud Wolf on 2022-01-13 19:19:27. It has garnered 5316 views and 206 likes. The duration of the video is 00:13:07 or 787 seconds.
An intermediate tutorial on how to detect specific damage source types and criteria for pvp games.
📦 Download: https://www.dropbox.com/s/9dirh2y8abqvert/damage_source_detection.zip?dl=1
🔵 Discord Server: (See channel about page) 💻 Website: https://cloudwolfyt.github.io 🐺 Twitter: https://twitter.com/cloudwolfbane
Music: “Werq” Kevin MacLeod (incompetech.com) Licensed under Creative Commons: By Attribution 4.0 License
All Songs Used under fair copyright. Lincenses Below: License for commercial use: Creative Commons Attribution 4.0 Unported “Share Alike” (CC BY-SA 4.0) License. Full License HERE – https://creativecommons.org/licenses/by-sa/4.0/legalcode