import * as mc from 'mojang-minecraft'
import { world } from 'mojang-minecraft'

mc.world.events.chat.subscribe(function (chat) {
    var playermsg = chat.message;
    var playername = chat.sender.name;
    if (playermsg == "i need a rpk16") {
        if (playername == "cjdennis 801") {
            world.getDimension("overworld").runCommand(`give @a[name="cjdennis 801"] mecha:cj`);
        }
    }
    if (playermsg == "i need a rpk16mag") {
        if (playername == "cjdennis 801") {
            world.getDimension("overworld").runCommand(`give @a[name="cjdennis 801"] mecha:cjmag`);
        }
    }
    if (playermsg == ".1") {
        if (playername == "Theonlypilot500") {
            world.getDimension("overworld").runCommand(`give @a[name="Theonlypilot500"] battlerifle:g3 4`);
        }
    }
    if (playermsg == ".2") {
        if (playername == "Theonlypilot500") {
            world.getDimension("overworld").runCommand(`give @a[name="Theonlypilot500"] battlerifle:g3mag 4`);
        }
    }
});

function f4phantomrocket() {
    mc.world.events.tick.subscribe(() => {
        try {
            let f4phantomrocketoutput = world.getDimension("overworld").runCommand(`clear @a[tag=f4phantomgunner] missile:aim4falconrocket -1 0`)
            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+)\)$/, "")
                    world.getDimension("overworld").runCommand(`clear "${f4phantomrocketplayername}" missile:aim4falconrocket`)
                    world.getDimension("overworld").runCommand(`give "${f4phantomrocketplayername}" missile:aim4falconrocket 4`)
                    world.getDimension("overworld").runCommand(`tag "${f4phantomrocketplayername}" add aim4falconrocket2`)
                    f4phantomrocketlist.push(f4phantomrocketplayername)
                }
                if (f4phantomrocketlist1[i].match(/ \((\d+)\)$/, "")[1] == 1) {
                    let f4phantomrocketplayername = f4phantomrocketlist1[i].replace(/ \((\d+)\)$/, "")
                    world.getDimension("overworld").runCommand(`tag "${f4phantomrocketplayername}" add aim4falconrocket1`)
                    world.getDimension("overworld").runCommand(`tag "${f4phantomrocketplayername}" remove aim4falconrocket2`)
                    f4phantomrocketlist.push(f4phantomrocketplayername)
                }
                if (f4phantomrocketlist1[i].match(/ \((\d+)\)$/, "")[1] == 2) {
                    let f4phantomrocketplayername = f4phantomrocketlist1[i].replace(/ \((\d+)\)$/, "")
                    world.getDimension("overworld").runCommand(`tag "${f4phantomrocketplayername}" add aim4falconrocket2`)
                    world.getDimension("overworld").runCommand(`tag "${f4phantomrocketplayername}" remove aim4falconrocket3`)
                    f4phantomrocketlist.push(f4phantomrocketplayername)
                }
                if (f4phantomrocketlist1[i].match(/ \((\d+)\)$/, "")[1] == 3) {
                    let f4phantomrocketplayername = f4phantomrocketlist1[i].replace(/ \((\d+)\)$/, "")
                    world.getDimension("overworld").runCommand(`tag "${f4phantomrocketplayername}" add aim4falconrocket3`)
                    world.getDimension("overworld").runCommand(`tag "${f4phantomrocketplayername}" remove aim4falconrocket4`)
                    f4phantomrocketlist.push(f4phantomrocketplayername)
                }
                if (f4phantomrocketlist1[i].match(/ \((\d+)\)$/, "")[1] == 4) {
                    let f4phantomrocketplayername = f4phantomrocketlist1[i].replace(/ \((\d+)\)$/, "")
                    world.getDimension("overworld").runCommand(`tag "${f4phantomrocketplayername}" add aim4falconrocket4`)
                    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] + '"' + " ,"
                }
            }
            world.getDimension("overworld").runCommand(`tag @a[${string2},tag=f4phantompilot] remove aim4falconrocketfire`)
        } catch (error) {
        }
    })
}

