🏠 Home 

Advanced Paper.io Bot with Food Collection

Smart bot for Paper.io that collects food, avoids threats, and grows bigger by targeting high-value items when nearby.


Install this script?
  1. // ==UserScript==
  2. // @name Advanced Paper.io Bot with Food Collection
  3. // @namespace http://tampermonkey.net/
  4. // @version 3.0
  5. // @description Smart bot for Paper.io that collects food, avoids threats, and grows bigger by targeting high-value items when nearby.
  6. // @author hunter
  7. // @match *://paper-io.com/*
  8. // @grant none
  9. // ==/UserScript==
  10. (function() {
  11. 'use strict';
  12. // Key bindings for controls
  13. const KEYS = {
  14. freeze: 'F', // Press 'F' to toggle freeze mode
  15. autoPlay: 'A' // Press 'A' to toggle auto-play mode
  16. };
  17. let freezeMode = false;
  18. let autoPlayMode = false;
  19. let intervalId;
  20. // Log status updates to the console
  21. function logStatus(message) {
  22. console.log(`[Paper.io Bot]: ${message}`);
  23. }
  24. // Simulate key presses to control the player
  25. function movePlayer(dir) {
  26. const event = new KeyboardEvent('keydown', { key: dir });
  27. document.dispatchEvent(event);
  28. }
  29. // Get all food items on the map
  30. function getFoodItems() {
  31. return Array.from(document.querySelectorAll('.food')); // Assumes food items have the class "food"
  32. }
  33. // Detect the closest or most valuable food
  34. function getClosestFood(playerBounds) {
  35. const foodItems = getFoodItems();
  36. let closestFood = null;
  37. let closestDistance = Infinity;
  38. for (let food of foodItems) {
  39. const foodBounds = food.getBoundingClientRect();
  40. // Calculate the distance between the player and the food
  41. const distance = Math.hypot(
  42. playerBounds.left - foodBounds.left,
  43. playerBounds.top - foodBounds.top
  44. );
  45. // Prioritize closer and more valuable food
  46. const value = food.dataset.value || 1; // Assume higher `data-value` means more valuable
  47. const weightedDistance = distance / value;
  48. if (weightedDistance < closestDistance) {
  49. closestDistance = weightedDistance;
  50. closestFood = food;
  51. }
  52. }
  53. return closestFood;
  54. }
  55. // Check for nearby opponents
  56. function detectThreat() {
  57. const opponents = Array.from(document.querySelectorAll('.enemy')); // Find all enemy players
  58. const player = document.querySelector('.player');
  59. if (!player || opponents.length === 0) return false;
  60. const playerBounds = player.getBoundingClientRect();
  61. for (let opponent of opponents) {
  62. const opponentBounds = opponent.getBoundingClientRect();
  63. // Check if opponent is near the player in any direction
  64. const isThreatNearby =
  65. Math.abs(opponentBounds.top - playerBounds.top) < 50 &&
  66. Math.abs(opponentBounds.left - playerBounds.left) < 50;
  67. if (isThreatNearby) {
  68. logStatus('Threat detected! Initiating evasive action...');
  69. return true;
  70. }
  71. }
  72. return false;
  73. }
  74. // Determine the safest direction to move
  75. function getSafeDirection() {
  76. const directions = ['up', 'down', 'left', 'right'];
  77. let safeDirection = directions[Math.floor(Math.random() * directions.length)];
  78. // Simple logic: Avoid edges as much as possible
  79. const player = document.querySelector('.player');
  80. if (player) {
  81. const bounds = player.getBoundingClientRect();
  82. if (bounds.top <= 50) safeDirection = 'down';
  83. else if (bounds.bottom >= window.innerHeight - 50) safeDirection = 'up';
  84. else if (bounds.left <= 50) safeDirection = 'right';
  85. else if (bounds.right >= window.innerWidth - 50) safeDirection = 'left';
  86. }
  87. return safeDirection;
  88. }
  89. // Main bot logic
  90. function startBot() {
  91. intervalId = setInterval(() => {
  92. if (!freezeMode) {
  93. const player = document.querySelector('.player');
  94. if (!player) return;
  95. const playerBounds = player.getBoundingClientRect();
  96. if (detectThreat()) {
  97. // If a threat is detected, move in the safest direction
  98. const escapeDirection = getSafeDirection();
  99. movePlayer(escapeDirection);
  100. logStatus(`Escaping to ${escapeDirection}`);
  101. } else {
  102. // Target the closest and most valuable food
  103. const closestFood = getClosestFood(playerBounds);
  104. if (closestFood) {
  105. const foodBounds = closestFood.getBoundingClientRect();
  106. const dx = foodBounds.left - playerBounds.left;
  107. const dy = foodBounds.top - playerBounds.top;
  108. if (Math.abs(dx) > Math.abs(dy)) {
  109. movePlayer(dx > 0 ? 'right' : 'left');
  110. } else {
  111. movePlayer(dy > 0 ? 'down' : 'up');
  112. }
  113. logStatus(`Moving towards food at (${foodBounds.left}, ${foodBounds.top})`);
  114. } else {
  115. // No food detected; continue expanding territory
  116. const nextDirection = getSafeDirection();
  117. movePlayer(nextDirection);
  118. logStatus(`Expanding territory by moving ${nextDirection}`);
  119. }
  120. }
  121. } else {
  122. logStatus('Freeze mode activated. No movement.');
  123. }
  124. }, 100); // Adjust speed as needed
  125. }
  126. // Stop the bot
  127. function stopBot() {
  128. clearInterval(intervalId);
  129. logStatus('Bot stopped.');
  130. }
  131. // Toggle freeze mode
  132. function toggleFreeze() {
  133. freezeMode = !freezeMode;
  134. logStatus(freezeMode ? 'Freeze mode ON' : 'Freeze mode OFF');
  135. }
  136. // Toggle auto-play mode
  137. function toggleAutoPlay() {
  138. autoPlayMode = !autoPlayMode;
  139. if (autoPlayMode) {
  140. logStatus('Auto-play mode ON');
  141. startBot();
  142. } else {
  143. logStatus('Auto-play mode OFF');
  144. stopBot();
  145. }
  146. }
  147. // Listen for user input (toggle features)
  148. document.addEventListener('keydown', (e) => {
  149. if (e.key.toUpperCase() === KEYS.freeze) toggleFreeze();
  150. if (e.key.toUpperCase() === KEYS.autoPlay) toggleAutoPlay();
  151. });
  152. // Notify user of controls
  153. logStatus(`Script loaded. Press "${KEYS.autoPlay}" to toggle Auto-Play, "${KEYS.freeze}" to toggle Freeze.`);
  154. })();