var pi = 3.141592653589793;


function distance2radius(distance){
    return distance* (pi/ 180)
}

function draw_circle_3d(x,y,z,radius1,radius,radius2,col,outline,outlinecol)
{
    var  persission=8;
    var _0xb52exc8,_0xb52exc9;radius= radius< 361&& radius|| 360;radius= radius>  -1&& radius|| 0;radius2 = radius2 + 1;
    for(rot = radius2; rot< radius + radius2 + 1; rot+= radius2 * persission){
        rot_r= distance2radius(rot);
        line_x= radius1 * Math.cos(rot_r) + x,line_y = radius1 * Math.sin(rot_r)+ y;
        var _0xb52exca = Render.WorldToScreen([line_x,line_y,z]), RendP = Render.WorldToScreen([x,y,z]);
        var _0xb52excb = Render.WorldToScreen([x, y, z]);
        if(_0xb52excb[0]!= null&& _0xb52exca[0]!= null&& _0xb52exc8!= null){
            if(outline){
                Render.Polygon([[_0xb52exca[0],_0xb52exca[1]],[_0xb52exc8,_0xb52exc9],[_0xb52excb[0],_0xb52excb[1]]],outlinecol)
            };
        Render.Line(_0xb52exca[0],_0xb52exca[1],_0xb52exc8,_0xb52exc9,col)
        };
        _0xb52exc8= _0xb52exca[0],_0xb52exc9= _0xb52exca[1]
    }
}

function draw_cool_circle_3d(x,y,z, radius, color) {
    if(UI.GetValue("Script items", "Autopeek Indicator Optimization") == 6)
    {
        draw_circle_3d(x, y, z, 20, 360, 0, color,true, [ color[0], color[1], color[2], 50])
    }
    else
    {
    for(var i = 0; i < radius; i += UI.GetValue("Script items", "Autopeek Indicator Optimization")) {
        draw_circle_3d(x, y, z, i, 360, 0, color,true, [ color[0], color[1], color[2], color[3] + 6 * UI.GetValue("Script items", "Autopeek Indicator Optimization")])
    }
    }
}

function go_to(subtractee) {
    var activeEntityKey = Entity.GetLocalPlayer();
    if (activeEntityKey == null || !Entity.IsAlive(activeEntityKey)) {
    return;
    }
    var subtractor = Entity.GetRenderOrigin(activeEntityKey);
    var _0xb52exce = Local.GetViewAngles();
    var uv2v = subtractor[0] - subtractee[0];
    var uv1v = subtractor[1] - subtractee[1];
    var _0xb52exd1 = uv2v * Math.cos(_0xb52exce[1] / 180 * pi) + uv1v * Math.sin(_0xb52exce[1] / 180 * pi);
    var _0xb52exd2 = uv1v * Math.cos(_0xb52exce[1] / 180 * pi) - uv2v * Math.sin(_0xb52exce[1] / 180 * pi);
    UserCMD.SetMovement([-_0xb52exd1 * 100, _0xb52exd2 * 100, 0]);
}

UI.AddSliderInt("", 0, 0);
UI.AddLabel("Skeet Autopeek by Karambot");
UI.AddHotkey("Autopeek");
UI.AddSliderInt("Autopeek Indicator Optimization", 1, 6);
UI.AddSliderInt("", 0, 0);
var IsSet = false;
var Pos = [0,0,0]
var ShouldMove = false;
var estimatedtime = 0;

function AutopeeekReset(){
    var Loc = Entity.GetLocalPlayer();
    var IT = Entity.GetRenderOrigin(Loc);
    if(UI.IsHotkeyActive("Misc", "JAVASCRIPT", "Script Items", "Autopeek") && !ShouldMove) { ShouldMove = true; }
}



Cheat.RegisterCallback("weapon_fire", "AutopeeekReset");





function AutoPeeek() {
    var Loc = Entity.GetLocalPlayer();       
    var IT = Entity.GetRenderOrigin(Loc);
    if(!Entity.IsAlive(Loc) || World.GetServerString() == "") {return;}
    if(ShouldMove) {
        go_to(Pos)
    
    }
    if (IT[0] > Pos[0] - 14 && IT[1] > Pos[1] - 14 && IT[0] < Pos[0] + 14 && IT[1] < Pos[1] + 14) {
        ShouldMove = false;
    }
    else if(!UI.IsHotkeyActive("Misc", "JAVASCRIPT", "Script Items", "Autopeek"))
    {
        ShouldMove = false;
    }
}


Global.RegisterCallback("CreateMove", "AutoPeeek");
function drawshit() {
    
    var Loc = Entity.GetLocalPlayer();
    if(!Entity.IsAlive(Loc) || World.GetServerString() == "") {return;}
    if(!IsSet && UI.IsHotkeyActive("Misc", "JAVASCRIPT", "Script Items", "Autopeek"))
    {
    Pos = Entity.GetRenderOrigin(Loc);
    IsSet = true
    }
    else if(!UI.IsHotkeyActive("Misc", "JAVASCRIPT", "Script Items", "Autopeek") && IsSet)
    {
        IsSet = false
    }

    var world_pos = Pos
    
    //var diffVector = Entity.GetProp(Loc, "CBasePlayer", "m_fFlags");
    //draw_circle_3d(world_pos[0], world_pos[1], world_pos[2], 40, 360, 0, [ 66, 155, 245, 20 ],true, [66, 155, 245, 20])
    if(UI.IsHotkeyActive("Misc", "JAVASCRIPT", "Script Items", "Autopeek"))
    {
    draw_cool_circle_3d(world_pos[0], world_pos[1], world_pos[2], 20, [ 66, 155, 245, 2 ])
    }
    //
    //draw_circle_3d(saved_pos[0],saved_pos[1],saved_pos[2],UI.GetValue(_0xd790[11],_0xd790[73]),360,0, [ 255,255,255,255 ],true, [255,255,255,255])
}



Global.RegisterCallback("Draw", "drawshit");


