forked from Simnation/Main
ed
This commit is contained in:
parent
30bf7c8604
commit
8dbe79a29d
135 changed files with 0 additions and 0 deletions
55
resources/[standalone]/tgiann-core/client/functions/duty.lua
Normal file
55
resources/[standalone]/tgiann-core/client/functions/duty.lua
Normal file
|
@ -0,0 +1,55 @@
|
|||
local lang = langs[config.lang]
|
||||
local esxDuty = nil
|
||||
|
||||
--- @return boolean @true if on duty, false if off duty
|
||||
function tgiCore.IsOnDuty()
|
||||
if config.framework == "esx" then
|
||||
if config.esx_service then
|
||||
if esxDuty == nil then
|
||||
local p = promise.new()
|
||||
tgiCore.core.TriggerServerCallback('esx_service:isInService', function(isInService)
|
||||
p:resolve(isInService)
|
||||
end, PlayerData.job.name)
|
||||
esxDuty = Citizen.Await(p)
|
||||
end
|
||||
return esxDuty
|
||||
else
|
||||
return true -- If there is no service script, return true for default
|
||||
end
|
||||
elseif config.framework == "qb" then
|
||||
return PlayerData.job.onduty
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
--- Toogle on/off duty
|
||||
--- @return string @ dutyFull | onDuty | offDuty
|
||||
function tgiCore.ToggleDuty()
|
||||
local onDuty = tgiCore.IsOnDuty()
|
||||
if onDuty == nil then return end
|
||||
if config.framework == "esx" then
|
||||
if config.esx_service then
|
||||
if onDuty then
|
||||
TriggerServerEvent('esx_service:disableService', PlayerData.job.name)
|
||||
esxDuty = false
|
||||
else
|
||||
local p = promise.new()
|
||||
tgiCore.core.TriggerServerCallback('esx_service:enableService', function(canTakeService, maxInService, inServiceCount)
|
||||
esxDuty = canTakeService
|
||||
if not canTakeService then
|
||||
tgiCore.notif(lang.dutyFull, "error")
|
||||
return p:resolve("dutyFull")
|
||||
end
|
||||
p:resolve("onDuty")
|
||||
end, PlayerData.job.name)
|
||||
return Citizen.Await(p)
|
||||
end
|
||||
else
|
||||
tgiCore.DebugWarningLog("Not found any service/duty script for ESX! You can edit from 'client/functions/duty.lua'")
|
||||
return "offDuty"
|
||||
end
|
||||
elseif config.framework == "qb" then
|
||||
TriggerServerEvent('QBCore:ToggleDuty')
|
||||
end
|
||||
return onDuty and "offDuty" or "onDuty"
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue