Utils

Utils config. (sh_utils.lua)

Misc features

This allows you to add custom checks, features and other goodies to certain app functions.

Config.Utils = {
    IsPlayersWorking = function(restaurantJobName)
        if not restaurantJobName or restaurantJobName == '' then
            return false
        end
        
        local employees = lib.Framework.GetJobPlayerCount(restaurantJobName)
  
        if not employees or employees <= 0 then
            return false
        end

        return true
    end,

    --This function is used when player completes the restaurant incoming food order
    PayJobEmployee = function(source, amount)
        lib.Framework.Money.Give(source, amount, 'bank')
    end,

    SendJobEvent = function(job, event, data)
        local players = lib.Framework.GetPlayers()
        if not players then return end

        for k,_ in pairs(players) do
            local playerJob = lib.Framework.Job.Get(k)
            if playerJob and playerJob == job then
                TriggerClientEvent(event, k, data)
            end
        end
    end,

    SendCourierEvent = function(event, data)
        local players = lib.Framework.GetPlayers()
        if not players then return end

        for k,_ in pairs(players) do
            if Player(k).state.hasFoodBagOn then
                TriggerClientEvent(event, k, data)
            end
        end
    end,

    ---Access checks for different food app windows, like food ordering, delivering and restaurant management
    GetWindowAccess = function()
        local access = {
            ordering = true,
            courier = false,
            restaurant = false
        }

        local playerServerId = GetPlayerServerId(PlayerId())
        if Player(playerServerId).state.hasFoodBagOn then
            access.courier = true
            access.ordering = false
        end

        for _,restaurant in pairs(Config.Restaurants) do
            if restaurant.playerOwned and lib.Framework.Job.Get() == restaurant.job then
                access.restaurant = true
                access.courier = false
                access.ordering = false
                break
            end
        end

        return access
    end
}

Last updated