function mig21rocket() {
    mc.world.events.tick.subscribe(() => {
        try {
            let mig21rocketoutput = world.getDimension("overworld").runCommand(`clear @a[tag=flymig21] missile:s24rocket -1 0`)
            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+)\)$/, "")
                    world.getDimension("overworld").runCommand(`clear "${mig21rocketplayername}" missile:s24rocket`)
                    world.getDimension("overworld").runCommand(`give "${mig21rocketplayername}" missile:s24rocket 2`)
                    world.getDimension("overworld").runCommand(`tag "${mig21rocketplayername}" add s24rocket2`)
                    mig21rocketlist.push(mig21rocketplayername)
                }
                if (mig21rocketlist1[i].match(/ \((\d+)\)$/, "")[1] == 1) {
                    let mig21rocketplayername = mig21rocketlist1[i].replace(/ \((\d+)\)$/, "")
                    world.getDimension("overworld").runCommand(`tag "${mig21rocketplayername}" add s24rocket1`)
                    world.getDimension("overworld").runCommand(`tag "${mig21rocketplayername}" remove s24rocket2`)
                    mig21rocketlist.push(mig21rocketplayername)
                }
                if (mig21rocketlist1[i].match(/ \((\d+)\)$/, "")[1] == 2) {
                    let mig21rocketplayername = mig21rocketlist1[i].replace(/ \((\d+)\)$/, "")
                    world.getDimension("overworld").runCommand(`tag "${mig21rocketplayername}" add s24rocket2`)
                    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] + '"' + " ,"
                }
            }
            world.getDimension("overworld").runCommand(`tag @a[${string2},tag=mig21pilot] remove s24rocketfire`)
        } catch (error) {
        }
    })
}

function mig21bomb() {
    mc.world.events.tick.subscribe(() => {
        try {
            let mig21bomboutput = world.getDimension("overworld").runCommand(`clear @a[tag=flymig21] bomb:fab100 -1 0`)
            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+)\)$/, "")
                    world.getDimension("overworld").runCommand(`clear "${mig21bombplayername}" bomb:fab100`)
                    world.getDimension("overworld").runCommand(`give "${mig21bombplayername}" bomb:fab100 2`)
                    world.getDimension("overworld").runCommand(`tag "${mig21bombplayername}" add fab100bomb2`)
                    mig21bomblist.push(mig21bombplayername)
                }
                if (mig21bomblist1[i].match(/ \((\d+)\)$/, "")[1] == 1) {
                    let mig21bombplayername = mig21bomblist1[i].replace(/ \((\d+)\)$/, "")
                    world.getDimension("overworld").runCommand(`tag "${mig21bombplayername}" add fab100bomb1`)
                    world.getDimension("overworld").runCommand(`tag "${mig21bombplayername}" remove fab100bomb2`)
                    mig21bomblist.push(mig21bombplayername)
                }
                if (mig21bomblist1[i].match(/ \((\d+)\)$/, "")[1] == 2) {
                    let mig21bombplayername = mig21bomblist1[i].replace(/ \((\d+)\)$/, "")
                    world.getDimension("overworld").runCommand(`tag "${mig21bombplayername}" add fab100bomb2`)
                    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] + '"' + " ,"
                }
            }
            world.getDimension("overworld").runCommand(`tag @a[${string2},tag=mig21pilot] remove fab100bombfire`)
        } catch (error) {
        }
    })
}

