//Special thanks to WavePlayz, JustAsh & Bedrock Dev Community.
//Made and owned by Morningstar Defence

import * as mc from 'mojang-minecraft'
import { Commands, World } from 'mojang-minecraft'

function f4phantomrocket() {
    mc.World.events.tick.subscribe(() => {
        try {
            let f4phantomrocketoutput = Commands.run(`clear @a[tag=f4phantomgunner] missile:aim4falconrocket -1 0`, World.getDimension("overworld"))
            let f4phantomrocketlist1 = f4phantomrocketoutput.playerTest;
            let f4phantomrocketlist = []
            for (var i = 0; i < f4phantomrocketlist1.length; i++) {
                if (f4phantomrocketlist1[i].match(/ \((\d+)\)$/, "")[1] > 4) {
                    let f4phantomrocketplayername = f4phantomrocketlist1[i].replace(/ \((\d+)\)$/, "")
                    Commands.run(`clear "${f4phantomrocketplayername}" missile:aim4falconrocket`, World.getDimension("overworld"))
                    Commands.run(`give "${f4phantomrocketplayername}" missile:aim4falconrocket 4`, World.getDimension("overworld"))
                    Commands.run(`tag "${f4phantomrocketplayername}" add aim4falconrocket2`, World.getDimension("overworld"))
                    f4phantomrocketlist.push(f4phantomrocketplayername)
                }
                if (f4phantomrocketlist1[i].match(/ \((\d+)\)$/, "")[1] == 1) {
                    let f4phantomrocketplayername = f4phantomrocketlist1[i].replace(/ \((\d+)\)$/, "")
                    Commands.run(`tag "${f4phantomrocketplayername}" add aim4falconrocket1`, World.getDimension("overworld"))
                    Commands.run(`tag "${f4phantomrocketplayername}" remove aim4falconrocket2`, World.getDimension("overworld"))
                    f4phantomrocketlist.push(f4phantomrocketplayername)
                }
                if (f4phantomrocketlist1[i].match(/ \((\d+)\)$/, "")[1] == 2) {
                    let f4phantomrocketplayername = f4phantomrocketlist1[i].replace(/ \((\d+)\)$/, "")
                    Commands.run(`tag "${f4phantomrocketplayername}" add aim4falconrocket2`, World.getDimension("overworld"))
                    Commands.run(`tag "${f4phantomrocketplayername}" remove aim4falconrocket3`, World.getDimension("overworld"))
                    f4phantomrocketlist.push(f4phantomrocketplayername)
                }
                if (f4phantomrocketlist1[i].match(/ \((\d+)\)$/, "")[1] == 3) {
                    let f4phantomrocketplayername = f4phantomrocketlist1[i].replace(/ \((\d+)\)$/, "")
                    Commands.run(`tag "${f4phantomrocketplayername}" add aim4falconrocket3`, World.getDimension("overworld"))
                    Commands.run(`tag "${f4phantomrocketplayername}" remove aim4falconrocket4`, World.getDimension("overworld"))
                    f4phantomrocketlist.push(f4phantomrocketplayername)
                }
                if (f4phantomrocketlist1[i].match(/ \((\d+)\)$/, "")[1] == 4) {
                    let f4phantomrocketplayername = f4phantomrocketlist1[i].replace(/ \((\d+)\)$/, "")
                    Commands.run(`tag "${f4phantomrocketplayername}" add aim4falconrocket4`, World.getDimension("overworld"))
                    f4phantomrocketlist.push(f4phantomrocketplayername)
                }

            }
            var string2 = ""
            for (var i = 0; i < f4phantomrocketlist.length; i++) {
                if (i == (f4phantomrocketlist.length - 1)) {
                    var string2 = string2 + "name!=" + '"' + f4phantomrocketlist[i] + '"'
                }
                if (i < (f4phantomrocketlist.length - 1)) {
                    var string2 = string2 + "name!=" + '"' + f4phantomrocketlist[i] + '"' + " ,"
                }
            }
            Commands.run(`tag @a[${string2},tag=f4phantompilot] remove aim4falconrocketfire`, World.getDimension("overworld"))
        } catch (error) {
        }
    })
}

