107 | Font Size: 108 |
109 | 110 |No output logged
60 | {:else} 61 | {#each $luaOutputStore as output, i} 62 | {@html output} 63 | {/each} 64 | {/if} 65 |No history logged
70 | {:else} 71 | {#each $debugOutputStore as debug, i} 72 | {@html debug} 73 | {/each} 74 | {/if} 75 |No variables logged
80 | {:else} 81 | {#each $variablesLogStore as varLog, i} 82 | {@html varLog.html} 83 | {/each} 84 | {/if} 85 |Spawn Vehicle
137 | 142 | 143 |Teleport
169 | 174 | 175 |Kick
201 | 206 | 207 |Ban
233 | 238 | 239 |AutoRestart on Edit
192 | 198 | 199 | 200 |(events: DebugEvent
[], timer = 1000): void => { 16 | if (isEnvBrowser()) { 17 | for (const event of events) { 18 | setTimeout(() => { 19 | window.dispatchEvent( 20 | new MessageEvent("message", { 21 | data: { 22 | action: event.action, 23 | data: event.data, 24 | }, 25 | }) 26 | ); 27 | }, timer); 28 | } 29 | } 30 | }; -------------------------------------------------------------------------------- /ui/src/utils/luaHandler.ts: -------------------------------------------------------------------------------- 1 | import { SendNUI } from "./SendNUI"; 2 | import { debugOutputStore, variablesLogStore, variablesStore, luaOutputStore, variablesHTMLStore } from "../store/stores"; 3 | 4 | 5 | function getDateTime() { 6 | let date = new Date(); 7 | let hour = date.getHours(); 8 | let min = date.getMinutes(); 9 | let sec = date.getSeconds(); 10 | let time = hour + ":" + min + ":" + sec; 11 | return time; 12 | } 13 | 14 | 15 | 16 | function updateOutput(output, eventType, red) { 17 | //add a string to luaOutputStore array 18 | luaOutputStore.update((n) => { 19 | if (red) { 20 | n.push(`
[${getDateTime()}][${eventType}]: ${output}`); 21 | } else { 22 | n.push(`
[${getDateTime()}][${eventType}]: ${output}`); 23 | } 24 | return n = [...n] 25 | }); 26 | // scrollToBottom(luaOutputElement); 27 | } 28 | function updateVariables(variables) { 29 | // variablesHTMLStore.set([]); 30 | variablesLogStore.update((n) => { 31 | if (variables.length == 0) return n = [...n]; 32 | for (let i = 0; i < variables.length; i++) { 33 | let varName = variables[i].value.split(" ")[0]; 34 | if (variables[i].global) { 35 | // if (n) { 36 | // n = n.filter((item) => {item.name != varName}); 37 | // n = [...n]; 38 | // } 39 | for (let i = 0; i < n.length; i++) { 40 | if (n[i].name == varName) { 41 | n.splice(i, 1); 42 | } 43 | } 44 | // n.push({`${varName}` : `
${variables[i].value}
`}); 45 | n.push({ 46 | "name": varName, 47 | "html": `${variables[i].value}`}); 48 | // n = [...n]; 49 | } 50 | } 51 | n = [...n]; 52 | // console.log('updateVarriable', n) 53 | return n 54 | }); 55 | } 56 | 57 | function updateDebugOutput(code, eventType, source) { 58 | debugOutputStore.update((n) => { 59 | // console.log(code) 60 | let htmlString = `
[${getDateTime()}][${eventType}${eventType == "source" ? `: ${source}` : ""}]: `; 61 | htmlString = htmlString + code 62 | htmlString = htmlString + ``; 63 | n.push(htmlString); 64 | return n = [...n] 65 | }); 66 | } 67 | 68 | window.addEventListener("message", (event) => { 69 | const item = event.data; 70 | // console.log(item) 71 | if (item.action === "updateOutput") { 72 | updateOutput(item.data.output, item.data.eventType, item.data.red); 73 | } 74 | }); 75 | 76 | 77 | export class LuaHandler { 78 | 79 | ExecuteLua(lua: string, eventType: string, source: string) { 80 | let code = `(function() return (function() \n 81 | ${lua} \n 82 | end)() end)()` 83 | updateDebugOutput(lua, eventType, source); 84 | SendNUI("ExecuteLua", {code: code, eventType: eventType, source: source}); 85 | } 86 | 87 | ExecuteQuickFunction(func: object, params: Array