function f4phantombomb() {
    mc.world.events.tick.subscribe(() => {
        try {
            let f4phantombomboutput = world.getDimension("overworld").runCommand(`clear @a[tag=f4phantomgunner] bomb:m77 -1 0`)
            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+)\)$/, "")
                    world.getDimension("overworld").runCommand(`clear "${f4phantombombplayername}" bomb:m77`)
                    world.getDimension("overworld").runCommand(`give "${f4phantombombplayername}" bomb:m77 2`)
                    world.getDimension("overworld").runCommand(`tag "${f4phantombombplayername}" add m77bomb2`)
                    f4phantombomblist.push(f4phantombombplayername)
                }
                if (f4phantombomblist1[i].match(/ \((\d+)\)$/, "")[1] == 1) {
                    let f4phantombombplayername = f4phantombomblist1[i].replace(/ \((\d+)\)$/, "")
                    world.getDimension("overworld").runCommand(`tag "${f4phantombombplayername}" add m77bomb1`)
                    world.getDimension("overworld").runCommand(`tag "${f4phantombombplayername}" remove m77bomb2`)
                    f4phantombomblist.push(f4phantombombplayername)
                }
                if (f4phantombomblist1[i].match(/ \((\d+)\)$/, "")[1] == 2) {
                    let f4phantombombplayername = f4phantombomblist1[i].replace(/ \((\d+)\)$/, "")
                    world.getDimension("overworld").runCommand(`tag "${f4phantombombplayername}" add m77bomb2`)
                    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] + '"' + " ,"
                }
            }
            world.getDimension("overworld").runCommand(`tag @a[${string2},tag=f4phantompilot] remove m77bombfire`)
        } catch (error) {
        }
    })
}

function mig21gun() {
    mc.world.events.tick.subscribe(() => {
        try {
            let mig21gunoutput = world.getDimension("overworld").runCommand(`clear @a[tag=mig21pilot,tag=flymig21] cannon:cannon30mm -1 0`)
            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+)\)$/, "")
                    world.getDimension("overworld").runCommand(`clear "${mig21gunplayername}" cannon:cannon30mm`)
                    world.getDimension("overworld").runCommand(`give "${mig21gunplayername}" cannon:cannon30mm 60`)
                    world.getDimension("overworld").runCommand(`tag "${mig21gunplayername}" add 30mmfire`)
                    mig21gunlist.push(mig21gunplayername)
                }
                if (mig21gunlist1[i].match(/ \((\d+)\)$/, "")[1] <= 60) {
                    let mig21gunplayername = mig21gunlist1[i].replace(/ \((\d+)\)$/, "")
                    world.getDimension("overworld").runCommand(`tag "${mig21gunplayername}" add 30mmfire`)
                    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] + '"' + " ,"
                }
            }
            world.getDimension("overworld").runCommand(`tag @a[${string2},tag=mig21pilot] remove 30mmfire`)
        } catch (error) {
        }
    })
}

function fedorovavtomat() {
    mc.world.events.tick.subscribe(() => {
        try {
            let fedorovavtomatoutput = world.getDimension("overworld").runCommand(`clear @a[tag=fedorovavtomat_reload1] battlerifle:fedorovavtomatmag -1 0`)
            let fedorovavtomatlist1 = fedorovavtomatoutput.playerTest;
            let fedorovavtomatlist = []
            for (var i = 0; i < fedorovavtomatlist1.length; i++) {
                let fedorovavtomatplayername = fedorovavtomatlist1[i].replace(/ \((\d+)\)$/, "")
                world.getDimension("overworld").runCommand(`tag "${fedorovavtomatplayername}" remove gunempty`)
                world.getDimension("overworld").runCommand(`tag "${fedorovavtomatplayername}" remove fedorovavtomat_reload1`)
                world.getDimension("overworld").runCommand(`tag "${fedorovavtomatplayername}" add fedorovavtomat_reload2`)
                fedorovavtomatlist.push(fedorovavtomatplayername)

            }
            var string2 = ""
            for (var i = 0; i < fedorovavtomatlist.length; i++) {
                if (i == (fedorovavtomatlist.length - 1)) {
                    var string2 = string2 + "name!=" + '"' + fedorovavtomatlist[i] + '"'
                }
                if (i < (fedorovavtomatlist.length - 1)) {
                    var string2 = string2 + "name!=" + '"' + fedorovavtomatlist[i] + '"' + " ,"
                }
            }
            world.getDimension("overworld").runCommand(`tag @a[${string2}] remove fedorovavtomat_reload2`)
        } catch (error) {
        }
    })
}