function mig21rocket() {
    mc.World.events.tick.subscribe(() => {
        try {
            let mig21rocketoutput = Commands.run(`clear @a[tag=flymig21] missile:s24rocket -1 0`, World.getDimension("overworld"))
            let mig21rocketlist1 = mig21rocketoutput.playerTest;
            let mig21rocketlist = []
            for (var i = 0; i < mig21rocketlist1.length; i++) {
                if (mig21rocketlist1[i].match(/ \((\d+)\)$/, "")[1] > 2) {
                    let mig21rocketplayername = mig21rocketlist1[i].replace(/ \((\d+)\)$/, "")
                    Commands.run(`clear "${mig21rocketplayername}" missile:s24rocket`, World.getDimension("overworld"))
                    Commands.run(`give "${mig21rocketplayername}" missile:s24rocket 2`, World.getDimension("overworld"))
                    Commands.run(`tag "${mig21rocketplayername}" add s24rocket2`, World.getDimension("overworld"))
                    mig21rocketlist.push(mig21rocketplayername)
                }
                if (mig21rocketlist1[i].match(/ \((\d+)\)$/, "")[1] == 1) {
                    let mig21rocketplayername = mig21rocketlist1[i].replace(/ \((\d+)\)$/, "")
                    Commands.run(`tag "${mig21rocketplayername}" add s24rocket1`, World.getDimension("overworld"))
                    Commands.run(`tag "${mig21rocketplayername}" remove s24rocket2`, World.getDimension("overworld"))
                    mig21rocketlist.push(mig21rocketplayername)
                }
                if (mig21rocketlist1[i].match(/ \((\d+)\)$/, "")[1] == 2) {
                    let mig21rocketplayername = mig21rocketlist1[i].replace(/ \((\d+)\)$/, "")
                    Commands.run(`tag "${mig21rocketplayername}" add s24rocket2`, World.getDimension("overworld"))
                    mig21rocketlist.push(mig21rocketplayername)
                }

            }
            var string2 = ""
            for (var i = 0; i < mig21rocketlist.length; i++) {
                if (i == (mig21rocketlist.length - 1)) {
                    var string2 = string2 + "name!=" + '"' + mig21rocketlist[i] + '"'
                }
                if (i < (mig21rocketlist.length - 1)) {
                    var string2 = string2 + "name!=" + '"' + mig21rocketlist[i] + '"' + " ,"
                }
            }
            Commands.run(`tag @a[${string2},tag=mig21pilot] remove s24rocketfire`, World.getDimension("overworld"))
        } catch (error) {
        }
    })
}

