Skip to content

Commit

Permalink
feat(client/utils): extra utility exports
Browse files Browse the repository at this point in the history
Resolves #173.
  • Loading branch information
thelindat committed Feb 2, 2024
1 parent b7f3db1 commit e64ec68
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions client/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ local function getDoorFromEntity(data)
return door
end

exports('getClosestDoorId', function() return ClosestDoor?.id end)
exports('getDoorIdFromEntity', function(entityId) return getDoorFromEntity(entityId)?.doorId end) -- same as Entity(entityId).state.doorId

local function entityIsNotDoor(data)
local entity = type(data) == 'number' and data or data.entity
return not getDoorFromEntity(entity)
Expand Down Expand Up @@ -94,8 +97,8 @@ end
local isAddingDoorlock = false

RegisterNUICallback('notify', function(data, cb)
cb(1)
lib.notify({title = data})
cb(1)
lib.notify({ title = data })
end)

RegisterNUICallback('createDoor', function(data, cb)
Expand Down Expand Up @@ -143,7 +146,8 @@ RegisterNUICallback('createDoor', function(data, cb)

if hit then
---@diagnostic disable-next-line: param-type-mismatch
DrawMarker(28, coords.x, coords.y, coords.z, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.2, 0.2, 0.2, 255, 42, 24, 100, false, false, 0, true, false, false, false)
DrawMarker(28, coords.x, coords.y, coords.z, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.2, 0.2, 0.2, 255, 42, 24,
100, false, false, 0, true, false, false, false)
end

if hit and entity > 0 and GetEntityType(entity) == 3 and (doorCount == 1 or doorA ~= entity) and entityIsNotDoor(entity) then
Expand Down Expand Up @@ -182,7 +186,6 @@ RegisterNUICallback('createDoor', function(data, cb)
data.coords = tempData[1].coords
data.heading = tempData[1].heading
end

else
if data.doors then
for i = 1, 2 do
Expand Down Expand Up @@ -211,11 +214,11 @@ RegisterNUICallback('deleteDoor', function(id, cb)
end)

RegisterNUICallback('teleportToDoor', function(id, cb)
cb(1)
SetNuiFocus(false, false)
local doorCoords = doors[id].coords
if not doorCoords then return end
SetEntityCoords(cache.ped, doorCoords.x, doorCoords.y, doorCoords.z, false, false, false, false)
cb(1)
SetNuiFocus(false, false)
local doorCoords = doors[id].coords
if not doorCoords then return end
SetEntityCoords(cache.ped, doorCoords.x, doorCoords.y, doorCoords.z, false, false, false, false)
end)

RegisterNUICallback('exit', function(_, cb)
Expand Down

0 comments on commit e64ec68

Please sign in to comment.