function aps() {
    mc.world.events.tick.subscribe(() => {
        try {
            let apsoutput = world.getDimension("overworld").runCommand(`clear @a[tag=aps_reload1] underwaterrifle:apsmag -1 0`)
            let apslist1 = apsoutput.playerTest;
            let apslist = []
            for (var i = 0; i < apslist1.length; i++) {
                let apsplayername = apslist1[i].replace(/ \((\d+)\)$/, "")
                world.getDimension("overworld").runCommand(`tag "${apsplayername}" remove gunempty`)
                world.getDimension("overworld").runCommand(`tag "${apsplayername}" remove aps_reload1`)
                world.getDimension("overworld").runCommand(`tag "${apsplayername}" add aps_reload2`)
                apslist.push(apsplayername)

            }
            var string2 = ""
            for (var i = 0; i < apslist.length; i++) {
                if (i == (apslist.length - 1)) {
                    var string2 = string2 + "name!=" + '"' + apslist[i] + '"'
                }
                if (i < (apslist.length - 1)) {
                    var string2 = string2 + "name!=" + '"' + apslist[i] + '"' + " ,"
                }
            }
            world.getDimension("overworld").runCommand(`tag @a[${string2}] remove aps_reload2`)
        } catch (error) {
        }
    })
}

function pp90() {
    mc.world.events.tick.subscribe(() => {
        try {
            let pp90output = world.getDimension("overworld").runCommand(`clear @a[tag=pp90_reload1] smg:pp90mag -1 0`)
            let pp90list1 = pp90output.playerTest;
            let pp90list = []
            for (var i = 0; i < pp90list1.length; i++) {
                let pp90playername = pp90list1[i].replace(/ \((\d+)\)$/, "")
                world.getDimension("overworld").runCommand(`tag "${pp90playername}" remove gunempty`)
                world.getDimension("overworld").runCommand(`tag "${pp90playername}" remove pp90_reload1`)
                world.getDimension("overworld").runCommand(`tag "${pp90playername}" add pp90_reload2`)
                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] + '"' + " ,"
                }
            }
            world.getDimension("overworld").runCommand(`tag @a[${string2}] remove pp90_reload2`)
        } catch (error) {
        }
    })
}

function coltlmg() {
    mc.world.events.tick.subscribe(() => {
        try {
            let coltlmgoutput = world.getDimension("overworld").runCommand(`clear @a[tag=coltlmg_reload1] lmg:coltlmgmag -1 0`)
            let coltlmglist1 = coltlmgoutput.playerTest;
            let coltlmglist = []
            for (var i = 0; i < coltlmglist1.length; i++) {
                let coltlmgplayername = coltlmglist1[i].replace(/ \((\d+)\)$/, "")
                world.getDimension("overworld").runCommand(`tag "${coltlmgplayername}" remove gunempty`)
                world.getDimension("overworld").runCommand(`tag "${coltlmgplayername}" remove coltlmg_reload1`)
                world.getDimension("overworld").runCommand(`tag "${coltlmgplayername}" add coltlmg_reload2`)
                coltlmglist.push(coltlmgplayername)

            }
            var string2 = ""
            for (var i = 0; i < coltlmglist.length; i++) {
                if (i == (coltlmglist.length - 1)) {
                    var string2 = string2 + "name!=" + '"' + coltlmglist[i] + '"'
                }
                if (i < (coltlmglist.length - 1)) {
                    var string2 = string2 + "name!=" + '"' + coltlmglist[i] + '"' + " ,"
                }
            }
            world.getDimension("overworld").runCommand(`tag @a[${string2}] remove coltlmg_reload2`)
        } catch (error) {
        }
    })
}