function mig21bomb() {
    mc.World.events.tick.subscribe(() => {
        try {
            let mig21bomboutput = Commands.run(`clear @a[tag=flymig21] bomb:fab100 -1 0`, World.getDimension("overworld"))
            let mig21bomblist1 = mig21bomboutput.playerTest;
            let mig21bomblist = []
            for (var i = 0; i < mig21bomblist1.length; i++) {
                if (mig21bomblist1[i].match(/ \((\d+)\)$/, "")[1] > 2) {
                    let mig21bombplayername = mig21bomblist1[i].replace(/ \((\d+)\)$/, "")
                    Commands.run(`clear "${mig21bombplayername}" bomb:fab100`, World.getDimension("overworld"))
                    Commands.run(`give "${mig21bombplayername}" bomb:fab100 2`, World.getDimension("overworld"))
                    Commands.run(`tag "${mig21bombplayername}" add fab100bomb2`, World.getDimension("overworld"))
                    mig21bomblist.push(mig21bombplayername)
                }
                if (mig21bomblist1[i].match(/ \((\d+)\)$/, "")[1] == 1) {
                    let mig21bombplayername = mig21bomblist1[i].replace(/ \((\d+)\)$/, "")
                    Commands.run(`tag "${mig21bombplayername}" add fab100bomb1`, World.getDimension("overworld"))
                    Commands.run(`tag "${mig21bombplayername}" remove fab100bomb2`, World.getDimension("overworld"))
                    mig21bomblist.push(mig21bombplayername)
                }
                if (mig21bomblist1[i].match(/ \((\d+)\)$/, "")[1] == 2) {
                    let mig21bombplayername = mig21bomblist1[i].replace(/ \((\d+)\)$/, "")
                    Commands.run(`tag "${mig21bombplayername}" add fab100bomb2`, World.getDimension("overworld"))
                    mig21bomblist.push(mig21bombplayername)
                }

            }
            var string2 = ""
            for (var i = 0; i < mig21bomblist.length; i++) {
                if (i == (mig21bomblist.length - 1)) {
                    var string2 = string2 + "name!=" + '"' + mig21bomblist[i] + '"'
                }
                if (i < (mig21bomblist.length - 1)) {
                    var string2 = string2 + "name!=" + '"' + mig21bomblist[i] + '"' + " ,"
                }
            }
            Commands.run(`tag @a[${string2},tag=mig21pilot] remove fab100bombfire`, World.getDimension("overworld"))
        } catch (error) {
        }
    })
}

function f4phantombomb() {
    mc.World.events.tick.subscribe(() => {
        try {
            let f4phantombomboutput = Commands.run(`clear @a[tag=f4phantomgunner] bomb:m77 -1 0`, World.getDimension("overworld"))
            let f4phantombomblist1 = f4phantombomboutput.playerTest;
            let f4phantombomblist = []
            for (var i = 0; i < f4phantombomblist1.length; i++) {
                if (f4phantombomblist1[i].match(/ \((\d+)\)$/, "")[1] > 2) {
                    let f4phantombombplayername = f4phantombomblist1[i].replace(/ \((\d+)\)$/, "")
                    Commands.run(`clear "${f4phantombombplayername}" bomb:m77`, World.getDimension("overworld"))
                    Commands.run(`give "${f4phantombombplayername}" bomb:m77 2`, World.getDimension("overworld"))
                    Commands.run(`tag "${f4phantombombplayername}" add m77bomb2`, World.getDimension("overworld"))
                    f4phantombomblist.push(f4phantombombplayername)
                }
                if (f4phantombomblist1[i].match(/ \((\d+)\)$/, "")[1] == 1) {
                    let f4phantombombplayername = f4phantombomblist1[i].replace(/ \((\d+)\)$/, "")
                    Commands.run(`tag "${f4phantombombplayername}" add m77bomb1`, World.getDimension("overworld"))
                    Commands.run(`tag "${f4phantombombplayername}" remove m77bomb2`, World.getDimension("overworld"))
                    f4phantombomblist.push(f4phantombombplayername)
                }
                if (f4phantombomblist1[i].match(/ \((\d+)\)$/, "")[1] == 2) {
                    let f4phantombombplayername = f4phantombomblist1[i].replace(/ \((\d+)\)$/, "")
                    Commands.run(`tag "${f4phantombombplayername}" add m77bomb2`, World.getDimension("overworld"))
                    f4phantombomblist.push(f4phantombombplayername)
                }

            }
            var string2 = ""
            for (var i = 0; i < f4phantombomblist.length; i++) {
                if (i == (f4phantombomblist.length - 1)) {
                    var string2 = string2 + "name!=" + '"' + f4phantombomblist[i] + '"'
                }
                if (i < (f4phantombomblist.length - 1)) {
                    var string2 = string2 + "name!=" + '"' + f4phantombomblist[i] + '"' + " ,"
                }
            }
            Commands.run(`tag @a[${string2},tag=f4phantompilot] remove m77bombfire`, World.getDimension("overworld"))
        } catch (error) {
        }
    })
}

