Skip to content

Commit

Permalink
refactor: copyToClipboard
Browse files Browse the repository at this point in the history
* refactor: copyToClipboard

* fix: DrawText2D
  • Loading branch information
mafewtm authored Nov 17, 2023
1 parent bb4c273 commit ad8abb7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 40 deletions.
11 changes: 5 additions & 6 deletions client/dev.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand Down
52 changes: 18 additions & 34 deletions client/vectors.lua
Original file line number Diff line number Diff line change
@@ -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)
Expand Down

0 comments on commit ad8abb7

Please sign in to comment.