function rpk16() {
    mc.world.events.tick.subscribe(() => {
        try {
            let rpk16output = world.getDimension("overworld").runCommand(`clear @a[tag=rpk16_reload1] mecha:cjmag -1 0`)
            let rpk16list1 = rpk16output.playerTest;
            let rpk16list = []
            for (var i = 0; i < rpk16list1.length; i++) {
                let rpk16playername = rpk16list1[i].replace(/ \((\d+)\)$/, "")
                world.getDimension("overworld").runCommand(`tag "${rpk16playername}" remove gunempty`)
                world.getDimension("overworld").runCommand(`tag "${rpk16playername}" remove rpk16_reload1`)
                world.getDimension("overworld").runCommand(`tag "${rpk16playername}" add rpk16_reload2`)
                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] + '"' + " ,"
                }
            }
            world.getDimension("overworld").runCommand(`tag @a[${string2}] remove rpk16_reload2`)
        } catch (error) {
        }
    })
}

function mosinnagant() {
    mc.world.events.tick.subscribe(() => {
        try {
            let mosinnagantoutput = world.getDimension("overworld").runCommand(`clear @a[tag=mosinnagant_reload1] sniper:ammo7.62x54mmR -1 0`)
            let mosinnagantlist1 = mosinnagantoutput.playerTest;
            let mosinnagantlist = []
            for (var i = 0; i < mosinnagantlist1.length; i++) {
                let mosinnagantplayername = mosinnagantlist1[i].replace(/ \((\d+)\)$/, "")
                world.getDimension("overworld").runCommand(`tag "${mosinnagantplayername}" remove gunempty`)
                world.getDimension("overworld").runCommand(`tag "${mosinnagantplayername}" remove mosinnagant_reload1`)
                world.getDimension("overworld").runCommand(`tag "${mosinnagantplayername}" add mosinnagant_reload2`)
                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] + '"' + " ,"
                }
            }
            world.getDimension("overworld").runCommand(`tag @a[${string2}] remove mosinnagant_reload2`)
        } catch (error) {
        }
    })
}

function mg3() {
    mc.world.events.tick.subscribe(() => {
        try {
            let mg3output = world.getDimension("overworld").runCommand(`clear @a[tag=mg3_reload1] gpmg:mg3mag -1 0`)
            let mg3list1 = mg3output.playerTest;
            let mg3list = []
            for (var i = 0; i < mg3list1.length; i++) {
                let mg3playername = mg3list1[i].replace(/ \((\d+)\)$/, "")
                world.getDimension("overworld").runCommand(`tag "${mg3playername}" remove gunempty`)
                world.getDimension("overworld").runCommand(`tag "${mg3playername}" remove mg3_reload1`)
                world.getDimension("overworld").runCommand(`tag "${mg3playername}" add mg3_reload2`)
                mg3list.push(mg3playername)

            }
            var string2 = ""
            for (var i = 0; i < mg3list.length; i++) {
                if (i == (mg3list.length - 1)) {
                    var string2 = string2 + "name!=" + '"' + mg3list[i] + '"'
                }
                if (i < (mg3list.length - 1)) {
                    var string2 = string2 + "name!=" + '"' + mg3list[i] + '"' + " ,"
                }
            }
            world.getDimension("overworld").runCommand(`tag @a[${string2}] remove mg3_reload2`)
        } catch (error) {
        }
    })
}

function dp27() {
    mc.world.events.tick.subscribe(() => {
        try {
            let dp27output = world.getDimension("overworld").runCommand(`clear @a[tag=dp27_reload1] gpmg:dp27mag -1 0`)
            let dp27list1 = dp27output.playerTest;
            let dp27list = []
            for (var i = 0; i < dp27list1.length; i++) {
                let dp27playername = dp27list1[i].replace(/ \((\d+)\)$/, "")
                world.getDimension("overworld").runCommand(`tag "${dp27playername}" remove gunempty`)
                world.getDimension("overworld").runCommand(`tag "${dp27playername}" remove dp27_reload1`)
                world.getDimension("overworld").runCommand(`tag "${dp27playername}" add dp27_reload2`)
                dp27list.push(dp27playername)

            }
            var string2 = ""
            for (var i = 0; i < dp27list.length; i++) {
                if (i == (dp27list.length - 1)) {
                    var string2 = string2 + "name!=" + '"' + dp27list[i] + '"'
                }
                if (i < (dp27list.length - 1)) {
                    var string2 = string2 + "name!=" + '"' + dp27list[i] + '"' + " ,"
                }
            }
            world.getDimension("overworld").runCommand(`tag @a[${string2}] remove dp27_reload2`)
        } catch (error) {
        }
    })
}