function mig21gun() {
    mc.World.events.tick.subscribe(() => {
        try {
            let mig21gunoutput = Commands.run(`clear @a[tag=mig21pilot,tag=flymig21] cannon:cannon30mm -1 0`, World.getDimension("overworld"))
            let mig21gunlist1 = mig21gunoutput.playerTest;
            let mig21gunlist = []
            for (var i = 0; i < mig21gunlist1.length; i++) {
                if (mig21gunlist1[i].match(/ \((\d+)\)$/, "")[1] > 60) {
                    let mig21gunplayername = mig21gunlist1[i].replace(/ \((\d+)\)$/, "")
                    Commands.run(`clear "${mig21gunplayername}" cannon:cannon30mm`, World.getDimension("overworld"))
                    Commands.run(`give "${mig21gunplayername}" cannon:cannon30mm 60`, World.getDimension("overworld"))
                    Commands.run(`tag "${mig21gunplayername}" add 30mmfire`, World.getDimension("overworld"))
                    mig21gunlist.push(mig21gunplayername)
                }
                if (mig21gunlist1[i].match(/ \((\d+)\)$/, "")[1] <= 60) {
                    let mig21gunplayername = mig21gunlist1[i].replace(/ \((\d+)\)$/, "")
                    Commands.run(`tag "${mig21gunplayername}" add 30mmfire`, World.getDimension("overworld"))
                    mig21gunlist.push(mig21gunplayername)
                }
            }
            var string2 = ""
            for (var i = 0; i < mig21gunlist.length; i++) {
                if (i == (mig21gunlist.length - 1)) {
                    var string2 = string2 + "name!=" + '"' + mig21gunlist[i] + '"'
                }
                if (i < (mig21gunlist.length - 1)) {
                    var string2 = string2 + "name!=" + '"' + mig21gunlist[i] + '"' + " ,"
                }
            }
            Commands.run(`tag @a[${string2},tag=mig21pilot] remove 30mmfire`, World.getDimension("overworld"))
        } catch (error) {
        }
    })
}

function pp90() {
    mc.World.events.tick.subscribe(() => {
        try {
            let pp90output = Commands.run(`clear @a[tag=pp90_reload1] smg:pp90mag -1 0`, World.getDimension("overworld"))
            let pp90list1 = pp90output.playerTest;
            let pp90list = []
            for (var i = 0; i < pp90list1.length; i++) {
                let pp90playername = pp90list1[i].replace(/ \((\d+)\)$/, "")
                Commands.run(`tag "${pp90playername}" remove gunempty`, World.getDimension("overworld"))
                Commands.run(`tag "${pp90playername}" remove pp90_reload1`, World.getDimension("overworld"))
                Commands.run(`tag "${pp90playername}" add pp90_reload2`, World.getDimension("overworld"))
                pp90list.push(pp90playername)

            }
            var string2 = ""
            for (var i = 0; i < pp90list.length; i++) {
                if (i == (pp90list.length - 1)) {
                    var string2 = string2 + "name!=" + '"' + pp90list[i] + '"'
                }
                if (i < (pp90list.length - 1)) {
                    var string2 = string2 + "name!=" + '"' + pp90list[i] + '"' + " ,"
                }
            }
            Commands.run(`tag @a[${string2}] remove pp90_reload2`, World.getDimension("overworld"))
        } catch (error) {
        }
    })
}

