JustPaste.it

UI.AddSliderInt("", 0, 0);
UI.AddLabel("< KittenPopo's HvH Bot >");
UI.AddLabel("NOTE: If your FPS is too low,");
UI.AddLabel("use a lower collision resolution.");
UI.AddCheckbox("Enable Bot");
UI.AddCheckbox("Auto Team-Switch");
UI.AddCheckbox("Shared Chat Debug");
UI.AddCheckbox("Always Scope");
UI.AddCheckbox("Render Collision Circle");
UI.AddSliderInt("Collision Height", 10, 80);
UI.AddSliderInt("Collision Scan Range", 50, 200);
UI.AddSliderInt("Collision Resolution", 10, 50);
UI.AddSliderInt("Collision Edge Safety", 0, 8);
UI.AddSliderInt("Collision Verticals", 0, 30);
UI.AddSliderInt("Movement Update Rate", 1, 10);
UI.AddCheckbox("Rotate Collision Circle");
UI.AddCheckbox("Kill Messages");
UI.AddCheckbox("Death Messages");

UI.AddSliderInt("", 0, 0);

 

/*
https://www.youtube.com/watch?v=dQw4w9WgXcQ

Watch this video to see how the script works in more detail, and how to go extremely positive on hvh servers with the config linked in the description
*/ 


function getVal(name) {
    return UI.GetValue("Misc", "JAVASCRIPT", "Script items", name);
}

function degreesToRadians(degress)
{
    return degress * Math.PI / 180.0;
}

function angle_to_vec(pitch, yaw)
{
    var p = degreesToRadians(pitch);
    var y = degreesToRadians(yaw)
    var sin_p = Math.sin(p);
    var cos_p = Math.cos(p);
    var sin_y = Math.sin(y);
    var cos_y = Math.cos(y);
    return [cos_p * cos_y, cos_p * sin_y, -sin_p];
}

function vec_add(vec, vec2)
{
    newVec = [
        vec[0] + vec2[0],
        vec[1] + vec2[1],
        vec[2] + vec2[2]
    ];
    return newVec;
}

function vec_scale(vec, multiplier) {
     newVec = [
        vec[0] * multiplier,
        vec[1] * multiplier,
        vec[2] * multiplier
    ];
    return newVec;  
}

function thiccLine(x1, y1, x2, y2, color) {
    Render.Line(x1+0.5, y1+0.5, x2+0.5, y2+0.5, color);
    //Render.Line(x1-0.5, y1-0.5, x2-0.5, y2-0.5, color);
    Render.Line(x1, y1, x2, y2, color);

}

function offsetVec(vec, dir, dist) {
    var x = Math.sin(dir) * dist;
    var y = Math.cos(dir) * dist;
    return vec_add(vec, [x, y, 0]);
}

function vecDist(vec1, vec2) {
    var dx = vec1[0] - vec2[0];
    var dy = vec1[1] - vec2[1];
    var dz = vec1[2] - vec2[2];
        
    return Math.sqrt(dx*dx + dy*dy + dz*dz);
}

// Globals
var endPositions = [];
var endRanges = [];
var startLoc = [0, 0, 0];
var travelLoc = [0, 0, 0];
var local = Entity.GetLocalPlayer();
var maxDistance = 10000;
var currentTask = "No task";
var isThereEnemy = false;

function closestTarget() {
    var players = Entity.GetPlayers();
    
    var ourTeamNum = Entity.GetProp(Entity.GetLocalPlayer(), "CBaseEntity", "m_iTeamNum");
    
    isThereEnemy = false;
    
    var bestIndex = -1;
    var bestDistance = maxDistance;
    for (var i = 0; i < players.length; i++) {
        if (players[i] == Entity.GetLocalPlayer()) {
            continue;
        }
        
        var fVel = Entity.GetProp(players[i], "CBasePlayer", "m_vecVelocity[0]");
        
        if (Math.abs(fVel[0]) < 1 && Math.abs(fVel[1]) < 1) continue;
        
        var teamNum = Entity.GetProp(players[i], "CBaseEntity", "m_iTeamNum");
        
        if (teamNum != ourTeamNum && Entity.IsAlive(players[i]) && !Entity.IsDormant(players[i])) {
            isThereEnemy = true;
        }
        
        var pos = Entity.GetEyePosition(players[i]);
        var distance = vecDist(pos, startLoc);
        
        if (distance < bestDistance) {
            bestDistance = distance;
            bestIndex = i;
        }
    }
    
    if (bestIndex == -1) {
        return "none";
    } else {
        return players[bestIndex];
    }
}