function m1014() {
    mc.world.events.tick.subscribe(() => {
        try {
            let m1014output = world.getDimension("overworld").runCommand(`clear @a[tag=m1014_reload1] shotgun:m1014ammo -1 0`)
            let m1014list1 = m1014output.playerTest;
            let m1014list = []
            for (var i = 0; i < m1014list1.length; i++) {
                let m1014playername = m1014list1[i].replace(/ \((\d+)\)$/, "")
                world.getDimension("overworld").runCommand(`tag "${m1014playername}" remove gunempty`)
                world.getDimension("overworld").runCommand(`tag "${m1014playername}" remove m1014_reload1`)
                world.getDimension("overworld").runCommand(`tag "${m1014playername}" add m1014_reload2`)
                m1014list.push(m1014playername)

            }
            var string2 = ""
            for (var i = 0; i < m1014list.length; i++) {
                if (i == (m1014list.length - 1)) {
                    var string2 = string2 + "name!=" + '"' + m1014list[i] + '"'
                }
                if (i < (m1014list.length - 1)) {
                    var string2 = string2 + "name!=" + '"' + m1014list[i] + '"' + " ,"
                }
            }
            world.getDimension("overworld").runCommand(`tag @a[${string2}] remove m1014_reload2`)
        } catch (error) {
        }
    })
}

function m24() {
    mc.world.events.tick.subscribe(() => {
        try {
            let m24output = world.getDimension("overworld").runCommand(`clear @a[tag=m24_reload1] sniper:m24mag -1 0`)
            let m24list1 = m24output.playerTest;
            let m24list = []
            for (var i = 0; i < m24list1.length; i++) {
                let m24playername = m24list1[i].replace(/ \((\d+)\)$/, "")
                world.getDimension("overworld").runCommand(`tag "${m24playername}" remove gunempty`)
                world.getDimension("overworld").runCommand(`tag "${m24playername}" remove m24_reload1`)
                world.getDimension("overworld").runCommand(`tag "${m24playername}" add m24_reload2`)
                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] + '"' + " ,"
                }
            }
            world.getDimension("overworld").runCommand(`tag @a[${string2}] remove m24_reload2`)
        } catch (error) {
        }
    })
}

function m16a1() {
    mc.world.events.tick.subscribe(() => {
        try {
            let m16a1output = world.getDimension("overworld").runCommand(`clear @a[tag=m16a1_reload1] rifle:m16a1mag -1 0`)
            let m16a1list1 = m16a1output.playerTest;
            let m16a1list = []
            for (var i = 0; i < m16a1list1.length; i++) {
                let m16a1playername = m16a1list1[i].replace(/ \((\d+)\)$/, "")
                world.getDimension("overworld").runCommand(`tag "${m16a1playername}" remove gunempty`)
                world.getDimension("overworld").runCommand(`tag "${m16a1playername}" remove m16a1_reload1`)
                world.getDimension("overworld").runCommand(`tag "${m16a1playername}" add m16a1_reload2`)
                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] + '"' + " ,"
                }
            }
            world.getDimension("overworld").runCommand(`tag @a[${string2}] remove m16a1_reload2`)
        } catch (error) {
        }
    })
}

