From ad8abb7c00653c8aa178d9897a0fc342ca58ee43 Mon Sep 17 00:00:00 2001 From: Matthew <22198949+MafewTM@users.noreply.github.com> Date: Fri, 17 Nov 2023 15:55:11 -0500 Subject: [PATCH] refactor: copyToClipboard * refactor: copyToClipboard * fix: DrawText2D --- client/dev.lua | 11 +++++----- client/vectors.lua | 52 ++++++++++++++++------------------------------ 2 files changed, 23 insertions(+), 40 deletions(-) diff --git a/client/dev.lua b/client/dev.lua index 9de3d3f..c87c53f 100644 --- a/client/dev.lua +++ b/client/dev.lua @@ -10,7 +10,7 @@ local options = { showCoords = not showCoords while showCoords do local coords, heading = GetEntityCoords(cache.ped), GetEntityHeading(cache.ped) - DrawText2D(string.format('~o~vector4~w~(%s, %s, %s, %s)', math.round(coords.x, 2), math.round(coords.y, 2), math.round(coords.z, 2), math.round(heading, 2)), vec2(0.5, 0.020), 1.0, 1.0, 0.5, 6, 255, 255, 255) + DrawText2D(string.format('~o~vector4~w~(%s, %s, %s, %s)', math.round(coords.x, 2), math.round(coords.y, 2), math.round(coords.z, 2), math.round(heading, 2)), vec2(1.0, 0.5), 1.0, 1.0, 0.5, 6, 255, 255, 255) Wait(0) end end, @@ -22,11 +22,10 @@ local options = { local oil, angle, body, class = GetVehicleOilLevel(cache.vehicle), GetVehicleSteeringAngle(cache.vehicle), GetVehicleBodyHealth(cache.vehicle), vehicleTypes[GetVehicleClass(cache.vehicle)] local dirt, maxSpeed, netId, hash = GetVehicleDirtLevel(cache.vehicle), GetVehicleEstimatedMaxSpeed(cache.vehicle), VehToNet(cache.vehicle), GetEntityModel(cache.vehicle) local name = GetLabelText(GetDisplayNameFromVehicleModel(hash)) - EndTextCommandDisplayText() - DrawText2D(string.format('~o~Clutch: ~w~ %s | ~o~Gear: ~w~ %s | ~o~Rpm: ~w~ %s | ~o~Temperature: ~w~ %s', math.round(clutch, 4), gear, math.round(rpm, 4), temperature), vec2(0.5, 0.075), 1.0, 1.0, 0.45, 6, 255, 255, 255) - DrawText2D(string.format('~o~Oil: ~w~ %s | ~o~Steering Angle: ~w~ %s | ~o~Body: ~w~ %s | ~o~Class: ~w~ %s', math.round(oil, 4), math.round(angle, 4), math.round(body, 4), class), vec2(0.5, 0.1), 1.0, 1.0, 0.45, 6, 255, 255, 255) - DrawText2D(string.format('~o~Dirt: ~w~ %s | ~o~Est Max Speed: ~w~ %s | ~o~Net ID: ~w~ %s | ~o~Hash: ~w~ %s', math.round(dirt, 4), math.round(maxSpeed, 4) * 3.6, netId, hash), vec2(0.5, 0.125), 1.0, 1.0, 0.45, 6, 255, 255, 255) - DrawText2D(string.format('~o~Vehicle Name: ~w~ %s', name), vec2(0.5, 0.150), 1.0, 1.0, 0.45, 6, 255, 255, 255) + DrawText2D(string.format('~o~Clutch: ~w~ %s | ~o~Gear: ~w~ %s | ~o~Rpm: ~w~ %s | ~o~Temperature: ~w~ %s', math.round(clutch, 4), gear, math.round(rpm, 4), temperature), vec2(1.0, 0.575), 1.0, 1.0, 0.45, 6, 255, 255, 255) + DrawText2D(string.format('~o~Oil: ~w~ %s | ~o~Steering Angle: ~w~ %s | ~o~Body: ~w~ %s | ~o~Class: ~w~ %s', math.round(oil, 4), math.round(angle, 4), math.round(body, 4), class), vec2(1.0, 0.600), 1.0, 1.0, 0.45, 6, 255, 255, 255) + DrawText2D(string.format('~o~Dirt: ~w~ %s | ~o~Est Max Speed: ~w~ %s | ~o~Net ID: ~w~ %s | ~o~Hash: ~w~ %s', math.round(dirt, 4), math.round(maxSpeed, 4) * 3.6, netId, hash), vec2(1.0, 0.625), 1.0, 1.0, 0.45, 6, 255, 255, 255) + DrawText2D(string.format('~o~Vehicle Name: ~w~ %s', name), vec2(1.0, 0.650), 1.0, 1.0, 0.45, 6, 255, 255, 255) Wait(0) else Wait(800) diff --git a/client/vectors.lua b/client/vectors.lua index 4085198..81fe18b 100644 --- a/client/vectors.lua +++ b/client/vectors.lua @@ -1,44 +1,28 @@ function CopyToClipboard(dataType) - if dataType == 'coords2' then - local coords = GetEntityCoords(cache.ped) - local x = math.round(coords.x, 2) - local y = math.round(coords.y, 2) + local coords = GetEntityCoords(cache.ped) + local x, y, z = math.round(coords.x, 2), math.round(coords.y, 2), math.round(coords.z, 2) + local heading = GetEntityHeading(cache.ped) + local h = math.round(heading, 2) - local string = string.format('vec2(%s, %s)', x, y) - lib.setClipboard(string) + local data + local message - exports.qbx_core:Notify(Lang:t('success.coords_copied'), 'success') + if dataType == 'coords2' then + data = string.format('vec2(%s, %s)', x, y) + message = Lang:t('success.coords_copied') elseif dataType == 'coords3' then - local coords = GetEntityCoords(cache.ped) - local x = math.round(coords.x, 2) - local y = math.round(coords.y, 2) - local z = math.round(coords.z, 2) - - local string = string.format('vec3(%s, %s, %s)', x, y, z) - lib.setClipboard(string) - - exports.qbx_core:Notify(Lang:t('success.coords_copied'), 'success') + data = string.format('vec3(%s, %s, %s)', x, y, z) + message = Lang:t('success.coords_copied') elseif dataType == 'coords4' then - local coords = GetEntityCoords(cache.ped) - local x = math.round(coords.x, 2) - local y = math.round(coords.y, 2) - local z = math.round(coords.z, 2) - local heading = GetEntityHeading(cache.ped) - local h = math.round(heading, 2) - - local string = string.format('vec4(%s, %s, %s, %s)', x, y, z, h) - lib.setClipboard(string) - - exports.qbx_core:Notify(Lang:t('success.coords_copied'), 'success') + data = string.format('vec4(%s, %s, %s, %s)', x, y, z, h) + message = Lang:t('success.coords_copied') elseif dataType == 'heading' then - local heading = GetEntityHeading(cache.ped) - local h = math.round(heading, 2) - - local string = h - lib.setClipboard(tostring(string)) - - exports.qbx_core:Notify(Lang:t('success.heading_copied'), 'success') + data = tostring(h) + message = Lang:t('success.heading_copied') end + + lib.setClipboard(data) + exports.qbx_core:Notify(message, 'success') end RegisterNetEvent('qbx_admin:client:copyToClipboard', function(dataType)