Skip to content

Commit

Permalink
refactor(client): disable mouse if no options are available
Browse files Browse the repository at this point in the history
  • Loading branch information
thelindat committed May 28, 2023
1 parent 88ab161 commit c869b12
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ local function startTargeting()
state.setActive(true)

local flag = 511
local hit, entityHit, endCoords, distance, currentZone, nearbyZones, lastEntity, entityType, entityModel, hasTick
local hit, entityHit, endCoords, distance, currentZone, nearbyZones, lastEntity, entityType, entityModel, hasTick, hasTarget

while state.isActive() do
local playerCoords = GetEntityCoords(cache.ped)
Expand Down Expand Up @@ -210,20 +210,31 @@ local function startTargeting()
options = newOptions

if hidden == totalOptions then
hasTarget = false
SendNuiMessage('{"event": "leftTarget"}')
else
hasTarget = true
SendNuiMessage(json.encode({
event = 'setTarget',
options = options
}, { sort_keys=true }))
end
end
elseif lastEntity then
if debug then SetEntityDrawOutline(lastEntity, false) end
if options then table.wipe(options) end
SendNuiMessage('{"event": "leftTarget"}')
lastEntity = nil
else Wait(50) end
else
if hasTarget then
hasTarget = false
SendNuiMessage('{"event": "leftTarget"}')
end

if lastEntity then
if debug then SetEntityDrawOutline(lastEntity, false) end
if options then table.wipe(options) end

lastEntity = nil
else
Wait(50)
end
end

if toggleHotkey and IsPauseMenuActive() then
state.setActive(false)
Expand Down Expand Up @@ -251,10 +262,10 @@ local function startTargeting()
DisableControlAction(0, 1, true)
DisableControlAction(0, 2, true)

if options and IsDisabledControlJustPressed(0, 25) then
if not hasTarget or options and IsDisabledControlJustPressed(0, 25) then
state.setNuiFocus(false, false)
end
elseif options and IsDisabledControlJustPressed(0, mouseButton) then
elseif hasTarget and IsDisabledControlJustPressed(0, mouseButton) then
state.setNuiFocus(true, true)
end

Expand All @@ -265,7 +276,7 @@ local function startTargeting()
end)
end

if not next(options) then
if not hasTarget then
flag = flag == 511 and 26 or 511
end

Expand Down

0 comments on commit c869b12

Please sign in to comment.