In my 'Tag' minigame I'm making, I want people to have a dodgeball.
Whoever's 'IT' gets given a snowball called 'Dodgeball'. Now, I had a system rigged up where if a snowball was within 4 blocks of a player it gives the player a score of 'Snowball'. Then, if a player with the score of 'Snowball' gets hurt by the snowball, or flashes red (HurtTime?) It makes them it.
However, snowballs don't seem to make players flash red, or do knockback, or do anything to players anymore. I tried it on entities, and that works, but not players.
Any ideas anyone?
Rollback Post to RevisionRollBack
Please, everyone, if your post is solved, edit the name and mark it [SOLVED]. Period.
Snowball knockback was removed prior to 1.12. Therefore its impossible to knock people off using snowballs, unless you have a plugin which is what I did.
When a snowball hits an player or a block, the snowball disappears. The block the snowball disappeared can be culculated by getting the coordinates of the said entity in the last tick it existed, and adding it's motion values (which is the amount the entity is going to move by the next tick) of the same tick to it.
So, if any player exist in the block the entity disappeared, the player must be hit. If multiple players, the one closer to the point where the snowball was last tick, must be the one who was hit.
This might not work for high-speed snowballs, if it flies through more than 2 blocks in a tick, but should be good enough.
*All of the following commands are ran every tick.
first summon an armor_stand (or AOEcloud) at every snowball entity. the "TAG1" tag here is to keep this from happening every tick.
execute as @e[type=minecraft:snowball,tag=!TAG1] run at @s summon armorstand ~ ~ ~ {NoGravity:1b,Marker:1b,Invulnerable:1b,Tags:["snowball"]}
now let me explain how to keep each snowballs and armorstands matched together.
1st, keep the UUIDM of each snowball in the snowball's scoreboard score, AND the armorstand's score.
execute as @e[type=minecraft:snowball,tag=!TAG1] store result score @s SCORE1 store result score @e[tag=snowball,tag=!TAG1,sort=nearest,limit=1] SCORE1 run data get entity @s UUIDMost 0.0000000001
and then you can tag the snowballs and armorstands "TAG1" to have this happen only once for each snowball.
tag @e[type=minecraft:snowball,tag=!TAG1] add TAG1
tag @e[tag=snowball,tag=!TAG1] add TAG1
2nd, tp the armorstand to the snowball its score matches, and store its Motion values mutiplied by 100.
make a function (named example_function) like this:
tag @s add TAG2
execute as @e[type=minecraft:snowball,tag=TAG,distance=..5] run scoreboard operation @s SCORE2 = @s SCORE1
execute as @e[type=minecraft:snowball,tag=TAG,distance=..5] run scoreboard operation @s SCORE2 -= @e[tag=TAG2] SCORE1
tp @e[type=minecraft:snowball,tag=TAG,distance=..5,scores={SCORE2:0},sort=nearest,limit=1]
execute store result score @s SCORE3_X run data get entity @e[type=minecraft:snowball,tag=TAG,distance=..5,scores={SCORE2:0},sort=nearest,limit=1] Motion[0] 100
execute store result score @s SCORE3_Y run data get entity @e[type=minecraft:snowball,tag=TAG,distance=..5,scores={SCORE2:0},sort=nearest,limit=1] Motion[1] 100
execute store result score @s SCORE3_Z run data get entity @e[type=minecraft:snowball,tag=TAG,distance=..5,scores={SCORE2:0},sort=nearest,limit=1] Motion[2] 100
execute unless entity @e[type=minecraft:snowball,tag=TAG,distance=..5,scores={SCORE2:0}] run tag @s add TAG3
tag @s remove TAG2
since this is a function, each line will be executed in order for each of the armor stands.
(extracting the armor stand's UUIDM score from each snowballs, one who results with 0 is the match)
and by executing this function, if a snowball crushes, the armorstand which is standing at where the snowball was a tick ealier, gets a tag of "TAG3"
execute as @e[tag=snowball] at @s run function namespace:example_funciton
finally, another function (example_function_2)
summon armorstand ~ ~ ~ {NoGravity:1b,Marker:1b,Tags:["snowball_2",TAG3]}
execute store result score @s SCORE2 run data get entity @s Pos[0] 100
execute store result entity @s Pos[0] double 0.01 run scoreboard players operation @s SCORE2 += @s SCORE3_X
execute store result score @s SCORE2 run data get entity @s Pos[1] 100
execute store result entity @s Pos[1] double 0.01 run scoreboard players operation @s SCORE2 += @s SCORE3_Y
execute store result score @s SCORE2 run data get entity @s Pos[2] 100
execute store result entity @s Pos[2] double 0.01 run scoreboard players operation @s SCORE2 += @s SCORE3_Z
execute at @s run tag @a[distance=..1] add hit_candidate
execute at @e[tag=snowball_2] run tag add @p[tag=hit_candidate] HIT
tag @a[tag=hit_candidate] remove hit_candidate
kill @e[tag=TAG3]
which moves the armorstand to the estimated coords of where the snowball disappeared, also summoning another to keep track of where it was the tick before (which is basically the place the tag=snowball armorstand was, before it's location was modified). the last 4 lines then picks a player nearest to the summoned armorstand, and in the radius of 1 (this can be changed to ..0.5 or sth like that to make it more accurate) from the estimated point.
...and tags the player "HIT".
the function should be ran like this.
execute as @e[tag=TAG3,tag=snowball] at @s run function namespace:example_function_2
Haven't tested this on minecraft, but the logic should be good. Pls fix and use this if there are any syntax errors.
The 2nd function might have to be devided in 2 parts (the 2nd part being the last 4 lines) and run in a different tick (use tags to do that). This is because I'm not sure how the "at @s" works when an entity's Pos nbt is directly edited in the same tick. It would be very helpful if you could post how it went.
Oh, and you might want to make the Armorstands invisible after you've tested the whole thing. Good luck!
In my 'Tag' minigame I'm making, I want people to have a dodgeball.
Whoever's 'IT' gets given a snowball called 'Dodgeball'. Now, I had a system rigged up where if a snowball was within 4 blocks of a player it gives the player a score of 'Snowball'. Then, if a player with the score of 'Snowball' gets hurt by the snowball, or flashes red (HurtTime?) It makes them it.
However, snowballs don't seem to make players flash red, or do knockback, or do anything to players anymore. I tried it on entities, and that works, but not players.
Any ideas anyone?
Please, everyone, if your post is solved, edit the name and mark it [SOLVED]. Period.
Snowball knockback was removed prior to 1.12. Therefore its impossible to knock people off using snowballs, unless you have a plugin which is what I did.
Can I even detect if it hits them, though?
Please, everyone, if your post is solved, edit the name and mark it [SOLVED]. Period.
When a snowball hits an player or a block, the snowball disappears. The block the snowball disappeared can be culculated by getting the coordinates of the said entity in the last tick it existed, and adding it's motion values (which is the amount the entity is going to move by the next tick) of the same tick to it.
So, if any player exist in the block the entity disappeared, the player must be hit. If multiple players, the one closer to the point where the snowball was last tick, must be the one who was hit.
This might not work for high-speed snowballs, if it flies through more than 2 blocks in a tick, but should be good enough.
^ That would work, but would you be able to show me how I could do that? (a few example commands would be good :D).
Please, everyone, if your post is solved, edit the name and mark it [SOLVED]. Period.
*All of the following commands are ran every tick.
first summon an armor_stand (or AOEcloud) at every snowball entity. the "TAG1" tag here is to keep this from happening every tick.
now let me explain how to keep each snowballs and armorstands matched together.
1st, keep the UUIDM of each snowball in the snowball's scoreboard score, AND the armorstand's score.
and then you can tag the snowballs and armorstands "TAG1" to have this happen only once for each snowball.
2nd, tp the armorstand to the snowball its score matches, and store its Motion values mutiplied by 100.
make a function (named example_function) like this:
since this is a function, each line will be executed in order for each of the armor stands.
(extracting the armor stand's UUIDM score from each snowballs, one who results with 0 is the match)
and by executing this function, if a snowball crushes, the armorstand which is standing at where the snowball was a tick ealier, gets a tag of "TAG3"
finally, another function (example_function_2)
which moves the armorstand to the estimated coords of where the snowball disappeared, also summoning another to keep track of where it was the tick before (which is basically the place the tag=snowball armorstand was, before it's location was modified). the last 4 lines then picks a player nearest to the summoned armorstand, and in the radius of 1 (this can be changed to ..0.5 or sth like that to make it more accurate) from the estimated point.
...and tags the player "HIT".
the function should be ran like this.
Haven't tested this on minecraft, but the logic should be good. Pls fix and use this if there are any syntax errors.
The 2nd function might have to be devided in 2 parts (the 2nd part being the last 4 lines) and run in a different tick (use tags to do that). This is because I'm not sure how the "at @s" works when an entity's Pos nbt is directly edited in the same tick. It would be very helpful if you could post how it went.
Oh, and you might want to make the Armorstands invisible after you've tested the whole thing. Good luck!