function findBestDirectionIndex() {
    var bestScore = 0;
    var bestIndex = 0;
    
    for (var i = 0; i < endPositions.length; i++) {
        var isFull = (endRanges[i] == 1);
        
        var score = endRanges[i];
        
        if (isFull) {
            var closest = closestTarget();
            if (closest != "none") {
                score = maxDistance - vecDist(endPositions[i], Entity.GetEyePosition(closest));
            }
        }
        
        if (score > bestScore) {
            bestScore = score;
            bestIndex = i;
        }
    }
    
    return bestIndex;
}

function draw()
{
    if (!getVal("Enable Bot")) { return; }
    if (endPositions.length < 1) { return; }
    if (!Entity.IsAlive(Entity.GetLocalPlayer())) { return; }
    
    var screen_startLoc = Render.WorldToScreen(startLoc);
    
    var best = findBestDirectionIndex();
    if (best != -1) {
        var bestPos = endPositions[best];
        var src = Render.WorldToScreen(bestPos);
        thiccLine(src[0], src[1], screen_startLoc[0], screen_startLoc[1], [0, 255, 0, 255]);
    }
    
    if (!getVal("Render Collision Circle")) { return };
    
    Render.FilledCircle(screen_startLoc[0], screen_startLoc[1], 5, [0, 100, 255, 255]);
    
    var wasLast = true;
    
    for (var i = 1; i < endPositions.length; i++) {
        var endPos = endPositions[i];
        var lastEndPos = endPositions[i-1];
        
        var screen_endLoc1 = Render.WorldToScreen(endPos);
        var screen_endLoc2 = Render.WorldToScreen(lastEndPos);
        
        var isNotCollided = (endRanges[i] == 1 && wasLast);
        
        var color = [isNotCollided ? 0 : 255, 0, 100, isNotCollided ? 100 : 255 ];
        thiccLine(screen_endLoc1[0], screen_endLoc1[1], screen_endLoc2[0], screen_endLoc2[1], color);
            
        var screen_vrt = Render.WorldToScreen([endPos[0], endPos[1], endPos[2] - getVal("Collision Verticals")]);
        thiccLine(screen_endLoc1[0], screen_endLoc1[1], screen_vrt[0], screen_vrt[1], color);

        
        wasLast = endRanges[i] == 1;
    }
}

var scanAmount = 30;
var scanDist = 120;
var pi2 = 3.1415926535 * 2;
var targetWalkAngle = 0;
var ticker = 0;
var strafe = 0;
function move() {
    
    if (!getVal("Enable Bot")) { return; }
    
    scanAmount = getVal("Collision Resolution");
    scanDist = getVal("Collision Scan Range");
    
    ticker++;
        
    if (ticker % 64 == 0) {
        // Close rule menus on HvH servers
        Cheat.ExecuteCommand("slot9");
        
        Cheat.ExecuteCommand("slot2");
        Cheat.ExecuteCommand("slot1");
    }
    
    
    if (ticker % 256 == 0) {
        if (getVal("Shared Chat Debug")) {
            var data = "LOC: ";
            var dataAdded = true;
            var enemies = Entity.GetEnemies();
            
            for (var i = 0; i < enemies.length; i++) {
                if (Entity.IsDormant(enemies[i])) {
                    continue;
                }
                
                dataAdded = true;
                
                var str = "(" + i + ": " + Entity.GetEyePosition(enemies[i]) + ")";
                
                if (i == 0) {
                    data += "|";
                }
                
                data += str;
            }
        
            if (dataAdded) {
                Cheat.ExecuteCommand("say " + data);
            }
        }
    }
    
    // Clear end positions & ranges
    endPositions = [];
    endRanges = [];
    
    local = Entity.GetLocalPlayer();
    
    // Recalculate start positions
    startLoc = Entity.GetProp(local, "CBasePlayer", "m_vecOrigin");
    startLoc[2] += getVal("Collision Height");
    
    // Recalculate end positions
    var scanDiv = pi2 / scanAmount;
    for (var scan = 0; scan <= scanAmount; scan++) {
        var angle = scan * scanDiv;
        
        if (getVal("Rotate Collision Circle")) {
            angle += Globals.Curtime();
        }
        
        // Move this down a little bit
        var traceEndPos = offsetVec([startLoc[0], startLoc[1], startLoc[2] - getVal("Collision Verticals")], angle, scanDist); 
        
        var edgeSafety = getVal("Collision Edge Safety")/10;
        var traceEndPos_a1 = offsetVec(startLoc, angle - edgeSafety, scanDist); 
        var traceEndPos_a2 = offsetVec(startLoc, angle + edgeSafety, scanDist); 
        
        var f1 = Trace.Line(local, startLoc, traceEndPos)[1];
        var f2 = Trace.Line(local, startLoc, traceEndPos_a1)[1];
        var f3 = Trace.Line(local, startLoc, traceEndPos_a2)[1];
        
        var fraction = Math.min(Math.min(f1, f2), f3);
        endRanges.push(fraction);    
        endPositions.push(offsetVec(startLoc, angle, scanDist * fraction));
    }

    if (Math.random() > 1 - getVal("Movement Update Rate")/10) {
        var bestIndex = findBestDirectionIndex();
        var offset = vec_add(endPositions[bestIndex], vec_scale(startLoc, -1));
        targetWalkAngle = Math.atan2(offset[1], offset[0]) * ( 360 / pi2);
        
        if (Math.random() > 0.5) {
            strafe = 200;
        } else {
            strafe = -200;
        }
    }
    
    if (getVal("Rotate Collision Circle")) {
        targetWalkAngle += 0.1;
    }
    
    if (targetWalkAngle > 180) {
        targetWalkAngle -= 360;
    }
    
    var viewAngles = Local.GetViewAngles();
    
    var walkAngle = viewAngles[1] - targetWalkAngle;
    
    walkAngle *= (pi2 / 360);
    
    var multiplier = isThereEnemy ? 200 : 450;
    
    UserCMD.SetMovement([Math.cos(walkAngle)*multiplier, Math.sin(walkAngle)*multiplier, 0]);
    
    // Autoscope
    if (getVal("Always Scope")) {
        if (Entity.GetProp(local, "CCSPlayer", "m_bIsScoped") == (isThereEnemy ? 0 : 1)) {
            var buttons = UserCMD.GetButtons();
            UserCMD.SetButtons(buttons | (1 << 11));
        }
    }
}

