All = [
    'GET GOOD, GET RANK',
    'BRITISH 1',
    'BRITISH 2',
    'BRITISH 3',
    'BRITISH 4',
    'BRITISH ELITE',
    'BRITISH ELITE MASTER',
    'AMERICA WANT GOLD 1',
    'AMERICA WANT GOLD 2',
    'AMERICA WANT GOLD 3',
    'AMERICA WANT GOLD MASTER',
    'MASTER GAY 1',
    'MASTER GAY 2',
    'MASTER GAY ELITE',
    'DISTINGUISHED MASTER GAY',
    'LEGENDARY GOOSE',
    'LEGENDARY GOOSE MASTER',
    'ADIDAS MASTER LAST CLASS',
    'GLOBAL WARMING'
]

var spam = [];
var pos = 0;
var lastexec = 0;


UI.AddCheckbox("All");
UI.AddCheckbox("Enemies");

function onPlayerSay() {
    if(UI.GetValue('Misc', 'JAVASCRIPT', 'Script items', 'All'))
    {
        UI.SetValue('Misc', 'JAVASCRIPT', 'Script items', 'Enemies', 0)
        spam = []
        players = Entity.GetPlayers();
        for (i = 0; i < players.length; i++) {
            name = Entity.GetName(players[i])
            if (name != "GOTV") { // dumb check for GOTV
                wins = Entity.GetProp(players[i], "CCSPlayerResource", "m_iCompetitiveWins")
                rank = All[Entity.GetProp(players[i], "CCSPlayerResource", "m_iCompetitiveRanking")]
                spam[i] = "say " + name + " has " + wins + " wins (" + rank + ")";
                lastexec = Globals.Curtime() + 1;
            }
            pos = -1;
        }
    }
    if(UI.GetValue('Misc', 'JAVASCRIPT', 'Script items', 'Enemies'))
    {
        UI.SetValue('Misc', 'JAVASCRIPT', 'Script items', 'All', 0)
        spam = []
        players = Entity.GetEnemies();
        for (i = 0; i < players.length; i++) {
            name = Entity.GetName(players[i])
            if (name != "GOTV") { // dumb check for GOTV
                wins = Entity.GetProp(players[i], "CCSPlayerResource", "m_iCompetitiveWins")
                rank = All[Entity.GetProp(players[i], "CCSPlayerResource", "m_iCompetitiveRanking")]
                spam[i] = "say " + name + " has " + wins + " wins (" + rank + ")";
                lastexec = Globals.Curtime() + 1;
            }
            pos = -1;
        }
    }
}




function spamPrint() {
    if (Globals.Curtime() > lastexec && pos < spam.length) {
        // might have a race condition but meh...
        // can be fixed by simply adding a isdone check
        // pos can be replaced by tick%spam.length
        // discord * ･ﾟ𝙈𝙞𝙘･ﾟ *#0001
        if (pos == -1) {
            Cheat.ExecuteCommand("say hvh?")
            pos++
        } else {
            Cheat.ExecuteCommand(spam[pos++])
        }
        lastexec = Globals.Curtime() + 1;
    }
}


Cheat.RegisterCallback("FrameStageNotify", "onPlayerSay");
Cheat.RegisterCallback("Draw", "spamPrint")