162 lines
4.7 KiB
Lua
162 lines
4.7 KiB
Lua
local playerLoaded = false
|
|
|
|
Citizen.CreateThread(function()
|
|
if Config.Framework == 'ESX' then
|
|
local status, ESX = pcall(function()
|
|
return exports['es_extended']:getSharedObject()
|
|
end)
|
|
|
|
if not status then
|
|
while not ESX do
|
|
TriggerEvent("esx:getSharedObject", function(object) ESX = object end)
|
|
Citizen.Wait(50)
|
|
end
|
|
end
|
|
|
|
while ESX.GetPlayerData().job == nil do
|
|
Citizen.Wait(100)
|
|
end
|
|
|
|
while not ESX.IsPlayerLoaded() do
|
|
Citizen.Wait(50)
|
|
end
|
|
|
|
Citizen.Wait(500)
|
|
|
|
ESX.PlayerData = ESX.GetPlayerData()
|
|
|
|
playerLoaded = true
|
|
|
|
RegisterNetEvent('esx:setJob', function(job)
|
|
ESX.PlayerData.job = job
|
|
end)
|
|
|
|
RegisterNetEvent('esx:setAccountMoney', function(account)
|
|
SendNUIMessage({
|
|
action = 'setMoney',
|
|
data = {
|
|
type = account.name,
|
|
money = account.money
|
|
}
|
|
})
|
|
end)
|
|
|
|
RegisterNetEvent('esx:setJob', function(job)
|
|
ESX.PlayerData.job = job
|
|
|
|
SendNUIMessage({
|
|
action = 'setJob',
|
|
data = {
|
|
label = ESX.PlayerData.job.label,
|
|
gLabel = ESX.PlayerData.job.grade_label
|
|
}
|
|
})
|
|
end)
|
|
|
|
function GetJob()
|
|
return {
|
|
label = ESX.PlayerData.job.label,
|
|
gLabel = ESX.PlayerData.job.grade_label
|
|
}
|
|
end
|
|
|
|
if GetResourceState('hex_food') == 'started' then
|
|
RegisterNetEvent('hex_food:onTick', function(food, thirst)
|
|
SendNUIMessage({
|
|
action = 'refreshFood',
|
|
data = {
|
|
food = food,
|
|
thirst = thirst
|
|
}
|
|
})
|
|
end)
|
|
elseif GetResourceState('esx_status') == 'started' then
|
|
RegisterNetEvent('esx_status:onTick', function(data)
|
|
local hunger, thirst
|
|
|
|
for i = 1, #data do
|
|
if data[i].name == "thirst" then
|
|
thirst = math.ceil(data[i].percent)
|
|
end
|
|
if data[i].name == "hunger" then
|
|
hunger = math.ceil(data[i].percent)
|
|
end
|
|
end
|
|
|
|
SendNUIMessage({
|
|
action = 'refreshFood',
|
|
data = {
|
|
food = hunger,
|
|
thirst = thirst
|
|
}
|
|
})
|
|
end)
|
|
end
|
|
|
|
function GetFood()
|
|
if GetResourceState('hex_food') == 'started' then
|
|
return exports['hex_food']:GetFood()
|
|
elseif GetResourceState('esx_status') == 'started' then
|
|
local status = nil
|
|
local timesToTry = 0
|
|
|
|
while status == nil and timesToTry < 10 do
|
|
Citizen.Wait(50)
|
|
timesToTry = timesToTry + 1
|
|
|
|
TriggerEvent('esx_status:getStatus', 'hunger', function(stats)
|
|
status = stats.val / 10000
|
|
end)
|
|
end
|
|
|
|
return status ~= nil and math.ceil(status) or 0
|
|
else
|
|
return math.random(1, 100)
|
|
end
|
|
end
|
|
|
|
function GetThirst()
|
|
if GetResourceState('hex_food') == 'started' then
|
|
return exports['hex_food']:GetThirst()
|
|
elseif GetResourceState('esx_status') == 'started' then
|
|
local status = nil
|
|
local timesToTry = 0
|
|
|
|
while status == nil and timesToTry < 10 do
|
|
Citizen.Wait(50)
|
|
timesToTry = timesToTry + 1
|
|
|
|
TriggerEvent('esx_status:getStatus', 'thirst', function(stats)
|
|
status = stats.val / 10000
|
|
end)
|
|
end
|
|
|
|
return status ~= nil and math.ceil(status) or 0
|
|
else
|
|
return math.random(1, 100)
|
|
end
|
|
end
|
|
|
|
function GetWeaponFromHash(weapon)
|
|
return ESX.GetWeaponFromHash(weapon)
|
|
end
|
|
|
|
function GetWeaponLabel(weaponName)
|
|
return ESX.GetWeaponLabel(weaponName)
|
|
end
|
|
|
|
function GetMoney(account)
|
|
for k, v in pairs(ESX.GetPlayerData().accounts) do
|
|
if v.name == account then
|
|
return v.money
|
|
end
|
|
end
|
|
|
|
return 0
|
|
end
|
|
end
|
|
end)
|
|
|
|
function IsPlayerLoaded()
|
|
return playerLoaded
|
|
end |