function rpk16() {
    mc.World.events.tick.subscribe(() => {
        try {
            let rpk16output = Commands.run(`clear @a[tag=rpk16_reload1] mecha:cjmag -1 0`, World.getDimension("overworld"))
            let rpk16list1 = rpk16output.playerTest;
            let rpk16list = []
            for (var i = 0; i < rpk16list1.length; i++) {
                let rpk16playername = rpk16list1[i].replace(/ \((\d+)\)$/, "")
                Commands.run(`tag "${rpk16playername}" remove gunempty`, World.getDimension("overworld"))
                Commands.run(`tag "${rpk16playername}" remove rpk16_reload1`, World.getDimension("overworld"))
                Commands.run(`tag "${rpk16playername}" add rpk16_reload2`, World.getDimension("overworld"))
                rpk16list.push(rpk16playername)

            }
            var string2 = ""
            for (var i = 0; i < rpk16list.length; i++) {
                if (i == (rpk16list.length - 1)) {
                    var string2 = string2 + "name!=" + '"' + rpk16list[i] + '"'
                }
                if (i < (rpk16list.length - 1)) {
                    var string2 = string2 + "name!=" + '"' + rpk16list[i] + '"' + " ,"
                }
            }
            Commands.run(`tag @a[${string2}] remove rpk16_reload2`, World.getDimension("overworld"))
        } catch (error) {
        }
    })
}

function mosinnagant() {
    mc.World.events.tick.subscribe(() => {
        try {
            let mosinnagantoutput = Commands.run(`clear @a[tag=mosinnagant_reload1] sniper:ammo7.62x54mmR -1 0`, World.getDimension("overworld"))
            let mosinnagantlist1 = mosinnagantoutput.playerTest;
            let mosinnagantlist = []
            for (var i = 0; i < mosinnagantlist1.length; i++) {
                let mosinnagantplayername = mosinnagantlist1[i].replace(/ \((\d+)\)$/, "")
                Commands.run(`tag "${mosinnagantplayername}" remove gunempty`, World.getDimension("overworld"))
                Commands.run(`tag "${mosinnagantplayername}" remove mosinnagant_reload1`, World.getDimension("overworld"))
                Commands.run(`tag "${mosinnagantplayername}" add mosinnagant_reload2`, World.getDimension("overworld"))
                mosinnagantlist.push(mosinnagantplayername)

            }
            var string2 = ""
            for (var i = 0; i < mosinnagantlist.length; i++) {
                if (i == (mosinnagantlist.length - 1)) {
                    var string2 = string2 + "name!=" + '"' + mosinnagantlist[i] + '"'
                }
                if (i < (mosinnagantlist.length - 1)) {
                    var string2 = string2 + "name!=" + '"' + mosinnagantlist[i] + '"' + " ,"
                }
            }
            Commands.run(`tag @a[${string2}] remove mosinnagant_reload2`, World.getDimension("overworld"))
        } catch (error) {
        }
    })
}

function m240() {
    mc.World.events.tick.subscribe(() => {
        try {
            let m240output = Commands.run(`clear @a[tag=m240_reload1] lmg:m240mag -1 0`, World.getDimension("overworld"))
            let m240list1 = m240output.playerTest;
            let m240list = []
            for (var i = 0; i < m240list1.length; i++) {
                let m240playername = m240list1[i].replace(/ \((\d+)\)$/, "")
                Commands.run(`tag "${m240playername}" remove gunempty`, World.getDimension("overworld"))
                Commands.run(`tag "${m240playername}" remove m240_reload1`, World.getDimension("overworld"))
                Commands.run(`tag "${m240playername}" add m240_reload2`, World.getDimension("overworld"))
                m240list.push(m240playername)

            }
            var string2 = ""
            for (var i = 0; i < m240list.length; i++) {
                if (i == (m240list.length - 1)) {
                    var string2 = string2 + "name!=" + '"' + m240list[i] + '"'
                }
                if (i < (m240list.length - 1)) {
                    var string2 = string2 + "name!=" + '"' + m240list[i] + '"' + " ,"
                }
            }
            Commands.run(`tag @a[${string2}] remove m240_reload2`, World.getDimension("overworld"))
        } catch (error) {
        }
    })
}

