//custom script by Sketchy#7750 and KittenPopo#9336
players = Entity.GetPlayers();
var textureIDs = [
    ["peter", "kibby.png", 0], //the man, the myth, the legend himself
    ["meg", "kibby.png", 0], //peters soon-to-be-put-up-for-adoption daughter
    ["brian", "kibby.png", 0], //peters dog
    ["chris", "kibby.png", 0], //peters son
    ["stewie", "kibby.png", 0], //peters baby son
    ["loius", "kibby.png", 0], //peters wife
    ["quagmire", "kibby.png", 0], //horny dude
    ["joe", "kibby.png", 0], //disabled dude
    ["cleveland", "kibby.png", 0], //black dude
    ["jerome", "kibby.png", 0], //bartender
    ["herbert", "kibby.png", 0], //herbert da pervert, real gangster shit here folks
    ["ernie", "kibby.png", 0], //big chicken guy i think
    ["koolaid", "kibby.png", 0], //kool aid man
    ["adam", "kibby.png", 0], //mayor of quahog
    ["tom", "kibby.png", 0], //news reporter man
    ["donna", "kibby.png", 0], //peters boss i think idk
    ["connie", "kibby.png", 0], //popular girl at chris' school
    ["bonnie", "kibby.png", 0], //joe wife
    ["barbara", "kibby.png", 0], //louis' mom i think
    ["opie", "kibby.png", 0], //retarded guy
    ["mort", "kibby.png", 0], //jewish kid
    ["joe2", "kibby.png", 0], //black joe
    ["peter2", "kibby.png", 0], //black peter
    ["quagmire2", "kibby.png", 0], //black quagmire
    ["junior", "kibby.png", 0], //cleveland's son
    ["kevin", "kibby.png", 0], //joe's son
    ["carter", "kibby.png", 0], //louis' dad i think
    ["seamus", "kibby.png", 0], //pirate dude
    ["tricia", "kibby.png", 0], //japanese reporter
];

// Function to retrieve texture by name
function tex(name) {
    for (var i = 0; i < textureIDs.length; i++) {
        if (textureIDs[i][0] === name) {
            return textureIDs[i][2];
        }
    }

    return -1;
}
/////////////////////////
var first = true;
function draw() {
    var badguy = Entity.GetEnemies(); //enemies for fetching enemy location
    var goodguy = Entity.GetTeammates(); //teammates for fetching teammate location
    var chicken = Entity.GetEntities(); //chickens for fetching chicken location

    // Load Textures
    if (first) {
        first = false;
        for (var i = 0; i < textureIDs.length; i++) {
            var name = textureIDs[i][1];
            //Cheat.Print("Loading texture: " + name + "\n");
            textureIDs[i][2] = Render.AddTexture("ot/scripts/gameing/" + name);
        }
    }

    for (var i = 0; i < badguy.length; i++) { //enemy esp start, dont fuck with anything except for where i put the comment
        if (Entity.IsEnemy(badguy[i])) {   
            if (Entity.IsAlive(badguy[i])) { //checks if the enemy is alive before it starts drawing
                var pos = Entity.GetRenderBox(badguy[i]); //defines the position variable
                
                var sizeY = (pos[4] - pos[2]); //defines sizeY variable
                var sizeX = (pos[3] - pos[1]);
                Render.TexturedRect(pos[1], pos[2], sizeX, sizeY, tex("meg"));
            }
        }
    }

    for (var i = 0; i < goodguy.length; i++) { //teammate esp start, dont fuck with anything except for where i put the comment
        if (Entity.IsTeammate(goodguy[i])) { 
            if ( Entity.IsLocalPlayer(players[i]))
             {
                 var pos = Entity.GetRenderBox(players[i]);

                 var sizeY = (pos[4] - pos[2]);
                 var sizeX = (pos[3] - pos[1]);
                
                 Render.TexturedRect(pos[1], pos[2], sizeX, sizeY, tex("peter"));
             }
            else 
            if (Entity.IsAlive(goodguy[i])) { //checks if the teammate is alive before it starts drawing
                var pos1 = Entity.GetRenderBox(goodguy[i]); //defines the position variable
                
                var sizeY1 = (pos1[4] - pos1[2]); //defines sizeY1 variable
                var sizeX1 = (pos1[3] - pos1[1]); //defines sizeX1 variable
                
                Render.TexturedRect(pos1[1], pos1[2], sizeX1, sizeY1, tex("chris")); //peter is var peter, u can replace peter with the name of any character
            }
        }
    }

    for (var i = 0; i < chicken.length; i++) { //chicken esp start, dont fuck with anything except for where i put the comment
        world_pos = Entity.GetRenderOrigin(chicken[i]); //defines the world_position variable
        var pos2 = Entity.GetRenderBox(chicken[i]);
        world_pos[2] += 26; //does some math shit idk
        name = Entity.GetClassName(chicken[i]); //makes sure its a chicken i think
        screen_pos = Render.WorldToScreen(world_pos);  //fetches the chickens position on ur screen
        var sizeY2 = (pos2[4] - pos2[2]); //defines sizeY2 variable
        var sizeX2 = (pos2[3] - pos2[1]); //defines sizeX2 variable 
        if (name != "CChicken") //another chicken check, CChicken is NOT A TYPO
            continue; //keep going bruh
        
        Render.TexturedRect(pos2[1], pos2[2], sizeX2, sizeY2, tex("brian")); //brian is var brian, u can replace brian with the name of any character
    }
}

Cheat.RegisterCallback("Draw", "draw"); //makes the function run itself every frame

// for ( i = 0; i < players.length; i++)
//     {
//         if ( Entity.IsLocalPlayer(players[i]))
//         {
//             var pos = Entity.GetRenderBox(players[i]);

//             var sizeY = (pos[4] - pos[2]);
//             var sizeX = (pos[3] - pos[1]);

//             Render.TexturedRect(pos[1], pos[2], sizeX, sizeY, tex("peter"));
//         }
//     }