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

execute positioned ~-0.5 ~ ~-0.5 run summon minecraft:armor_stand ~0.5 ~ ~0.5 {Invisible:1,Tags:["minigun_base","minigun"],NoGravity:1,DisabledSlots:2039552,ArmorItems:[{},{},{},{id:"minecraft:lime_dye",Count:1b,tag:{CustomModelData:43}}]}
execute positioned ~-0.5 ~ ~-0.5 run summon minecraft:armor_stand ~0.5 ~-0.75 ~0.5 {Invisible:1,Tags:["minigun_tower","minigun"],NoGravity:1,DisabledSlots:2039552,ArmorItems:[{},{},{},{id:"minecraft:lime_dye",Count:1b,tag:{CustomModelData:42}}]}
scoreboard players add @e[tag=minigun] id2 0
execute at @e[tag=minigun_tower,scores={id2=0}] run summon minecraft:armor_stand ^-0.17 ^0.37 ^-0.03 {Rotation:[-90.0f,0.0f],Invisible:1,Tags:["minigun_barrel","minigun"],NoGravity:1,DisabledSlots:2039552,ArmorItems:[{},{},{},{id:"minecraft:lime_dye",Count:1b,tag:{CustomModelData:41}}]}
particle minecraft:cloud ~ ~ ~ 0 0 0 0.5 100
setblock ~ ~0.6 ~ barrier
playsound minecraft:block.anvil.place master @a ~ ~ ~ 1

#id
scoreboard players add @e[tag=minigun] id2 0
execute if entity @p[scores={minigun=1..},team=red,distance=..5,sort=nearest] run team join minigun_red @e[tag=minigun,scores={id2=0}]
execute if entity @p[scores={minigun=1..},team=blue,distance=..5,sort=nearest] run team join minigun_blue @e[tag=minigun,scores={id2=0}]
execute if entity @p[scores={minigun=1..},team=green,distance=..5,sort=nearest] run team join minigun_green @e[tag=minigun,scores={id2=0}]
execute if entity @p[scores={minigun=1..},team=yellow,distance=..5,sort=nearest] run team join minigun_yellow @e[tag=minigun,scores={id2=0}]
scoreboard players operation @e[tag=minigun,scores={id2=0}] id = @p[scores={minigun=1..},distance=..5,gamemode=!spectator] id
execute as @e[tag=minigun_base,scores={id2=0}] run function f:game/store/minigun/id

scoreboard players set @a minigun 0
tp @s ~ ~-300 ~
kill @s
