From 0ce227153e717f178f5ad0f146e0da3a04ee526d Mon Sep 17 00:00:00 2001 From: Tony <97451137+TonybynMp4@users.noreply.github.com> Date: Wed, 18 Oct 2023 01:24:26 +0200 Subject: [PATCH] fix DOM manipulation & exports (#8) --- client/main.lua | 8 ++++---- config.lua | 1 + html/main.js | 15 +++++++++------ 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/client/main.lua b/client/main.lua index b0d2561..ffe6892 100644 --- a/client/main.lua +++ b/client/main.lua @@ -113,7 +113,7 @@ local function fight(ped) if CheckJob(Config.Events.fight.jobwhitelist, QBX.PlayerData.job) and QBX.PlayerData.job.onduty then return end fightAntiSpam = true - exports['qbx-dispatch']:Fight() + exports.qbx_dispatch:Fight() SetTimeout(30 * 1000, function() -- Wait 30 seconds to avoid spam. fightAntiSpam = false end) @@ -129,9 +129,9 @@ local function shotfired(ped) shotsfiredAntiSpam = true if cache.vehicle then - exports['qbx-dispatch']:DriveBy() + exports.qbx_dispatch:DriveBy() else - exports['qbx-dispatch']:Shooting() + exports.qbx_dispatch:Shooting() end SetTimeout(30 * 1000, function() -- Wait 30 seconds to avoid spam. shotsfiredAntiSpam = false @@ -195,7 +195,7 @@ RegisterNetEvent('qbx-dispatch:client:AddCall', function(Data, CallId) if not Data.coords then return end if Data.speed then Data.speed = (Config.UseMPH and math.ceil(Data.speed * 2.236936) .. " Mph") or (math.ceil(Data.speed * 3.6) .. " Km/h") end Data.distance = math.round(#(GetEntityCoords(cache.ped) - Data.coords)) - + SendNUIMessage({ type = "AddCall", id = CallId, diff --git a/config.lua b/config.lua index b6e523f..e873881 100644 --- a/config.lua +++ b/config.lua @@ -24,6 +24,7 @@ Config.AllowAnonCalls = true -- Requires UseNpwd = true, Allow anonymous Texts t Config.UseMPH = false -- Use MPH instead of KMH +-- These need to be tested and might spam the dispatch Config.Events = { fight = { enabled = true, diff --git a/html/main.js b/html/main.js index 557a8f9..60d24ec 100644 --- a/html/main.js +++ b/html/main.js @@ -39,8 +39,8 @@ function NewCall(Id, length, data) {
${data.title}
-
${locale('justnow')}
-
${locale('distance', {distance: data.distance})}
+
${locale('justnow')}
+
${locale('distance', {distance: data.distance})}
` if (data.location || data.heading) { @@ -141,10 +141,13 @@ function NewCall(Id, length, data) { UpdateCalls(); setTimeout(() => { - document.getElementById(Id).classList.add("removing"); + const call = document.getElementById(Id); + if (!call) return; + call.classList.add("removing"); setTimeout(() => { - document.getElementById(Id).remove(); + if (!call) return; + call.remove(); UpdateCalls(); }, 1500); }, length); @@ -153,7 +156,7 @@ function NewCall(Id, length, data) { function UpdateCalls() { const calls = document.getElementsByClassName('dispatch-call') if (calls.length == 0) return; - Object.keys(calls).forEach(function(call, index) { + Object.values(calls).forEach(function(call, index) { if (index == 0) return; const callButtons = call.getElementsByClassName('call-buttons')[0]; if (callButtons) { @@ -177,7 +180,7 @@ function RemoveCall() { const calls = document.getElementsByClassName('dispatch-call') if (calls.length == 0) return; if (calls[0].classList.contains("animate__slideOutRight")) return; - calls[0].classList.add("animate__slideOutRight"); + calls[0].classList.add("removing"); setTimeout(() => { calls[0].remove();