Documentation

Setup

Steps for setting up your zyke_status resource.

#Installation

#Download

Download zyke_status.zip from the latest release.

#Dependencies

Install oxmysql and zyke_lib, and configure the framework in zyke_lib. zyke_sounds is optional, for the reaction sounds. See Dependencies.

#Resource

Place the resource in your server's resources folder as zyke_status. Keep the folder name as it is, since other resources call it by name. There are no items to install.

#Database

The zyke_status table is created on the first start, so there is no SQL to import.

#Start Order

Start it after its dependencies and before every resource that uses it, such as Consumables and Smoking:

cfg
ensure oxmysql
ensure zyke_lib
ensure zyke_sounds
ensure zyke_status

#Framework Compatibility

Follow the guide for your framework below. It removes your old status system, so hunger, thirst, and stress are only handled by zyke_status.


#ESX Guide

#Remove Old Status

Remove your old esx_status resource from the server and server.cfg.

We replicate everything this resource does within zyke_status and more!

#Remove Basic Needs

Remove your old esx_basicneeds resource from the server files, and optionally server.cfg.

We replicate everything that happens in this resource within zyke_status, no need for it anymore.


#QBCore Guide

#Basic Compatibility

To get the basic compatibility going, you will need to modify the SetMetaData function. This allows us to catch any attempts to modify your status, which then dispatch it to our system to handle the rest. Our system will execute everything needed for the rest of your server to proceed as normal.

#Modify Player Method

Navigate here and replace the entire function with the code provided below (L274-L281).

lua
-- 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()
end

The instructions below removes all draining/additions/effects from the core.

  • [Hunger & Thirst Drain] Navigate here and replace the entire event with the code provided below (L151-167).
lua
-- Modified to remove hunger & thirst drain
RegisterNetEvent('QBCore:UpdatePlayer', function()
    local ply = QBCore.Functions.GetPlayer(source)
    if (not ply) then return end

    ply.Functions.Save()
end)
  • [Stress Effects] Navigate here and remove the entire thread (L977-L1011)

#Qbox Guide

#Basic Compatibility

To get the basic compatibility going, you will need to modify the SetMetaData function. This allows us to catch any attempts to modify your status, which then dispatch it to our system to handle the rest. Our system will execute everything needed for the rest of your server to proceed as normal.

#Modify SetMetadata

Replace the SetMetadata function inside of qbx_core/server/player.lua with the snippet that matches your qbx_core version. You can find your version on the version line of qbx_core/fxmanifest.lua.

qbx_core v1.24.0 rewrote this function, so the snippets are not interchangeable. Pasting the older snippet into v1.24.0 or newer removes its new value checks and brings back bugs it fixed.

v1.24.0 and newer (matches v1.24.0 and v1.24.1)

lua
function SetMetadata(identifier, metadata, value)
    if type(metadata) ~= 'string' then return end

    local player = resolvePlayer(identifier)

    if not player then return end

    local numeric = numericMetadata[metadata]
    if numeric then
        value = tonumber(value)
        -- Defined in modules/lib.lua but not yet included in the external qbox_lib lint standard.
        if not qbx.math.isFinite(value) then -- luacheck: ignore
            lib.print.warn(('rejected non-finite value for metadata "%s"'):format(metadata))
            return
        end
        value = lib.math.clamp(value, numeric.min, numeric.max)
    end

    local oldValue

    if metadata:match('%.') then
        local metaTable, metaKey = metadata:match('([^%.]+)%.(.+)')

        if metaKey:match('%.') then
            lib.print.error('cannot set nested metadata more than 1 level deep')
            return
        end

        local nested = player.PlayerData.metadata[metaTable]
        if type(nested) ~= 'table' then
            lib.print.error(('cannot set nested metadata, %s is not a table'):format(metaTable))
            return
        end

        oldValue = nested[metaKey]
        nested[metaKey] = value

        metadata = metaTable
    else
        oldValue = player.PlayerData.metadata[metadata]

        -- Hands hunger, thirst & stress to zyke_status, which sets them back through here once its own values are updated
        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

                return exports["zyke_status"]:SetStatusValue(player.PlayerData.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 numericMetadata[metadata] then
            if playerState[metadata] ~= value then
                playerState:set(metadata, value, true)
            end
        end

        if (metadata == 'isdead' or metadata == 'inlaststand') then
            playerState:set('canUseWeapons', not value, true)
        end
    end

    savePlayer(player)
end

The instructions below removes all draining/additions/effects from the core.

  • [Hunger & Thirst Drain] Remove the entire thread that calls removeHungerAndThirst in qbx_core/server/loops.lua.
  • [Stress Effects] Remove the entire thread that checks stress >= 100 in qbx_hud/client/main.lua.