Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (async function() {
- const startX = -20;
- const startY = -10;
- const endX = 19;
- const endY = 9;
- const typingCooldown = 10;
- let isRunning = true;
- let chatText = '';
- let chatX = 0;
- let chatY = 0;
- let chatTimeout = null;
- const grassY = 1;
- const grassChar = '🮑';
- const dirtChar = '🮐';
- // Helper function for cooldown
- function wait(ms) {
- return new Promise(resolve => setTimeout(resolve, ms));
- }
- // Square position
- let squareX = 0;
- let squareY = 0;
- // Input values for movement (default)
- const inputx = 1;
- const inputy = 1;
- // Coordinate display position (top corner of area)
- const coordDisplayX = startX;
- const coordDisplayY = startY;
- const versionDisplayY = startY + 1;
- const versionText = 'Square Area Testing 1.0.3';
- // Previous coordinate text for checking
- let prevCoordText = '';
- let prevCoordTextLength = 0;
- // Check if position is dirt (below grass, Y negated so y > grassY)
- function isDirtPosition(y) {
- return y > grassY && y <= endY;
- }
- // Function to draw text at position
- async function drawText(x, y, text) {
- await w.changeColor(25);
- for (let i = 0; i < text.length; i++) {
- await w.tp(x + i, y);
- await w.typeChar(text[i], 1);
- await wait(typingCooldown);
- }
- }
- // Function to clear text at position
- async function clearText(x, y, length) {
- await w.changeColor(25);
- for (let i = 0; i < length; i++) {
- await w.tp(x + i, y);
- await w.typeChar(' ', 1);
- await wait(typingCooldown);
- }
- }
- // Function to draw grass line
- async function drawGrass() {
- await w.changeColor(9);
- for (let x = startX; x <= endX; x++) {
- // Skip square position on grass line
- if (squareY === grassY && (x === squareX || x === squareX + 1)) {
- continue;
- }
- await w.tp(x, grassY);
- await w.typeChar(grassChar, 1);
- await wait(typingCooldown);
- }
- await w.changeColor(25);
- }
- // Function to draw dirt (below grass, Y negated)
- async function drawDirt() {
- await w.changeColor(22);
- for (let y = grassY + 1; y <= endY; y++) {
- for (let x = startX; x <= endX; x++) {
- // Skip square position on dirt
- if (squareY === y && (x === squareX || x === squareX + 1)) {
- continue;
- }
- await w.tp(x, y);
- await w.typeChar(dirtChar, 1);
- await wait(typingCooldown);
- }
- }
- await w.changeColor(25);
- }
- // Function to update coordinate display
- async function updateCoordDisplay() {
- let coordText = 'square is at ' + squareX + ', ' + (-squareY);
- // Clear previous text if longer
- if (prevCoordTextLength > coordText.length) {
- await clearText(coordDisplayX, coordDisplayY, prevCoordTextLength);
- }
- await drawText(coordDisplayX, coordDisplayY, coordText);
- prevCoordText = coordText;
- prevCoordTextLength = coordText.length;
- }
- // Function to draw version text
- async function drawVersionText() {
- await drawText(coordDisplayX, versionDisplayY, versionText);
- }
- // Function to draw the square
- async function drawSquare() {
- await w.changeColor(25);
- await w.tp(squareX, squareY);
- await w.typeChar('[', 1);
- await wait(typingCooldown);
- await w.typeChar(']', 1);
- await wait(typingCooldown);
- }
- // Function to clear the square (replace with spaces, grass, or dirt)
- async function clearSquare() {
- let oldSquareX = squareX;
- let oldSquareY = squareY;
- if (oldSquareY === grassY) {
- // Redraw grass where square was
- await w.changeColor(9);
- await w.tp(oldSquareX, oldSquareY);
- await w.typeChar(grassChar, 1);
- await wait(typingCooldown);
- await w.tp(oldSquareX + 1, oldSquareY);
- await w.typeChar(grassChar, 1);
- await wait(typingCooldown);
- await w.changeColor(25);
- } else if (isDirtPosition(oldSquareY)) {
- // Redraw dirt where square was
- await w.changeColor(22);
- await w.tp(oldSquareX, oldSquareY);
- await w.typeChar(dirtChar, 1);
- await wait(typingCooldown);
- await w.tp(oldSquareX + 1, oldSquareY);
- await w.typeChar(dirtChar, 1);
- await wait(typingCooldown);
- await w.changeColor(25);
- } else {
- await w.changeColor(25);
- await w.tp(oldSquareX, oldSquareY);
- await w.typeChar(' ', 1);
- await wait(typingCooldown);
- await w.typeChar(' ', 1);
- await wait(typingCooldown);
- }
- }
- // Function to clear chat text
- async function clearChatText() {
- if (chatText.length > 0) {
- let oldChatText = chatText;
- let oldChatX = chatX;
- let oldChatY = chatY;
- chatText = '';
- for (let i = 0; i < oldChatText.length; i++) {
- let currentX = oldChatX + i;
- if (oldChatY === grassY) {
- await w.changeColor(9);
- await w.tp(currentX, oldChatY);
- await w.typeChar(grassChar, 1);
- await wait(typingCooldown);
- } else if (isDirtPosition(oldChatY)) {
- await w.changeColor(22);
- await w.tp(currentX, oldChatY);
- await w.typeChar(dirtChar, 1);
- await wait(typingCooldown);
- } else {
- await w.changeColor(25);
- await w.tp(currentX, oldChatY);
- await w.typeChar(' ', 1);
- await wait(typingCooldown);
- }
- }
- await w.changeColor(25);
- }
- }
- // Function to draw chat text
- async function drawChatText() {
- if (chatText.length > 0) {
- // Calculate middle of square (square is 2 chars wide: [ and ])
- let squareMiddle = squareX + 0.5;
- let textHalfLength = Math.floor(chatText.length / 2);
- chatX = Math.round(squareMiddle - textHalfLength);
- chatY = squareY - 1; // -1 Y above square
- await w.changeColor(25);
- for (let i = 0; i < chatText.length; i++) {
- await w.tp(chatX + i, chatY);
- await w.typeChar(chatText[i], 1);
- await wait(typingCooldown);
- }
- }
- }
- // Check if position is part of UI elements
- function isUIPosition(x, y) {
- // Square position
- if (y === squareY && (x === squareX || x === squareX + 1)) {
- return true;
- }
- // Chat text position
- if (chatText.length > 0 && y === chatY && x >= chatX && x < chatX + chatText.length) {
- return true;
- }
- // Coordinate display position
- if (y === coordDisplayY && x >= coordDisplayX && x < coordDisplayX + prevCoordTextLength) {
- return true;
- }
- // Version text position
- if (y === versionDisplayY && x >= coordDisplayX && x < coordDisplayX + versionText.length) {
- return true;
- }
- // Grass position
- if (y === grassY) {
- return true;
- }
- // Dirt position
- if (isDirtPosition(y)) {
- return true;
- }
- return false;
- }
- // Check if square brackets are missing and redraw if needed
- async function checkSquare() {
- if (!isRunning) return;
- try {
- let leftBracket = await getCharInfoXY(squareX, squareY);
- let rightBracket = await getCharInfoXY(squareX + 1, squareY);
- let needRedraw = false;
- if (!leftBracket || leftBracket.char !== '[') {
- needRedraw = true;
- }
- if (!rightBracket || rightBracket.char !== ']') {
- needRedraw = true;
- }
- if (needRedraw) {
- await drawSquare();
- console.log('Square restored at (' + squareX + ', ' + (-squareY) + ')');
- }
- } catch (e) {
- console.log('checkSquare error:', e);
- }
- }
- // Check version text and restore if needed
- async function checkVersionText() {
- if (!isRunning) return;
- try {
- for (let i = 0; i < versionText.length; i++) {
- if (!isRunning) return;
- let charInfo = await getCharInfoXY(coordDisplayX + i, versionDisplayY);
- if (!charInfo || charInfo.char !== versionText[i]) {
- await w.changeColor(25);
- await w.tp(coordDisplayX + i, versionDisplayY);
- await w.typeChar(versionText[i], 1);
- await wait(typingCooldown);
- console.log('Version char restored at (' + (coordDisplayX + i) + ', ' + (-versionDisplayY) + ')');
- }
- }
- } catch (e) {
- console.log('checkVersionText error:', e);
- }
- }
- // Check coordinate display and restore if needed
- async function checkCoordDisplay() {
- if (!isRunning) return;
- try {
- let coordText = 'square is at ' + squareX + ', ' + (-squareY);
- for (let i = 0; i < coordText.length; i++) {
- if (!isRunning) return;
- let charInfo = await getCharInfoXY(coordDisplayX + i, coordDisplayY);
- if (!charInfo || charInfo.char !== coordText[i]) {
- await w.changeColor(25);
- await w.tp(coordDisplayX + i, coordDisplayY);
- await w.typeChar(coordText[i], 1);
- await wait(typingCooldown);
- console.log('Coord char restored at (' + (coordDisplayX + i) + ', ' + (-coordDisplayY) + ')');
- }
- }
- } catch (e) {
- console.log('checkCoordDisplay error:', e);
- }
- }
- // Check grass line and restore if needed
- async function checkGrass() {
- if (!isRunning) return;
- try {
- for (let x = startX; x <= endX; x++) {
- if (!isRunning) return;
- // Skip square position
- if (squareY === grassY && (x === squareX || x === squareX + 1)) {
- continue;
- }
- // Skip chat text on grass
- if (chatText.length > 0 && chatY === grassY && x >= chatX && x < chatX + chatText.length) {
- continue;
- }
- let charInfo = await getCharInfoXY(x, grassY);
- if (!charInfo || charInfo.char !== grassChar) {
- await w.changeColor(9);
- await w.tp(x, grassY);
- await w.typeChar(grassChar, 1);
- await wait(typingCooldown);
- await w.changeColor(25);
- }
- }
- } catch (e) {
- console.log('checkGrass error:', e);
- }
- }
- // Check dirt and restore if needed
- async function checkDirt() {
- if (!isRunning) return;
- try {
- for (let y = grassY + 1; y <= endY; y++) {
- for (let x = startX; x <= endX; x++) {
- if (!isRunning) return;
- // Skip square position
- if (squareY === y && (x === squareX || x === squareX + 1)) {
- continue;
- }
- // Skip chat text on dirt
- if (chatText.length > 0 && chatY === y && x >= chatX && x < chatX + chatText.length) {
- continue;
- }
- let charInfo = await getCharInfoXY(x, y);
- if (!charInfo || charInfo.char !== dirtChar) {
- await w.changeColor(22);
- await w.tp(x, y);
- await w.typeChar(dirtChar, 1);
- await wait(typingCooldown);
- await w.changeColor(25);
- }
- }
- }
- } catch (e) {
- console.log('checkDirt error:', e);
- }
- }
- // Check area for any non-space characters and replace with space
- async function checkArea() {
- if (!isRunning) return;
- try {
- for (let y = startY; y <= endY; y++) {
- for (let x = startX; x <= endX; x++) {
- if (!isRunning) return;
- // Skip UI elements
- if (isUIPosition(x, y)) {
- continue;
- }
- let charInfo = await getCharInfoXY(x, y);
- // Skip if already space or null
- if (!charInfo || charInfo.char === ' ') {
- continue;
- }
- await w.changeColor(25);
- await w.tp(x, y);
- await w.typeChar(' ', 1);
- await wait(typingCooldown);
- console.log('Cleared foreign char at (' + x + ', ' + (-y) + ')');
- }
- }
- } catch (e) {
- console.log('checkArea error:', e);
- }
- }
- // Clear the area and fill with spaces (skip if already space)
- console.log('Clearing area...');
- await w.changeColor(25);
- for (let y = startY; y <= endY; y++) {
- for (let x = startX; x <= endX; x++) {
- try {
- let charInfo = await getCharInfoXY(x, y);
- if (charInfo && charInfo.char === ' ') {
- continue; // Skip if already space
- }
- } catch (e) {
- // If error getting char info, just clear it
- }
- await w.tp(x, y);
- await w.typeChar(' ', 1);
- await wait(typingCooldown);
- }
- }
- console.log('Area cleared!');
- // Draw grass line
- console.log('Drawing grass...');
- await drawGrass();
- console.log('Grass drawn!');
- // Draw dirt below grass
- console.log('Drawing dirt...');
- await drawDirt();
- console.log('Dirt drawn!');
- // Draw version text first
- await drawVersionText();
- console.log('Version text drawn!');
- // Initial coordinate display
- await updateCoordDisplay();
- console.log('Coord display drawn!');
- // Initial draw
- await drawSquare();
- console.log('Square drawn!');
- // Start monitoring loop
- async function monitorLoop() {
- while (isRunning) {
- await checkSquare();
- await checkVersionText();
- await checkCoordDisplay();
- await checkGrass();
- await checkDirt();
- await checkArea();
- await wait(500); // Check every 500ms
- }
- }
- // Start monitor in background
- setTimeout(function() {
- monitorLoop();
- }, 100);
- // Move right (d)
- window.moved = async function(amount) {
- if (!isRunning) return;
- let moveAmount = (typeof amount === 'number') ? amount : inputx;
- await clearChatText();
- await clearSquare();
- squareX += moveAmount;
- // Boundary check
- if (squareX > endX - 1) squareX = endX - 1;
- await drawSquare();
- await drawChatText();
- await updateCoordDisplay();
- console.log('Square position: (' + squareX + ', ' + (-squareY) + ')');
- };
- // Move left (a)
- window.movea = async function(amount) {
- if (!isRunning) return;
- let moveAmount = (typeof amount === 'number') ? amount : inputx;
- await clearChatText();
- await clearSquare();
- squareX -= moveAmount;
- // Boundary check
- if (squareX < startX) squareX = startX;
- await drawSquare();
- await drawChatText();
- await updateCoordDisplay();
- console.log('Square position: (' + squareX + ', ' + (-squareY) + ')');
- };
- // Move up (w) - negated Y
- window.movew = async function(amount) {
- if (!isRunning) return;
- let moveAmount = (typeof amount === 'number') ? amount : inputy;
- await clearChatText();
- await clearSquare();
- squareY -= moveAmount; // Negated
- // Boundary check
- if (squareY < startY) squareY = startY;
- await drawSquare();
- await drawChatText();
- await updateCoordDisplay();
- console.log('Square position: (' + squareX + ', ' + (-squareY) + ')');
- };
- // Move down (s) - negated Y
- window.moves = async function(amount) {
- if (!isRunning) return;
- let moveAmount = (typeof amount === 'number') ? amount : inputy;
- await clearChatText();
- await clearSquare();
- squareY += moveAmount; // Negated (so going down is positive)
- // Boundary check
- if (squareY > endY) squareY = endY;
- await drawSquare();
- await drawChatText();
- await updateCoordDisplay();
- console.log('Square position: (' + squareX + ', ' + (-squareY) + ')');
- };
- // Chat function - puts text above square, clears after 6 seconds
- window.chat = async function(text) {
- if (!isRunning) return;
- // Clear any existing timeout
- if (chatTimeout) {
- clearTimeout(chatTimeout);
- chatTimeout = null;
- }
- // Clear old chat text first
- await clearChatText();
- // Set new chat text
- chatText = text || '';
- if (chatText.length > 0) {
- await drawChatText();
- console.log('Chat: "' + chatText + '" at (' + chatX + ', ' + (-chatY) + ')');
- // Set timeout to clear chat after 6 seconds
- chatTimeout = setTimeout(async function() {
- if (isRunning) {
- await clearChatText();
- console.log('Chat cleared (timeout)');
- }
- }, 6000);
- } else {
- console.log('Chat cleared');
- }
- };
- // Quit function - stops script and sends message
- window.quit = async function() {
- isRunning = false;
- // Clear timeout if exists
- if (chatTimeout) {
- clearTimeout(chatTimeout);
- chatTimeout = null;
- }
- await w.chat.send('Script Shutdown');
- console.log('Script Shutdown');
- // Clean up window functions
- delete window.movew;
- delete window.movea;
- delete window.moves;
- delete window.moved;
- delete window.chat;
- delete window.quit;
- };
- console.log('Controls ready!');
- console.log('Use: movew(n), movea(n), moves(n), moved(n) - n is optional move amount');
- console.log('Use: chat("your message") - displays text above square for 6 seconds');
- console.log('Use: quit() - stops script');
- console.log('Square starts at (' + squareX + ', ' + (-squareY) + ')');
- })();
Advertisement