Setup
Steps for setting up your zyke_status resource.
ESX Guide
QBCore Guide
Basic Compatibility
1
Modify Player Method
-- Modified to execute our export when triggered
-- Also blocks duplicate requests that will occur when we dispatch
function self.Functions.SetMetaData(meta, value)
if (not meta or type(meta) ~= "string") then return end
local invoker = GetInvokingResource()
-- If the request was not made by our resource, dispatch it to us and block the rest
-- Our system will re-trigger this event after updating all of our values and sync qb-core
if (invoker ~= "zyke_status") then
if (meta == "hunger" or meta == "thirst" or meta == "stress") then
if (value > 100.0) then value = 100.0 end
if (value < 0.0) then value = 0.0 end
return exports["zyke_status"]:SetStatusValue(self.PlayerData.source, {meta, meta}, value)
end
end
self.PlayerData.metadata[meta] = value
self.Functions.UpdatePlayerData()
endQbox Guide
Basic Compatibility
1
Modify SetMetadata
function SetMetadata(identifier, metadata, value)
if type(metadata) ~= 'string' then return end
local player = type(identifier) == 'string' and (GetPlayerByCitizenId(identifier) or GetOfflinePlayer(identifier)) or GetPlayer(identifier)
if not player then return end
local oldValue
if metadata:match('%.') then
local metaTable, metaKey = metadata:match('([^%.]+)%.(.+)')
if metaKey:match('%.') then
lib.print.error('cannot get nested metadata more than 1 level deep')
end
oldValue = player.PlayerData.metadata[metaTable]
player.PlayerData.metadata[metaTable][metaKey] = value
metadata = metaTable
else
oldValue = player.PlayerData.metadata[metadata]
if (metadata == "hunger" or metadata == "thirst" or metadata == "stress") then
if (GetInvokingResource() ~= "zyke_status") then
-- We don't support changing these values offline at the moment
if (player.Offline) then return end
if (value > 100.0) then value = 100.0 end
if (value < 0.0) then value = 0.0 end
local source = player.PlayerData.source
return exports["zyke_status"]:SetStatusValue(source, {metadata, metadata}, value)
end
end
player.PlayerData.metadata[metadata] = value
end
UpdatePlayerData(identifier)
if not player.Offline then
local playerState = Player(player.PlayerData.source).state
TriggerClientEvent('qbx_core:client:onSetMetaData', player.PlayerData.source, metadata, oldValue, value)
TriggerEvent('qbx_core:server:onSetMetaData', metadata, oldValue, value, player.PlayerData.source)
if (metadata == 'hunger' or metadata == 'thirst' or metadata == 'stress') then
value = lib.math.clamp(value, 0, 100)
if playerState[metadata] ~= value then
playerState:set(metadata, value, true)
end
end
if (metadata == 'dead' or metadata == 'inlaststand') then
playerState:set('canUseWeapons', not value, true)
end
end
if metadata == 'inlaststand' or metadata == 'isdead' then
if player.Offline then
SaveOffline(player.PlayerData)
else
Save(player.PlayerData.source)
end
end
endLast updated