function aa12() {
    mc.World.events.tick.subscribe(() => {
        try {
            let aa12output = Commands.run(`clear @a[tag=aa12_reload1] shotgun:aa12mag -1 0`, World.getDimension("overworld"))
            let aa12list1 = aa12output.playerTest;
            let aa12list = []
            for (var i = 0; i < aa12list1.length; i++) {
                let aa12playername = aa12list1[i].replace(/ \((\d+)\)$/, "")
                Commands.run(`tag "${aa12playername}" remove gunempty`, World.getDimension("overworld"))
                Commands.run(`tag "${aa12playername}" remove aa12_reload1`, World.getDimension("overworld"))
                Commands.run(`tag "${aa12playername}" add aa12_reload2`, World.getDimension("overworld"))
                aa12list.push(aa12playername)

            }
            var string2 = ""
            for (var i = 0; i < aa12list.length; i++) {
                if (i == (aa12list.length - 1)) {
                    var string2 = string2 + "name!=" + '"' + aa12list[i] + '"'
                }
                if (i < (aa12list.length - 1)) {
                    var string2 = string2 + "name!=" + '"' + aa12list[i] + '"' + " ,"
                }
            }
            Commands.run(`tag @a[${string2}] remove aa12_reload2`, World.getDimension("overworld"))
        } catch (error) {
        }
    })
}

function m24() {
    mc.World.events.tick.subscribe(() => {
        try {
            let m24output = Commands.run(`clear @a[tag=m24_reload1] sniper:m24mag -1 0`, World.getDimension("overworld"))
            let m24list1 = m24output.playerTest;
            let m24list = []
            for (var i = 0; i < m24list1.length; i++) {
                let m24playername = m24list1[i].replace(/ \((\d+)\)$/, "")
                Commands.run(`tag "${m24playername}" remove gunempty`, World.getDimension("overworld"))
                Commands.run(`tag "${m24playername}" remove m24_reload1`, World.getDimension("overworld"))
                Commands.run(`tag "${m24playername}" add m24_reload2`, World.getDimension("overworld"))
                m24list.push(m24playername)

            }
            var string2 = ""
            for (var i = 0; i < m24list.length; i++) {
                if (i == (m24list.length - 1)) {
                    var string2 = string2 + "name!=" + '"' + m24list[i] + '"'
                }
                if (i < (m24list.length - 1)) {
                    var string2 = string2 + "name!=" + '"' + m24list[i] + '"' + " ,"
                }
            }
            Commands.run(`tag @a[${string2}] remove m24_reload2`, World.getDimension("overworld"))
        } catch (error) {
        }
    })
}

function m16a1() {
    mc.World.events.tick.subscribe(() => {
        try {
            let m16a1output = Commands.run(`clear @a[tag=m16a1_reload1] rifle:m16a1mag -1 0`, World.getDimension("overworld"))
            let m16a1list1 = m16a1output.playerTest;
            let m16a1list = []
            for (var i = 0; i < m16a1list1.length; i++) {
                let m16a1playername = m16a1list1[i].replace(/ \((\d+)\)$/, "")
                Commands.run(`tag "${m16a1playername}" remove gunempty`, World.getDimension("overworld"))
                Commands.run(`tag "${m16a1playername}" remove m16a1_reload1`, World.getDimension("overworld"))
                Commands.run(`tag "${m16a1playername}" add m16a1_reload2`, World.getDimension("overworld"))
                m16a1list.push(m16a1playername)

            }
            var string2 = ""
            for (var i = 0; i < m16a1list.length; i++) {
                if (i == (m16a1list.length - 1)) {
                    var string2 = string2 + "name!=" + '"' + m16a1list[i] + '"'
                }
                if (i < (m16a1list.length - 1)) {
                    var string2 = string2 + "name!=" + '"' + m16a1list[i] + '"' + " ,"
                }
            }
            Commands.run(`tag @a[${string2}] remove m16a1_reload2`, World.getDimension("overworld"))
        } catch (error) {
        }
    })
}

