client/editable.lua
editable = {}
---@return boolean
function editable.canOpen()
if client.isDead then
return false
end
if IsPauseMenuActive() or IsNuiFocused() then
return false
end
if config.scripts.lb_phone and exports["lb-phone"]:IsOpen() then
return false
end
if config.scripts.cylex_animmenuv2 and exports["cylex_animmenuv2"]:isMenuOpened() then
return false
end
return true
end
function editable.uiOpened()
TriggerEvent("tgiann-lumihud:ui", false)
end
function editable.uiClosed()
TriggerEvent("tgiann-lumihud:ui", true)
end
function editable.openInventory()
if config.scripts.tgiann_inventory then
exports["tgiann-inventory"]:OpenInventory()
end
end
---@return { inventoryLvl: number?, maxWeight: number, weight: number }
function editable.getInventoryData()
if config.scripts.tgiann_inventory then
local inventoryData = lib.callback.await("tgiann-esc:getInventoryData", false)
return {
inventoryLvl = config.tgiannInventoryShowInventoryLevel and inventoryData.backpackLvl,
maxWeight = math.floor(inventoryData.maxweight / 1000),
weight = math.floor(exports["tgiann-inventory"]:GetPlayerWeight() / 1000)
}
end
return {
inventoryLvl = nil,
maxWeight = 0,
weight = 0,
}
end
---@return string
function editable.getPlayerJobLabel()
if config.framework == "esx" then
return client.PlayerData.job.label .. " - " .. client.PlayerData.job.grade_label
elseif config.framework == "qb" then
return client.PlayerData.job.label .. " - " .. client.PlayerData.job.grade.name
end
return "Unemployed"
end
---@return string
function editable.getPlayerName()
local playerName = tgiCore.getCharacterName()
return playerName
end
---@param name string
---@param help string
---@param params? table
function editable.addSuggestion(name, help, params)
assert(type(name) == "string", "name must be a string")
assert(type(help) == "string", "help must be a string")
assert(type(params) == "table" or params == nil, "params must be a table or nil")
-- Ignore commands for keybindings
if name:find("_") or name:find("-") or name:find("+") then
return
end
uiUtilty.sendNuiMessage("addCommand", {
name = name,
help = help,
params = params
})
end
---@param name string
function editable.removeSuggestion(name)
assert(type(name) == "string", "name must be a string")
uiUtilty.sendNuiMessage("removeCommand", {
name = name
})
end
-- if you are using custom chat scripts, maybe you need to change these events
RegisterNetEvent('chat:addSuggestion')
AddEventHandler('chat:addSuggestion', editable.addSuggestion)
RegisterNetEvent('chat:removeSuggestion')
AddEventHandler('chat:removeSuggestion', editable.removeSuggestion)
RegisterNetEvent('chat:addSuggestions')
AddEventHandler('chat:addSuggestions', function(suggestions)
for _, suggestion in ipairs(suggestions) do
editable.addSuggestion(suggestion.name, suggestion.help, suggestion.params)
end
end)
Last updated