smoothretro82

Square Area Testing v1.0.3 by Diamond25

Nov 30th, 2025 (edited)
61
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.17 KB | None | 0 0
  1. (async function() {
  2. const startX = -20;
  3. const startY = -10;
  4. const endX = 19;
  5. const endY = 9;
  6.  
  7. const typingCooldown = 10;
  8. let isRunning = true;
  9. let chatText = '';
  10. let chatX = 0;
  11. let chatY = 0;
  12. let chatTimeout = null;
  13.  
  14. const grassY = 1;
  15. const grassChar = '🮑';
  16. const dirtChar = '🮐';
  17.  
  18. // Helper function for cooldown
  19. function wait(ms) {
  20. return new Promise(resolve => setTimeout(resolve, ms));
  21. }
  22.  
  23. // Square position
  24. let squareX = 0;
  25. let squareY = 0;
  26.  
  27. // Input values for movement (default)
  28. const inputx = 1;
  29. const inputy = 1;
  30.  
  31. // Coordinate display position (top corner of area)
  32. const coordDisplayX = startX;
  33. const coordDisplayY = startY;
  34. const versionDisplayY = startY + 1;
  35.  
  36. const versionText = 'Square Area Testing 1.0.3';
  37.  
  38. // Previous coordinate text for checking
  39. let prevCoordText = '';
  40. let prevCoordTextLength = 0;
  41.  
  42. // Check if position is dirt (below grass, Y negated so y > grassY)
  43. function isDirtPosition(y) {
  44. return y > grassY && y <= endY;
  45. }
  46.  
  47. // Function to draw text at position
  48. async function drawText(x, y, text) {
  49. await w.changeColor(25);
  50. for (let i = 0; i < text.length; i++) {
  51. await w.tp(x + i, y);
  52. await w.typeChar(text[i], 1);
  53. await wait(typingCooldown);
  54. }
  55. }
  56.  
  57. // Function to clear text at position
  58. async function clearText(x, y, length) {
  59. await w.changeColor(25);
  60. for (let i = 0; i < length; i++) {
  61. await w.tp(x + i, y);
  62. await w.typeChar(' ', 1);
  63. await wait(typingCooldown);
  64. }
  65. }
  66.  
  67. // Function to draw grass line
  68. async function drawGrass() {
  69. await w.changeColor(9);
  70. for (let x = startX; x <= endX; x++) {
  71. // Skip square position on grass line
  72. if (squareY === grassY && (x === squareX || x === squareX + 1)) {
  73. continue;
  74. }
  75. await w.tp(x, grassY);
  76. await w.typeChar(grassChar, 1);
  77. await wait(typingCooldown);
  78. }
  79. await w.changeColor(25);
  80. }
  81.  
  82. // Function to draw dirt (below grass, Y negated)
  83. async function drawDirt() {
  84. await w.changeColor(22);
  85. for (let y = grassY + 1; y <= endY; y++) {
  86. for (let x = startX; x <= endX; x++) {
  87. // Skip square position on dirt
  88. if (squareY === y && (x === squareX || x === squareX + 1)) {
  89. continue;
  90. }
  91. await w.tp(x, y);
  92. await w.typeChar(dirtChar, 1);
  93. await wait(typingCooldown);
  94. }
  95. }
  96. await w.changeColor(25);
  97. }
  98.  
  99. // Function to update coordinate display
  100. async function updateCoordDisplay() {
  101. let coordText = 'square is at ' + squareX + ', ' + (-squareY);
  102.  
  103. // Clear previous text if longer
  104. if (prevCoordTextLength > coordText.length) {
  105. await clearText(coordDisplayX, coordDisplayY, prevCoordTextLength);
  106. }
  107.  
  108. await drawText(coordDisplayX, coordDisplayY, coordText);
  109. prevCoordText = coordText;
  110. prevCoordTextLength = coordText.length;
  111. }
  112.  
  113. // Function to draw version text
  114. async function drawVersionText() {
  115. await drawText(coordDisplayX, versionDisplayY, versionText);
  116. }
  117.  
  118. // Function to draw the square
  119. async function drawSquare() {
  120. await w.changeColor(25);
  121. await w.tp(squareX, squareY);
  122. await w.typeChar('[', 1);
  123. await wait(typingCooldown);
  124. await w.typeChar(']', 1);
  125. await wait(typingCooldown);
  126. }
  127.  
  128. // Function to clear the square (replace with spaces, grass, or dirt)
  129. async function clearSquare() {
  130. let oldSquareX = squareX;
  131. let oldSquareY = squareY;
  132.  
  133. if (oldSquareY === grassY) {
  134. // Redraw grass where square was
  135. await w.changeColor(9);
  136. await w.tp(oldSquareX, oldSquareY);
  137. await w.typeChar(grassChar, 1);
  138. await wait(typingCooldown);
  139. await w.tp(oldSquareX + 1, oldSquareY);
  140. await w.typeChar(grassChar, 1);
  141. await wait(typingCooldown);
  142. await w.changeColor(25);
  143. } else if (isDirtPosition(oldSquareY)) {
  144. // Redraw dirt where square was
  145. await w.changeColor(22);
  146. await w.tp(oldSquareX, oldSquareY);
  147. await w.typeChar(dirtChar, 1);
  148. await wait(typingCooldown);
  149. await w.tp(oldSquareX + 1, oldSquareY);
  150. await w.typeChar(dirtChar, 1);
  151. await wait(typingCooldown);
  152. await w.changeColor(25);
  153. } else {
  154. await w.changeColor(25);
  155. await w.tp(oldSquareX, oldSquareY);
  156. await w.typeChar(' ', 1);
  157. await wait(typingCooldown);
  158. await w.typeChar(' ', 1);
  159. await wait(typingCooldown);
  160. }
  161. }
  162.  
  163. // Function to clear chat text
  164. async function clearChatText() {
  165. if (chatText.length > 0) {
  166. let oldChatText = chatText;
  167. let oldChatX = chatX;
  168. let oldChatY = chatY;
  169. chatText = '';
  170.  
  171. for (let i = 0; i < oldChatText.length; i++) {
  172. let currentX = oldChatX + i;
  173.  
  174. if (oldChatY === grassY) {
  175. await w.changeColor(9);
  176. await w.tp(currentX, oldChatY);
  177. await w.typeChar(grassChar, 1);
  178. await wait(typingCooldown);
  179. } else if (isDirtPosition(oldChatY)) {
  180. await w.changeColor(22);
  181. await w.tp(currentX, oldChatY);
  182. await w.typeChar(dirtChar, 1);
  183. await wait(typingCooldown);
  184. } else {
  185. await w.changeColor(25);
  186. await w.tp(currentX, oldChatY);
  187. await w.typeChar(' ', 1);
  188. await wait(typingCooldown);
  189. }
  190. }
  191. await w.changeColor(25);
  192. }
  193. }
  194.  
  195. // Function to draw chat text
  196. async function drawChatText() {
  197. if (chatText.length > 0) {
  198. // Calculate middle of square (square is 2 chars wide: [ and ])
  199. let squareMiddle = squareX + 0.5;
  200. let textHalfLength = Math.floor(chatText.length / 2);
  201. chatX = Math.round(squareMiddle - textHalfLength);
  202. chatY = squareY - 1; // -1 Y above square
  203.  
  204. await w.changeColor(25);
  205. for (let i = 0; i < chatText.length; i++) {
  206. await w.tp(chatX + i, chatY);
  207. await w.typeChar(chatText[i], 1);
  208. await wait(typingCooldown);
  209. }
  210. }
  211. }
  212.  
  213. // Check if position is part of UI elements
  214. function isUIPosition(x, y) {
  215. // Square position
  216. if (y === squareY && (x === squareX || x === squareX + 1)) {
  217. return true;
  218. }
  219.  
  220. // Chat text position
  221. if (chatText.length > 0 && y === chatY && x >= chatX && x < chatX + chatText.length) {
  222. return true;
  223. }
  224.  
  225. // Coordinate display position
  226. if (y === coordDisplayY && x >= coordDisplayX && x < coordDisplayX + prevCoordTextLength) {
  227. return true;
  228. }
  229.  
  230. // Version text position
  231. if (y === versionDisplayY && x >= coordDisplayX && x < coordDisplayX + versionText.length) {
  232. return true;
  233. }
  234.  
  235. // Grass position
  236. if (y === grassY) {
  237. return true;
  238. }
  239.  
  240. // Dirt position
  241. if (isDirtPosition(y)) {
  242. return true;
  243. }
  244.  
  245. return false;
  246. }
  247.  
  248. // Check if square brackets are missing and redraw if needed
  249. async function checkSquare() {
  250. if (!isRunning) return;
  251.  
  252. try {
  253. let leftBracket = await getCharInfoXY(squareX, squareY);
  254. let rightBracket = await getCharInfoXY(squareX + 1, squareY);
  255.  
  256. let needRedraw = false;
  257.  
  258. if (!leftBracket || leftBracket.char !== '[') {
  259. needRedraw = true;
  260. }
  261. if (!rightBracket || rightBracket.char !== ']') {
  262. needRedraw = true;
  263. }
  264.  
  265. if (needRedraw) {
  266. await drawSquare();
  267. console.log('Square restored at (' + squareX + ', ' + (-squareY) + ')');
  268. }
  269. } catch (e) {
  270. console.log('checkSquare error:', e);
  271. }
  272. }
  273.  
  274. // Check version text and restore if needed
  275. async function checkVersionText() {
  276. if (!isRunning) return;
  277.  
  278. try {
  279. for (let i = 0; i < versionText.length; i++) {
  280. if (!isRunning) return;
  281.  
  282. let charInfo = await getCharInfoXY(coordDisplayX + i, versionDisplayY);
  283.  
  284. if (!charInfo || charInfo.char !== versionText[i]) {
  285. await w.changeColor(25);
  286. await w.tp(coordDisplayX + i, versionDisplayY);
  287. await w.typeChar(versionText[i], 1);
  288. await wait(typingCooldown);
  289. console.log('Version char restored at (' + (coordDisplayX + i) + ', ' + (-versionDisplayY) + ')');
  290. }
  291. }
  292. } catch (e) {
  293. console.log('checkVersionText error:', e);
  294. }
  295. }
  296.  
  297. // Check coordinate display and restore if needed
  298. async function checkCoordDisplay() {
  299. if (!isRunning) return;
  300.  
  301. try {
  302. let coordText = 'square is at ' + squareX + ', ' + (-squareY);
  303.  
  304. for (let i = 0; i < coordText.length; i++) {
  305. if (!isRunning) return;
  306.  
  307. let charInfo = await getCharInfoXY(coordDisplayX + i, coordDisplayY);
  308.  
  309. if (!charInfo || charInfo.char !== coordText[i]) {
  310. await w.changeColor(25);
  311. await w.tp(coordDisplayX + i, coordDisplayY);
  312. await w.typeChar(coordText[i], 1);
  313. await wait(typingCooldown);
  314. console.log('Coord char restored at (' + (coordDisplayX + i) + ', ' + (-coordDisplayY) + ')');
  315. }
  316. }
  317. } catch (e) {
  318. console.log('checkCoordDisplay error:', e);
  319. }
  320. }
  321.  
  322. // Check grass line and restore if needed
  323. async function checkGrass() {
  324. if (!isRunning) return;
  325.  
  326. try {
  327. for (let x = startX; x <= endX; x++) {
  328. if (!isRunning) return;
  329.  
  330. // Skip square position
  331. if (squareY === grassY && (x === squareX || x === squareX + 1)) {
  332. continue;
  333. }
  334.  
  335. // Skip chat text on grass
  336. if (chatText.length > 0 && chatY === grassY && x >= chatX && x < chatX + chatText.length) {
  337. continue;
  338. }
  339.  
  340. let charInfo = await getCharInfoXY(x, grassY);
  341.  
  342. if (!charInfo || charInfo.char !== grassChar) {
  343. await w.changeColor(9);
  344. await w.tp(x, grassY);
  345. await w.typeChar(grassChar, 1);
  346. await wait(typingCooldown);
  347. await w.changeColor(25);
  348. }
  349. }
  350. } catch (e) {
  351. console.log('checkGrass error:', e);
  352. }
  353. }
  354.  
  355. // Check dirt and restore if needed
  356. async function checkDirt() {
  357. if (!isRunning) return;
  358.  
  359. try {
  360. for (let y = grassY + 1; y <= endY; y++) {
  361. for (let x = startX; x <= endX; x++) {
  362. if (!isRunning) return;
  363.  
  364. // Skip square position
  365. if (squareY === y && (x === squareX || x === squareX + 1)) {
  366. continue;
  367. }
  368.  
  369. // Skip chat text on dirt
  370. if (chatText.length > 0 && chatY === y && x >= chatX && x < chatX + chatText.length) {
  371. continue;
  372. }
  373.  
  374. let charInfo = await getCharInfoXY(x, y);
  375.  
  376. if (!charInfo || charInfo.char !== dirtChar) {
  377. await w.changeColor(22);
  378. await w.tp(x, y);
  379. await w.typeChar(dirtChar, 1);
  380. await wait(typingCooldown);
  381. await w.changeColor(25);
  382. }
  383. }
  384. }
  385. } catch (e) {
  386. console.log('checkDirt error:', e);
  387. }
  388. }
  389.  
  390. // Check area for any non-space characters and replace with space
  391. async function checkArea() {
  392. if (!isRunning) return;
  393.  
  394. try {
  395. for (let y = startY; y <= endY; y++) {
  396. for (let x = startX; x <= endX; x++) {
  397. if (!isRunning) return;
  398.  
  399. // Skip UI elements
  400. if (isUIPosition(x, y)) {
  401. continue;
  402. }
  403.  
  404. let charInfo = await getCharInfoXY(x, y);
  405.  
  406. // Skip if already space or null
  407. if (!charInfo || charInfo.char === ' ') {
  408. continue;
  409. }
  410.  
  411. await w.changeColor(25);
  412. await w.tp(x, y);
  413. await w.typeChar(' ', 1);
  414. await wait(typingCooldown);
  415. console.log('Cleared foreign char at (' + x + ', ' + (-y) + ')');
  416. }
  417. }
  418. } catch (e) {
  419. console.log('checkArea error:', e);
  420. }
  421. }
  422.  
  423. // Clear the area and fill with spaces (skip if already space)
  424. console.log('Clearing area...');
  425. await w.changeColor(25);
  426. for (let y = startY; y <= endY; y++) {
  427. for (let x = startX; x <= endX; x++) {
  428. try {
  429. let charInfo = await getCharInfoXY(x, y);
  430. if (charInfo && charInfo.char === ' ') {
  431. continue; // Skip if already space
  432. }
  433. } catch (e) {
  434. // If error getting char info, just clear it
  435. }
  436. await w.tp(x, y);
  437. await w.typeChar(' ', 1);
  438. await wait(typingCooldown);
  439. }
  440. }
  441. console.log('Area cleared!');
  442.  
  443. // Draw grass line
  444. console.log('Drawing grass...');
  445. await drawGrass();
  446. console.log('Grass drawn!');
  447.  
  448. // Draw dirt below grass
  449. console.log('Drawing dirt...');
  450. await drawDirt();
  451. console.log('Dirt drawn!');
  452.  
  453. // Draw version text first
  454. await drawVersionText();
  455. console.log('Version text drawn!');
  456.  
  457. // Initial coordinate display
  458. await updateCoordDisplay();
  459. console.log('Coord display drawn!');
  460.  
  461. // Initial draw
  462. await drawSquare();
  463. console.log('Square drawn!');
  464.  
  465. // Start monitoring loop
  466. async function monitorLoop() {
  467. while (isRunning) {
  468. await checkSquare();
  469. await checkVersionText();
  470. await checkCoordDisplay();
  471. await checkGrass();
  472. await checkDirt();
  473. await checkArea();
  474. await wait(500); // Check every 500ms
  475. }
  476. }
  477.  
  478. // Start monitor in background
  479. setTimeout(function() {
  480. monitorLoop();
  481. }, 100);
  482.  
  483. // Move right (d)
  484. window.moved = async function(amount) {
  485. if (!isRunning) return;
  486. let moveAmount = (typeof amount === 'number') ? amount : inputx;
  487. await clearChatText();
  488. await clearSquare();
  489. squareX += moveAmount;
  490. // Boundary check
  491. if (squareX > endX - 1) squareX = endX - 1;
  492. await drawSquare();
  493. await drawChatText();
  494. await updateCoordDisplay();
  495. console.log('Square position: (' + squareX + ', ' + (-squareY) + ')');
  496. };
  497.  
  498. // Move left (a)
  499. window.movea = async function(amount) {
  500. if (!isRunning) return;
  501. let moveAmount = (typeof amount === 'number') ? amount : inputx;
  502. await clearChatText();
  503. await clearSquare();
  504. squareX -= moveAmount;
  505. // Boundary check
  506. if (squareX < startX) squareX = startX;
  507. await drawSquare();
  508. await drawChatText();
  509. await updateCoordDisplay();
  510. console.log('Square position: (' + squareX + ', ' + (-squareY) + ')');
  511. };
  512.  
  513. // Move up (w) - negated Y
  514. window.movew = async function(amount) {
  515. if (!isRunning) return;
  516. let moveAmount = (typeof amount === 'number') ? amount : inputy;
  517. await clearChatText();
  518. await clearSquare();
  519. squareY -= moveAmount; // Negated
  520. // Boundary check
  521. if (squareY < startY) squareY = startY;
  522. await drawSquare();
  523. await drawChatText();
  524. await updateCoordDisplay();
  525. console.log('Square position: (' + squareX + ', ' + (-squareY) + ')');
  526. };
  527.  
  528. // Move down (s) - negated Y
  529. window.moves = async function(amount) {
  530. if (!isRunning) return;
  531. let moveAmount = (typeof amount === 'number') ? amount : inputy;
  532. await clearChatText();
  533. await clearSquare();
  534. squareY += moveAmount; // Negated (so going down is positive)
  535. // Boundary check
  536. if (squareY > endY) squareY = endY;
  537. await drawSquare();
  538. await drawChatText();
  539. await updateCoordDisplay();
  540. console.log('Square position: (' + squareX + ', ' + (-squareY) + ')');
  541. };
  542.  
  543. // Chat function - puts text above square, clears after 6 seconds
  544. window.chat = async function(text) {
  545. if (!isRunning) return;
  546.  
  547. // Clear any existing timeout
  548. if (chatTimeout) {
  549. clearTimeout(chatTimeout);
  550. chatTimeout = null;
  551. }
  552.  
  553. // Clear old chat text first
  554. await clearChatText();
  555.  
  556. // Set new chat text
  557. chatText = text || '';
  558.  
  559. if (chatText.length > 0) {
  560. await drawChatText();
  561. console.log('Chat: "' + chatText + '" at (' + chatX + ', ' + (-chatY) + ')');
  562.  
  563. // Set timeout to clear chat after 6 seconds
  564. chatTimeout = setTimeout(async function() {
  565. if (isRunning) {
  566. await clearChatText();
  567. console.log('Chat cleared (timeout)');
  568. }
  569. }, 6000);
  570. } else {
  571. console.log('Chat cleared');
  572. }
  573. };
  574.  
  575. // Quit function - stops script and sends message
  576. window.quit = async function() {
  577. isRunning = false;
  578.  
  579. // Clear timeout if exists
  580. if (chatTimeout) {
  581. clearTimeout(chatTimeout);
  582. chatTimeout = null;
  583. }
  584.  
  585. await w.chat.send('Script Shutdown');
  586. console.log('Script Shutdown');
  587.  
  588. // Clean up window functions
  589. delete window.movew;
  590. delete window.movea;
  591. delete window.moves;
  592. delete window.moved;
  593. delete window.chat;
  594. delete window.quit;
  595. };
  596.  
  597. console.log('Controls ready!');
  598. console.log('Use: movew(n), movea(n), moves(n), moved(n) - n is optional move amount');
  599. console.log('Use: chat("your message") - displays text above square for 6 seconds');
  600. console.log('Use: quit() - stops script');
  601. console.log('Square starts at (' + squareX + ', ' + (-squareY) + ')');
  602. })();
Advertisement
Comments
Add Comment
Please, Sign In to add comment