mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-29 01:08:54 +00:00
Add files
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
resource_manifest_version '44febabe-d386-4d18-afbe-5e627f4af937'
|
||||
|
||||
description 'ESX Service'
|
||||
|
||||
server_scripts {
|
||||
'server/main.lua'
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
ESX = nil
|
||||
local InService = {}
|
||||
local MaxInService = {}
|
||||
|
||||
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
|
||||
|
||||
function GetInServiceCount(name)
|
||||
|
||||
local count = 0
|
||||
|
||||
for k,v in pairs(InService[name]) do
|
||||
if v == true then
|
||||
count = count + 1
|
||||
end
|
||||
end
|
||||
|
||||
return count
|
||||
|
||||
end
|
||||
|
||||
AddEventHandler('esx_service:activateService', function(name, max)
|
||||
InService[name] = {}
|
||||
MaxInService[name] = max
|
||||
end)
|
||||
|
||||
AddEventHandler('esx_service:disableService', function(name)
|
||||
InService[name][source] = nil
|
||||
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] = enable
|
||||
cb(true, MaxInService[name], inServiceCount)
|
||||
end
|
||||
|
||||
end)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user