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;
- // 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.1';
- // Previous coordinate text length for clearing
- let prevCoordTextLength = 0;
- // Function to draw text at position
- async function drawText(x, y, text) {
- 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) {
- for (let i = 0; i < length; i++) {
- await w.tp(x + i, y);
- await w.typeChar(' ', 1);
- await wait(typingCooldown);
- }
- }
- // Function to update coordinate display
- async function updateCoordDisplay() {
- const 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);
- 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.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)
- async function clearSquare() {
- await w.tp(squareX, squareY);
- 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++) {
- await w.tp(oldChatX + i, oldChatY);
- await w.typeChar(' ', 1);
- await wait(typingCooldown);
- }
- }
- }
- // 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
- 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;
- }
- return false;
- }
- // Check if square brackets are missing and redraw if needed
- async function checkSquare() {
- if (!isRunning) return;
- try {
- let leftBracket = await w.getCharInfoXY(squareX, squareY);
- let rightBracket = await w.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 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 w.getCharInfoXY(x, y);
- // Skip if already space or null
- if (!charInfo || charInfo.char === ' ') {
- continue;
- }
- 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...');
- for (let y = startY; y <= endY; y++) {
- for (let x = startX; x <= endX; x++) {
- try {
- let charInfo = await w.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 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 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
Add Comment
Please, Sign In to add comment