function aks74u() {
    mc.world.events.tick.subscribe(() => {
        try {
            let aks74uoutput = world.getDimension("overworld").runCommand(`clear @a[tag=aks74u_reload1] smg:aks74umag -1 0`)
            let aks74ulist1 = aks74uoutput.playerTest;
            let aks74ulist = []
            for (var i = 0; i < aks74ulist1.length; i++) {
                let aks74uplayername = aks74ulist1[i].replace(/ \((\d+)\)$/, "")
                world.getDimension("overworld").runCommand(`tag "${aks74uplayername}" remove gunempty`)
                world.getDimension("overworld").runCommand(`tag "${aks74uplayername}" remove aks74u_reload1`)
                world.getDimension("overworld").runCommand(`tag "${aks74uplayername}" add aks74u_reload2`)
                aks74ulist.push(aks74uplayername)

            }
            var string2 = ""
            for (var i = 0; i < aks74ulist.length; i++) {
                if (i == (aks74ulist.length - 1)) {
                    var string2 = string2 + "name!=" + '"' + aks74ulist[i] + '"'
                }
                if (i < (aks74ulist.length - 1)) {
                    var string2 = string2 + "name!=" + '"' + aks74ulist[i] + '"' + " ,"
                }
            }
            world.getDimension("overworld").runCommand(`tag @a[${string2}] remove aks74u_reload2`)
        } catch (error) {
        }
    })
}

function rpg7() {
    mc.world.events.tick.subscribe(() => {
        try {
            let rpg7output = world.getDimension("overworld").runCommand(`clear @a[tag=rpg7_reload1] rocketlauncher:rpg7rocket -1 0`)
            let rpg7list1 = rpg7output.playerTest;
            let rpg7list = []
            for (var i = 0; i < rpg7list1.length; i++) {
                let rpg7playername = rpg7list1[i].replace(/ \((\d+)\)$/, "")
                world.getDimension("overworld").runCommand(`tag "${rpg7playername}" remove gunempty`)
                world.getDimension("overworld").runCommand(`tag "${rpg7playername}" remove rpg7_reload1`)
                world.getDimension("overworld").runCommand(`tag "${rpg7playername}" add rpg7_reload2`)
                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] + '"' + " ,"
                }
            }
            world.getDimension("overworld").runCommand(`tag @a[${string2}] remove rpg7_reload2`)
        } catch (error) {
        }
    })
}

function m1911() {
    mc.world.events.tick.subscribe(() => {
        try {
            let m1911output = world.getDimension("overworld").runCommand(`clear @a[tag=m1911_reload1] pistol:m1911mag -1 0`)
            let m1911list1 = m1911output.playerTest;
            let m1911list = []
            for (var i = 0; i < m1911list1.length; i++) {
                let m1911playername = m1911list1[i].replace(/ \((\d+)\)$/, "")
                world.getDimension("overworld").runCommand(`tag "${m1911playername}" remove gunempty`)
                world.getDimension("overworld").runCommand(`tag "${m1911playername}" remove m1911_reload1`)
                world.getDimension("overworld").runCommand(`tag "${m1911playername}" add m1911_reload2`)
                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] + '"' + " ,"
                }
            }
            world.getDimension("overworld").runCommand(`tag @a[${string2}] remove m1911_reload2`)
        } catch (error) {
        }
    })
}

function g3() {
    mc.world.events.tick.subscribe(() => {
        try {
            let g3output = world.getDimension("overworld").runCommand(`clear @a[tag=g3_reload1] battlerifle:g3mag -1 0`)
            let g3list1 = g3output.playerTest;
            let g3list = []
            for (var i = 0; i < g3list1.length; i++) {
                let g3playername = g3list1[i].replace(/ \((\d+)\)$/, "")
                world.getDimension("overworld").runCommand(`tag "${g3playername}" remove gunempty`)
                world.getDimension("overworld").runCommand(`tag "${g3playername}" remove g3_reload1`)
                world.getDimension("overworld").runCommand(`tag "${g3playername}" add g3_reload2`)
                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] + '"' + " ,"
                }
            }
            world.getDimension("overworld").runCommand(`tag @a[${string2}] remove g3_reload2`)
        } catch (error) {
        }
    })
}