function rpg7() {
    mc.World.events.tick.subscribe(() => {
        try {
            let rpg7output = Commands.run(`clear @a[tag=rpg7_reload1] rocketlauncher:rpg7rocket -1 0`, World.getDimension("overworld"))
            let rpg7list1 = rpg7output.playerTest;
            let rpg7list = []
            for (var i = 0; i < rpg7list1.length; i++) {
                let rpg7playername = rpg7list1[i].replace(/ \((\d+)\)$/, "")
                Commands.run(`tag "${rpg7playername}" remove gunempty`, World.getDimension("overworld"))
                Commands.run(`tag "${rpg7playername}" remove rpg7_reload1`, World.getDimension("overworld"))
                Commands.run(`tag "${rpg7playername}" add rpg7_reload2`, World.getDimension("overworld"))
                rpg7list.push(rpg7playername)

            }
            var string2 = ""
            for (var i = 0; i < rpg7list.length; i++) {
                if (i == (rpg7list.length - 1)) {
                    var string2 = string2 + "name!=" + '"' + rpg7list[i] + '"'
                }
                if (i < (rpg7list.length - 1)) {
                    var string2 = string2 + "name!=" + '"' + rpg7list[i] + '"' + " ,"
                }
            }
            Commands.run(`tag @a[${string2}] remove rpg7_reload2`, World.getDimension("overworld"))
        } catch (error) {
        }
    })
}

function m1911() {
    mc.World.events.tick.subscribe(() => {
        try {
            let m1911output = Commands.run(`clear @a[tag=m1911_reload1] pistol:m1911mag -1 0`, World.getDimension("overworld"))
            let m1911list1 = m1911output.playerTest;
            let m1911list = []
            for (var i = 0; i < m1911list1.length; i++) {
                let m1911playername = m1911list1[i].replace(/ \((\d+)\)$/, "")
                Commands.run(`tag "${m1911playername}" remove gunempty`, World.getDimension("overworld"))
                Commands.run(`tag "${m1911playername}" remove m1911_reload1`, World.getDimension("overworld"))
                Commands.run(`tag "${m1911playername}" add m1911_reload2`, World.getDimension("overworld"))
                m1911list.push(m1911playername)

            }
            var string2 = ""
            for (var i = 0; i < m1911list.length; i++) {
                if (i == (m1911list.length - 1)) {
                    var string2 = string2 + "name!=" + '"' + m1911list[i] + '"'
                }
                if (i < (m1911list.length - 1)) {
                    var string2 = string2 + "name!=" + '"' + m1911list[i] + '"' + " ,"
                }
            }
            Commands.run(`tag @a[${string2}] remove m1911_reload2`, World.getDimension("overworld"))
        } catch (error) {
        }
    })
}

function g3() {
    mc.World.events.tick.subscribe(() => {
        try {
            let g3output = Commands.run(`clear @a[tag=g3_reload1] rifle:g3mag -1 0`, World.getDimension("overworld"))
            let g3list1 = g3output.playerTest;
            let g3list = []
            for (var i = 0; i < g3list1.length; i++) {
                let g3playername = g3list1[i].replace(/ \((\d+)\)$/, "")
                Commands.run(`tag "${g3playername}" remove gunempty`, World.getDimension("overworld"))
                Commands.run(`tag "${g3playername}" remove g3_reload1`, World.getDimension("overworld"))
                Commands.run(`tag "${g3playername}" add g3_reload2`, World.getDimension("overworld"))
                g3list.push(g3playername)

            }
            var string2 = ""
            for (var i = 0; i < g3list.length; i++) {
                if (i == (g3list.length - 1)) {
                    var string2 = string2 + "name!=" + '"' + g3list[i] + '"'
                }
                if (i < (g3list.length - 1)) {
                    var string2 = string2 + "name!=" + '"' + g3list[i] + '"' + " ,"
                }
            }
            Commands.run(`tag @a[${string2}] remove g3_reload2`, World.getDimension("overworld"))
        } catch (error) {
        }
    })
}

