var target_name;

function move() {
    dt_enabled = UI.IsHotkeyActive("Rage", "GENERAL", "Exploits", "Doubletap");
    if(!dt_enabled) {
        UI.SetValue("Rage", "AUTOSNIPER", "Targeting", "Minimum damage", Number(mindmg_auto))
        target_name = null;
        return;
    }
    target = Ragebot.GetTarget();
    target_health = Entity.GetProp(target, "CBasePlayer", "m_iHealth");
    if(target_health == 0) return;
    local = Entity.GetLocalPlayer()
    result = Trace.Line(local, Entity.GetEyePosition(local), Entity.GetHitboxPosition(target, 0));
    if(!result[0] || result[1] < 0.87) {
        UI.SetValue("Rage", "AUTOSNIPER", "Targeting", "Minimum damage", Math.ceil(target_health / 3) + 2)
    } else {
        UI.SetValue("Rage", "AUTOSNIPER", "Targeting", "Minimum damage", Math.ceil(target_health / 2) + 2)
    }
    target_name = Entity.GetName(target);
}

function draw() {
    if(!UI.GetValue(this, "Watermark")) return;
    if(!World.GetMapName()) return;
    y = Render.GetScreenSize( )[1];
    color = UI.GetColor(this, "Watermark color");
    targ = target_name || "NONE";
    Render.String(10, y / 2 + 16, 0, "AUTO MIN DMG: " + UI.GetValue("Rage", "AUTOSNIPER", "Targeting", "Minimum damage").toString(), color, 4);
    Render.String(10, y / 2 - 10, 0, "DT TARGET: " + targ, color, 4);
}

function main() {
    mindmg_auto = UI.GetValue("Rage", "AUTOSNIPER", "Targeting", "Minimum damage");
    UI.AddCheckbox("Watermark");
    UI.AddColorPicker("Watermark color");
    Cheat.RegisterCallback("CreateMove", "move");
    Cheat.RegisterCallback("Draw", "draw");
}

main();