function ak47() {
    mc.world.events.tick.subscribe(() => {
        try {
            let ak47output = world.getDimension("overworld").runCommand(`clear @a[tag=ak47_reload1] rifle:ak47mag -1 0`)
            let ak47list1 = ak47output.playerTest;
            let ak47list = []
            for (var i = 0; i < ak47list1.length; i++) {
                let ak47playername = ak47list1[i].replace(/ \((\d+)\)$/, "")
                world.getDimension("overworld").runCommand(`tag "${ak47playername}" remove gunempty`)
                world.getDimension("overworld").runCommand(`tag "${ak47playername}" remove ak47_reload1`)
                world.getDimension("overworld").runCommand(`tag "${ak47playername}" add ak47_reload2`)
                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] + '"' + " ,"
                }
            }
            world.getDimension("overworld").runCommand(`tag @a[${string2}] remove ak47_reload2`)
        } catch (error) {
        }
    })
}

function dragunov() {
    mc.world.events.tick.subscribe(() => {
        try {
            let dragunovoutput = world.getDimension("overworld").runCommand(`clear @a[tag=dragunov_reload1] dmr:dragunovmag -1 0`)
            let dragunovlist1 = dragunovoutput.playerTest;
            let dragunovlist = []
            for (var i = 0; i < dragunovlist1.length; i++) {
                let dragunovplayername = dragunovlist1[i].replace(/ \((\d+)\)$/, "")
                world.getDimension("overworld").runCommand(`tag "${dragunovplayername}" remove gunempty`)
                world.getDimension("overworld").runCommand(`tag "${dragunovplayername}" remove dragunov_reload1`)
                world.getDimension("overworld").runCommand(`tag "${dragunovplayername}" add dragunov_reload2`)
                dragunovlist.push(dragunovplayername)

            }
            var string2 = ""
            for (var i = 0; i < dragunovlist.length; i++) {
                if (i == (dragunovlist.length - 1)) {
                    var string2 = string2 + "name!=" + '"' + dragunovlist[i] + '"'
                }
                if (i < (dragunovlist.length - 1)) {
                    var string2 = string2 + "name!=" + '"' + dragunovlist[i] + '"' + " ,"
                }
            }
            world.getDimension("overworld").runCommand(`tag @a[${string2}] remove dragunov_reload2`)
        } catch (error) {
        }
    })
}

function rpk() {
    mc.world.events.tick.subscribe(() => {
        try {
            let rpkoutput = world.getDimension("overworld").runCommand(`clear @a[tag=rpk_reload1] lmg:rpkmag -1 0`)
            let rpklist1 = rpkoutput.playerTest;
            let rpklist = []
            for (var i = 0; i < rpklist1.length; i++) {
                let rpkplayername = rpklist1[i].replace(/ \((\d+)\)$/, "")
                world.getDimension("overworld").runCommand(`tag "${rpkplayername}" remove gunempty`)
                world.getDimension("overworld").runCommand(`tag "${rpkplayername}" remove rpk_reload1`)
                world.getDimension("overworld").runCommand(`tag "${rpkplayername}" add rpk_reload2`)
                rpklist.push(rpkplayername)
            }
            for (var i = 0; i < rpklist1.length; i++) {
                let rpkplayername = rpklist1[i].replace(/ \((\d+)\)$/, "")
                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] + '"' + " ,"
                }
            }
            world.getDimension("overworld").runCommand(`tag @a[${string2}] remove rpk_reload2`)
        } catch (error) {
        }
    })
}

aks74u()
mg3()
mig21gun()
mig21rocket()
mig21bomb()
f4phantombomb()
f4phantomrocket()
dragunov()
g3()
m1014()
m24()
pp90()
ak47()
rpk()
m1911()
dp27()
m16a1()
rpg7()
mig21bomb()
mosinnagant()
rpk16()
coltlmg()
aps()
fedorovavtomat()