Skip to content

Commit d904fc0

Browse files
committed
fix new callback functions
1 parent 2e58a01 commit d904fc0

File tree

1 file changed

+57
-41
lines changed

1 file changed

+57
-41
lines changed

client/main.lua

Lines changed: 57 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -434,43 +434,6 @@ local function drawLoop()
434434
if lastValidOptions then
435435
shouldUpdate = not lib.table.matches(validOpts, lastValidOptions)
436436
end
437-
438-
if shouldUpdate and validOpts then
439-
440-
local newOptions = {}
441-
442-
for j = 1, #validOpts do
443-
local opt = validOpts[j]
444-
newOptions[opt] = true
445-
activeOptions[opt] = true
446-
local resp = (opt.onActive or opt.whileActive ) and utils.getResponse(opt)
447-
448-
if opt.onActive and not activeOptions[opt] then
449-
pcall(opt.onActive, resp)
450-
end
451-
452-
453-
if opt.whileActive then
454-
CreateThread(function ()
455-
while activeOptions[opt] do
456-
pcall(opt.whileActive, resp)
457-
Wait(0)
458-
end
459-
end)
460-
end
461-
462-
end
463-
464-
for j = 1, #lastValidOptions do
465-
local opt = lastValidOptions[j]
466-
if opt.onInactive and not newOptions[opt] and activeOptions[opt] then
467-
pcall(opt.onInactive, utils.getResponse(opt))
468-
activeOptions[opt] = nil
469-
end
470-
end
471-
end
472-
473-
lastValidOptions = validOpts
474437
end
475438

476439
nearbyData[i] = {
@@ -507,9 +470,52 @@ local function drawLoop()
507470
DrawSprite(dui.instance.dictName, dui.instance.txtName, 0.0, 0.0, 1.0, 1.0, 0.0, 255, 255, 255, 255)
508471
local newClosestId = item.bone or item.offset or item.entity or item.coordId
509472
if data.shouldUpdate or lastClosestItem ~= newClosestId or lastValidCount ~= data.validCount then
473+
local newOptions = {}
474+
475+
if data.validOpts then
476+
for _, opts in pairs(data.validOpts) do
477+
for j = 1, #opts do
478+
local opt = opts[j]
479+
newOptions[opt] = true
480+
if not activeOptions[opt] then
481+
activeOptions[opt] = true
482+
local resp = (opt.onActive or opt.whileActive) and utils.getResponse(opt)
483+
484+
if opt.onActive then
485+
pcall(opt.onActive, resp)
486+
end
487+
488+
if opt.whileActive then
489+
CreateThread(function()
490+
while activeOptions[opt] do
491+
pcall(opt.whileActive, resp)
492+
Wait(0)
493+
end
494+
end)
495+
end
496+
end
497+
end
498+
end
499+
end
500+
501+
if lastValidOptions then
502+
for _, opts in pairs(lastValidOptions) do
503+
for j = 1, #opts do
504+
local opt = opts[j]
505+
506+
if opt.onInactive and not newOptions[opt] and activeOptions[opt] then
507+
pcall(opt.onInactive, utils.getResponse(opt))
508+
activeOptions[opt] = nil
509+
end
510+
end
511+
end
512+
end
513+
510514
local resetIndex = lastClosestItem ~= newClosestId
511515
lastClosestItem = newClosestId
512516
lastValidCount = data.validCount
517+
lastValidOptions = data.validOpts
518+
513519
store.current = {
514520
options = data.validOpts,
515521
entity = item.entity,
@@ -522,9 +528,9 @@ local function drawLoop()
522528
else
523529
local distance = #(playerCoords - coords)
524530
if distance < config.maxInteractDistance and item.currentScreenDistance < math.huge then
525-
local distanceRatio = math.min(0.5 + (0.25 * (distance / 10.0)), 1.0)
526-
local scale = 0.025 * distanceRatio
527-
DrawSprite('shared', 'emptydot_32', 0.0, 0.0, scale, scale * aspectRatio, 0.0, r, g, b, a)
531+
local distanceRatio = math.min(0.5 + (0.25 * (distance / 10.0)), 1.0)
532+
local scale = 0.025 * distanceRatio
533+
DrawSprite('shared', 'emptydot_32', 0.0, 0.0, scale, scale * aspectRatio, 0.0, r, g, b, a)
528534
end
529535
end
530536

@@ -533,6 +539,16 @@ local function drawLoop()
533539
end
534540

535541
if not foundValid and next(store.current) then
542+
for _, opts in pairs(store.current.options) do
543+
for j = 1, #opts do
544+
local opt = opts[j]
545+
546+
if opt.onInactive and activeOptions[opt] then
547+
pcall(opt.onInactive, utils.getResponse(opt))
548+
activeOptions[opt] = nil
549+
end
550+
end
551+
end
536552
store.current = {}
537553
lastClosestItem = nil
538554
end
@@ -592,4 +608,4 @@ RegisterNUICallback('select', function(data, cb)
592608
cb(1)
593609
end)
594610

595-
CreateThread(BuilderLoop)
611+
CreateThread(BuilderLoop)

0 commit comments

Comments
 (0)