function rand(array) {
    return array[Math.floor(Math.random() * array.length)];
}

var killMessages = [
    "ded ez clap",
    "ded 1",
    "1",
    "p100 moment",
    "k lol",
    "hehe",
    "hahahaha",
    "lmao bye",
    "xddd",
    "ded sorry about that",
    "gg bois",
    "hell yeah",
    "bye ded",
    "sorry ded but i gotta get kills",
    "hvh bot hittin' p",
    "why do it yourself when robots can do it for you",
    "lmao",
    "lol ok", 
    "bot hittin p",
    "robot moment",
    "beep boop bitches",
    "<3",
    "rank",
    "rank",
    "rank",
];
var dieMessages = [
    "f",
    "f",
    "ffidjuiodhugifh",
    "szzvxfijsidass",
    "F",
    "F",
    "thats an f",
    "i tried",
    "i got resolved",
    "got resolved by killer",
    "this is so sad alexa play despacito",
    "awwww man",
    "unfortunate",
    "i has the bad",
    "k",
    "killer why",
    "killer is too p",
    "killer stop",
    "killer wtf",
    "k bet",
    "smh",
    ":(",
    ":/",
    "my stupid autodirection",
    "bruh",
    "bro wtf",
    "dude killer wtf",
    "killer can you maybe not",
    "killer can you not",
    "giv sket",
    "rank",
    "rank",
    "rank",
    "killer what cheat u got",
    "killer what u using",
    "killer giv invite",
    
];

function debugChat(msg) {
    Cheat.ExecuteCommand("say [BOT]: " + msg);
}

function onDie() {
    var isDeath = Entity.GetEntityFromUserID(Event.GetInt("userid")) == Entity.GetLocalPlayer();
    var isKill = Entity.GetEntityFromUserID(Event.GetInt("attacker")) == Entity.GetLocalPlayer();

    if (getVal("Auto Team-Switch") && !Entity.IsAlive(Entity.GetLocalPlayer())) {
        Cheat.ExecuteCommand("jointeam " + (Math.random() > 0.5 ? "3 2" : "2 3"));
    }
    
    if (isDeath) {
        if (getVal("Death Messages")) {
            var message = rand(dieMessages);
            var name = Entity.GetName(Entity.GetEntityFromUserID(Event.GetInt("attacker")));
            debugChat("Died to " + name);
            
            //Cheat.ExecuteCommand("say " + message.replace("killer", name.toLowerCase()));
        }
    }
    
    if (isKill && !isDeath && getVal("Kill Messages")) {
        var message = rand(killMessages);
        var name = Entity.GetName(Entity.GetEntityFromUserID(Event.GetInt("userid")));
        //Cheat.ExecuteCommand("say " + message.replace("ded", name.toLowerCase()));
        
        debugChat("Killed " + name);
    }
    
}

Cheat.RegisterCallback("Draw", "draw");
Cheat.RegisterCallback("CreateMove", "move");
Cheat.RegisterCallback("player_death", "onDie");