function ak47() {
    mc.World.events.tick.subscribe(() => {
        try {
            let ak47output = Commands.run(`clear @a[tag=ak47_reload1] rifle:ak47mag -1 0`, World.getDimension("overworld"))
            let ak47list1 = ak47output.playerTest;
            let ak47list = []
            for (var i = 0; i < ak47list1.length; i++) {
                let ak47playername = ak47list1[i].replace(/ \((\d+)\)$/, "")
                Commands.run(`tag "${ak47playername}" remove gunempty`, World.getDimension("overworld"))
                Commands.run(`tag "${ak47playername}" remove ak47_reload1`, World.getDimension("overworld"))
                Commands.run(`tag "${ak47playername}" add ak47_reload2`, World.getDimension("overworld"))
                ak47list.push(ak47playername)

            }
            var string2 = ""
            for (var i = 0; i < ak47list.length; i++) {
                if (i == (ak47list.length - 1)) {
                    var string2 = string2 + "name!=" + '"' + ak47list[i] + '"'
                }
                if (i < (ak47list.length - 1)) {
                    var string2 = string2 + "name!=" + '"' + ak47list[i] + '"' + " ,"
                }
            }
            Commands.run(`tag @a[${string2}] remove ak47_reload2`, World.getDimension("overworld"))
        } catch (error) {
        }
    })
}

function rpk() {
    mc.World.events.tick.subscribe(() => {
        try {
            let rpkoutput = Commands.run(`clear @a[tag=rpk_reload1] lmg:rpkmag -1 0`, World.getDimension("overworld"))
            let rpklist1 = rpkoutput.playerTest;
            let rpklist = []
            for (var i = 0; i < rpklist1.length; i++) {
                let rpkplayername = rpklist1[i].replace(/ \((\d+)\)$/, "")
                Commands.run(`tag "${rpkplayername}" remove gunempty`, World.getDimension("overworld"))
                Commands.run(`tag "${rpkplayername}" remove rpk_reload1`, World.getDimension("overworld"))
                Commands.run(`tag "${rpkplayername}" add rpk_reload2`, World.getDimension("overworld"))
                rpklist.push(rpkplayername)

            }
            var string2 = ""
            for (var i = 0; i < rpklist.length; i++) {
                if (i == (rpklist.length - 1)) {
                    var string2 = string2 + "name!=" + '"' + rpklist[i] + '"'
                }
                if (i < (rpklist.length - 1)) {
                    var string2 = string2 + "name!=" + '"' + rpklist[i] + '"' + " ,"
                }
            }
            Commands.run(`tag @a[${string2}] remove rpk_reload2`, World.getDimension("overworld"))
        } catch (error) {
        }
    })
}
try {
    m240()
} catch (error) {
}
try {
    mig21gun()
} catch (error) {
}
try {
    mig21rocket()
} catch (error) {
}
try {
    mig21bomb()
} catch (error) {
}
try {
    f4phantombomb()
} catch (error) {
}
try {
    f4phantomrocket()
} catch (error) {
}
try {
    g3()
} catch (error) {
}
try {
    aa12()
} catch (error) {
}
try {
    m24()
} catch (error) {
}
try {
    pp90()
} catch (error) {
}
try {
    ak47()
} catch (error) {
}
try {
    rpk()
} catch (error) {
}
try {
    m1911()
} catch (error) {
}

try {
    m16a1()
} catch (error) {
}
try {
    rpg7()
} catch (error) {
}
try {
    fab100()
} catch (error) {
}
try {
    mosinnagant()
} catch (error) {
}
try {
    rpk16()
} catch (error) {
}

