TheLazySquid / GimkitCheat

Scripts to cheat in various Gimkit gamemodes
74 stars 30 forks source link

Add aimbot #67

Open The-Arx opened 7 months ago

The-Arx commented 7 months ago

I wrote this aimbot script a while ago and was wondering if it intrests you at all. It assumes that everyone is moving in a straight line and is not adapted for blast ball (you would need to use the positions in the devices and check which ones are active but I don't play that game mode enough for the work to be worth it). The math could be improved but it works decently and when paired with auto answer is pretty powerful in snowbrawl. It also does not account for walls but having a key bind to quickly enable and disable it works.

const stores = parcelRequire388b('jk0d0').default; // replace me with your stores reference
function getTarget(player) {
  if (player == null) {
    return;
  }
  if(typeof player == 'string'){
    player = stores.phaser.scene.characterManager.characters.get(player);
  }
  const p = player.movement.currentPoint;
  let tx, ty;
  // if the movement is currently playing
  if (p == null||p.endTime<Date.now()) {
    // aim at position
    ({x: tx, y: ty} = player.body);
  } else {
    // find position based on distance and speed
    const {
      endX: nx, endY: ny, endTime: nt,
      startX: ox, startY: oy, startTime: ot
    } = p;
    const dt = nt - ot;
    const xVel = (nx - ox) * dt;
    const yVel = (ny - oy) * dt;
    const {x: px, y: py} = player.body;
    const {x, y} = stores.phaser.mainCharacter.body;
    const dist = Math.sqrt((x - px) ** 2 + (y - py) ** 2);
    const mult = 1 / 3600; // needs adjusting
    tx = px + xVel*dist*mult;
    ty = py + yVel*dist*mult;
  }
  return [tx,ty];
}

// this simulates a click to shoot, there is a better way to do this
// you can probably use the websockets directly
function shootAt(x, y) {
  const mouse = stores.phaser.scene.inputManager.mouse;
  mouse.worldX = x;
  mouse.worldY = y;
  [...mouse.clickListeners.values()][1](mouse);
}

function getBestTarget(maxDist=1000) {
  const {x, y} = stores.phaser.mainCharacter.body;
  let bestDist = maxDist;
  let bestTarget = null;
  let myTeam = stores.phaser.mainCharacter.teamId;
  if (myTeam == "__NO_TEAM_ID") {
    myTeam = null;
  }
  for(let c of stores.phaser.scene.characterManager.characters.values()){
    // only target other players on different teams who are alive (and sentries)
    if(c.isMain || c.spawnImmunity.active || c.scale.respawningScale == 0 || c.teamId == myTeam) {
      continue;
    }
    let t = getTarget(c);
    let dist = Math.sqrt((x - t[0])**2 + (y - t[1])**2);
    if(dist < bestDist) {
      bestDist = dist;
      bestTarget = t;
    }
  }
  return bestTarget;
}

It can be called like this:

let target = getBestTarget();
if(target != null) {
  shootAt(...target);
}
TheLazySquid commented 7 months ago

This is super interesting! I've avoided an aimbot because I assumed it would suck and people would get mad, but this looks pretty good from some testing. I'll do my best to add this soon.