Skip to content

Commit

Permalink
Merge pull request esx-framework#834 from lexinor/patch-2
Browse files Browse the repository at this point in the history
refactor(esx_service/server/main.lua): Added some new globalstate stuff and fixed stuff
  • Loading branch information
Benzo00 authored Jan 18, 2023
2 parents b09776b + 1d06e24 commit 3589976
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions [esx_addons]/esx_service/server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ RegisterServerEvent('esx_service:activateService')
AddEventHandler('esx_service:activateService', function(name, max)
InService[name] = {}
MaxInService[name] = max
GlobalState[name] = GetInServiceCount(name)
end)

RegisterServerEvent('esx_service:disableService')
AddEventHandler('esx_service:disableService', function(name)
InService[name][source] = nil
GlobalState[name] = GetInServiceCount(name)
end)

RegisterServerEvent('esx_service:notifyAllInService')
Expand All @@ -35,12 +37,13 @@ end)

ESX.RegisterServerCallback('esx_service:enableService', function(source, cb, name)
local inServiceCount = GetInServiceCount(name)

if inServiceCount >= MaxInService[name] then
cb(false, MaxInService[name], inServiceCount)
else
InService[name][source] = true
cb(true, MaxInService[name], inServiceCount)
GlobalState[name] = GetInServiceCount(name)
cb(true, MaxInService[name], inServiceCount)
end
end)

Expand Down Expand Up @@ -75,8 +78,10 @@ end)

AddEventHandler('esx:playerDropped', function(playerId, reason)
for k,v in pairs(InService) do
if v[source] == true then
v[source] = nil
if v[playerId] == true then
v[playerId] = nil
GlobalState[k] = GetInServiceCount(k)
end
end
end)

0 comments on commit 3589976

Please sign in to comment.