//This plugin makes several changes to HUDs, improving them in the ways done in Kawaii Mod.
//CP and Arena: Percentage on a control point being capped. Arena: Improved MVP board. Generator: HP display.
//CTF: Distance to intels, time remaining, improved visability. Superburst HUD: Percentage display.
//Also, a few extra controls: R - superburst bubble, I - toggles chat on and off, arrows - arrow bubbles
//These can all be changed in controls.gg2
out("Blaze's Kawaii Plugin (Essentials)");

if !variable_global_exists("kawaiiNeDesu") global.kawaiiNeDesu = 0;
else global.kawaiiNeDesu = 1;

if global.kawaiiNeDesu != 1 {
if file_exists("Plugins/Sprites/BetterMVPBanner.png") && file_exists("Plugins/Sprites/NewIntelHUD.png")
&& file_exists("Plugins/Sprites/BigUberHUD.png") {
sprite_replace(MVPBannerS,"Plugins/Sprites/BetterMVPBanner.png",4,1,0,141,82);
sprite_replace(ScorePanelS,"Plugins/Sprites/NewIntelHUD.png",1,1,0,140,72);
sprite_replace(UberHudS,"Plugins/Sprites/BigUberHUD.png",2,1,0,52,11);
}else{
out("One of the files cannot be found!");
exit;
}

object_event_clear(ControlPointHUD,ev_draw,0);
object_event_add(ControlPointHUD,ev_draw,0,'xoffset = view_xview[0];
yoffset = view_yview[0];
xsize = view_wview[0];
ysize = view_hview[0];

if global.totalControlPoints == 1 drawx = xoffset+xsize/2;
else drawx = xoffset+xsize/2 - floor(global.totalControlPoints)/2*48;

draw_set_alpha(1);

for (i=1; i<= global.totalControlPoints; i+=1) {
    if global.cp[i].team == TEAM_RED teamoffset = 60;
    else if global.cp[i].team == TEAM_BLUE teamoffset = 90;
    if global.cp[i].cappingTeam == TEAM_RED && global.cp[i].team == -1 teamoffset = 30;
    else if global.cp[i].cappingTeam != TEAM_RED && global.cp[i].team == -1 teamoffset = 0;    
    //
    if global.cp[i].capping != 0 {
    draw_sprite_ext(ControlPointStatusS, teamoffset+floor(global.cp[i].capping/global.cp[i].capTime*30), drawx, yoffset+560, 3, 3, 0, c_white, 1);
    cpcappercent = string(floor(global.cp[i].capping/global.cp[i].capTime*100)) + "%";
    draw_set_halign(fa_center);
    draw_set_valign(fa_center);
    draw_text_transformed_color(drawx+4, yoffset+572, cpcappercent,1,1,0,c_black,c_black,c_black,c_black,1);
    }
    //
    else if global.cp[i].capping == 0 draw_sprite_ext(ControlPointStatusS, teamoffset, drawx, yoffset+560, 3, 3, 0, c_white, 1);
    if global.cp[i].locked draw_sprite_ext(ControlPointLockS, 0, drawx, yoffset+560, 3, 3, 0, c_white, 1);
    if global.cp[i].cappers > 0 && not global.cp[i].locked {
        //
        draw_sprite_ext(ControlPointCappersS, 0, drawx, yoffset+555, 3, 3, 0, c_white, 1);
        draw_set_halign(fa_center);
        draw_set_valign(fa_center);
        draw_set_color(c_black);
        draw_text_transformed(drawx+13, yoffset+557, string(global.cp[i].cappers),1.5,1.5,0);
        //
    }
    drawx+=60;
}

    
//timer
if instance_exists(WinBanner) exit;
draw_set_color(c_white);
draw_set_valign(fa_center);

if global.myself != -1 {
    if global.myself.team == TEAM_RED teamoffset=0;
    else if global.myself.team == TEAM_BLUE teamoffset=1;
}
if overtime == 1 {
    draw_set_halign(fa_center);
    draw_sprite_ext(TimerHudS,2+teamoffset,xoffset+xsize/2,yoffset+30,3,3,0,c_white,1);
    draw_text(xoffset+xsize/2,yoffset+30,"OVERTIME");
}
else{
    draw_set_halign(fa_right);
    if mode == 1 && global.setupTimer > 0 {
        draw_sprite_ext(TimerHudS,teamoffset,xoffset+xsize/2,yoffset+30,3,3,0,c_white,1);
        draw_sprite_ext(TimerS,floor(global.setupTimer/1800*12),xoffset+xsize/2+39,yoffset+30,3,3,0,c_white,1);
        seconds=floor(global.setupTimer/30);
        draw_text_transformed(xoffset+xsize/2-10,yoffset+27,"00",1.5,1.5,0);
        draw_text_transformed(xoffset+xsize/2,yoffset+27,":",1.5,1.5,0);
        if seconds >= 10 draw_text_transformed(xoffset+xsize/2+20,yoffset+27,string(seconds),1.5,1.5,0);
        else if seconds < 10 draw_text_transformed(xoffset+xsize/2+20,yoffset+27,"0"+string(seconds),1.5,1.5,0);
        draw_set_halign(fa_center);
        draw_text_transformed(xoffset+xsize/2-5,yoffset+38,"Setup",1,1,0);
    }
    else{
        draw_sprite_ext(TimerHudS,teamoffset,xoffset+xsize/2,yoffset+30,3,3,0,c_white,1);
        if timer > timeLimit timeDraw = timeLimit-1;
        else timeDraw = timer;
        draw_sprite_ext(TimerS,floor(timeDraw/timeLimit*12),xoffset+xsize/2+39,yoffset+30,3,3,0,c_white,1);
        minutes=floor(timer/1800);
        secondcounter=timer-minutes*1800;
        seconds=floor(secondcounter/30);    
        draw_text_transformed(xoffset+xsize/2-10,yoffset+32,string(minutes),1.5,1.5,0);
        draw_text_transformed(xoffset+xsize/2,yoffset+32,":",1.5,1.5,0);
        if seconds >= 10 draw_text_transformed(xoffset+xsize/2+20,yoffset+32,string(seconds),1.5,1.5,0);
        else if seconds < 10 draw_text_transformed(xoffset+xsize/2+20,yoffset+32,"0"+string(seconds),1.5,1.5,0);
    }
}
');

object_event_clear(ArenaHUD,ev_draw,0);
object_event_add(ArenaHUD,ev_draw,0,'xoffset = view_xview[0];
yoffset = view_yview[0];
xsize = view_wview[0];
ysize = view_hview[0];
    
//
redteamcolor = make_color_rgb(217,217,183);
blueteamcolor = make_color_rgb(227,226,225);
//

if instance_exists(WinBanner) with WinBanner instance_destroy();

draw_set_color(c_white);
draw_set_valign(fa_center);
draw_set_alpha(1);
        
//CP
if ArenaControlPoint.team == TEAM_RED teamoffset = 60;
else if ArenaControlPoint.team == TEAM_BLUE teamoffset = 90;
if ArenaControlPoint.cappingTeam == TEAM_RED && ArenaControlPoint.team == -1 teamoffset = 30;
else if ArenaControlPoint.cappingTeam != TEAM_RED && ArenaControlPoint.team == -1 teamoffset = 0;    
//
if ArenaControlPoint.capping != 0 {
draw_sprite_ext(ControlPointStatusS, teamoffset+floor(ArenaControlPoint.capping/ArenaControlPoint.capTime*30), xoffset+xsize/2, yoffset+560, 3, 3, 0, c_white, 1);
cpcappercent = string(floor(ArenaControlPoint.capping/ArenaControlPoint.capTime*100)) + "%";
draw_set_halign(fa_center);
draw_set_valign(fa_center);
draw_text_transformed_color((xoffset+xsize/2)+4, yoffset+572, cpcappercent,1,1,0,c_black,c_black,c_black,c_black,1);
}
//
else if ArenaControlPoint.capping == 0 draw_sprite_ext(ControlPointStatusS, teamoffset, xoffset+xsize/2, yoffset+560, 3, 3, 0, c_white, 1);
if ArenaControlPoint.locked == 1 {
    draw_set_halign(fa_center);
    draw_set_valign(fa_center);
    //
    if cpUnlock >= 1800 {} //To prevent display problems at server join and during set-up
    else if cpUnlock > 900 draw_text_transformed(xoffset+xsize/2+2, yoffset+562, ceil(cpUnlock/30), 1.0, 1.0, 0);
    else if cpUnlock > 450 draw_text_transformed(xoffset+xsize/2+2, yoffset+562, ceil(cpUnlock/30), 1.5, 1.5, 0);
    else if cpUnlock > 300 draw_text_transformed(xoffset+xsize/2+2, yoffset+562, ceil(cpUnlock/30), 2.0, 2.0, 0);
    else if cpUnlock > 150 draw_text_transformed(xoffset+xsize/2+2, yoffset+562, ceil(cpUnlock/30), 2.5, 2.5, 0);
    else if cpUnlock >= 1 draw_text_transformed(xoffset+xsize/2+2, yoffset+562, ceil(cpUnlock/30), 3, 3, 0);
    //
}
else if ArenaControlPoint.cappers > 0 && ArenaControlPoint.locked == 0{
    //
    draw_sprite_ext(ControlPointCappersS, 0, xoffset+xsize/2, yoffset+555, 3, 3, 0, c_white, 1);
    draw_set_halign(fa_center);
    draw_set_valign(fa_center);
    draw_set_color(c_black);
    draw_text_transformed(xoffset+xsize/2+13, yoffset+557, string(ArenaControlPoint.cappers),1.5,1.5,0);
    //
}

//timer
draw_set_color(c_white);
if global.myself != -1 {
    if global.myself.team == TEAM_RED teamoffset=0;
    else if global.myself.team == TEAM_BLUE teamoffset=1;
}
if overtime == 1 {
    draw_set_halign(fa_center);
    draw_sprite_ext(TimerHudS,2+teamoffset,xoffset+xsize/2,yoffset+30,3,3,0,c_white,1);
    draw_text(xoffset+xsize/2,yoffset+30,"OVERTIME");
}
else{
    draw_set_halign(fa_right);
    draw_sprite_ext(TimerHudS,teamoffset,xoffset+xsize/2,yoffset+30,3,3,0,c_white,1);
    draw_sprite_ext(TimerS,floor(timer/timeLimit * 12),xoffset+xsize/2+39,yoffset+30,3,3,0,c_white,1);
    minutes=floor(timer/1800);
    secondcounter=timer-minutes*1800;
    seconds=floor(secondcounter/30);    
    draw_text_transformed(xoffset+xsize/2-10,yoffset+32,string(minutes),1.5,1.5,0);
    draw_text_transformed(xoffset+xsize/2,yoffset+32,":",1.5,1.5,0);
    if seconds >= 10 draw_text_transformed(xoffset+xsize/2+20,yoffset+32,string(seconds),1.5,1.5,0);
    else if seconds < 10 draw_text_transformed(xoffset+xsize/2+20,yoffset+32,"0"+string(seconds),1.5,1.5,0);
}

draw_set_halign(fa_center); 
if roundStart > 0 {
    draw_text(xoffset+xsize/2,yoffset+ysize/2,"Game will start in "+string(floor(roundStart/30))+" seconds")
}

if global.myself != -1 {
    if global.myself.object == -1 && roundStart == 0 && winners == TEAM_SPECTATOR && global.winners == -1 && endCount == 0 && !instance_exists(DeathCam){
        draw_text(xoffset+xsize/2,yoffset+ysize/2,"You can spawn when the next round starts")
    }
    //Alive players remaining 
    draw_set_color(c_black);
    draw_sprite_ext(ArenaPlayerCountS,0,xoffset+xsize/2,yoffset+71,2,2,0,c_white,1);
    draw_text(xoffset+xsize/2+15,yoffset+73,redteamCharacters);
    draw_sprite_ext(ArenaPlayerCountS,1,xoffset+xsize/2,yoffset+104,2,2,0,c_white,1);
    draw_text(xoffset+xsize/2+15,yoffset+106,blueteamCharacters);
}
 
//MVPs
if endCount > 0 && global.winners == -1 && !instance_exists(ScoreTableController){
    if instance_exists(DeathCam) {
        with DeathCam instance_destroy();
    }
    
    draw_set_alpha(1);    
    draw_set_halign(fa_left);
    draw_set_color(c_white);

    offset = 25;
    if winners == TEAM_RED {
        if endCount < 150 {
            draw_set_color(redteamcolor);
            draw_sprite_ext(MVPBannerS,0,xoffset+xsize/2,yoffset+ysize/2+150,1.5,1.5,0,c_white,0.8);
            draw_text_transformed(xoffset+xsize/2-190,yoffset+ysize/2+170,"RED Team MVPs",1,1,0);
            draw_set_halign(fa_right);
            draw_text_transformed(xoffset+xsize/2+40,yoffset+ysize/2+170,"Kills",1,1,0);
            draw_text_transformed(xoffset+xsize/2+120,yoffset+ysize/2+170,"Healing",1,1,0);
            draw_text_transformed(xoffset+xsize/2+182,yoffset+ysize/2+170,"Score",1,1,0);
            for (i=0; i<redMVPs; i+=1) {
                draw_set_halign(fa_left);
                draw_text_transformed(xoffset+xsize/2-190,yoffset+ysize/2+71+125+offset*i,redMVPName[i],1,1,0);
                draw_set_halign(fa_right);
                draw_text_transformed(xoffset+xsize/2+40,yoffset+ysize/2+71+125+offset*i,redMVPKills[i],1,1,0);
                draw_text_transformed(xoffset+xsize/2+120,yoffset+ysize/2+71+125+offset*i,redMVPHealed[i],1,1,0);
                draw_text_transformed(xoffset+xsize/2+182,yoffset+ysize/2+71+125+offset*i,redMVPPoints[i],1,1,0);
            }
        }
        else if endCount >= 150 {
            draw_set_color(blueteamcolor);
            draw_sprite_ext(MVPBannerS,1,xoffset+xsize/2,yoffset+ysize/2+150,1.5,1.5,0,c_white,0.8);
            draw_text_transformed(xoffset+xsize/2-190,yoffset+ysize/2+170,"BLU Team MVPs",1,1,0);
            draw_set_halign(fa_right);
            draw_text_transformed(xoffset+xsize/2+40,yoffset+ysize/2+170,"Kills",1,1,0);
            draw_text_transformed(xoffset+xsize/2+120,yoffset+ysize/2+170,"Healing",1,1,0);
            draw_text_transformed(xoffset+xsize/2+182,yoffset+ysize/2+170,"Score",1,1,0);
            for (i=0; i<blueMVPs; i+=1) {
                draw_set_halign(fa_left);
                draw_text_transformed(xoffset+xsize/2-190,yoffset+ysize/2+71+125+offset*i,blueMVPName[i],1,1,0);
                draw_set_halign(fa_right);
                draw_text_transformed(xoffset+xsize/2+40,yoffset+ysize/2+71+125+offset*i,blueMVPKills[i],1,1,0);
                draw_text_transformed(xoffset+xsize/2+120,yoffset+ysize/2+71+125+offset*i,blueMVPHealed[i],1,1,0);
                draw_text_transformed(xoffset+xsize/2+182,yoffset+ysize/2+71+125+offset*i,blueMVPPoints[i],1,1,0);
            }
        }
    }
    else if winners == TEAM_BLUE {
        if endCount < 150 {
            draw_set_color(blueteamcolor);
            draw_sprite_ext(MVPBannerS,2,xoffset+xsize/2,yoffset+ysize/2+150,1.5,1.5,0,c_white,0.8);
            draw_text_transformed(xoffset+xsize/2-190,yoffset+ysize/2+170,"BLU Team MVPs",1,1,0);
            draw_set_halign(fa_right);
            draw_text_transformed(xoffset+xsize/2+40,yoffset+ysize/2+170,"Kills",1,1,0);
            draw_text_transformed(xoffset+xsize/2+120,yoffset+ysize/2+170,"Healing",1,1,0);
            draw_text_transformed(xoffset+xsize/2+182,yoffset+ysize/2+170,"Score",1,1,0);
            for (i=0; i<blueMVPs; i+=1) {
                draw_set_halign(fa_left);
                draw_text_transformed(xoffset+xsize/2-190,yoffset+ysize/2+71+125+offset*i,blueMVPName[i],1,1,0);
                draw_set_halign(fa_right);
                draw_text_transformed(xoffset+xsize/2+40,yoffset+ysize/2+71+125+offset*i,blueMVPKills[i],1,1,0);
                draw_text_transformed(xoffset+xsize/2+120,yoffset+ysize/2+71+125+offset*i,blueMVPHealed[i],1,1,0);
                draw_text_transformed(xoffset+xsize/2+182,yoffset+ysize/2+71+125+offset*i,blueMVPPoints[i],1,1,0);
            }
        }
        else if endCount >= 150 {
            draw_set_color(redteamcolor);
            draw_sprite_ext(MVPBannerS,3,xoffset+xsize/2,yoffset+ysize/2+150,1.5,1.5,0,c_white,0.8);
            draw_text_transformed(xoffset+xsize/2-190,yoffset+ysize/2+170,"RED Team MVPs",1,1,0);
            draw_set_halign(fa_right);
            draw_text_transformed(xoffset+xsize/2+40,yoffset+ysize/2+170,"Kills",1,1,0);
            draw_text_transformed(xoffset+xsize/2+120,yoffset+ysize/2+170,"Healing",1,1,0);
            draw_text_transformed(xoffset+xsize/2+182,yoffset+ysize/2+170,"Score",1,1,0);
            for (i=0; i<redMVPs; i+=1) {
                draw_set_halign(fa_left);
                draw_text_transformed(xoffset+xsize/2-190,yoffset+ysize/2+71+125+offset*i,redMVPName[i],1,1,0);
                draw_set_halign(fa_right);
                draw_text_transformed(xoffset+xsize/2+40,yoffset+ysize/2+71+125+offset*i,redMVPKills[i],1,1,0);
                draw_text_transformed(xoffset+xsize/2+120,yoffset+ysize/2+71+125+offset*i,redMVPHealed[i],1,1,0);
                draw_text_transformed(xoffset+xsize/2+182,yoffset+ysize/2+71+125+offset*i,redMVPPoints[i],1,1,0);
            }
        }
    }
    draw_set_color(make_color_rgb(227,226,225));
    draw_set_halign(fa_right);
    draw_text_transformed(xoffset+384,yoffset+209+180,consecutiveRedWins,3.5,3.5,0);
    draw_set_halign(fa_left);
    draw_text_transformed(xoffset+415,yoffset+209+180,consecutiveBlueWins,3.5,3.5,0);

}
');

object_event_clear(ScorePanel,ev_draw,0);
object_event_add(ScorePanel,ev_draw,0,'
    var xoffset, yoffset, xsize, ysize;
    
    xoffset = view_xview[0];
    yoffset = view_yview[0];
    xsize = view_wview[0];
    ysize = view_hview[0];
    
    draw_set_alpha(1);
    
    draw_sprite_ext(sprite_index, 0, (xoffset+xsize)-150, (yoffset+ysize) +100, 3, 3, 0, c_white, 1);

    draw_set_color(c_black);
    draw_set_valign(fa_middle);
    draw_set_halign(fa_center);

    //showing the amount of caps, and the amount of caps to win
    
    //
    draw_text_transformed(xoffset+xsize/2-135, yoffset+ysize-25, string(global.redCaps),2,2,0);
    draw_text_transformed(xoffset+xsize/2+130, yoffset+ysize-25, string(global.blueCaps),2,2,0);
    //
    
    // this next piece of code helps to resize the value of the numbers depending on the limit as not to overflow
    if (global.caplimit <= 9)
    {
        draw_text_transformed(xoffset+xsize/2-2, yoffset+ysize-15, string(global.caplimit),2,2,0);
    }
    else
    {
        if (global.caplimit > 999)
        {
            draw_sprite_ext(infinity,0,xoffset+xsize/2-3, yoffset+ysize-17, 2, 2, 0, c_white, 1);
        }
        else
        {
            draw_text(xoffset+xsize/2-2, yoffset+ysize-15, string(global.caplimit));   
        }
    }
    
    //Drawing intel status and arrows:
    
    redx=(xoffset+xsize)-465;
    redy=(yoffset+ysize)-50;
    bluex=(xoffset+xsize)-340;
    bluey=(yoffset+ysize)-50;

    if global.myself == -1 exit;
    if global.myself.object==-1{
        redsourcex=redx;    
        redsourcey=redy;
        bluesourcex=bluex;
        bluesourcey=bluey;
    }
    else{
        redsourcex=global.myself.object.x;
        redsourcey=global.myself.object.y;
        bluesourcex=redsourcex;
        bluesourcey=redsourcey;
    } 
      
    
    if instance_exists(IntelligenceRed)
    {
        reddir = point_direction(redsourcex,redsourcey,IntelligenceRed.x,IntelligenceRed.y);
        if IntelligenceRed.x==IntelligenceBaseRed.x && IntelligenceRed.y==IntelligenceBaseRed.y{
            redintelstatus=2;
        }
        else redintelstatus=0;
        if (IntelligenceRed.x!=IntelligenceBaseRed.x) {
            reddistancesitting = string(ceil(point_distance(redsourcex,redsourcey,IntelligenceRed.x,IntelligenceRed.y)/4/12)) + " ft";
            draw_set_halign(fa_left);
            draw_text_color(xoffset+243,yoffset+552,reddistancesitting,c_black,c_black,c_black,c_black,1);
            timeremainingred = string(ceil(IntelligenceRed.alarm[0]/30));
            draw_set_halign(fa_center);
            draw_text_transformed_color(xoffset+335,yoffset+500,timeremainingred,1.5,1.5,0,$0000FF,$0000FF,$0000FF,$0000FF,1);
        }
    }
    else {
        for(i=0; i<ds_list_size(global.players); i+=1) {
            player = ds_list_find_value(global.players, i);
            if(player.team == TEAM_BLUE) && player.object!= -1 {
                if player.object.intel == true {
                    reddir = point_direction(redsourcex,redsourcey,player.object.x,player.object.y);
                    
                        if (player = global.myself) {
                            reddistanceholding = string(ceil(point_distance(redsourcex, redsourcey, IntelligenceBaseBlue.x, IntelligenceBaseBlue.y)/48)) + " ft";
                            draw_set_halign(fa_left);
                            draw_text_color(xoffset+243,yoffset+552,reddistanceholding,c_black,c_black,c_black,c_black,1);
                        }
                        else {
                            reddistancemoving = string(ceil(point_distance(redsourcex,redsourcey,player.object.x,player.object.y)/48)) + " ft";
                            draw_set_halign(fa_left);
                            draw_text_color(xoffset+243,yoffset+552,reddistancemoving,c_black,c_black,c_black,c_black,1);
                        }
                }
            }
        }
        redintelstatus=1;
    }
     
    if instance_exists(IntelligenceBlue)
    {
        bluedir = point_direction(bluesourcex,bluesourcey,IntelligenceBlue.x,IntelligenceBlue.y);
        if IntelligenceBlue.x==IntelligenceBaseBlue.x && IntelligenceBlue.y==IntelligenceBaseBlue.y{
            blueintelstatus=2;
        }
        else blueintelstatus=0;
        
        //
        if (IntelligenceBlue.x!=IntelligenceBaseBlue.x) {
            bluedistancesitting = string(ceil(point_distance(bluesourcex,bluesourcey,IntelligenceBlue.x,IntelligenceBlue.y)/4/12)) + " ft";
            draw_set_halign(fa_right);
            draw_text_color(xoffset+558,yoffset+552,bluedistancesitting,c_black,c_black,c_black,c_black,1);
            timeremainingblue = ceil(IntelligenceBlue.alarm[0]/30);
            draw_set_halign(fa_center);
            draw_text_transformed_color(xoffset+460,yoffset+500,timeremainingblue,1.5,1.5,0,$EE9900,$EE9900,$EE9900,$EE9900,1);
        }
        //
    }
    else {
        for(i=0; i<ds_list_size(global.players); i+=1) {
            player = ds_list_find_value(global.players, i);
            if(player.team == TEAM_RED) && player.object!=-1{
                if player.object.intel == true {
                    bluedir = point_direction(bluesourcex,bluesourcey,player.object.x,player.object.y);
                        if (player = global.myself) {
                            bluedistanceholding = string(ceil(point_distance(bluesourcex, bluesourcey, IntelligenceBaseRed.x, IntelligenceBaseRed.y)/4/12)) + " ft";
                            draw_set_halign(fa_right);
                            draw_text_color(xoffset+558,yoffset+552,bluedistanceholding,c_black,c_black,c_black,c_black,1);
                            }
                        else {
                            bluedistancemoving = string(ceil(point_distance(bluesourcex,bluesourcey,player.object.x,player.object.y)/4/12)) + " ft";
                            draw_set_halign(fa_right);
                            draw_text_color(xoffset+558,yoffset+552,bluedistancemoving,c_black,c_black,c_black,c_black,1);
                            }
                }
            }
        }
        blueintelstatus=1;
    }

    drawred=true;
    drawblue=true;
    if global.myself.object!=-1{
        if global.myself.team==TEAM_RED && global.myself.object.intel==true drawblue=false;
        if global.myself.team==TEAM_BLUE && global.myself.object.intel==true drawred=false;
    }
    if drawred==true draw_sprite_ext(IntelArrowS, 0, redx, redy, 3, 3, reddir, c_white, 1);
    if drawblue==true draw_sprite_ext(IntelArrowS, 1, bluex, bluey, 3, 3, bluedir, c_white, 1);
    
    draw_sprite_ext(IntelStatusS, redintelstatus, redx, redy, 2, 2, 0, c_white, 1);
    draw_sprite_ext(IntelStatusS, blueintelstatus, bluex, bluey, 2, 2, 0, c_white, 1);

//timer
if instance_exists(WinBanner) exit;
draw_set_color(c_white);
draw_set_halign(fa_center);
draw_set_valign(fa_center);

if global.myself != -1 {
    if global.myself.team == TEAM_RED teamoffset=0;
    else if global.myself.team == TEAM_BLUE teamoffset=1;
}
if overtime == 1 {
    draw_set_halign(fa_center);
    draw_sprite_ext(TimerHudS,2+teamoffset,xoffset+xsize/2,yoffset+30,3,3,0,c_white,1);
    draw_text(xoffset+xsize/2,yoffset+30,"OVERTIME");
}
else{
    draw_set_halign(fa_right);
    draw_sprite_ext(TimerHudS,teamoffset,xoffset+xsize/2,yoffset+30,3,3,0,c_white,1);
    draw_sprite_ext(TimerS,floor(timer/timeLimit*12),xoffset+xsize/2+39,yoffset+30,3,3,0,c_white,1);
    minutes=floor(timer/1800);
    secondcounter=timer-minutes*1800;
    seconds=floor(secondcounter/30);    
    draw_text_transformed(xoffset+xsize/2-10,yoffset+32,string(minutes),1.5,1.5,0);
    draw_text_transformed(xoffset+xsize/2,yoffset+32,":",1.5,1.5,0);
    if seconds >= 10 draw_text_transformed(xoffset+xsize/2+20,yoffset+32,string(seconds),1.5,1.5,0);
    else if seconds < 10 draw_text_transformed(xoffset+xsize/2+20,yoffset+32,"0"+string(seconds),1.5,1.5,0);
}');

object_event_clear(GeneratorHUD,ev_draw,0);
object_event_add(GeneratorHUD,ev_draw,0,'var xoffset, yoffset, xsize, ysize;
xoffset = view_xview[0];
yoffset = view_yview[0];
xsize = view_wview[0];
ysize = view_hview[0];
barcolor=make_color_rgb(217,217,183);
draw_set_alpha(1);

draw_sprite_ext(GeneratorHUDS,0,xoffset+xsize/2,yoffset+550,2,2,0,c_white,1);
if instance_exists(GeneratorRed) {
    //
    draw_sprite_ext(GeneratorRedS,GeneratorRed.image_index,xoffset+xsize/2-50,yoffset+550,1,1,0,c_white,1);
    draw_healthbar(xoffset+xsize/2-77, yoffset+530, xoffset+xsize/2-25, yoffset+538,GeneratorRed.hp*100/GeneratorRed.maxHP,c_black,barcolor,barcolor,0,true,true);
    draw_set_alpha(0.25);
    draw_set_halign(fa_center);
    draw_set_valign(fa_center);
    draw_rectangle_color(xoffset+xsize/2-77, yoffset+538, xoffset+xsize/2-25, yoffset+552, c_black, c_black, c_black, c_black, false);
    draw_text_transformed_color(xoffset+xsize/2-51,yoffset+546,string(ceil(GeneratorRed.hp)) + "HP", 1, 1, 0, c_white, c_white, c_white, c_white, 1);
    draw_set_alpha(1);
    //
}
if instance_exists(GeneratorBlue) {
    //
    draw_sprite_ext(GeneratorBlueS,GeneratorBlue.image_index,xoffset+xsize/2+50,yoffset+550,1,1,0,c_white,1);
    draw_healthbar(xoffset+xsize/2+23, yoffset+530, xoffset+xsize/2+75, yoffset+538,GeneratorBlue.hp*100/GeneratorBlue.maxHP,c_black,barcolor,barcolor,0,true,true);
    draw_set_alpha(0.25);
    draw_set_halign(fa_center);
    draw_set_valign(fa_center);
    draw_rectangle_color(xoffset+xsize/2+23, yoffset+538, xoffset+xsize/2+75, yoffset+552, c_black, c_black, c_black, c_black, false);
    draw_text_transformed_color(xoffset+xsize/2+49,yoffset+546,string(ceil(GeneratorBlue.hp)) + "HP", 1, 1, 0, c_white, c_white, c_white, c_white, 1);
    draw_set_alpha(1);
    //
}

//timer
draw_set_color(c_white);
if global.myself != -1 {
    if global.myself.team == TEAM_RED teamoffset=0;
    else if global.myself.team == TEAM_BLUE teamoffset=1;
}

if instance_exists(WinBanner) exit;

draw_set_color(c_white);
draw_set_valign(fa_center);
draw_set_halign(fa_right);
draw_sprite_ext(TimerHudS,teamoffset,xoffset+xsize/2,yoffset+30,3,3,0,c_white,1);
draw_sprite_ext(TimerS,floor(timer/timeLimit*12),xoffset+xsize/2+39,yoffset+30,3,3,0,c_white,1);
minutes=floor(timer/1800);
secondcounter=timer-minutes*1800;
seconds=floor(secondcounter/30);    
draw_text_transformed(xoffset+xsize/2-10,yoffset+32,string(minutes),1.5,1.5,0);
draw_text_transformed(xoffset+xsize/2,yoffset+32,":",1.5,1.5,0);
if seconds >= 10 draw_text_transformed(xoffset+xsize/2+20,yoffset+32,string(seconds),1.5,1.5,0);
else if seconds < 10 draw_text_transformed(xoffset+xsize/2+20,yoffset+32,"0"+string(seconds),1.5,1.5,0);');

object_event_clear(DeathCam,ev_draw,0);
object_event_add(DeathCam,ev_draw,0,'    xoffset = view_xview[0];
    yoffset = view_yview[0];
    xsize = view_wview[0];
    ysize = view_hview[0];
    
if DeathCamS==-1 exit;

if zooming==true{
    if zoom < 2 zoom += 0.1;
}
draw_sprite_ext(DeathCamS,0,view_xview+400,view_yview+300,zoom,zoom,0,c_white,1);
draw_rectangle_color(view_xview,view_yview,view_xview+800,view_yview+100,c_black,c_black,c_black,c_black,0);
draw_rectangle_color(view_xview,view_yview+500,view_xview+800,view_yview+600,c_black,c_black,c_black,c_black,0);
draw_set_halign(fa_center);
draw_set_valign(fa_center);
if team == TEAM_RED draw_set_color(c_blue);
else draw_set_color(c_red);


draw_text_transformed(view_xview+400,view_yview+30, killmessage,2,2,0);
draw_text_transformed(view_xview+400,view_yview+60, name,2,2,0);
if maxHp != 0 {
    if killedby.object!=-1  {
        draw_healthbar(xoffset+400-18, yoffset+550-18, xoffset+400+18, yoffset+550+18, hp*100/maxHp,c_black,c_red,c_green,3,true,false);
        draw_sprite_ext(DeathCamHealthBarS,0,xoffset+400, yoffset+550,2,2,0,c_white,1);
    //
    var hpText,hpColor;
    hpText = string(ceil(max(hp,0)));
    if (hp > (maxHp/3.5)) hpColor = c_white;
    else hpColor = c_red;
    draw_text_color(xoffset+400,yoffset+550,hpText,hpColor,hpColor,hpColor,hpColor,1);
    //
    }
}');

object_event_clear(UberHud,ev_draw,0);
object_event_add(UberHud,ev_draw,0,'    if global.myself.object = -1 || global.myself.class!=CLASS_MEDIC exit;
    
    xoffset = view_xview[0];
    yoffset = view_yview[0];
    if global.myself.team == TEAM_BLUE uberoffset=1;
    else uberoffset=0;
    
    draw_set_valign(fa_center);
    draw_set_halign(fa_center);
    draw_set_alpha(1);

    var myMedigun;
    myMedigun=-1;
    with(Medigun) {
        if(ownerPlayer == global.myself) myMedigun=id;
    }
    /*if(myMedigun != -1) {
        draw_healthbar(xoffset+665, yoffset+500, xoffset+785, yoffset+532,myMedigun.uberCharge*100/2000,c_black,c_white,c_white,0,true,true);
        draw_sprite_ext(UberHudS,uberoffset,xoffset+720,yoffset+515,2,2,0,c_white,1);
        draw_text_color(xoffset+730,yoffset+510,"SUPERBURST",c_white,c_white,c_white,c_white,1);
    }*/
    
    //
    var uberPercent;
    uberPercent = string(floor(myMedigun.uberCharge*100/2000)) + "%";
    if(myMedigun != -1) {
        draw_healthbar(xoffset+629, yoffset+500, xoffset+785, yoffset+532,myMedigun.uberCharge*100/2000,c_black,c_white,c_white,0,true,true);
        draw_sprite_ext(UberHudS,uberoffset,xoffset+720,yoffset+515,2,2,0,c_white,1);
        draw_set_halign(fa_left);
        draw_text_color(xoffset+648,yoffset+510,"SUPERBURST: " + string(uberPercent),c_white,c_white,c_white,c_white,1);
    }
    //');

object_event_clear(PlayerControl,ev_step,ev_step_end);
object_event_add(PlayerControl,ev_step,ev_step_end,'if(global.myself.object == -1) exit;
/*if (global.isVindicatorServer && !instance_exists(ChatBox) && !instance_exists(Console)){
 instance_create(0,0,ChatBox);
 global.disable = true;
}*/
if object_is_ancestor(global.myself.object.object_index, Sniper) && global.myself.object.zoomed == 1 {
    var relxmouse, relymouse;
    relxmouse = min(max(window_views_mouse_get_x()-view_xview[0], 0), view_wview);
    relymouse = min(max(window_views_mouse_get_y()-view_yview[0], 0), view_hview);
        
    view_xview[0] = global.myself.object.x+relxmouse-view_wview[0];
    view_yview[0] = global.myself.object.y+relymouse-view_hview[0];
} else {
    view_xview[0] = global.myself.object.x-view_wview[0]/2;
    view_yview[0] = global.myself.object.y-view_hview[0]/2;
}
    
//AFK Check
afktimer-=1;
if(afktimer<=0) && global.myself.object.afk == false{
    global.myself.object.afk = true;
    if !instance_exists(TeamSelectController) instance_create(0,0,TeamSelectController);
    with(TeamSelectController) afk=true;
}
   
if global.myself.class == CLASS_ENGINEER {
    // Sentry HUD
    if (global.myself.sentry != -1) && !instance_exists(SentryHealthHud) instance_create(0,0,SentryHealthHud);
    // Metal HUD
    if global.myself.class == CLASS_ENGINEER && !instance_exists(NutsNBoltsHud) instance_create(0,0,NutsNBoltsHud);
}

// Sticky HUD. Because real men let computers count for them.
else if (global.myself.class == CLASS_DEMOMAN) && !instance_exists(StickyCounter) instance_create(0,0,StickyCounter);
  
else if global.myself.class == CLASS_MEDIC {
    //Uber HUD
    if !instance_exists(UberHud) instance_create(0,0,UberHud);
    //Healing Hud
    if !instance_exists(HealingHud) && global.showHealing = 1 instance_create(0,0,HealingHud);
    //Medic Radar
    if global.medicRadar == 1 && !instance_exists(MedicRadar) instance_create(0,0,MedicRadar);
}
        
// Health HUD
if  !instance_exists(HealthHud) instance_create(0,0,HealthHud);

// Healed HUD
if !instance_exists(HealedHud) && global.showHealer = 1 instance_create(0,0,HealedHud);');

global.watchForInput = object_add();
object_set_persistent(global.watchForInput, true);
ini_open("controls.gg2");
global.superburst = ini_read_real("Controls", "superburst", ord("R"));
global.uparrow = ini_read_real("Controls", "uparrow", vk_up);
global.downarrow = ini_read_real("Controls", "downarrow", vk_down);
global.leftarrow = ini_read_real("Controls", "leftarrow", vk_left);
global.rightarrow = ini_read_real("Controls", "rightarrow", vk_right);
global.closeChat = ini_read_real("Controls", "closeChat", ord("I"));
ini_close();

object_event_add(global.watchForInput,ev_step,0,'
if instance_exists(InGameMenuController) || instance_exists(OptionsController) ||
    instance_exists(ControlsController) || instance_exists(PlayerController) ||
    instance_exists(Console) || instance_exists(ClickMenu) || instance_exists(SubMenu) ||
    (instance_exists(ChatBox) && !global.disable) || instance_exists(MapController) exit;
if instance_exists(TeamSelectController) || instance_exists(ClassSelectController)
    menuOpen = true;
    else menuOpen = false;
if keyboard_check_pressed(global.closeChat) {
if instance_exists(ChatBox) with(ChatBox) instance_destroy();
else if (global.isHost || global.isVindicatorServer) && !instance_exists(Console) instance_create(0,0,ChatBox);
}
if keyboard_check_released(ord(global.allChat)) {
   if (global.isHost || global.isVindicatorServer) && !instance_exists(ChatBox) && !instance_exists(Console) instance_create(0,0,ChatBox);
}
if global.myself.object != -1 {
if keyboard_check_pressed(global.superburst) &&  menuOpen == false {
clearbuffer(global.sendBuffer);
writebyte(CHAT_BUBBLE,global.sendBuffer);
writebyte(46,global.sendBuffer);
sendmessage(global.serverSocket, 0, 0, global.sendBuffer);
}
if keyboard_check_pressed(global.uparrow) &&  menuOpen == false {
clearbuffer(global.sendBuffer);
writebyte(CHAT_BUBBLE,global.sendBuffer);
writebyte(40,global.sendBuffer);
sendmessage(global.serverSocket, 0, 0, global.sendBuffer);
}
if keyboard_check_pressed(global.downarrow) &&  menuOpen == false {
clearbuffer(global.sendBuffer);
writebyte(CHAT_BUBBLE,global.sendBuffer);
writebyte(39,global.sendBuffer);
sendmessage(global.serverSocket, 0, 0, global.sendBuffer);
}
if keyboard_check_pressed(global.leftarrow) &&  menuOpen == false {
clearbuffer(global.sendBuffer);
writebyte(CHAT_BUBBLE,global.sendBuffer);
writebyte(37,global.sendBuffer);
sendmessage(global.serverSocket, 0, 0, global.sendBuffer);
}
if keyboard_check_pressed(global.rightarrow) &&  menuOpen == false {
clearbuffer(global.sendBuffer);
writebyte(CHAT_BUBBLE,global.sendBuffer);
writebyte(38,global.sendBuffer);
sendmessage(global.serverSocket, 0, 0, global.sendBuffer);
}
}
');
}

instance_create(0,0,global.watchForInput);