Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (async () => {
- let endpoint = { x: -18, y: -1 };
- let startpoint = { x: 15, y: -1 };
- let nt = [];
- let isRunning = false;
- let shouldStop = false;
- // Print title FIRST at -19, 0
- await w.tp(-19, 0);
- let title = 'The Newsticker!';
- for (let i = 0; i < title.length; i++) {
- w.typeChar(title[i], 1);
- }
- await new Promise(resolve => setTimeout(resolve, 500));
- // Function to print brackets at y: -1
- async function printBrackets() {
- await w.tp(-19, -1);
- w.typeChar('[', 1);
- await w.tp(startpoint.x, -1);
- w.typeChar(']', 1);
- }
- // Print brackets on start
- await printBrackets();
- // Parse styled text with CID=idx{text}
- function parseStyledText(text) {
- let chars = [];
- let regex = /CID=(\d+)\{([^}]*)\}/g;
- let lastIndex = 0;
- let match;
- while ((match = regex.exec(text)) !== null) {
- // Add characters before the match (no color)
- for (let i = lastIndex; i < match.index; i++) {
- chars.push({ char: text[i], color: null });
- }
- // Add colored characters
- let coloredText = match[2];
- let colorIdx = parseInt(match[1]);
- for (let char of coloredText) {
- chars.push({ char: char, color: colorIdx });
- }
- lastIndex = regex.lastIndex;
- }
- // Add remaining characters (no color)
- for (let i = lastIndex; i < text.length; i++) {
- chars.push({ char: text[i], color: null });
- }
- return chars;
- }
- // Newsticker function
- async function runNewsTicker() {
- if (isRunning) return;
- isRunning = true;
- shouldStop = false;
- while (nt.length > 0 && !shouldStop) {
- for (let item of nt) {
- if (shouldStop) break;
- // Calculate ticker width
- let tickerWidth = Math.abs(startpoint.x - endpoint.x);
- // Parse text into characters with colors
- let chars = item.styled ? parseStyledText(item.text) :
- item.text.split('').map(c => ({ char: c, color: null }));
- // Add padding spaces
- let paddedChars = [];
- for (let i = 0; i < tickerWidth; i++) {
- paddedChars.push({ char: ' ', color: null });
- }
- paddedChars.push(...chars);
- for (let i = 0; i < tickerWidth; i++) {
- paddedChars.push({ char: ' ', color: null });
- }
- // Scroll through the text
- for (let i = 0; i <= paddedChars.length - tickerWidth; i++) {
- if (shouldStop) break;
- // Teleport back to start position
- await w.tp(endpoint.x, endpoint.y);
- // Get visible window
- let visibleChars = paddedChars.slice(i, i + tickerWidth);
- // Type each character with color - only change when CID is detected
- for (let charObj of visibleChars) {
- // Only change color if CID color is specified
- if (charObj.color !== null) {
- w.changeColor(charObj.color);
- }
- w.typeChar(charObj.char, 1);
- }
- // 0.4s cooldown between frames
- await new Promise(resolve => setTimeout(resolve, 400));
- }
- }
- }
- isRunning = false;
- }
- // Register console command
- window.newsticker = (message) => {
- if (message) {
- nt.push({ text: message, styled: false });
- runNewsTicker();
- }
- };
- // Register styled newsticker command
- window.ntstyled = (message) => {
- if (message) {
- nt.push({ text: message, styled: true });
- runNewsTicker();
- }
- };
- // Generate brackets and run newsticker
- window.ntgen = async () => {
- await printBrackets();
- runNewsTicker();
- };
- // Stop command
- window.stop = async () => {
- shouldStop = true;
- nt = [];
- // Clear the ticker area
- let tickerWidth = Math.abs(startpoint.x - endpoint.x);
- await w.tp(endpoint.x, endpoint.y);
- for (let i = 0; i < tickerWidth; i++) {
- w.typeChar(' ', 1);
- }
- // Reprint brackets
- await printBrackets();
- };
- })();
Advertisement
Add Comment
Please, Sign In to add comment