#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
#
#    This function has been created by Skilendarz Group.
#             https://skilendarz.com
#
#      GIVE MAP MAKERS THE CREDIT THEY DESERVE!
#             COPYING IS PROHIBITED!
#
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#

#Find player target
execute if entity @s[tag=red] run tag @p[tag=!invulnerable,gamemode=adventure,team=!red,distance=..0.1] add bullet_target
execute if entity @s[tag=blue] run tag @p[tag=!invulnerable,gamemode=adventure,team=!blue,distance=..0.1] add bullet_target
execute if entity @s[tag=green] run tag @p[tag=!invulnerable,gamemode=adventure,team=!green,distance=..0.1] add bullet_target
execute if entity @s[tag=yellow] run tag @p[tag=!invulnerable,gamemode=adventure,team=!yellow,distance=..0.1] add bullet_target

#Get minigun
scoreboard players operation $id id2 = @s id2
execute if entity @a[tag=bullet_target] as @e[tag=minigun_base] if score @s id2 = $id id2 run tag @s add this_m2
scoreboard players add @e[tag=this_m2] kills 1

#Get player
execute if entity @a[tag=bullet_target] run function f:game/kill/display_kill
execute if score @e[tag=this_m2,limit=1] kills matches 2.. run advancement grant @a[tag=killer] only f:cleaning_services
execute as @a[tag=bullet_target] at @s run function f:game/kill/kill


tag @a[tag=bullet_target] remove bullet_target
tag @e[tag=this_m2] remove this_m2
