Merge pull request #93 from The-Order-Of-The-Sacred-Framework/dev

Dev
This commit is contained in:
MrNewb authored and GitHub committed 2025-05-13 01:52:07 -04:00
commit a495fe8668
168 files changed
+3358 -1177

No files matched your search

+2 -2
View File
@@ -5,12 +5,12 @@ use_experimental_fxv2_oal 'yes'
author 'The Order of the Sacred Framework' author 'The Order of the Sacred Framework'
name 'community_bridge' name 'community_bridge'
description 'A Universal Bridge for Our Community, created by a group of contributors with a shared vision to enhance both user and developer experiences. This bridge connects various frameworks, inventories, target systems, notification systems, and more, fostering compatibility and seamless integration.' description 'A Universal Bridge for Our Community, created by a group of contributors with a shared vision to enhance both user and developer experiences. This bridge connects various frameworks, inventories, target systems, notification systems, and more, fostering compatibility and seamless integration.'
version '0.7.0' version '0.8.0'
shared_scripts { shared_scripts {
'@ox_lib/init.lua', '@ox_lib/init.lua',
'lib/init.lua',
'settings/sharedConfig.lua', 'settings/sharedConfig.lua',
'lib/init.lua',
'modules/math/*.lua', 'modules/math/*.lua',
'modules/locales/*.lua', 'modules/locales/*.lua',
} }
+23 -52
View File
@@ -8,7 +8,7 @@ function Bridge.RegisterModule(moduleName, moduleTable)
return return
end end
local wrappedModule = {} local wrappedModule = Bridge[moduleName] or {}
if type(moduleTable) == 'function' then if type(moduleTable) == 'function' then
Bridge[moduleName] = wrappedModule Bridge[moduleName] = wrappedModule
exports(moduleName, moduleTable) exports(moduleName, moduleTable)
@@ -21,7 +21,8 @@ function Bridge.RegisterModule(moduleName, moduleTable)
print("^2 Registering module:", moduleName, "^0") print("^2 Registering module:", moduleName, "^0")
end end
Bridge[moduleName] = wrappedModule Bridge[moduleName] = wrappedModule
_ENV[moduleName] = wrappedModule -- Add to the ENV table the modules so is more easy and safe to call from inside
_ENV.Bridge = Bridge -- Add the bridge too to the _ENV
exports(moduleName, function() exports(moduleName, function()
return wrappedModule return wrappedModule
@@ -55,24 +56,31 @@ Bridge.RegisterModule("Phone", Phone)
Bridge.RegisterModule("Dispatch", Dispatch) Bridge.RegisterModule("Dispatch", Dispatch)
Bridge.RegisterModule("Shops", Shops) Bridge.RegisterModule("Shops", Shops)
Bridge.RegisterModule("Housing", Housing) Bridge.RegisterModule("Housing", Housing)
Bridge.RegisterModule("Version", Version)
--lib --lib
Bridge.RegisterModule("Tables", cLib.Tables) -- Bridge.RegisterModule("Tables", cLib.Tables)
Bridge.RegisterModule("Math", cLib.Math) -- Bridge.RegisterModule("Math", cLib.Math)
Bridge.RegisterModule("Prints", cLib.Prints) -- Bridge.RegisterModule("Prints", cLib.Prints)
Bridge.RegisterModule("Callback", cLib.Callback) -- Bridge.RegisterModule("Callback", cLib.Callback)
--new -- --new
Bridge.RegisterModule("Require", Require) Bridge.RegisterModule("Require", Require)
Bridge.RegisterModule("Ids", cLib.Ids) -- Bridge.RegisterModule("Ids", cLib.Ids)
Bridge.RegisterModule("ReboundEntities", cLib.ReboundEntities) -- Bridge.RegisterModule("ReboundEntities", cLib.ReboundEntities)
Bridge.RegisterModule("LA", cLib.LA) -- Bridge.RegisterModule("LA", cLib.LA)
Bridge.RegisterModule("Perlin", cLib.Perlin) -- Bridge.RegisterModule("Perlin", cLib.Perlin)
Bridge.RegisterModule("Actions", cLib.Actions) -- Bridge.RegisterModule("Actions", cLib.Actions)
Bridge.RegisterModule("Cache", cLib.Cache) -- Bridge.RegisterModule("Cache", cLib.Cache)
Bridge.RegisterModule("Skills", Skills) -- Bridge.RegisterModule("Skills", Skills)
for k, v in pairs(cLib) do
if v then
Bridge.RegisterModule(k, v)
end
end
exports('Bridge', function() exports('Bridge', function()
return Bridge return Bridge
end) end)
@@ -80,14 +88,7 @@ end)
-- ▄▀▀ ██▀ █▀▄ █ █ ██▀ █▀▄ -- ▄▀▀ ██▀ █▀▄ █ █ ██▀ █▀▄
-- ▄█▀ █▄▄ █▀▄ ▀▄▀ █▄▄ █▀▄ -- ▄█▀ █▄▄ █▀▄ ▀▄▀ █▄▄ █▀▄
if not IsDuplicityVersion() then goto client end if not IsDuplicityVersion() then goto client end
Bridge.RegisterModule('Version', Version)
Bridge.RegisterModule("SQL", cLib.SQL)
Bridge.RegisterModule("Logs", cLib.Logs)
Bridge.RegisterModule("ItemsBuilder", cLib.ItemsBuilder)
Bridge.RegisterModule("LootTables", cLib.LootTables)
Bridge.RegisterModule("Version", Version)
Bridge.RegisterModule("ServerEntity", cLib.ServerEntity)
-- ▄▀▀ █ █ ██▀ █▄ █ ▀█▀ -- ▄▀▀ █ █ ██▀ █▄ █ ▀█▀
-- ▀▄▄ █▄▄ █ █▄▄ █ ▀█ █ -- ▀▄▄ █▄▄ █ █▄▄ █ ▀█ █
@@ -105,33 +106,3 @@ Bridge.RegisterModule("Target", Target)
Bridge.RegisterModule("Menu", Menu) Bridge.RegisterModule("Menu", Menu)
Bridge.RegisterModule("Dialogue", Dialogue) Bridge.RegisterModule("Dialogue", Dialogue)
Bridge.RegisterModule("Accessibility", Accessibility) -- new Bridge.RegisterModule("Accessibility", Accessibility) -- new
Bridge.RegisterModule("Utility", cLib.Utility)
Bridge.RegisterModule("Placeable", cLib.Placeable)--new
Bridge.RegisterModule("Gizmo", cLib.Gizmo)
Bridge.RegisterModule("Scaleform", cLib.Scaleform)
Bridge.RegisterModule("Raycast", cLib.Raycast)
Bridge.RegisterModule("PlaceableObject", cLib.PlaceableObject)
Bridge.RegisterModule("Point", cLib.Point)
Bridge.RegisterModule("Object", cLib.Object)
Bridge.RegisterModule("Particle", cLib.Particle)
Bridge.RegisterModule("ClientEntity", cLib.ClientEntity)
Bridge.RegisterModule("ClientEntityActions", cLib.ClientEntityActions)
-- Fill the bridge tables with player data.
function FillBridgeTables()
PlayerLoaded = true
PlayerIdentifier = Framework.GetPlayerIdentifier()
PlayerJobName, PlayerJobLabel, PlayerJobGradeName, PlayerJobGradeLevel = Framework.GetPlayerJob()
end
-- Clean the bridge tables.
function ClearClientSideVariables()
PlayerLoaded = false
PlayerIdentifier = nil
PlayerJobName = nil
PlayerJobLabel = nil
PlayerJobGradeName = nil
PlayerJobGradeLevel = nil
StoredOldClothing = {}
end
+161
View File
@@ -0,0 +1,161 @@
Anim = Anim or {}
Ids = Ids or Require("lib/utility/shared/ids.lua")
Anim.Active = Anim.Active or {}
Anim.isUpdateLoopRunning = Anim.isUpdateLoopRunning or false
--- This will request the animation dictionary.
--- @param animDict string
--- @return boolean
function Anim.RequestDict(animDict)
if not animDict or type(animDict) ~= "string" then
return false
end
if HasAnimDictLoaded(animDict) then
return true
end
RequestAnimDict(animDict)
local timeout = GetGameTimer() + 2000
while not HasAnimDictLoaded(animDict) and GetGameTimer() < timeout do
Wait(50)
end
return HasAnimDictLoaded(animDict)
end
--- This will start the animation update loop.
--- @return void
function Anim.Start()
if Anim.isUpdateLoopRunning then return end
Anim.isUpdateLoopRunning = true
CreateThread(function()
while Anim.isUpdateLoopRunning do
local idsToProcess = {}
for idKey, _ in pairs(Anim.Active) do
table.insert(idsToProcess, idKey)
end
if #idsToProcess == 0 then
Wait(750)
else
for _, id in ipairs(idsToProcess) do
local animData = Anim.Active[id]
if animData then
local entity = animData.entity
local onComplete = animData.onComplete
if not DoesEntityExist(entity) then
if onComplete then onComplete(false, "despawned") end
Anim.Active[id] = nil
elseif animData.status == "pending_task" then
TaskPlayAnim(entity, animData.animDict, animData.animName, animData.blendIn, animData.blendOut, animData.duration, animData.flag, animData.playbackRate, false, false, false)
animData.startTime = GetGameTimer()
animData.animEndTime = animData.duration > 0 and (animData.startTime + animData.duration) or -1
animData.status = "playing"
elseif animData.status == "playing" then
local animationCompletedNaturally = false
if animData.duration == -1 then
if not IsEntityPlayingAnim(entity, animData.animDict, animData.animName, 3) and GetEntityAnimCurrentTime(entity, animData.animDict, animData.animName) > 0.8 then
animationCompletedNaturally = true
end
elseif animData.animEndTime ~= -1 and GetGameTimer() >= animData.animEndTime then
animationCompletedNaturally = true
end
if animationCompletedNaturally then
if onComplete then onComplete(true, "completed") end
Anim.Active[id] = nil
end
end
end
end
Wait(100)
end
end
end)
end
--- This will play an animation on the specified ped.
--- @param id string | nil
--- @param entity number
--- @param animDict string
--- @param animName string
--- @param blendIn number | nil
--- @param blendOut number | nil
--- @param duration number | nil
--- @param flag number | nil
--- @param playbackRate number | nil
--- @param onComplete function | nil
--- @return string | nil
function Anim.Play(id, entity, animDict, animName, blendIn, blendOut, duration, flag, playbackRate, onComplete)
local newId = id or Ids.CreateUniqueId(Anim.Active)
if Anim.Active[newId] then
if onComplete then
onComplete(false, "id_in_use")
end
return newId
end
if not entity or not DoesEntityExist(entity) or not IsEntityAPed(entity) then
if onComplete then
onComplete(false, "invalid_entity")
end
return nil
end
if not Anim.RequestDict(animDict) then
if onComplete then
onComplete(false, "dict_load_failed")
end
return nil
end
Anim.Active[newId] = {
entity = entity,
animDict = animDict,
animName = animName,
blendIn = blendIn or 8.0,
blendOut = blendOut or -8.0,
duration = duration or -1,
flag = flag or 1,
playbackRate = playbackRate or 0.0,
onComplete = onComplete,
status = "pending_task",
startTime = 0,
animEndTime = 0
}
Anim.Start()
return newId
end
function Anim.Stop(id)
if not id or not Anim.Active or not Anim.Active[id] then
return false
end
local animData = Anim.Active[id]
if animData.entity and DoesEntityExist(animData.entity) and IsEntityAPed(animData.entity) then
if animData.status == "playing" or animData.status == "pending_task" then
StopAnimTask(animData.entity, animData.animDict, animData.animName, 1.0)
end
end
if animData.onComplete then
animData.onComplete(false, "stopped_by_id")
end
Anim.Active[id] = nil
local anyLeft = Anim.Active and next(Anim.Active) ~= nil
if not anyLeft then
Anim.isUpdateLoopRunning = false
end
return true
end
return Anim
+65
View File
@@ -0,0 +1,65 @@
Batch = Batch or {}
Batch.Event = Batch.Event or {}
Batch.Event.Queued = Batch.Event.Queued or {}
Batch.Event.IsQueued = Batch.Event.IsQueued or false
local SERVER = IsDuplicityVersion()
-- could do a callback from client to server back to client with a time stamp. Use that timestamp to generate some random string/number and use that fo
-- this event name. Would help by masking from exploits. Thinking about making a module out of it
--- This is used to batch single events together to reduce network strain
---
if SERVER then
function Batch.Event.Queue(src, event, ...)
if src == -1 then
src = GetPlayers()
for k, v in pairs(src) do
local strSrc = tostring(v)
Batch.Event.Queued[strSrc] = Batch.Event.Queued[strSrc] or {}
table.insert(Batch.Event.Queued[strSrc], {
src = v,
event = event,
args = {...}
})
end
else
local strSrc = tostring(src)
Batch.Event.Queued[strSrc] = Batch.Event.Queued[strSrc] or {}
table.insert(Batch.Event.Queued[strSrc], {
src = src,
event = event,
args = {...}
})
end
if Batch.Event.IsQueued then return end
Batch.Event.IsQueued = true
SetTimeout(100, function()
for k, v in pairs(Batch.Event.Queued) do
TriggerClientEvent('community_bridge:client:BatchEvents', v.src, v)
end
Batch.Event.IsQueued = false
Batch.Event.Queued = {}
end)
end
return Batch
else
Batch.Event.Fire = function(array)
local playerSrc = PlayerId()
for k, v in pairs(array) do
if v.src == playerSrc then
local event = v.event
local args = v.args
TriggerEvent(event, table.unpack(args))
end
end
end
RegisterNetEvent('community_bridge:client:BatchEvents', function(array)
Batch.Event.Fire(array)
end)
return Batch
end
+394
View File
@@ -0,0 +1,394 @@
-- Cutscene Manager for FiveM
-- Handles cutscene loading, playback, and character management
---@class Cutscene
Cutscenes = Cutscenes or {}
Cutscene = Cutscene or {}
Cutscene.done = true
-- Constants
local LOAD_TIMEOUT <const> = 10000
local FADE_DURATION <const> = 1000
local CUTSCENE_WAIT <const> = 1000
-- Character model definitions
local characterTags <const> = {
{ male = 'MP_1' },
{ male = 'MP_2' },
{ male = 'MP_3' },
{ male = 'MP_4' },
{ male = 'MP_Male_Character', female = 'MP_Female_Character' },
{ male = 'MP_Male_Character_1', female = 'MP_Female_Character_1' },
{ male = 'MP_Male_Character_2', female = 'MP_Female_Character_2' },
{ male = 'MP_Male_Character_3', female = 'MP_Female_Character_3' },
{ male = 'MP_Male_Character_4', female = 'MP_Female_Character_4' },
{ male = 'MP_Plane_Passenger_1' },
{ male = 'MP_Plane_Passenger_2' },
{ male = 'MP_Plane_Passenger_3' },
{ male = 'MP_Plane_Passenger_4' },
{ male = 'MP_Plane_Passenger_5' },
{ male = 'MP_Plane_Passenger_6' },
{ male = 'MP_Plane_Passenger_7' },
{ male = 'MP_Plane_Passenger_8' },
{ male = 'MP_Plane_Passenger_9' },
}
-- Component definitions for character customization
local componentsToSave <const> = {
-- Components
{ name = "head", id = 0, type = "drawable" },
{ name = "beard", id = 1, type = "drawable" },
{ name = "hair", id = 2, type = "drawable" },
{ name = "arms", id = 3, type = "drawable" },
{ name = "pants", id = 4, type = "drawable" },
{ name = "parachute", id = 5, type = "drawable" },
{ name = "feet", id = 6, type = "drawable" },
{ name = "accessories", id = 7, type = "drawable" },
{ name = "undershirt", id = 8, type = "drawable" },
{ name = "vest", id = 9, type = "drawable" },
{ name = "decals", id = 10, type = "drawable" },
{ name = "jacket", id = 11, type = "drawable" },
-- Props
{ name = "hat", id = 0, type = "prop" },
{ name = "glasses", id = 1, type = "prop" },
{ name = "ears", id = 2, type = "prop" },
{ name = "watch", id = 3, type = "prop" },
{ name = "bracelet", id = 4, type = "prop" },
{ name = "misc", id = 5, type = "prop" },
{ name = "left_wrist", id = 6, type = "prop" },
{ name = "right_wrist", id = 7, type = "prop" },
{ name = "prop8", id = 8, type = "prop" },
{ name = "prop9", id = 9, type = "prop" },
}
-- Utility Functions
function table.shallow_copy(t)
local t2 = {}
for k, v in pairs(t) do
t2[k] = v
end
return t2
end
local function WaitForModelLoad(modelHash)
local timeout = GetGameTimer() + LOAD_TIMEOUT
while not HasModelLoaded(modelHash) and GetGameTimer() < timeout do
Wait(0)
end
return HasModelLoaded(modelHash)
end
local function CreatePedFromModel(modelName, coords)
local model = GetHashKey(modelName)
RequestModel(model)
if not WaitForModelLoad(model) then
print("Failed to load model: " .. modelName)
return nil
end
local ped = CreatePed(0, model, coords.x, coords.y, coords.z, 0.0, true, false)
if not DoesEntityExist(ped) then
print("Failed to create ped from model: " .. modelName)
return nil
end
return ped
end
-- Cutscene Core Functions
local function LoadCutscene(cutscene)
assert(cutscene, "Cutscene.Load called without a cutscene name.")
local playbackList = IsPedMale(PlayerPedId()) and 31 or 103
RequestCutsceneWithPlaybackList(cutscene, playbackList, 8)
local timeout = GetGameTimer() + LOAD_TIMEOUT
while not HasCutsceneLoaded() and GetGameTimer() < timeout do
Wait(0)
end
if not HasCutsceneLoaded() then
print("Cutscene failed to load: ", cutscene)
return false
end
return true
end
local function GetCutsceneTags(cutscene)
if not LoadCutscene(cutscene) then return end
StartCutscene(0)
Wait(CUTSCENE_WAIT)
local tags = {}
for _, tag in pairs(characterTags) do
if DoesCutsceneEntityExist(tag.male, 0) or DoesCutsceneEntityExist(tag.female, 0) then
table.insert(tags, tag)
end
end
StopCutsceneImmediately()
Wait(CUTSCENE_WAIT * 2)
return tags
end
-- Character Outfit Management
local function SavePedOutfit(ped)
local outfitData = {}
for _, component in ipairs(componentsToSave) do
if component.type == "drawable" then
outfitData[component.name] = {
id = component.id,
type = component.type,
drawable = GetPedDrawableVariation(ped, component.id),
texture = GetPedTextureVariation(ped, component.id),
palette = GetPedPaletteVariation(ped, component.id),
}
elseif component.type == "prop" then
outfitData[component.name] = {
id = component.id,
type = component.type,
propIndex = GetPedPropIndex(ped, component.id),
propTexture = GetPedPropTextureIndex(ped, component.id),
}
end
end
return outfitData
end
local function ApplyPedOutfit(ped, outfitData)
if not outfitData or type(outfitData) ~= "table" then
print("ApplyPedOutfit: Invalid outfitData provided.")
return
end
for componentName, data in pairs(outfitData) do
if data.type == "drawable" then
SetPedComponentVariation(ped, data.id, data.drawable or 0, data.texture or 0, data.palette or 0)
elseif data.type == "prop" then
if data.propIndex == -1 or data.propIndex == nil then
ClearPedProp(ped, data.id)
else
SetPedPropIndex(ped, data.id, data.propIndex, data.propTexture or 0, true)
end
end
end
end
-- Public Interface
function Cutscene.GetTags(cutscene)
return GetCutsceneTags(cutscene)
end
function Cutscene.Load(cutscene)
return LoadCutscene(cutscene)
end
function Cutscene.SavePedOutfit(ped)
return SavePedOutfit(ped)
end
function Cutscene.ApplyPedOutfit(ped, outfitData)
return ApplyPedOutfit(ped, outfitData)
end
function Cutscene.Create(cutscene, coords, srcs)
local lastCoords = coords or GetEntityCoords(PlayerPedId())
DoScreenFadeOut(0)
local tagsFromCutscene = GetCutsceneTags(cutscene)
if not LoadCutscene(cutscene) then
print("Cutscene.Create: Failed to load cutscene", cutscene)
DoScreenFadeIn(0)
return false
end
srcs = srcs or {}
local clothes = {}
local localped = PlayerPedId()
-- Process players and create necessary peds
local playersToProcess = { { ped = localped, identifier = "localplayer", coords = lastCoords } }
for _, src_raw in ipairs(srcs) do
if type(src_raw) == 'number' then
if src_raw and not DoesEntityExist(src_raw) then
local playerPed = GetPlayerPed(GetPlayerFromServerId(src_raw))
if DoesEntityExist(playerPed) then
local ped = ClonePed(playerPed, false, false, true)
table.insert(playersToProcess, { ped = ped, identifier = "player" })
end
else
table.insert(playersToProcess, { ped = src_raw, identifier = "user" })
end
elseif type(src_raw) == 'string' then
local ped = CreatePedFromModel(src_raw, GetEntityCoords(localped))
if ped then
table.insert(playersToProcess, { ped = ped, identifier = 'script' })
end
end
end
-- Process available tags and assign to players
local availableTags = table.shallow_copy(tagsFromCutscene or {})
local usedTags = {}
local cleanupTags = {}
for _, playerData in ipairs(playersToProcess) do
local currentPed = playerData.ped
if not currentPed or not DoesEntityExist(currentPed) then goto continue end
local tagTable = table.remove(availableTags, 1)
if not tagTable then
print("Cutscene.Create: No available tags for player", playerData.identifier)
break
end
local isPedMale = IsPedMale(currentPed)
local tag = isPedMale and tagTable.male or tagTable.female
local unusedTag = not isPedMale and tagTable.male or tagTable.female -- needs to be this way as default has to be null for missing female
SetCutsceneEntityStreamingFlags(tag, 0, 1)
RegisterEntityForCutscene(currentPed, tag, 0, GetEntityModel(currentPed), 64)
SetCutscenePedComponentVariationFromPed(tag, currentPed, 0)
clothes[tag] = {
clothing = SavePedOutfit(currentPed),
ped = currentPed
}
table.insert(usedTags, tag)
if unusedTag then table.insert(cleanupTags, unusedTag) end
::continue::
end
-- Clean up unused tags
for _, tag in ipairs(cleanupTags) do
local ped = RegisterEntityForCutscene(0, tag, 3, 0, 64)
if ped then
SetEntityVisible(ped, false, false)
end
end
-- Handle remaining unused tags
for _, tag in ipairs(availableTags) do
for _, tagType in pairs({ tag.male, tag.female }) do
if tagType then
local ped = RegisterEntityForCutscene(0, tagType, 3, 0, 64)
if ped then
SetEntityVisible(ped, false, false)
end
end
end
end
return {
cutscene = cutscene,
coords = coords,
tags = usedTags,
srcs = srcs,
peds = playersToProcess,
clothes = clothes,
}
end
function Cutscene.Start(cutsceneData)
if not cutsceneData then
print("Cutscene.Start: Cutscene data is nil.")
return
end
DoScreenFadeIn(FADE_DURATION)
Cutscene.done = false
local clothes = cutsceneData.clothes
local coords = cutsceneData.coords
-- Start cutscene
if coords then
if type(coords) == 'boolean' then
coords = GetEntityCoords(PlayerPedId())
end
StartCutsceneAtCoords(coords.x, coords.y, coords.z, 0)
else
StartCutscene(0)
end
Wait(100)
-- Apply clothing to cutscene characters
for k, datam in pairs(clothes) do
local ped = datam.ped
if DoesEntityExist(ped) then
SetCutscenePedComponentVariationFromPed(k, ped, 0)
ApplyPedOutfit(ped, datam.clothing)
end
end
-- Scene loading thread
CreateThread(function()
local lastCoords
while not Cutscene.done do
local coords = GetWorldCoordFromScreenCoord(0.5, 0.5)
if not lastCoords or #(lastCoords - coords) > 100 then
NewLoadSceneStartSphere(coords.x, coords.y, coords.z, 2000, 0)
lastCoords = coords
end
Wait(500)
end
end)
-- Control blocking thread
CreateThread(function()
while not Cutscene.done do
DisableAllControlActions(0)
DisableFrontendThisFrame()
Wait(3)
end
end)
-- Main cutscene loop
while not HasCutsceneFinished() and not Cutscene.done do
Wait(0)
if IsDisabledControlJustPressed(0, 200) then
DoScreenFadeOut(FADE_DURATION)
Wait(FADE_DURATION)
StopCutsceneImmediately()
Wait(500)
Cutscene.done = true
break
end
end
-- Cleanup
DoScreenFadeIn(FADE_DURATION)
for _, playerData in ipairs(cutsceneData.peds) do
local ped = playerData.ped
if not ped or not DoesEntityExist(ped) then goto continue end
if playerData.identifier == 'script' then
DeleteEntity(ped)
elseif playerData.identifier == 'localplayer' then
SetEntityCoords(ped, playerData.coords.x, playerData.coords.y, playerData.coords.z, false, false, false, false)
end
::continue::
end
Cutscene.done = true
end
-- RegisterCommand('cutscene', function(source, args, rawCommand)
-- local cutscene = args[1]
-- if cutscene then
-- local cutsceneData = Cutscene.Create(cutscene, false, { 1,1,1 })
-- Cutscene.Start(cutsceneData)
-- end
-- end, false)
return Cutscene
+329
View File
@@ -0,0 +1,329 @@
-- DUI (Direct User Interface) Manager for FiveM
-- Basic table-based implementation with full mouse support
---@class DUI
DUI = {}
-- Constants
local DEFAULT_WIDTH <const> = 1280
local DEFAULT_HEIGHT <const> = 720
-- Store active DUI instances
local activeInstances = {}
local instanceCounter = 0
-- Mouse tracking state
local mouseState = {
tracking = false,
activeId = nil,
lastX = 0,
lastY = 0,
isPressed = false,
currentButton = nil
}
-- Mouse button constants
local MOUSE_BUTTONS <const> = {
LEFT = "left",
MIDDLE = "middle",
RIGHT = "right"
}
---@class DUIInstance
---@field id number Unique identifier for this DUI instance
---@field url string URL loaded in the DUI
---@field width number Width of the DUI
---@field height number Height of the DUI
---@field handle number DUI browser handle
---@field txd string Texture dictionary name
---@field txn string Texture name
---@field active boolean Whether the DUI is active
---@field trackMouse boolean Whether mouse tracking is enabled for this instance
---@field mouseScale table<string, number> Scale factors for mouse coordinates
-- Create a new DUI instance
---@param url string URL to load
---@param width? number Width of the DUI (default: 1280)
---@param height? number Height of the DUI (default: 720)
---@return number|nil id The DUI instance ID if successful, nil if failed
function DUI.Create(url, width, height)
if not url or type(url) ~= "string" then
return print("DUI.Create: URL is required and must be a string")
end
width = width or DEFAULT_WIDTH
height = height or DEFAULT_HEIGHT
instanceCounter = instanceCounter + 1
local id = instanceCounter
local handle = CreateDui(url, width, height)
if not handle then
return print("DUI.Create: Failed to create DUI instance")
end
local instance = {
id = id,
url = url,
width = width,
height = height,
handle = handle,
txd = "dui_" .. id,
txn = "texture_" .. id,
active = true,
trackMouse = false,
mouseScale = {
x = 1.0,
y = 1.0
}
}
-- Create runtime texture
local duiHandle = GetDuiHandle(handle)
CreateRuntimeTextureFromDuiHandle(CreateRuntimeTxd(instance.txd), instance.txn, duiHandle)
activeInstances[id] = instance
return id
end
-- Destroy a DUI instance
---@param id number DUI instance ID
---@return boolean success Whether the operation was successful
function DUI.Destroy(id)
local instance = activeInstances[id]
if not instance then return false end
if instance.handle then
DestroyDui(instance.handle)
end
activeInstances[id] = nil
return true
end
-- Set URL for a DUI instance
---@param id number DUI instance ID
---@param url string New URL to load
---@return boolean success Whether the operation was successful
function DUI.SetURL(id, url)
local instance = activeInstances[id]
if not instance then return false end
SetDuiUrl(instance.handle, url)
instance.url = url
return true
end
-- Send a message to the DUI
---@param id number DUI instance ID
---@param message table Message to send (will be JSON encoded)
---@return boolean success Whether the operation was successful
function DUI.SendMessage(id, message)
local instance = activeInstances[id]
if not instance then return false end
SendDuiMessage(instance.handle, json.encode(message))
return true
end
-- Mouse interaction functions
-- Move mouse cursor on DUI
---@param id number DUI instance ID
---@param x number X coordinate
---@param y number Y coordinate
---@return boolean success Whether the operation was successful
function DUI.MoveMouse(id, x, y)
local instance = activeInstances[id]
if not instance then return false end
SendDuiMouseMove(instance.handle, x, y)
return true
end
-- Simulate mouse button press
---@param id number DUI instance ID
---@param button "left"|"middle"|"right" Mouse button to simulate
---@return boolean success Whether the operation was successful
function DUI.MouseDown(id, button)
local instance = activeInstances[id]
if not instance then return false end
if not MOUSE_BUTTONS[button:upper()] then
return print("DUI.MouseDown: Invalid button. Must be 'left', 'middle', or 'right'")
end
-- Update mouse state
if instance.trackMouse then
mouseState.isPressed = true
mouseState.currentButton = button
end
SendDuiMouseDown(instance.handle, button)
return true
end
-- Simulate mouse button release
---@param id number DUI instance ID
---@param button "left"|"middle"|"right" Mouse button to simulate
---@return boolean success Whether the operation was successful
function DUI.MouseUp(id, button)
local instance = activeInstances[id]
if not instance then return false end
if not MOUSE_BUTTONS[button:upper()] then
return print("DUI.MouseUp: Invalid button. Must be 'left', 'middle', or 'right'")
end
-- Update mouse state
if instance.trackMouse then
mouseState.isPressed = false
mouseState.currentButton = nil
end
SendDuiMouseUp(instance.handle, button)
return true
end
-- Simulate mouse wheel movement
---@param id number DUI instance ID
---@param deltaY number Vertical scroll amount
---@param deltaX number Horizontal scroll amount
---@return boolean success Whether the operation was successful
function DUI.MouseWheel(id, deltaY, deltaX)
local instance = activeInstances[id]
if not instance then return false end
SendDuiMouseWheel(instance.handle, deltaY, deltaX)
return true
end
-- Click helper function (combines MoveMouse, MouseDown, and MouseUp)
---@param id number DUI instance ID
---@param x number X coordinate
---@param y number Y coordinate
---@param button? "left"|"middle"|"right" Mouse button to click (default: "left")
---@return boolean success Whether the operation was successful
function DUI.Click(id, x, y, button)
button = button or "left"
if not DUI.MoveMouse(id, x, y) then return false end
if not DUI.MouseDown(id, button) then return false end
-- Small delay to simulate real click
Citizen.Wait(50)
return DUI.MouseUp(id, button)
end
-- Enable or disable mouse tracking for a DUI instance
---@param id number DUI instance ID
---@param enabled boolean Whether to enable mouse tracking
---@param scaleX? number Scale factor for X coordinates (default: 1.0)
---@param scaleY? number Scale factor for Y coordinates (default: 1.0)
---@return boolean success Whether the operation was successful
function DUI.TrackMouse(id, enabled, scaleX, scaleY)
local instance = activeInstances[id]
if not instance then return false end
instance.trackMouse = enabled
instance.mouseScale.x = scaleX or 1.0
instance.mouseScale.y = scaleY or 1.0
if enabled then
mouseState.tracking = true
mouseState.activeId = id
elseif mouseState.activeId == id then
mouseState.tracking = false
mouseState.activeId = nil
end
return true
end
-- Update mouse coordinates from screen position
---@param screenX number Screen X coordinate
---@param screenY number Screen Y coordinate
---@return boolean updated Whether coordinates were updated
local function UpdateMousePosition(screenX, screenY)
if not mouseState.tracking or not mouseState.activeId then return false end
local instance = activeInstances[mouseState.activeId]
if not instance or not instance.trackMouse then return false end
-- Scale coordinates based on DUI dimensions and scale factors
local scaledX = screenX * instance.mouseScale.x
local scaledY = screenY * instance.mouseScale.y
-- Only update if position changed
if scaledX ~= mouseState.lastX or scaledY ~= mouseState.lastY then
mouseState.lastX = scaledX
mouseState.lastY = scaledY
DUI.MoveMouse(mouseState.activeId, scaledX, scaledY)
return true
end
return false
end
-- Mouse tracking thread
Citizen.CreateThread(function()
while true do
if mouseState.tracking and mouseState.activeId then
local instance = activeInstances[mouseState.activeId]
if instance and instance.trackMouse then
-- Get current cursor position
local screenX, screenY = GetNuiCursorPosition()
UpdateMousePosition(screenX, screenY)
-- Handle held mouse buttons
if mouseState.isPressed and mouseState.currentButton then
-- Keep the button pressed state
SendDuiMouseDown(instance.handle, mouseState.currentButton)
end
end
end
Citizen.Wait(0)
end
end)
-- Utility functions
-- Get textures for a DUI instance
---@param id number DUI instance ID
---@return string|nil txd, string|nil txn Texture dictionary and name, or nil if instance not found
function DUI.GetTextures(id)
local instance = activeInstances[id]
if not instance then return nil, nil end
return instance.txd, instance.txn
end
-- Check if a DUI instance exists
---@param id number DUI instance ID
---@return boolean exists Whether the instance exists and is active
function DUI.Exists(id)
local instance = activeInstances[id]
return instance ~= nil and instance.active
end
-- Get all active DUI instances
---@return table<number, DUIInstance> instances Table of active DUI instances
function DUI.GetActiveInstances()
return activeInstances
end
-- Cleanup all DUI instances
function DUI.CleanupAll()
for id in pairs(activeInstances) do
DUI.Destroy(id)
end
end
-- Automatic cleanup on resource stop
AddEventHandler('onResourceStop', function(resourceName)
if GetCurrentResourceName() ~= resourceName then return end
DUI.CleanupAll()
end)
return DUI
+12 -16
View File
@@ -35,10 +35,11 @@ local function SpawnEntity(entityData)
print(string.format("[ClientEntity] Unknown entity type '%s' for entity %s", entityData.entityType, entityData.id)) print(string.format("[ClientEntity] Unknown entity type '%s' for entity %s", entityData.entityType, entityData.id))
end end
if entity then if entity then
-- print(string.format("[ClientEntity] Spawned %s entity %s (GameID: %s)", entityData.entityType, entityData.id, entity))
entityData.spawned = entity entityData.spawned = entity
SetModelAsNoLongerNeeded(model) SetModelAsNoLongerNeeded(model)
SetEntityAsMissionEntity(entity, true, true) -- Keep entity from being deleted by game engine SetEntityAsMissionEntity(entity, true, true) -- Keep entity from being deleted by game engine
FreezeEntityPosition(entity, entityData.freeze or false) -- Optional freeze based on meta FreezeEntityPosition(entity, true) -- Optional freeze based on meta
if entityData.OnSpawn and type(entityData.OnSpawn) == 'function' then if entityData.OnSpawn and type(entityData.OnSpawn) == 'function' then
entityData.OnSpawn(entityData) entityData.OnSpawn(entityData)
end end
@@ -49,17 +50,14 @@ local function SpawnEntity(entityData)
end end
local function RemoveEntity(entityData) local function RemoveEntity(entityData)
entityData = entityData and entityData.args entityData = entityData and entityData.args or entityData
if not entityData then return end -- Added safety check if not entityData then return end
ClientEntityActions.StopAction(entityData.id)
ClientEntityActions.StopAction(entityData.id) -- Stop any ongoing action AND clear queue before despawning
if entityData.spawned and DoesEntityExist(entityData.spawned) then if entityData.spawned and DoesEntityExist(entityData.spawned) then
local entityHandle = entityData.spawned local entityHandle = entityData.spawned
entityData.spawned = nil -- Clear handle first entityData.spawned = nil
SetEntityAsMissionEntity(entityHandle, false, false) -- Allow game engine to delete if needed, though we delete manually SetEntityAsMissionEntity(entityHandle, false, false)
DeleteEntity(entityHandle) DeleteEntity(entityHandle)
-- print(string.format("[ClientEntity] Removed %s entity %s (GameID: %s)", entityData.entityType, entityData.id, entityHandle))
end end
if entityData.OnRemove and type(entityData.OnRemove) == 'function' then if entityData.OnRemove and type(entityData.OnRemove) == 'function' then
entityData.OnRemove(entityData) entityData.OnRemove(entityData)
@@ -75,7 +73,7 @@ function ClientEntity.Register(entityData)
-- print(string.format("[ClientEntity] Registering %s entity %s", entityData.entityType, entityData.id)) -- print(string.format("[ClientEntity] Registering %s entity %s", entityData.entityType, entityData.id))
-- Use Point system for proximity checks -- Use Point system for proximity checks
print(string.format("[ClientEntity] Registering entity %s at %s", entityData.id, json.encode(entityData))) -- print(string.format("[ClientEntity] Registering entity %s at %s", entityData.id, json.encode(entityData)))
Point.Register(entityData.id, entityData.coords, entityData.spawnDistance or 50.0, entityData, SpawnEntity, RemoveEntity, function() end) Point.Register(entityData.id, entityData.coords, entityData.spawnDistance or 50.0, entityData, SpawnEntity, RemoveEntity, function() end)
end end
@@ -85,9 +83,8 @@ function ClientEntity.Unregister(id)
local entityData = Entities[id] local entityData = Entities[id]
if not entityData then return end if not entityData then return end
-- print(string.format("[ClientEntity] Unregistering entity %s", id)) Point.Remove(id)
Point.Remove(id) -- Remove from proximity checks (this will call RemoveEntity if currently in range) RemoveEntity(entityData)
RemoveEntity(entityData) -- Ensure it's removed even if Point.Remove didn't trigger it
Entities[id] = nil Entities[id] = nil
end end
@@ -96,13 +93,13 @@ end
-- @param data table The data fields to update. -- @param data table The data fields to update.
function ClientEntity.Update(id, data) function ClientEntity.Update(id, data)
local entityData = Entities[id] local entityData = Entities[id]
print(string.format("[ClientEntity] Updating entity %s", id)) -- print(string.format("[ClientEntity] Updating entity %s", id))
if not entityData then return end if not entityData then return end
local needsPointUpdate = false local needsPointUpdate = false
for key, value in pairs(data) do for key, value in pairs(data) do
if key == 'coords' and #(entityData.coords - value) > 0.1 then if key == 'coords' and #(entityData.coords - value) > 0.1 then
print(string.format("[ClientEntity] Updating coords for entity %s", id)) -- print(string.format("[ClientEntity] Updating coords for entity %s", id))
needsPointUpdate = true needsPointUpdate = true
end end
if key == 'spawnDistance' and entityData.spawnDistance ~= value then if key == 'spawnDistance' and entityData.spawnDistance ~= value then
@@ -176,7 +173,6 @@ end)
-- New handler for entity actions -- New handler for entity actions
RegisterNetEvent("community_bridge:client:TriggerEntityAction", function(entityId, actionName, ...) RegisterNetEvent("community_bridge:client:TriggerEntityAction", function(entityId, actionName, ...)
local entityData = Entities[entityId] local entityData = Entities[entityId]
print("here", json.encode(entityData))
-- Check if entity exists locally (it doesn't need to be spawned to queue actions) -- Check if entity exists locally (it doesn't need to be spawned to queue actions)
if entityData then if entityData then
if actionName == "Stop" then if actionName == "Stop" then
@@ -12,7 +12,6 @@ ClientEntityActions.RegisteredActions = {} -- New: Registry for action implemen
-- @param entityId string|number The ID of the entity. -- @param entityId string|number The ID of the entity.
function ClientEntityActions.ProcessNextAction(entityId) function ClientEntityActions.ProcessNextAction(entityId)
if ClientEntityActions.IsActionRunning [entityId] then return end -- Already running something if ClientEntityActions.IsActionRunning [entityId] then return end -- Already running something
print(string.format("[ClientEntityActions] Processing next action for entity %s", entityId))
local queue = ClientEntityActions.ActionQueue[entityId] local queue = ClientEntityActions.ActionQueue[entityId]
if not queue or #queue == 0 then return end -- Queue is empty if not queue or #queue == 0 then return end -- Queue is empty
@@ -27,7 +26,6 @@ function ClientEntityActions.ProcessNextAction(entityId)
-- Look up the action in the registry -- Look up the action in the registry
local actionFunc = ClientEntityActions.RegisteredActions [nextAction.name] local actionFunc = ClientEntityActions.RegisteredActions [nextAction.name]
print(string.format("[ClientEntityActions] Action '%s' dequeued for entity %s", nextAction.name, entityId))
if actionFunc then if actionFunc then
-- print(string.format("[ClientEntityActions] Starting action '%s' for entity %s", nextAction.name, entityId)) -- print(string.format("[ClientEntityActions] Starting action '%s' for entity %s", nextAction.name, entityId))
ClientEntityActions.IsActionRunning [entityId] = true ClientEntityActions.IsActionRunning [entityId] = true
@@ -4,7 +4,6 @@ LA = LA or Require("lib/utility/shared/la.lua")
--- Internal implementation for walking. Registered via RegisterAction. --- Internal implementation for walking. Registered via RegisterAction.
function DefaultActions.WalkTo(entityData, coords, speed, timeout) function DefaultActions.WalkTo(entityData, coords, speed, timeout)
print("[ClientEntityActions] WalkTo action called", coords, speed, timeout)
local entity = entityData.spawned local entity = entityData.spawned
local entityId = entityData.id -- Store ID locally for safety in thread local entityId = entityData.id -- Store ID locally for safety in thread
@@ -35,14 +34,14 @@ function DefaultActions.WalkTo(entityData, coords, speed, timeout)
ClientEntityActions.ActionThreads[entityId] = thread ClientEntityActions.ActionThreads[entityId] = thread
end end
--- Internal implementation for playing an animation. Registered via RegisterAction. --- Internal implementation for playing an animation. Registered via RegisterAction.
-- @param entityData table --- @param entityData table
-- @param animDict string --- @param animDict string
-- @param animName string --- @param animName string
-- @param blendIn number (Optional, default 8.0) --- @param blendIn number (Optional, default 8.0)
-- @param blendOut number (Optional, default -8.0) --- @param blendOut number (Optional, default -8.0)
-- @param duration number (Optional, default -1 for loop/until stopped) --- @param duration number (Optional, default -1 for loop/until stopped)
-- @param flag number (Optional, default 0) --- @param flag number (Optional, default 0)
-- @param playbackRate number (Optional, default 0.0) --- @param playbackRate number (Optional, default 0.0)
function DefaultActions.PlayAnim(entityData, animDict, animName, blendIn, blendOut, duration, flag, playbackRate) function DefaultActions.PlayAnim(entityData, animDict, animName, blendIn, blendOut, duration, flag, playbackRate)
local entity = entityData.spawned local entity = entityData.spawned
local entityId = entityData.id local entityId = entityData.id
@@ -157,17 +156,17 @@ function DefaultActions.LerpTo(entityData, targetCoords, duration, easingType, e
ClientEntityActions.ActionThreads[entityId] = thread ClientEntityActions.ActionThreads[entityId] = thread
end end
--- Internal implementation for attaching a prop. Registered via RegisterAction. --- Internal implementation for attaching a prop. Registered via RegisterAction.
-- This action completes immediately after attaching. Use DetachProp to remove. --- This action completes immediately after attaching. Use DetachProp to remove.
-- @param entityData table --- @param entityData table
-- @param propModel string|number --- @param propModel string|number
-- @param boneIndex number (Optional, default -1 for root) --- @param boneIndex number (Optional, default -1 for root)
-- @param offsetPos vector3 (Optional, default vector3(0,0,0)) --- @param offsetPos vector3 (Optional, default vector3(0,0,0))
-- @param offsetRot vector3 (Optional, default vector3(0,0,0)) --- @param offsetRot vector3 (Optional, default vector3(0,0,0))
-- @param useSoftPinning boolean (Optional, default false) --- @param useSoftPinning boolean (Optional, default false)
-- @param collision boolean (Optional, default false) --- @param collision boolean (Optional, default false)
-- @param isPed boolean (Optional, default false) - Seems unused in native? --- @param isPed boolean (Optional, default false) - Seems unused in native?
-- @param vertexIndex number (Optional, default 2) - Seems unused in native? --- @param vertexIndex number (Optional, default 2) - Seems unused in native?
-- @param fixedRot boolean (Optional, default true) --- @param fixedRot boolean (Optional, default true)
function DefaultActions.AttachProp(entityData, propModel, boneName, offsetPos, offsetRot, useSoftPinning, collision, isPed, vertexIndex, fixedRot) function DefaultActions.AttachProp(entityData, propModel, boneName, offsetPos, offsetRot, useSoftPinning, collision, isPed, vertexIndex, fixedRot)
local entity = entityData.spawned local entity = entityData.spawned
local entityId = entityData.id local entityId = entityData.id
@@ -179,9 +178,7 @@ function DefaultActions.AttachProp(entityData, propModel, boneName, offsetPos, o
end end
local modelHash = Utility.GetEntityHashFromModel(propModel) local modelHash = Utility.GetEntityHashFromModel(propModel)
print(modelHash, propModel)
if not Utility.LoadModel(modelHash) then if not Utility.LoadModel(modelHash) then
print(string.format("[ClientEntityActions] Failed to load prop model '%s' for entity %s", propModel, entityId))
ClientEntityActions.IsActionRunning[entityId] = false ClientEntityActions.IsActionRunning[entityId] = false
ClientEntityActions.ProcessNextAction(entityId) ClientEntityActions.ProcessNextAction(entityId)
return return
@@ -196,7 +193,6 @@ function DefaultActions.AttachProp(entityData, propModel, boneName, offsetPos, o
if boneIndex == -1 then boneIndex = 0 end -- Default to root if bone not found or not ped if boneIndex == -1 then boneIndex = 0 end -- Default to root if bone not found or not ped
offsetPos = offsetPos or vector3(0.0, 0.0, 0.0) offsetPos = offsetPos or vector3(0.0, 0.0, 0.0)
offsetRot = offsetRot or vector3(0.0, 0.0, 0.0) offsetRot = offsetRot or vector3(0.0, 0.0, 0.0)
print(string.format("[ClientEntityActions] Attaching prop '%s' to entity %s at bone %d", propModel, entityId, boneIndex))
AttachEntityToEntity(prop, entity, boneIndex, offsetPos.x, offsetPos.y, offsetPos.z, offsetRot.x, offsetRot.y, offsetRot.z, false, useSoftPinning or false, collision or false, isPed or false, vertexIndex or 2, fixedRot == nil and true or fixedRot) AttachEntityToEntity(prop, entity, boneIndex, offsetPos.x, offsetPos.y, offsetPos.z, offsetRot.x, offsetRot.y, offsetRot.z, false, useSoftPinning or false, collision or false, isPed or false, vertexIndex or 2, fixedRot == nil and true or fixedRot)
entityData.props = entityData.props or {} -- Ensure props table exists entityData.props = entityData.props or {} -- Ensure props table exists
table.insert(entityData.props, prop) -- Store the prop handle in the entity data table.insert(entityData.props, prop) -- Store the prop handle in the entity data
@@ -209,8 +205,8 @@ function DefaultActions.AttachProp(entityData, propModel, boneName, offsetPos, o
ClientEntityActions.ProcessNextAction(entityId) ClientEntityActions.ProcessNextAction(entityId)
end end
--- Internal implementation for detaching a prop. Registered via RegisterAction. --- Internal implementation for detaching a prop. Registered via RegisterAction.
-- @param entityData table --- @param entityData table
-- @param propModel string|number The model name/hash of the prop to detach. --- @param propModel string|number The model name/hash of the prop to detach.
function DefaultActions.DetachProp(entityData, propModel) function DefaultActions.DetachProp(entityData, propModel)
local entityId = entityData.id local entityId = entityData.id
@@ -268,7 +264,6 @@ function DefaultActions.GetInCar(entityData, vehicleData, seatIndex, timeout)
end end
function DefaultActions.Freeze(entityData, freeze) function DefaultActions.Freeze(entityData, freeze)
print("[ClientEntityActions] Freeze action called", freeze)
local entity = entityData.spawned local entity = entityData.spawned
local entityId = entityData.id local entityId = entityData.id
@@ -351,6 +346,11 @@ function DefaultActions.Circle(entityData, radius, speed)
-- ClientEntityActions.ProcessNextAction(entityId) -- Try next action if this one failed immediately -- ClientEntityActions.ProcessNextAction(entityId) -- Try next action if this one failed immediately
end end
function DefaultActions.Collisions(entityData, enable, keepPhysics)
local entity = entityData.spawned
SetEntityCollision(entity, enable, keepPhysics)
end
for name, func in pairs(DefaultActions) do for name, func in pairs(DefaultActions) do
ClientEntityActions.RegisterAction(name, func) ClientEntityActions.RegisterAction(name, func)
end end
+10 -1
View File
@@ -35,6 +35,8 @@ function Require(modulePath, resourceName)
return result return result
end end
cLib = { cLib = {
Require = Require, Require = Require,
Callback = Callback or Require("lib/utility/shared/callbacks.lua"), Callback = Callback or Require("lib/utility/shared/callbacks.lua"),
@@ -58,7 +60,8 @@ cLib.ItemsBuilder = ItemsBuilder or Require("lib/generators/server/ItemsBuilder.
cLib.LootTables = LootTables or Require("lib/generators/server/lootTables.lua") cLib.LootTables = LootTables or Require("lib/generators/server/lootTables.lua")
cLib.Cache = Cache or Require("lib/cache/shared/cache.lua") cLib.Cache = Cache or Require("lib/cache/shared/cache.lua")
cLib.ServerEntity = ServerEntity or Require("lib/entities/server/server_entity.lua") cLib.ServerEntity = ServerEntity or Require("lib/entities/server/server_entity.lua")
cLib.Marker = Marker or Require("lib/markers/server/server.lua")
cLib.Particle = Particle or Require("lib/particles/server/particles.lua")
if IsDuplicityVersion() then return cLib end if IsDuplicityVersion() then return cLib end
::client:: ::client::
@@ -74,4 +77,10 @@ cLib.Cache = Cache or Require("lib/cache/client/cache.lua")
cLib.ClientEntity = ClientEntity or Require("lib/entities/client/client_entity.lua") cLib.ClientEntity = ClientEntity or Require("lib/entities/client/client_entity.lua")
cLib.ClientEntityActions = ClientEntityActions or Require("lib/entities/client/client_entity_actions.lua") cLib.ClientEntityActions = ClientEntityActions or Require("lib/entities/client/client_entity_actions.lua")
cLib.ClientStateBag = ClientStateBag or Require("lib/statebags/client/client.lua") cLib.ClientStateBag = ClientStateBag or Require("lib/statebags/client/client.lua")
cLib.Marker = Marker or Require("lib/markers/client/markers.lua")
cLib.Anim = Anim or Require("lib/anim/client/client.lua")
cLib.Cutscene = Cutscene or Require("lib/cutscenes/client/cutscene.lua")
cLib.DUI = DUI or Require("lib/dui/client/dui.lua")
cLib.Particle = Particle or Require("lib/particles/client/particles.lua")
return cLib return cLib
+108 -75
View File
@@ -1,8 +1,10 @@
Marker = { ---@diagnostic disable: duplicate-set-field
Marker = {}
} local Created = setmetatable({}, { __mode = "k" }) --what is mode?
local Created = setmetatable({}, { __mode = "k" }) local Ids = Ids or Require("lib/utility/shared/ids.lua")
local id = Require("lib/utility/shared/ids") local point = Point or Require("lib/points/client/points.lua")
local loopRunning = false
local Drawing = {}
--- This will validate the marker data. --- This will validate the marker data.
--- @param data table{position: vector3, offset: vector3, rotation: vector3, size: vector3, color: vector3, alpha: number, bobUpAndDown: boolean, marker: number, interaction: function} --- @param data table{position: vector3, offset: vector3, rotation: vector3, size: vector3, color: vector3, alpha: number, bobUpAndDown: boolean, marker: number, interaction: function}
@@ -23,91 +25,122 @@ local function validateMarkerData(data)
return true return true
end end
AddEventHandler("community_bridge:client:marker", function(data)
if not validateMarkerData(data) then return end
if source == "" then return end
Marker.DrawMarker(data)
end)
--- This will create a marker. --- This will create a marker.
--- @param data table{position: vector3, offset: vector3, rotation: vector3, size: vector3, color: vector3, alpha: number, bobUpAndDown: boolean, marker: number, interaction: function} --- @param data table{position: vector3, offset: vector3, rotation: vector3, size: vector3, color: vector3, alpha: number, bobUpAndDown: boolean, marker: number, interaction: function}
---@return number --- @return string|nil
function Marker.DrawMarker(data) function Marker.Create(data)
local _id = data.id or id.Random() local _id = data.id or Ids.CreateUniqueId(Created)
local position = data.position or vector3(0.0, 0.0, 0.0) if not validateMarkerData(data) then return end
local offset = data.offset or vector3(0.0, 0.0, 0.0) local basePosition = data.position or vector3(0.0, 0.0, 0.0)
local marker = data.marker or 1 local baseOffset = data.offset or vector3(0.0, 0.0, 0.0)
local pos = vector3(position.x + offset.x, position.y + offset.y, position.z + offset.z)
local rotation = data.rotation or vector3(0, 0, 0) local data = {
local size = data.size or vector3(1.0, 1.0, 1.0)
local color = data.color or vector3(0, 255, 0)
local alpha = data.alpha or 255
local bobUpAndDown = data.bobUpAndDown
local interaction = data.interaction or false
Created[_id] = {
position = pos,
rotation = rotation,
size = size,
color = color,
alpha = alpha,
bobUpAndDown =
bobUpAndDown,
marker = marker,
offset = offset,
interaction = interaction,
id = _id, id = _id,
position = vector3(basePosition.x + baseOffset.x, basePosition.y + baseOffset.y, basePosition.z + baseOffset.z),
marker = data.marker or 1,
rotation = data.rotation or vector3(0, 0, 0),
size = data.size or vector3(1.0, 1.0, 1.0),
color = data.color or vector3(0, 255, 0),
alpha = data.alpha or 255,
bobUpAndDown = data.bobUpAndDown,
-- interaction = data.interaction or false, -- Uncomment if you re-implement interaction logic
rotate = data.rotate,
textureDict = data.textureDict,
textureName = data.textureName,
drawOnEnts = data.drawOnEnts,
} }
Created[_id] = data
point.Register(
_id, data.position, data.drawDistance or 50.0, data,
function(_)
if not Created[_id] then return point.Remove(_id) end
Drawing[_id] = Created[_id]
Marker.Run()
end,
function(markerData)
Drawing[_id] = nil
end, nil
)
return _id return _id
end end
function Marker.RemoveMarker(id) --- This will remove a marker.
if Created[id] then --- @param id string
--- @return boolean
function Marker.Remove(id)
if not Created[id] then return false end
point.Remove(id)
Drawing[id] = nil
Created[id] = nil
return true
end
--- This will remove all markers.
--- @param id string
function Marker.RemoveAll()
for id, _ in pairs(Created) do
point.Remove(id)
Created[id] = nil Created[id] = nil
return true
end end
return false
end end
function Marker.Draw() -- This will loop through all marker(points) in range and draw them.
while true do -- @param data table{marker: number, position: vector3, rotation: vector3, size: vector3, color: vector3, alpha: number, bobUpAndDown: boolean, faceCamera: boolean, rotate: boolean, textureDict: string, textureName: string, drawOnEnts: boolean}
Wait(0) -- @return nil
if not next(Created) then function Marker.Run()
Wait(1000) -- Reduce CPU usage when no markers are present if loopRunning then return end
goto continue loopRunning = true
end CreateThread(function()
while loopRunning do
for id, _ in pairs(Created) do if not next(Created) then
if Created[id] then loopRunning = false
local data = Created[id] return
if #(data.position - GetEntityCoords(PlayerPedId())) > 100.0 then
goto continue
else
DrawMarker(
data.marker,
data.position.x, data.position.y, data.position.z,
0.0, 0.0, 0.0,
data.rotation.x, data.rotation.y, data.rotation.z,
data.size.x, data.size.y, data.size.z,
data.color.x, data.color.y, data.color.z, data.alpha,
data.bobUpAndDown, false, false
)
if data.interaction then
local playerCoords = GetEntityCoords(PlayerPedId())
local distance = #(data.position - playerCoords)
if distance < 2.0 then
if IsControlJustReleased(0, 38) then -- E key
data.interaction(data.id)
end
end
end
end
end end
for drawingId, drawingData in pairs(Drawing) do
if not Created[drawingId] then
Drawing[drawingId] = nil
goto continue
end
DrawMarker(
drawingData.marker,
drawingData.position.x, drawingData.position.y, drawingData.position.z,
0.0, 0.0, 0.0,
drawingData.rotation.x, drawingData.rotation.y, drawingData.rotation.z,
drawingData.size.x, drawingData.size.y, drawingData.size.z,
drawingData.color.x, drawingData.color.y, drawingData.color.z, drawingData.alpha,
drawingData.bobUpAndDown, drawingData.faceCamera, false,
drawingData.rotate, drawingData.textureDict, drawingData.textureName, drawingData.drawOnEnts
)
::continue::
end
Wait(3)
end end
::continue:: end)
end
end end
Marker.Draw() -- Start the marker drawing loop RegisterNetEvent("community_bridge:Client:Marker", function(data)
Marker.Create(data)
end)
RegisterNetEvent("community_bridge:Client:MarkerBulk", function(datas)
if not datas then return end
for _, data in pairs(datas) do
Marker.Create(data)
end
end)
RegisterNetEvent("community_bridge:Client:MarkerRemove", function(id)
Marker.Remove(id)
end)
RegisterNetEvent("community_bridge:Client:MarkerRemoveBulk", function(ids)
if not ids then return end
for _, id in pairs(ids) do
Marker.Remove(id)
end
end)
exports("Marker", Marker) exports("Marker", Marker)
+68 -17
View File
@@ -1,24 +1,75 @@
local function RegisterNewMarker(data) ---@diagnostic disable: duplicate-set-field
local id = Ids or Require("lib/utility/shared/ids.lua")
Marker = {}
local Created = {}
function Marker.New(data)
if not data.position or not data.position.x or not data.position.y or not data.position.z then if not data.position or not data.position.x or not data.position.y or not data.position.z then
print("Invalid marker position. Must be a vector3 with x, y, and z coordinates.") print("Invalid marker position. Must be a vector3 with x, y, and z coordinates.")
return return
end end
if data.offset and (not data.offset.x or not data.offset.y or not data.offset.z) then
print("Invalid marker offset. Must be a vector3 with x, y, and z coordinates.")
return
end
if data.rotation and (not data.rotation.x or not data.rotation.y or not data.rotation.z) then
print("Invalid marker rotation. Must be a vector3 with x, y, and z coordinates.")
return
end
if not data.size or not data.size.x or not data.size.y or not data.size.z then local _id = data.id or id.CreateUniqueId(Created)
print("Invalid marker size. Must be a vector3 with x, y, and z dimensions.") local data = {
return id = _id,
end position = data.position,
offset = data.offset or vector3(0.0, 0.0, 0.0),
TriggerClientEvent("community_bridge:client:marker", source, data) marker = data.marker or 1,
rotation = data.rotation or vector3(0, 0, 0),
size = data.size or vector3(1.0, 1.0, 1.0),
color = data.color or vector3(0, 255, 0),
alpha = data.alpha or 255,
bobUpAndDown = data.bobUpAndDown,
-- interaction = data.interaction or false, -- Uncomment if you re-implement interaction logic
rotate = data.rotate,
textureDict = data.textureDict,
textureName = data.textureName,
drawOnEnts = data.drawOnEnts,
}
Created[_id] = data
return _id
end
function Marker.Destroy(id)
if not id or not Created[id] then return end
Created[id] = nil
return true
end end
RegisterNetEvent("community_bridge:server:createMarker", RegisterNewMarker) function Marker.Create(data)
exports("RegisterNewMarker", RegisterNewMarker) local _id = Marker.New(data)
if not _id then return end
TriggerClientEvent("community_bridge:Client:Marker", -1, Created[_id])
return _id
end
function Marker.Remove(id)
if not Marker.Destroy(id) then return end
TriggerClientEvent("community_bridge:Client:MarkerRemove", -1, id)
end
function Marker.CreateBulk(datas)
if not datas then return end
local toClient = {}
for k, v in pairs(datas) do
table.insert(toClient, Marker.Create(v))
end
TriggerClientEvent("community_bridge:Client:MarkerBulk", -1, toClient)
return toClient
end
function Marker.RemoveBulk(ids)
if not ids then return end
local toClient = {}
for k, v in pairs(ids) do
local id = v
if type(v) == "table" then
id = v.id
end
Marker.Destroy(id)
table.insert(toClient, id)
end
TriggerClientEvent("community_bridge:Client:MarkerRemoveBulk", -1, toClient)
end
exports("Marker", Marker)
return Marker
+94 -4
View File
@@ -1,4 +1,8 @@
Particles = {}
Particle = {} Particle = {}
---@diagnostic disable: duplicate-set-field
local Ids = Ids or Require("lib/utility/shared/ids.lua")
local point = Require("lib/points/client/points.lua")
---Loads a ptfx asset into memory. ---Loads a ptfx asset into memory.
---@param dict string ---@param dict string
@@ -14,7 +18,6 @@ function LoadPtfxAsset(dict)
return HasNamedPtfxAssetLoaded(dict) return HasNamedPtfxAssetLoaded(dict)
end end
--- Create a particle effect at the specified position and rotation. --- Create a particle effect at the specified position and rotation.
--- @param dict string --- @param dict string
--- @param ptfx string --- @param ptfx string
@@ -25,7 +28,7 @@ end
--- @param looped boolean --- @param looped boolean
--- @param loopLength number|nil --- @param loopLength number|nil
--- @return number|nil ptfxHandle -- The handle of the particle effect, or nil if it failed to create. --- @return number|nil ptfxHandle -- The handle of the particle effect, or nil if it failed to create.
function Particle.Create(dict, ptfx, pos, rot, scale, color, looped, loopLength) function Particle.Play(dict, ptfx, pos, rot, scale, color, looped, loopLength)
LoadPtfxAsset(dict) LoadPtfxAsset(dict)
UseParticleFxAssetNextCall(dict) UseParticleFxAssetNextCall(dict)
SetParticleFxNonLoopedColour(color.x, color.y, color.z) SetParticleFxNonLoopedColour(color.x, color.y, color.z)
@@ -45,14 +48,101 @@ function Particle.Create(dict, ptfx, pos, rot, scale, color, looped, loopLength)
return particle return particle
end end
function Particle.Remove(particle) function Particle.Stop(particle)
if not particle then return end if not particle then return end
StopParticleFxLooped(particle, false) StopParticleFxLooped(particle, false)
RemoveParticleFx(particle, false) RemoveParticleFx(particle, false)
RemoveNamedPtfxAsset(particle) RemoveNamedPtfxAsset(particle)
end end
function Particle.Create(data)
assert(data, "Particle data is nil")
assert(data.dict, "Invalid particle data. Must contain string dict.")
assert(data.ptfx, "Invalid particle data. Must contain string ptfx.")
local _id = data.id or Ids.CreateUniqueId(Particles)
data = {
id = _id,
dict = data.dict,
ptfx = data.ptfx,
position = data.position or vector3(0.0, 0.0, 0.0),
rotation = data.rotation or vector3(0, 0, 0),
size = data.size or 1.0,
color = data.color or vector3(255, 255, 255),
looped = data.looped or false,
loopLength = data.loopLength or nil,
spawned = false,
}
Particles[_id] = data
point.Register( -- checking if players in range
_id,
data.position,
data.drawDistance or 50.0,
data,
function(_)
if not Particles[_id] then return point.Remove(_id) end
local particleData = Particles[_id]
if particleData.spawned then return end
particleData.spawned = Particle.Play(
particleData.dict,
particleData.ptfx,
particleData.position,
particleData.rotation,
particleData.size,
particleData.color,
particleData.looped,
particleData.loopLength
)
end,
function(markerData)
if not Particles[_id] then return end
local particleData = Particles[_id]
if not particleData.spawned then return end
Particle.Stop(particleData.spawned)
particleData.spawned = nil
end
)
return _id
end
function Particle.Remove(id)
if not id then return end
local particle = Particles[id]
if not particle then return end
Particle.Stop(particle.spawned)
Particles[id] = nil
point.Remove(id)
end
RegisterNetEvent("community_bridge:Client:Particle", function(data)
if not data then return end
Particle.Create(data)
end)
RegisterNetEvent("community_bridge:Client:ParticleBulk", function(datas)
if not datas then return end
for _, data in pairs(datas) do
Particle.Create(data)
end
end)
RegisterNetEvent("community_bridge:Client:ParticleRemove", function(id)
local particle = Particles[id]
if not particle then return end
Particle.Remove(Drawing[id])
end)
RegisterNetEvent("community_bridge:Client:ParticleRemoveBulk", function(ids)
for _, id in pairs(ids) do
Particle.Remove(id)
end
end)
function Particle.CreateOnEntity(dict, ptfx, entity, offset, rot, scale, color, looped, loopLength) function Particle.CreateOnEntity(dict, ptfx, entity, offset, rot, scale, color, looped, loopLength)
LoadPtfxAsset(dict) LoadPtfxAsset(dict)
UseParticleFxAssetNextCall(dict) UseParticleFxAssetNextCall(dict)
+72
View File
@@ -0,0 +1,72 @@
---@diagnostic disable: duplicate-set-field
Particles = {}
Particle = Particles or {}
function Particle.New(data)
assert(data, "Particle data is nil")
assert(data.dict, "Invalid particle data. Must contain string dict.")
assert(data.ptfx, "Invalid particle data. Must contain string ptfx.")
local _id = data.id or id.CreateUniqueId(Particles)
data = {
id = _id,
dict = data.dict,
ptfx = data.ptfx,
position = data.position or vector3(0.0, 0.0, 0.0),
rotation = data.rotation or vector3(0, 0, 0),
size = data.size or 1.0,
color = data.color or vector3(255, 255, 255),
looped = data.looped or false,
loopLength = data.loopLength or nil,
}
Particles[_id] = data
return data
end
function Particle.Destroy(id)
if not id or not Particles[id] then return end
Particles[id] = nil
return true
end
function Particle.Create(data)
local particleData = Particle.New(data)
if not particleData then return end
TriggerClientEvent("community_bridge:Client:Particle", -1, particleData)
return
end
function Particle.Remove(id)
if not Particle.Destroy(id) then return end
TriggerClientEvent("community_bridge:Client:ParticleRemove", -1, id)
end
function Particle.CreateBulk(datas)
if not datas then return end
local toClient = {}
for k, v in pairs(datas) do
local data = Particle.New(v)
table.insert(toClient, data)
end
TriggerClientEvent("community_bridge:Client:ParticleBulk", -1, toClient)
return toClient
end
function Particle.RemoveBulk(ids)
if not ids then return end
local toClient = {}
for k, v in pairs(ids) do
local id = v
if type(v) == "table" then
id = v.id
end
Particle.Destroy(id)
table.insert(toClient, id)
end
TriggerClientEvent("community_bridge:Client:ParticleRemoveBulk", -1, toClient)
return ids
end
return Particle
+85 -34
View File
@@ -1,40 +1,84 @@
Scaleform = {} ---@class Scaleform
local Scaleform = {}
function SetupScaleform(scaleform, Buttons) -- Constants
local scaleform = RequestScaleformMovie(scaleform) local SCALEFORM_TIMEOUT = 5000
local timeout = 5000 local BACKGROUND_COLOR_VALUE = 80
local CONTROL_TYPE = 2
local RENDER_WAIT_TIME = 2
-- Local utility functions
local function setupButton(scaleform, button)
PushScaleformMovieFunction(scaleform, button.type)
if button.int then
PushScaleformMovieFunctionParameterInt(button.int)
end
-- Handle key index setup
if button.keyIndex then
if type(button.keyIndex) == "table" then
for _, keyCode in pairs(button.keyIndex) do
N_0xe83a3e3557a56640(GetControlInstructionalButton(CONTROL_TYPE, keyCode, true))
end
else
ScaleformMovieMethodAddParamPlayerNameString(GetControlInstructionalButton(CONTROL_TYPE, button.keyIndex[1],
true))
end
end
-- Handle button name setup
if button.name then
BeginTextCommandScaleformString("STRING")
AddTextComponentScaleform(button.name)
EndTextCommandScaleformString()
end
-- Handle background color
if button.type == 'SET_BACKGROUND_COLOUR' then
for _ = 1, 4 do
PushScaleformMovieFunctionParameterInt(BACKGROUND_COLOR_VALUE)
end
end
PopScaleformMovieFunctionVoid()
end
---Creates and sets up a scaleform movie
---@param scaleformName string The name of the scaleform to load
---@param buttons table Array of button configurations
---@return number scaleform The loaded scaleform handle
local function setupScaleform(scaleformName, buttons)
local scaleform = RequestScaleformMovie(scaleformName)
local timeout = SCALEFORM_TIMEOUT
-- Wait for scaleform to load
while not HasScaleformMovieLoaded(scaleform) and timeout > 0 do while not HasScaleformMovieLoaded(scaleform) and timeout > 0 do
timeout = timeout - 1 timeout = timeout - 1
Wait(0) Wait(0)
end end
assert(timeout > 0, 'Scaleform failed to load')
if timeout <= 0 then
error('Scaleform failed to load: ' .. scaleformName)
end
DrawScaleformMovieFullscreen(scaleform, 255, 255, 255, 0, 0) DrawScaleformMovieFullscreen(scaleform, 255, 255, 255, 0, 0)
for i = 1,#Buttons do
PushScaleformMovieFunction(scaleform, Buttons[i].type) -- Setup each button
if Buttons[i].int then PushScaleformMovieFunctionParameterInt(Buttons[i].int) end for _, button in ipairs(buttons) do
if Buttons[i].keyIndex then setupButton(scaleform, button)
if type(Buttons[i].keyIndex) == "table" then
for _, v in pairs(Buttons[i].keyIndex) do N_0xe83a3e3557a56640(GetControlInstructionalButton(2, v, true)) end
else
ScaleformMovieMethodAddParamPlayerNameString(GetControlInstructionalButton(2, Buttons[i].keyIndex[1], true))
end
end
if Buttons[i].name then
BeginTextCommandScaleformString("STRING")
AddTextComponentScaleform(Buttons[i].name)
EndTextCommandScaleformString()
end
if Buttons[i].type == 'SET_BACKGROUND_COLOUR' then
for u = 1,4 do PushScaleformMovieFunctionParameterInt(80) end
end
PopScaleformMovieFunctionVoid()
end end
return scaleform return scaleform
end end
---Sets up instructional buttons with default configuration
---@param buttons table Optional custom button configuration
---@return number scaleform The configured instructional buttons scaleform
function Scaleform.SetupInstructionalButtons(buttons) function Scaleform.SetupInstructionalButtons(buttons)
buttons = buttons or { buttons = buttons or {
-- Default button configuration commented out
-- Uncomment and modify as needed
-- {type = "CLEAR_ALL"}, -- {type = "CLEAR_ALL"},
-- {type = "SET_CLEAR_SPACE", int = 200}, -- {type = "SET_CLEAR_SPACE", int = 200},
-- {type = "SET_DATA_SLOT", name = config?.place_object?.name or 'Place Object:', keyIndex = config?.place_object?.key or {223}, int = 5}, -- {type = "SET_DATA_SLOT", name = config?.place_object?.name or 'Place Object:', keyIndex = config?.place_object?.key or {223}, int = 5},
@@ -46,33 +90,40 @@ function Scaleform.SetupInstructionalButtons(buttons)
-- {type = "DRAW_INSTRUCTIONAL_BUTTONS"}, -- {type = "DRAW_INSTRUCTIONAL_BUTTONS"},
-- {type = "SET_BACKGROUND_COLOUR"}, -- {type = "SET_BACKGROUND_COLOUR"},
} }
local scaleform = SetupScaleform("instructional_buttons", buttons)
return scaleform return setupScaleform("instructional_buttons", buttons)
end end
-- Active scaleform tracking
local activeScaleform = nil
local runningScaleform = nil ---Runs a scaleform with optional update callback
---@param scaleform number The scaleform handle to run
---@param onUpdate function Optional callback for updates during runtime
function Scaleform.Run(scaleform, onUpdate) function Scaleform.Run(scaleform, onUpdate)
if runningScaleform then return end if activeScaleform then return end
runningScaleform = scaleform activeScaleform = scaleform
CreateThread(function() CreateThread(function()
while runningScaleform do while activeScaleform do
DrawScaleformMovieFullscreen(scaleform, 255, 255, 255, 255, 0) DrawScaleformMovieFullscreen(scaleform, 255, 255, 255, 255, 0)
if onUpdate then if onUpdate then
shouldQuit = onUpdate() local shouldStop = onUpdate()
if shouldQuit then if shouldStop then
Scaleform.Stop() Scaleform.Stop()
break break
end end
end end
Wait(2)
Wait(RENDER_WAIT_TIME)
end end
end) end)
end end
---Stops the currently running scaleform
function Scaleform.Stop() function Scaleform.Stop()
runningScaleform = nil activeScaleform = nil
end end
exports("Scaleform", Scaleform) exports("Scaleform", Scaleform)
+92
View File
@@ -404,6 +404,98 @@ function Utility.RemovePoint(pointID)
return Point.Remove(pointID) return Point.Remove(pointID)
end end
---Simple switch-case function
---@generic T
---@param value T The value to match against the cases
---@param cases table<T|false, fun(): any> Table with case functions and an optional default (false key)
---@return any|false result The return value of the matched case function, or false if none matched
function Utility.Switch(value, cases)
local caseFunc = cases[value] or cases[false]
if caseFunc and type(caseFunc) == "function" then
local ok, result = pcall(caseFunc)
return ok and result or false
end
return false
end
--[[
local vehicleType = "boat"
local result = Utility.Switch(vehicleType, {
car = function()
print("This is a Car")
-- Car-related logic here
return "Car logic executed"
end,
bike = function()
print("This is a Bike")
-- Bike-related logic here
return "Bike logic executed"
end,
[false] = function()
print("Unknown vehicle type. Running default logic.")
-- Default logic here
return "Default logic executed"
end,
})
print("Result:", result)
]]
--- Pattern match-like function
---@generic T
---@param value T The value to match
---@param patterns table<T|fun(T):boolean|false, fun(): any> A list of matchers and their handlers
---@return any|false result The result of the first matched case, or false if none
function Utility.Match(value, patterns)
for pattern, handler in pairs(patterns) do
if type(pattern) == "function" then
local ok, matched = pcall(pattern, value)
if ok and matched then
local success, result = pcall(handler)
return success and result or false
end
elseif pattern == value then
local success, result = pcall(handler)
return success and result or false
end
end
if patterns[false] then
local ok, result = pcall(patterns[false])
return ok and result or false
end
return false
end
--[[
local input = 42
local result = Utility.Match(input, {
[function(v) return v < 0 end] = function()
print("Negative number")
return "Negative"
end,
[function(v) return v % 2 == 0 end] = function()
print("Even number")
return "Even"
end,
[false] = function()
print("No match")
return "Default"
end,
})
print("Result:", result)
]]
AddEventHandler('onResourceStop', function(resource) AddEventHandler('onResourceStop', function(resource)
if resource ~= GetCurrentResourceName() then return end if resource ~= GetCurrentResourceName() then return end
for _, blip in pairs(blipIDs) do for _, blip in pairs(blipIDs) do
+2 -1
View File
@@ -49,7 +49,8 @@ local function triggerCallback(eventName, target, name, args, callback)
if not callback then if not callback then
local result = Citizen.Await(promise) local result = Citizen.Await(promise)
return #result == 1 and result[1] or table.unpack(result) local returnResults = (result and type(result) == 'table' ) and result or {result}
return table.unpack(returnResults)
end end
end end
+3 -3
View File
@@ -2,9 +2,9 @@ Ids = Ids or {}
---This will generate a unique id. ---This will generate a unique id.
---@param tbl table ---@param tbl table | nil
---@param len number ---@param len number | nil
---@param pattern string ---@param pattern string | nil
---@return string ---@return string
Ids.CreateUniqueId = function(tbl, len, pattern) -- both optional Ids.CreateUniqueId = function(tbl, len, pattern) -- both optional
tbl = tbl or {} -- table to check uniqueness. Ids to check against must be the key to the tables value tbl = tbl or {} -- table to check uniqueness. Ids to check against must be the key to the tables value
+2
View File
@@ -208,3 +208,5 @@ Accessibility.getAdjustedColour = function(colourName, returnAsRGB)
return "#FFFFFF" -- Default to white if the colour name is invalid return "#FFFFFF" -- Default to white if the colour name is invalid
end end
end end
return Accessibility
+2 -2
View File
@@ -34,8 +34,6 @@ Clothing.ReloadSkin = function()
return true return true
end end
Clothing.UpdateAppearanceBackup = function(data) Clothing.UpdateAppearanceBackup = function(data)
ClothingBackup = data ClothingBackup = data
end end
@@ -59,3 +57,5 @@ end)
RegisterNetEvent('community_bridge:client:ReloadSkin', function() RegisterNetEvent('community_bridge:client:ReloadSkin', function()
Clothing.ReloadSkin() Clothing.ReloadSkin()
end) end)
return Clothing
+2
View File
@@ -30,3 +30,5 @@ end)
RegisterNetEvent('community_bridge:client:ReloadSkin', function() RegisterNetEvent('community_bridge:client:ReloadSkin', function()
Clothing.ReloadSkin() Clothing.ReloadSkin()
end) end)
return Clothing
@@ -162,3 +162,5 @@ if BridgeSharedConfig.DebugLevel >= 1 then
end) end)
end) end)
end end
return Dialogue
@@ -27,3 +27,5 @@ RegisterNetEvent('community_bridge:Client:DispatchAlert', function(alert)
Wait(alert.time) Wait(alert.time)
Bridge.Utility.RemoveBlip(blip) Bridge.Utility.RemoveBlip(blip)
end) end)
return Dispatch
@@ -9,3 +9,5 @@ RegisterNetEvent("community_bridge:Server:DispatchAlert", function(data)
end end
end end
end) end)
return Dispatch
@@ -13,3 +13,5 @@ Dispatch.SendAlert = function(data)
} }
exports["bub-mdt"]:CustomAlert(alertData) exports["bub-mdt"]:CustomAlert(alertData)
end end
return Dispatch
@@ -1,2 +1,4 @@
if GetResourceState('bub-mdt') ~= 'started' then return end if GetResourceState('bub-mdt') ~= 'started' then return end
Dispatch = Dispatch or {} Dispatch = Dispatch or {}
return Dispatch
@@ -22,3 +22,5 @@ Dispatch.SendAlert = function(data)
} }
}) })
end end
return Dispatch
@@ -1,2 +1,4 @@
if GetResourceState('cd_dispatch') ~= 'started' then return end if GetResourceState('cd_dispatch') ~= 'started' then return end
Dispatch = Dispatch or {} Dispatch = Dispatch or {}
return Dispatch
@@ -38,3 +38,5 @@ Dispatch.SendAlert = function(data)
} }
TriggerServerEvent("community_bridge:server:dispatch:sendAlert", alertData) TriggerServerEvent("community_bridge:server:dispatch:sendAlert", alertData)
end end
return Dispatch
@@ -4,3 +4,5 @@ Dispatch = Dispatch or {}
RegisterNetEvent("community_bridge:server:dispatch:sendAlert", function(data) RegisterNetEvent("community_bridge:server:dispatch:sendAlert", function(data)
exports["lb-tablet"]:AddDispatch(data) -- this has a return value but we dont really have a use for it atm. exports["lb-tablet"]:AddDispatch(data) -- this has a return value but we dont really have a use for it atm.
end) end)
return Dispatch
@@ -16,3 +16,5 @@ Dispatch.SendAlert = function(data)
coords = data.coords or GetEntityCoords(cache.ped) coords = data.coords or GetEntityCoords(cache.ped)
}) })
end end
return Dispatch
@@ -1,2 +1,4 @@
if GetResourceState('linden_outlawalert') ~= 'started' then return end if GetResourceState('linden_outlawalert') ~= 'started' then return end
Dispatch = Dispatch or {} Dispatch = Dispatch or {}
return Dispatch
@@ -28,3 +28,5 @@ Dispatch.SendAlert = function(data)
} }
exports["ps-dispatch"]:CustomAlert(alertData) exports["ps-dispatch"]:CustomAlert(alertData)
end end
return Dispatch
@@ -1,3 +1,5 @@
if GetResourceState('ps-dispatch') ~= 'started' then return end if GetResourceState('ps-dispatch') ~= 'started' then return end
if GetResourceState('lb-tablet') == 'started' then return end if GetResourceState('lb-tablet') == 'started' then return end
Dispatch = Dispatch or {} Dispatch = Dispatch or {}
return Dispatch
@@ -36,3 +36,5 @@ Dispatch.SendAlert = function(data)
TriggerServerEvent('qs-dispatch:server:CreateDispatchCall', customData) TriggerServerEvent('qs-dispatch:server:CreateDispatchCall', customData)
end) end)
end end
return Dispatch
@@ -1,2 +1,4 @@
if GetResourceState('qs-dispatch') ~= 'started' then return end if GetResourceState('qs-dispatch') ~= 'started' then return end
Dispatch = Dispatch or {} Dispatch = Dispatch or {}
return Dispatch
@@ -12,3 +12,5 @@ Dispatch.SendAlert = function(data)
} }
TriggerServerEvent("community_bridge:server:dispatch:sendAlert", alertData) TriggerServerEvent("community_bridge:server:dispatch:sendAlert", alertData)
end end
return Dispatch
@@ -10,3 +10,5 @@ RegisterNetEvent("community_bridge:server:dispatch:sendAlert", function(data)
coords = data.coords coords = data.coords
}) })
end) end)
return Dispatch
@@ -18,3 +18,5 @@ Dispatch.SendAlert = function(data)
jobs = data.jobs or {'police'}, jobs = data.jobs or {'police'},
}) })
end end
return Dispatch
@@ -1,2 +1,4 @@
if GetResourceState('tk_dispatch') ~= 'started' then return end if GetResourceState('tk_dispatch') ~= 'started' then return end
Dispatch = Dispatch or {} Dispatch = Dispatch or {}
return Dispatch
@@ -1,3 +1,4 @@
---@diagnostic disable: duplicate-set-field
if GetResourceState('doors_creator') ~= 'started' then return end if GetResourceState('doors_creator') ~= 'started' then return end
Doorlock = Doorlock or {} Doorlock = Doorlock or {}
@@ -7,3 +8,5 @@ Doorlock = Doorlock or {}
Doorlock.GetClosestDoor = function() Doorlock.GetClosestDoor = function()
return exports["doors_creator"]:getClosestActiveDoor() return exports["doors_creator"]:getClosestActiveDoor()
end end
return Doorlock
@@ -1,3 +1,4 @@
---@diagnostic disable: duplicate-set-field
if GetResourceState('doors_creator') ~= 'started' then return end if GetResourceState('doors_creator') ~= 'started' then return end
Doorlock = Doorlock or {} Doorlock = Doorlock or {}
@@ -16,3 +17,5 @@ Doorlock.ToggleDoorLock = function(doorID, toggle)
end end
return true return true
end end
return Doorlock
+6 -1
View File
@@ -1,3 +1,4 @@
---@diagnostic disable: duplicate-set-field
if GetResourceState('ox_doorlock') ~= 'started' then return end if GetResourceState('ox_doorlock') ~= 'started' then return end
Doorlock = Doorlock or {} Doorlock = Doorlock or {}
@@ -5,5 +6,9 @@ Doorlock = Doorlock or {}
---This will get the closest door to the ped ---This will get the closest door to the ped
---@return string | nil ---@return string | nil
Doorlock.GetClosestDoor = function() Doorlock.GetClosestDoor = function()
return exports.ox_doorlock:getClosestDoor() local doorData = exports.ox_doorlock:getClosestDoor()
if not doorData then return end
return tostring(doorData.id) or nil
end end
return Doorlock
+3
View File
@@ -1,3 +1,4 @@
---@diagnostic disable: duplicate-set-field
if GetResourceState('ox_doorlock') ~= 'started' then return end if GetResourceState('ox_doorlock') ~= 'started' then return end
Doorlock = Doorlock or {} Doorlock = Doorlock or {}
@@ -15,3 +16,5 @@ Doorlock.ToggleDoorLock = function(doorID, toggle)
end end
return true return true
end end
return Doorlock
+3
View File
@@ -1,3 +1,4 @@
---@diagnostic disable: duplicate-set-field
if GetResourceState('qb-doorlock') ~= 'started' then return end if GetResourceState('qb-doorlock') ~= 'started' then return end
Doorlock = Doorlock or {} Doorlock = Doorlock or {}
@@ -20,3 +21,5 @@ Doorlock.GetClosestDoor = function()
end end
return door return door
end end
return Doorlock
+3
View File
@@ -1,3 +1,4 @@
---@diagnostic disable: duplicate-set-field
if GetResourceState('qb-doorlock') ~= 'started' then return end if GetResourceState('qb-doorlock') ~= 'started' then return end
Doorlock = Doorlock or {} Doorlock = Doorlock or {}
@@ -10,3 +11,5 @@ Doorlock.ToggleDoorLock = function(doorID, toggle)
TriggerClientEvent('qb-doorlock:client:setState', -1, 0, doorID, toggle, false, false, false) TriggerClientEvent('qb-doorlock:client:setState', -1, 0, doorID, toggle, false, false, false)
return true return true
end end
return Doorlock
@@ -1,3 +1,4 @@
---@diagnostic disable: duplicate-set-field
if GetResourceState('rcore_doorlock') ~= 'started' then return end if GetResourceState('rcore_doorlock') ~= 'started' then return end
Doorlock = Doorlock or {} Doorlock = Doorlock or {}
@@ -18,3 +19,5 @@ Doorlock.GetClosestDoor = function()
end end
return door return door
end end
return Doorlock
@@ -1,3 +1,4 @@
---@diagnostic disable: duplicate-set-field
if GetResourceState('rcore_doorlock') ~= 'started' then return end if GetResourceState('rcore_doorlock') ~= 'started' then return end
Doorlock = Doorlock or {} Doorlock = Doorlock or {}
@@ -15,3 +16,4 @@ Doorlock.ToggleDoorLock = function(doorID, toggle)
end end
return true return true
end end
return Doorlock
+3
View File
@@ -0,0 +1,3 @@
Framework = Framework or {}
return Framework
+14 -17
View File
@@ -3,7 +3,7 @@ if GetResourceState('es_extended') ~= 'started' then return end
ESX = exports["es_extended"]:getSharedObject() ESX = exports["es_extended"]:getSharedObject()
Framework = {} Framework = Framework or {}
Framework.GetFrameworkName = function() Framework.GetFrameworkName = function()
return 'es_extended' return 'es_extended'
@@ -15,6 +15,7 @@ Framework.GetPlayerData = function()
return ESX.PlayerData return ESX.PlayerData
end end
--<-- TODO swap to internal callback system
---This will return a table of all the jobs in the framework. ---This will return a table of all the jobs in the framework.
---@return table ---@return table
Framework.GetFrameworkJobs = function() Framework.GetFrameworkJobs = function()
@@ -25,7 +26,7 @@ end
---This will return the players birth date ---This will return the players birth date
---@return string ---@return string
Framework.GetPlayerDob = function() Framework.GetPlayerDob = function()
local playerData = ESX.GetPlayerData() local playerData = Framework.GetPlayerData()
local dob = playerData.dateofbirth local dob = playerData.dateofbirth
return dob return dob
end end
@@ -34,7 +35,7 @@ end
---@param metadata string ---@param metadata string
---@return table | nil ---@return table | nil
Framework.GetPlayerMetaData = function(metadata) Framework.GetPlayerMetaData = function(metadata)
return ESX.GetPlayerData().metadata[metadata] return Framework.GetPlayerData().metadata[metadata]
end end
---This will prompt the user with a notification message ---This will prompt the user with a notification message
@@ -63,7 +64,7 @@ end
---This will return the players identifier ---This will return the players identifier
---@return string ---@return string
Framework.GetPlayerIdentifier = function() Framework.GetPlayerIdentifier = function()
local playerData = ESX.GetPlayerData() local playerData = Framework.GetPlayerData()
return playerData.identifier return playerData.identifier
end end
@@ -71,7 +72,7 @@ end
---@return string ---@return string
---@return string ---@return string
Framework.GetPlayerName = function() Framework.GetPlayerName = function()
local playerData = ESX.GetPlayerData() local playerData = Framework.GetPlayerData()
return playerData.firstName, playerData.lastName return playerData.firstName, playerData.lastName
end end
@@ -81,7 +82,7 @@ end
---@return string ---@return string
---@return string ---@return string
Framework.GetPlayerJob = function() Framework.GetPlayerJob = function()
local playerData = ESX.GetPlayerData() local playerData = Framework.GetPlayerData()
return playerData.job.name, playerData.job.label, playerData.job.grade_label, playerData.job.grade return playerData.job.name, playerData.job.label, playerData.job.grade_label, playerData.job.grade
end end
@@ -96,7 +97,7 @@ end
---This will return a table of the players inventory ---This will return a table of the players inventory
---@return table ---@return table
Framework.GetPlayerInventory = function() Framework.GetPlayerInventory = function()
local playerData = ESX.GetPlayerData() local playerData = Framework.GetPlayerData()
return playerData.inventory return playerData.inventory
end end
@@ -112,25 +113,21 @@ end
---This will return a boolean if the player is dead ---This will return a boolean if the player is dead
---@return boolean ---@return boolean
Framework.GetIsPlayerDead = function() Framework.GetIsPlayerDead = function()
local playerData = ESX.GetPlayerData() local playerData = Framework.GetPlayerData()
return playerData.dead return playerData.dead
end end
RegisterNetEvent('esx:playerLoaded', function(xPlayer) RegisterNetEvent('esx:playerLoaded', function(xPlayer)
Wait(1500) Wait(1500)
FillBridgeTables() TriggerEvent('community_bridge:Client:OnPlayerLoaded')
TriggerEvent('community_bridge:Client:OnPlayerLoaded')
end) end)
RegisterNetEvent('esx:onPlayerLogout', function() RegisterNetEvent('esx:onPlayerLogout', function()
ClearClientSideVariables() TriggerEvent('community_bridge:Client:OnPlayerUnload')
TriggerEvent('community_bridge:Client:OnPlayerUnload')
end) end)
RegisterNetEvent('esx:setJob', function(data) RegisterNetEvent('esx:setJob', function(data)
PlayerJobName = data.name TriggerEvent('community_bridge:Client:OnPlayerJobUpdate', data.name, data.label, data.grade_label, data.grade)
PlayerJobLabel = data.label
PlayerJobGradeName = data.grade_label
PlayerJobGradeLevel = data.grade
TriggerEvent('community_bridge:Client:OnPlayerJobUpdate',PlayerJobName, PlayerJobLabel, PlayerJobGradeName, PlayerJobGradeLevel)
end) end)
return Framework
+61 -36
View File
@@ -1,25 +1,37 @@
---@diagnostic disable: duplicate-set-field ---@diagnostic disable: duplicate-set-field
if GetResourceState('es_extended') ~= 'started' then return end if GetResourceState('es_extended') ~= 'started' then return end
Prints = Prints or Require("lib/utility/shared/prints.lua")
ESX = exports["es_extended"]:getSharedObject() ESX = exports["es_extended"]:getSharedObject()
Framework = {} Framework = Framework or {}
Framework.GetFrameworkName = function() Framework.GetFrameworkName = function()
return 'es_extended' return 'es_extended'
end end
Framework.GetPlayerDob = function(src) Framework.GetPlayerDob = function(src)
local xPlayer = ESX.GetPlayerFromId(src) local xPlayer = Framework.GetPlayer(src)
if not xPlayer then return end if not xPlayer then return end
local dob = xPlayer.get("dateofbirth") local dob = xPlayer.get("dateofbirth")
return dob return dob
end end
--- This will return a table of the players data
---
--- This table is in the framework format and not converted to any standard.
---@param src any
---@return table | nil
Framework.GetPlayer = function(src)
local xPlayer = ESX.GetPlayerFromId(src)
if not xPlayer then return end
return xPlayer
end
-- Framework.GetPlayerIdentifier(src) -- Framework.GetPlayerIdentifier(src)
-- Returns the citizen ID of the player. -- Returns the citizen ID of the player.
Framework.GetPlayerIdentifier = function(src) Framework.GetPlayerIdentifier = function(src)
local xPlayer = ESX.GetPlayerFromId(src) local xPlayer = Framework.GetPlayer(src)
if not xPlayer then return end if not xPlayer then return end
return xPlayer.getIdentifier() return xPlayer.getIdentifier()
end end
@@ -31,7 +43,7 @@ end
-- Framework.GetPlayerName(src) -- Framework.GetPlayerName(src)
-- Returns the first and last name of the player. -- Returns the first and last name of the player.
Framework.GetPlayerName = function(src) Framework.GetPlayerName = function(src)
local xPlayer = ESX.GetPlayerFromId(src) local xPlayer = Framework.GetPlayer(src)
if not xPlayer then return end if not xPlayer then return end
return xPlayer.variables.firstName, xPlayer.variables.lastName return xPlayer.variables.firstName, xPlayer.variables.lastName
end end
@@ -51,7 +63,7 @@ end
-- Returns a table of items matching the specified name and if passed metadata from the player's inventory. -- Returns a table of items matching the specified name and if passed metadata from the player's inventory.
-- returns {name = v.name, count = v.amount, metadata = v.info, slot = v.slot} -- returns {name = v.name, count = v.amount, metadata = v.info, slot = v.slot}
Framework.GetItem = function(src, item, _) Framework.GetItem = function(src, item, _)
local xPlayer = ESX.GetPlayerFromId(src) local xPlayer = Framework.GetPlayer(src)
if not xPlayer then return end if not xPlayer then return end
local playerItems = xPlayer.getInventory() local playerItems = xPlayer.getInventory()
local repackedTable = {} local repackedTable = {}
@@ -71,7 +83,7 @@ end
-- Framework.GetItemCount(src, item, _) -- Framework.GetItemCount(src, item, _)
-- Returns the count of items matching the specified name and if passed metadata from the player's inventory. -- Returns the count of items matching the specified name and if passed metadata from the player's inventory.
Framework.GetItemCount = function(src, item, _) Framework.GetItemCount = function(src, item, _)
local xPlayer = ESX.GetPlayerFromId(src) local xPlayer = Framework.GetPlayer(src)
if not xPlayer then return end if not xPlayer then return end
return xPlayer.getInventoryItem(item).count return xPlayer.getInventoryItem(item).count
end end
@@ -89,19 +101,19 @@ end
-- Returns the entire inventory of the player as a table. -- Returns the entire inventory of the player as a table.
-- returns {name = v.name, count = v.amount, _, _} -- returns {name = v.name, count = v.amount, _, _}
Framework.GetPlayerInventory = function(src) Framework.GetPlayerInventory = function(src)
local xPlayer = ESX.GetPlayerFromId(src) local xPlayer = Framework.GetPlayer(src)
if not xPlayer then return end if not xPlayer then return end
local playerItems = xPlayer.getInventory() local playerItems = xPlayer.getInventory()
local repackedTable = {} local repackedTable = {}
for _, v in pairs(playerItems) do for _, v in pairs(playerItems) do
if v.count > 0 then if v.count > 0 then
table.insert(repackedTable, { table.insert(repackedTable, {
name = v.name, name = v.name,
count = v.count, count = v.count,
--metadata = v.metadata, --metadata = v.metadata,
--slot = v.slot, --slot = v.slot,
}) })
end end
end end
return repackedTable return repackedTable
end end
@@ -109,7 +121,7 @@ end
-- Framework.SetMetadata(src, metadata, value) -- Framework.SetMetadata(src, metadata, value)
-- Adds the specified metadata key and number value to the player's data. -- Adds the specified metadata key and number value to the player's data.
Framework.SetPlayerMetadata = function(src, metadata, value) Framework.SetPlayerMetadata = function(src, metadata, value)
local xPlayer = ESX.GetPlayerFromId(src) local xPlayer = Framework.GetPlayer(src)
if not xPlayer then return end if not xPlayer then return end
xPlayer.setMeta(metadata, value, nil) xPlayer.setMeta(metadata, value, nil)
return true return true
@@ -118,7 +130,7 @@ end
-- Framework.GetMetadata(src, metadata) -- Framework.GetMetadata(src, metadata)
-- Gets the specified metadata key and value to the player's data. -- Gets the specified metadata key and value to the player's data.
Framework.GetPlayerMetadata = function(src, metadata) Framework.GetPlayerMetadata = function(src, metadata)
local xPlayer = ESX.GetPlayerFromId(src) local xPlayer = Framework.GetPlayer(src)
if not xPlayer then return end if not xPlayer then return end
return xPlayer.getMeta(metadata) or false return xPlayer.getMeta(metadata) or false
end end
@@ -129,17 +141,24 @@ end
-- skin, status, is_dead, id, disabled, last_property, created_at, last_seen, -- skin, status, is_dead, id, disabled, last_property, created_at, last_seen,
-- phone_number, pincode -- phone_number, pincode
Framework.GetStatus = function(src, column) Framework.GetStatus = function(src, column)
local xPlayer = ESX.GetPlayerFromId(src) local xPlayer = Framework.GetPlayer(src)
if not xPlayer then return end if not xPlayer then return end
return xPlayer.get(column) or nil return xPlayer.get(column) or nil
end end
Framework.GetIsPlayerDead = function(src) Framework.GetIsPlayerDead = function(src)
local xPlayer = ESX.GetPlayerFromId(src) local xPlayer = Framework.GetPlayer(src)
if not xPlayer then return end if not xPlayer then return end
return xPlayer.get("is_dead") or false return xPlayer.get("is_dead") or false
end end
Framework.RevivePlayer = function(src)
src = tonumber(src)
if not src then return false end
TriggerEvent('esx_ambulancejob:revive', src)
return true
end
-- Framework.AddThirst(src, value) -- Framework.AddThirst(src, value)
-- Adds the specified value from the player's thirst level. -- Adds the specified value from the player's thirst level.
Framework.AddThirst = function(src, value) Framework.AddThirst = function(src, value)
@@ -173,7 +192,7 @@ end
-- Framework.GetPlayerPhone(src) -- Framework.GetPlayerPhone(src)
-- Returns the phone number of the player. -- Returns the phone number of the player.
Framework.GetPlayerPhone = function(src) Framework.GetPlayerPhone = function(src)
local xPlayer = ESX.GetPlayerFromId(src) local xPlayer = Framework.GetPlayer(src)
if not xPlayer then return end if not xPlayer then return end
return xPlayer.get("phone_number") return xPlayer.get("phone_number")
end end
@@ -186,7 +205,7 @@ end
---@return string | nil ---@return string | nil
---@return string | nil ---@return string | nil
Framework.GetPlayerJob = function(src) Framework.GetPlayerJob = function(src)
local xPlayer = ESX.GetPlayerFromId(src) local xPlayer = Framework.GetPlayer(src)
if not xPlayer then return end if not xPlayer then return end
local job = xPlayer.getJob() local job = xPlayer.getJob()
return job.name, job.label, job.grade_label, job.grade return job.name, job.label, job.grade_label, job.grade
@@ -196,7 +215,7 @@ end
---@param src number ---@param src number
---@return boolean ---@return boolean
Framework.GetPlayerDuty = function(src) Framework.GetPlayerDuty = function(src)
local xPlayer = ESX.GetPlayerFromId(src) local xPlayer = Framework.GetPlayer(src)
if not xPlayer then return false end if not xPlayer then return false end
local job = xPlayer.getJob() local job = xPlayer.getJob()
if not job.onDuty then return false end if not job.onDuty then return false end
@@ -208,7 +227,7 @@ end
---@param dutystatus boolean ---@param dutystatus boolean
---@return boolean ---@return boolean
Framework.SetPlayerDuty = function(src, dutystatus) Framework.SetPlayerDuty = function(src, dutystatus)
local xPlayer = ESX.GetPlayerFromId(src) local xPlayer = Framework.GetPlayer(src)
if not xPlayer then return false end if not xPlayer then return false end
local job = xPlayer.getJob() local job = xPlayer.getJob()
if not job.onDuty then return false end if not job.onDuty then return false end
@@ -221,7 +240,7 @@ Framework.GetPlayersByJob = function(job)
local players = GetPlayers() local players = GetPlayers()
local playerList = {} local playerList = {}
for _, src in pairs(players) do for _, src in pairs(players) do
local xPlayer = ESX.GetPlayerFromId(src) local xPlayer = Framework.GetPlayer(src)
if xPlayer.getJob().name == job then if xPlayer.getJob().name == job then
table.insert(playerList, src) table.insert(playerList, src)
end end
@@ -232,16 +251,19 @@ end
-- Framework.SetPlayerJob(src, name, grade) -- Framework.SetPlayerJob(src, name, grade)
-- Sets the player's job to the specified name and grade. -- Sets the player's job to the specified name and grade.
Framework.SetPlayerJob = function(src, name, grade) Framework.SetPlayerJob = function(src, name, grade)
local xPlayer = ESX.GetPlayerFromId(src) local xPlayer = Framework.GetPlayer(src)
if not xPlayer then return end if not xPlayer then return end
if not ESX.DoesJobExist(name, grade) then lib.print.error("Job Does Not Exsist In Framework :NAME "..name.." Grade:"..grade) return end if not ESX.DoesJobExist(name, grade) then
Prints.Error("Job Does Not Exsist In Framework :NAME " .. name .. " Grade:" .. grade)
return
end
return xPlayer.setJob(name, grade, true) return xPlayer.setJob(name, grade, true)
end end
-- Framework.AddAccountBalance(src, _type, amount) -- Framework.AddAccountBalance(src, _type, amount)
-- Adds the specified amount to the player's account balance of the specified type. -- Adds the specified amount to the player's account balance of the specified type.
Framework.AddAccountBalance = function(src, _type, amount) Framework.AddAccountBalance = function(src, _type, amount)
local xPlayer = ESX.GetPlayerFromId(src) local xPlayer = Framework.GetPlayer(src)
if not xPlayer then return end if not xPlayer then return end
if _type == 'cash' then _type = 'money' end if _type == 'cash' then _type = 'money' end
return xPlayer.addAccountMoney(_type, amount) return xPlayer.addAccountMoney(_type, amount)
@@ -250,7 +272,7 @@ end
-- Framework.RemoveAccountBalance(src, _type, amount) -- Framework.RemoveAccountBalance(src, _type, amount)
-- Removes the specified amount from the player's account balance of the specified type. -- Removes the specified amount from the player's account balance of the specified type.
Framework.RemoveAccountBalance = function(src, _type, amount) Framework.RemoveAccountBalance = function(src, _type, amount)
local xPlayer = ESX.GetPlayerFromId(src) local xPlayer = Framework.GetPlayer(src)
if not xPlayer then return end if not xPlayer then return end
if _type == 'cash' then _type = 'money' end if _type == 'cash' then _type = 'money' end
xPlayer.removeAccountMoney(_type, amount) xPlayer.removeAccountMoney(_type, amount)
@@ -260,7 +282,7 @@ end
-- Framework.GetAccountBalance(src, _type) -- Framework.GetAccountBalance(src, _type)
-- Returns the player's account balance of the specified type. -- Returns the player's account balance of the specified type.
Framework.GetAccountBalance = function(src, _type) Framework.GetAccountBalance = function(src, _type)
local xPlayer = ESX.GetPlayerFromId(src) local xPlayer = Framework.GetPlayer(src)
if not xPlayer then return end if not xPlayer then return end
if _type == 'cash' then _type = 'money' end if _type == 'cash' then _type = 'money' end
return xPlayer.getAccount(_type).money return xPlayer.getAccount(_type).money
@@ -269,7 +291,7 @@ end
-- Framework.AddItem(src, item, amount, _, _) -- Framework.AddItem(src, item, amount, _, _)
-- Adds the specified item to the player's inventory. -- Adds the specified item to the player's inventory.
Framework.AddItem = function(src, item, amount, slot, metadata) Framework.AddItem = function(src, item, amount, slot, metadata)
local xPlayer = ESX.GetPlayerFromId(src) local xPlayer = Framework.GetPlayer(src)
if not xPlayer then return end if not xPlayer then return end
return xPlayer.addInventoryItem(item, amount) return xPlayer.addInventoryItem(item, amount)
end end
@@ -277,7 +299,7 @@ end
-- Framework.RemoveItem(src, item, amount, _, _) -- Framework.RemoveItem(src, item, amount, _, _)
-- Removes the specified item from the player's inventory. -- Removes the specified item from the player's inventory.
Framework.RemoveItem = function(src, item, amount, slot, metadata) Framework.RemoveItem = function(src, item, amount, slot, metadata)
local xPlayer = ESX.GetPlayerFromId(src) local xPlayer = Framework.GetPlayer(src)
if not xPlayer then return end if not xPlayer then return end
return xPlayer.removeInventoryItem(item, amount) return xPlayer.removeInventoryItem(item, amount)
end end
@@ -285,14 +307,14 @@ end
Framework.GetOwnedVehicles = function(src) Framework.GetOwnedVehicles = function(src)
local citizenId = Framework.GetPlayerIdentifier(src) local citizenId = Framework.GetPlayerIdentifier(src)
local result = MySQL.Sync.fetchAll("SELECT vehicle, plate FROM owned_vehicles WHERE owner = '" .. citizenId .. "'") local result = MySQL.Sync.fetchAll("SELECT vehicle, plate FROM owned_vehicles WHERE owner = '" .. citizenId .. "'")
local vehicles = {} local vehicles = {}
for i=1, #result do for i = 1, #result do
local vehicle = result[i].vehicle local vehicle = result[i].vehicle
local plate = result[i].plate local plate = result[i].plate
local model = json.decode(vehicle).model local model = json.decode(vehicle).model
table.insert(vehicles, {vehicle = model, plate = plate}) table.insert(vehicles, { vehicle = model, plate = plate })
end end
return vehicles return vehicles
end end
-- Framework.RegisterUsableItem(item, cb) -- Framework.RegisterUsableItem(item, cb)
@@ -322,8 +344,9 @@ AddEventHandler("playerDropped", function()
TriggerEvent("community_bridge:Server:OnPlayerUnload", src) TriggerEvent("community_bridge:Server:OnPlayerUnload", src)
end) end)
--<-- TODO swap to internal callback system
lib.callback.register('community_bridge:Callback:GetFrameworkJobs', function(source) lib.callback.register('community_bridge:Callback:GetFrameworkJobs', function(source)
return Framework.GetFrameworkJobs() or {} return Framework.GetFrameworkJobs() or {}
end) end)
Framework.Commands = {} Framework.Commands = {}
@@ -335,3 +358,5 @@ Framework.Commands.Add = function(name, help, arguments, argsrequired, callback,
arguments = arguments arguments = arguments
}) })
end end
return Framework
+13 -17
View File
@@ -4,7 +4,7 @@ if GetResourceState('qbx_core') == 'started' then return end
QBCore = exports['qb-core']:GetCoreObject() QBCore = exports['qb-core']:GetCoreObject()
Framework = {} Framework = Framework or {}
---This will get the name of the framework being used (if a supported framework). ---This will get the name of the framework being used (if a supported framework).
---@return string ---@return string
@@ -33,7 +33,7 @@ end
---This will get the players birth date ---This will get the players birth date
---@return string ---@return string
Framework.GetPlayerDob = function() Framework.GetPlayerDob = function()
local player = QBCore.Functions.GetPlayerData() local player = Framework.GetPlayerData()
local playerData = player.PlayerData local playerData = player.PlayerData
return playerData.charinfo.birthdate return playerData.charinfo.birthdate
end end
@@ -42,7 +42,7 @@ end
---@param metadata table | string ---@param metadata table | string
---@return table | string | number | boolean ---@return table | string | number | boolean
Framework.GetPlayerMetaData = function(metadata) Framework.GetPlayerMetaData = function(metadata)
return QBCore.Functions.GetPlayerData().metadata[metadata] return Framework.GetPlayerData().metadata[metadata]
end end
Framework.Notify = function(message, type, time) Framework.Notify = function(message, type, time)
@@ -80,14 +80,14 @@ end
---This will get the players identifier (citizenid) etc. ---This will get the players identifier (citizenid) etc.
---@return string ---@return string
Framework.GetPlayerIdentifier = function() Framework.GetPlayerIdentifier = function()
return QBCore.Functions.GetPlayerData().citizenid return Framework.GetPlayerData().citizenid
end end
---This will get the players name (first and last). ---This will get the players name (first and last).
---@return string ---@return string
---@return string ---@return string
Framework.GetPlayerName = function() Framework.GetPlayerName = function()
local playerData = QBCore.Functions.GetPlayerData() local playerData = Framework.GetPlayerData()
return playerData.charinfo.firstname, playerData.charinfo.lastname return playerData.charinfo.firstname, playerData.charinfo.lastname
end end
@@ -97,7 +97,7 @@ end
---@return string ---@return string
---@return string ---@return string
Framework.GetPlayerJob = function() Framework.GetPlayerJob = function()
local playerData = QBCore.Functions.GetPlayerData() local playerData = Framework.GetPlayerData()
return playerData.job.name, playerData.job.label, playerData.job.grade.name, playerData.job.grade.level return playerData.job.name, playerData.job.label, playerData.job.grade.name, playerData.job.grade.level
end end
@@ -109,7 +109,7 @@ end
---@param item string ---@param item string
---@return number ---@return number
Framework.GetItemCount = function(item) Framework.GetItemCount = function(item)
local frameworkInv = QBCore.Functions.GetPlayerData().items local frameworkInv = Framework.GetPlayerData().items
local count = 0 local count = 0
for _, v in pairs(frameworkInv) do for _, v in pairs(frameworkInv) do
if v.name == item then if v.name == item then
@@ -121,7 +121,7 @@ end
Framework.GetPlayerInventory = function() Framework.GetPlayerInventory = function()
local items = {} local items = {}
local frameworkInv = QBCore.Functions.GetPlayerData().items local frameworkInv = Framework.GetPlayerData().items
for _, v in pairs(frameworkInv) do for _, v in pairs(frameworkInv) do
table.insert(items, { table.insert(items, {
name = v.name, name = v.name,
@@ -140,7 +140,7 @@ end
---This will get a players dead status. ---This will get a players dead status.
---@return boolean ---@return boolean
Framework.GetIsPlayerDead = function() Framework.GetIsPlayerDead = function()
local playerData = QBCore.Functions.GetPlayerData() local playerData = Framework.GetPlayerData()
return playerData.metadata["isdead"] or playerData.metadata["inlaststand"] return playerData.metadata["isdead"] or playerData.metadata["inlaststand"]
end end
@@ -148,21 +148,15 @@ Framework.Shared = QBCore.Shared
RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function() RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function()
Wait(1500) Wait(1500)
FillBridgeTables()
TriggerEvent('community_bridge:Client:OnPlayerLoaded') TriggerEvent('community_bridge:Client:OnPlayerLoaded')
end) end)
RegisterNetEvent('QBCore:Client:OnPlayerUnload', function() RegisterNetEvent('QBCore:Client:OnPlayerUnload', function()
ClearClientSideVariables() TriggerEvent('community_bridge:Client:OnPlayerUnload')
TriggerEvent('community_bridge:Client:OnPlayerUnload')
end) end)
RegisterNetEvent('QBCore:Client:OnJobUpdate', function(data) RegisterNetEvent('QBCore:Client:OnJobUpdate', function(data)
PlayerJobName = data.name TriggerEvent('community_bridge:Client:OnPlayerJobUpdate', data.name, data.label, data.grade_label, data.grade)
PlayerJobLabel = data.label
PlayerJobGradeName = data.grade.name
PlayerJobGradeLevel = data.grade.level
TriggerEvent('community_bridge:Client:OnPlayerJobUpdate', PlayerJobName, PlayerJobLabel, PlayerJobGradeName, PlayerJobGradeLevel)
end) end)
RegisterNetEvent('QBCore:Client:OnGangUpdate', function(data) RegisterNetEvent('QBCore:Client:OnGangUpdate', function(data)
@@ -175,3 +169,5 @@ RegisterNetEvent('QBCore:Client:OnGangUpdate', function(data)
TriggerEvent('community_bridge:Client:OnPlayerGangUpdate', PlayerGangName, PlayerGangLabel, PlayerGangGradeName, PlayerGangGradeLevel) TriggerEvent('community_bridge:Client:OnPlayerGangUpdate', PlayerGangName, PlayerGangLabel, PlayerGangGradeName, PlayerGangGradeLevel)
--]] --]]
end) end)
return Framework
+64 -39
View File
@@ -4,7 +4,7 @@ if GetResourceState('qbx_core') == 'started' then return end
QBCore = exports['qb-core']:GetCoreObject() QBCore = exports['qb-core']:GetCoreObject()
Framework = {} Framework = Framework or {}
Framework.Shared = QBCore.Shared Framework.Shared = QBCore.Shared
Framework.GetFrameworkName = function() Framework.GetFrameworkName = function()
return 'qb-core' return 'qb-core'
@@ -13,12 +13,21 @@ end
-- Framework.GetPlayerIdentifier(src) -- Framework.GetPlayerIdentifier(src)
-- Returns the citizen ID of the player. -- Returns the citizen ID of the player.
Framework.GetPlayerIdentifier = function(src) Framework.GetPlayerIdentifier = function(src)
local player = QBCore.Functions.GetPlayer(src) local player = Framework.GetPlayer(src)
if not player then return end if not player then return end
local playerData = player.PlayerData local playerData = player.PlayerData
return playerData.citizenid return playerData.citizenid
end end
--- Returns the player data of the specified source.
---@param src any
---@return table | nil
Framework.GetPlayer = function(src)
local player = QBCore.Functions.GetPlayer(src)
if not player then return end
return player
end
Framework.GetFrameworkJobs = function() Framework.GetFrameworkJobs = function()
local jobs = {} local jobs = {}
for k, v in pairs(QBCore.Shared.Jobs) do for k, v in pairs(QBCore.Shared.Jobs) do
@@ -35,7 +44,7 @@ end
-- Returns the first and last name of the player. -- Returns the first and last name of the player.
---@return string, string ---@return string, string
Framework.GetPlayerName = function(src) Framework.GetPlayerName = function(src)
local player = QBCore.Functions.GetPlayer(src) local player = Framework.GetPlayer(src)
if not player then return end if not player then return end
local playerData = player.PlayerData local playerData = player.PlayerData
return playerData.charinfo.firstname, playerData.charinfo.lastname return playerData.charinfo.firstname, playerData.charinfo.lastname
@@ -44,7 +53,7 @@ end
---This will get the players birth date ---This will get the players birth date
---@return string ---@return string
Framework.GetPlayerDob = function(src) Framework.GetPlayerDob = function(src)
local player = QBCore.Functions.GetPlayer(src) local player = Framework.GetPlayer(src)
if not player then return end if not player then return end
local playerData = player.PlayerData local playerData = player.PlayerData
return playerData.charinfo.birthdate return playerData.charinfo.birthdate
@@ -54,7 +63,7 @@ end
-- Returns a table of items matching the specified name and if passed metadata from the player's inventory. -- Returns a table of items matching the specified name and if passed metadata from the player's inventory.
-- returns {name = v.name, count = v.amount, metadata = v.info, slot = v.slot} -- returns {name = v.name, count = v.amount, metadata = v.info, slot = v.slot}
Framework.GetItem = function(src, item, metadata) Framework.GetItem = function(src, item, metadata)
local player = QBCore.Functions.GetPlayer(src) local player = Framework.GetPlayer(src)
if not player then return end if not player then return end
local playerData = player.PlayerData local playerData = player.PlayerData
local playerInventory = playerData.items local playerInventory = playerData.items
@@ -72,7 +81,7 @@ Framework.GetItem = function(src, item, metadata)
return repackedTable return repackedTable
end end
---This will get the data about an item such as name, label, stack, weight, description and image. ---This will return a table with the item info, {name, label, stack, weight, description, image}
---@param item string ---@param item string
---@return table ---@return table
Framework.GetItemInfo = function(item) Framework.GetItemInfo = function(item)
@@ -89,10 +98,15 @@ Framework.GetItemInfo = function(item)
return repackedTable return repackedTable
end end
-- Framework.GetItemCount(src, item, metadata) ---This will return the count of the item in the players inventory, if not found will return 0.
-- Returns the count of items matching the specified name and if passed metadata from the player's inventory. ---
---if metadata is passed it will find the matching items count.
---@param src number
---@param item string
---@param metadata table
---@return number
Framework.GetItemCount = function(src, item, metadata) Framework.GetItemCount = function(src, item, metadata)
local player = QBCore.Functions.GetPlayer(src) local player = Framework.GetPlayer(src)
if not player then return end if not player then return end
local playerData = player.PlayerData local playerData = player.PlayerData
local playerInventory = playerData.items local playerInventory = playerData.items
@@ -105,7 +119,7 @@ Framework.GetItemCount = function(src, item, metadata)
return count return count
end end
---comment ---This will return a boolean if the player has the item.
---@param src number ---@param src number
---@param item string ---@param item string
---@return boolean ---@return boolean
@@ -118,7 +132,7 @@ end
-- Returns the entire inventory of the player as a table. -- Returns the entire inventory of the player as a table.
-- returns {name = v.name, count = v.amount, metadata = v.info, slot = v.slot} -- returns {name = v.name, count = v.amount, metadata = v.info, slot = v.slot}
Framework.GetPlayerInventory = function(src) Framework.GetPlayerInventory = function(src)
local player = QBCore.Functions.GetPlayer(src) local player = Framework.GetPlayer(src)
if not player then return end if not player then return end
local playerData = player.PlayerData local playerData = player.PlayerData
local playerInventory = playerData.items local playerInventory = playerData.items
@@ -146,7 +160,7 @@ Framework.GetPlayers = function()
end end
Framework.GetItemBySlot = function(src, slot) Framework.GetItemBySlot = function(src, slot)
local player = QBCore.Functions.GetPlayer(src) local player = Framework.GetPlayer(src)
if not player then return end if not player then return end
local playerData = player.PlayerData local playerData = player.PlayerData
local playerInventory = playerData.items local playerInventory = playerData.items
@@ -172,7 +186,7 @@ end
-- Adds the specified metadata key and number value to the player's data. -- Adds the specified metadata key and number value to the player's data.
---@return boolean | nil ---@return boolean | nil
Framework.SetPlayerMetadata = function(src, metadata, value) Framework.SetPlayerMetadata = function(src, metadata, value)
local player = QBCore.Functions.GetPlayer(src) local player = Framework.GetPlayer(src)
if not player then return end if not player then return end
player.Functions.SetMetaData(metadata, value) player.Functions.SetMetaData(metadata, value)
return true return true
@@ -181,7 +195,7 @@ end
-- Framework.GetMetadata(src, metadata) -- Framework.GetMetadata(src, metadata)
-- Gets the specified metadata key to the player's data. -- Gets the specified metadata key to the player's data.
Framework.GetPlayerMetadata = function(src, metadata) Framework.GetPlayerMetadata = function(src, metadata)
local player = QBCore.Functions.GetPlayer(src) local player = Framework.GetPlayer(src)
if not player then return end if not player then return end
local playerData = player.PlayerData local playerData = player.PlayerData
return playerData.metadata[metadata] or false return playerData.metadata[metadata] or false
@@ -191,7 +205,7 @@ end
-- Adds the specified value to the player's stress level and updates the client HUD. -- Adds the specified value to the player's stress level and updates the client HUD.
---@return number | nil ---@return number | nil
Framework.AddStress = function(src, value) Framework.AddStress = function(src, value)
local player = QBCore.Functions.GetPlayer(src) local player = Framework.GetPlayer(src)
if not player then return end if not player then return end
local playerData = player.PlayerData local playerData = player.PlayerData
local newStress = playerData.metadata.stress + value local newStress = playerData.metadata.stress + value
@@ -204,7 +218,7 @@ end
-- Removes the specified value from the player's stress level and updates the client HUD. -- Removes the specified value from the player's stress level and updates the client HUD.
---@return number | nil ---@return number | nil
Framework.RemoveStress = function(src, value) Framework.RemoveStress = function(src, value)
local player = QBCore.Functions.GetPlayer(src) local player = Framework.GetPlayer(src)
if not player then return end if not player then return end
local playerData = player.PlayerData local playerData = player.PlayerData
local newStress = (playerData.metadata.stress or 0) - value local newStress = (playerData.metadata.stress or 0) - value
@@ -217,7 +231,7 @@ end
-- Adds the specified value from the player's hunger level. -- Adds the specified value from the player's hunger level.
---@return number | nil ---@return number | nil
Framework.AddHunger = function(src, value) Framework.AddHunger = function(src, value)
local player = QBCore.Functions.GetPlayer(src) local player = Framework.GetPlayer(src)
if not player then return end if not player then return end
local playerData = player.PlayerData local playerData = player.PlayerData
local newHunger = (playerData.metadata.hunger or 0) + value local newHunger = (playerData.metadata.hunger or 0) + value
@@ -232,7 +246,7 @@ end
-- Adds the specified value from the player's thirst level. -- Adds the specified value from the player's thirst level.
---@return number | nil ---@return number | nil
Framework.AddThirst = function(src, value) Framework.AddThirst = function(src, value)
local player = QBCore.Functions.GetPlayer(src) local player = Framework.GetPlayer(src)
if not player then return end if not player then return end
local playerData = player.PlayerData local playerData = player.PlayerData
local newThirst = (playerData.metadata.thirst or 0) + value local newThirst = (playerData.metadata.thirst or 0) + value
@@ -246,7 +260,7 @@ end
---@param src any ---@param src any
---@return number | nil ---@return number | nil
Framework.GetHunger = function(src) Framework.GetHunger = function(src)
local player = QBCore.Functions.GetPlayer(src) local player = Framework.GetPlayer(src)
if not player then return end if not player then return end
local playerData = player.PlayerData local playerData = player.PlayerData
local newHunger = (playerData.metadata.hunger or 0) local newHunger = (playerData.metadata.hunger or 0)
@@ -254,18 +268,25 @@ Framework.GetHunger = function(src)
end end
Framework.GetIsPlayerDead = function(src) Framework.GetIsPlayerDead = function(src)
local player = QBCore.Functions.GetPlayer(src) local player = Framework.GetPlayer(src)
if not player then return end if not player then return end
local playerData = player.PlayerData local playerData = player.PlayerData
return playerData.metadata.isdead or playerData.metadata.inlaststand or false return playerData.metadata.isdead or playerData.metadata.inlaststand or false
end end
Framework.RevivePlayer = function(src)
src = tonumber(src)
if not src then return false end
TriggerClientEvent('hospital:client:Revive', src)
return true
end
---This will get the thirst of a player ---This will get the thirst of a player
---@param src any ---@param src any
---@return number | nil ---@return number | nil
Framework.GetThirst = function(src) Framework.GetThirst = function(src)
local player = QBCore.Functions.GetPlayer(src) local player = Framework.GetPlayer(src)
if not player then return end if not player then return end
local playerData = player.PlayerData local playerData = player.PlayerData
local newThirst = (playerData.metadata.thirst or 0) local newThirst = (playerData.metadata.thirst or 0)
@@ -275,7 +296,7 @@ end
-- Framework.GetPlayerPhone(src) -- Framework.GetPlayerPhone(src)
-- Returns the phone number of the player. -- Returns the phone number of the player.
Framework.GetPlayerPhone = function(src) Framework.GetPlayerPhone = function(src)
local player = QBCore.Functions.GetPlayer(src) local player = Framework.GetPlayer(src)
if not player then return end if not player then return end
local playerData = player.PlayerData local playerData = player.PlayerData
return playerData.charinfo.phone return playerData.charinfo.phone
@@ -284,7 +305,7 @@ end
-- Framework.GetPlayerGang(src) -- Framework.GetPlayerGang(src)
-- Returns the gang name of the player. -- Returns the gang name of the player.
Framework.GetPlayerGang = function(src) Framework.GetPlayerGang = function(src)
local player = QBCore.Functions.GetPlayer(src) local player = Framework.GetPlayer(src)
if not player then return end if not player then return end
local playerData = player.PlayerData local playerData = player.PlayerData
return playerData.gang.name return playerData.gang.name
@@ -297,7 +318,7 @@ Framework.GetPlayersByJob = function(job)
local playerList = {} local playerList = {}
local players = QBCore.Functions.GetPlayers() local players = QBCore.Functions.GetPlayers()
for _, src in pairs(players) do for _, src in pairs(players) do
local player = QBCore.Functions.GetPlayer(src).PlayerData local player = Framework.GetPlayer(src).PlayerData
if player.job.name == job then if player.job.name == job then
table.insert(playerList, src) table.insert(playerList, src)
end end
@@ -312,7 +333,7 @@ end
---@return string ---@return string
---@return string ---@return string
Framework.GetPlayerJob = function(src) Framework.GetPlayerJob = function(src)
local player = QBCore.Functions.GetPlayer(src) local player = Framework.GetPlayer(src)
if not player then return end if not player then return end
local playerData = player.PlayerData local playerData = player.PlayerData
return playerData.job.name, playerData.job.label, playerData.job.grade.name, playerData.job.grade.level return playerData.job.name, playerData.job.label, playerData.job.grade.name, playerData.job.grade.level
@@ -322,7 +343,7 @@ end
---@param src number ---@param src number
---@return boolean | nil ---@return boolean | nil
Framework.GetPlayerDuty = function(src) Framework.GetPlayerDuty = function(src)
local player = QBCore.Functions.GetPlayer(src) local player = Framework.GetPlayer(src)
if not player then return end if not player then return end
local playerData = player.PlayerData local playerData = player.PlayerData
if not playerData.job.onduty then return false end if not playerData.job.onduty then return false end
@@ -334,7 +355,7 @@ end
---@param status boolean ---@param status boolean
---@return nil ---@return nil
Framework.SetPlayerDuty = function(src, status) Framework.SetPlayerDuty = function(src, status)
local player = QBCore.Functions.GetPlayer(src) local player = Framework.GetPlayer(src)
if not player then return end if not player then return end
player.Functions.SetJobDuty(status) player.Functions.SetJobDuty(status)
TriggerEvent('QBCore:Server:SetDuty', src, player.PlayerData.job.onduty) TriggerEvent('QBCore:Server:SetDuty', src, player.PlayerData.job.onduty)
@@ -346,7 +367,7 @@ end
---@param grade string ---@param grade string
---@return nil ---@return nil
Framework.SetPlayerJob = function(src, name, grade) Framework.SetPlayerJob = function(src, name, grade)
local player = QBCore.Functions.GetPlayer(src) local player = Framework.GetPlayer(src)
if not player then return end if not player then return end
return player.Functions.SetJob(name, grade) return player.Functions.SetJob(name, grade)
end end
@@ -357,7 +378,7 @@ end
---@param amount number ---@param amount number
---@return boolean | nil ---@return boolean | nil
Framework.AddAccountBalance = function(src, _type, amount) Framework.AddAccountBalance = function(src, _type, amount)
local player = QBCore.Functions.GetPlayer(src) local player = Framework.GetPlayer(src)
if not player then return end if not player then return end
if _type == 'money' then _type = 'cash' end if _type == 'money' then _type = 'cash' end
return player.Functions.AddMoney(_type, amount) return player.Functions.AddMoney(_type, amount)
@@ -369,7 +390,7 @@ end
---@param amount number ---@param amount number
---@return boolean | nil ---@return boolean | nil
Framework.RemoveAccountBalance = function(src, _type, amount) Framework.RemoveAccountBalance = function(src, _type, amount)
local player = QBCore.Functions.GetPlayer(src) local player = Framework.GetPlayer(src)
if not player then return end if not player then return end
if _type == 'money' then _type = 'cash' end if _type == 'money' then _type = 'cash' end
return player.Functions.RemoveMoney(_type, amount) return player.Functions.RemoveMoney(_type, amount)
@@ -380,7 +401,7 @@ end
---@param _type string ---@param _type string
---@return string | nil ---@return string | nil
Framework.GetAccountBalance = function(src, _type) Framework.GetAccountBalance = function(src, _type)
local player = QBCore.Functions.GetPlayer(src) local player = Framework.GetPlayer(src)
if not player then return end if not player then return end
local playerData = player.PlayerData local playerData = player.PlayerData
if _type == 'money' then _type = 'cash' end if _type == 'money' then _type = 'cash' end
@@ -390,18 +411,20 @@ end
-- Framework.AddItem(src, item, amount, slot, metadata) -- Framework.AddItem(src, item, amount, slot, metadata)
-- Adds the specified item to the player's inventory. -- Adds the specified item to the player's inventory.
Framework.AddItem = function(src, item, amount, slot, metadata) Framework.AddItem = function(src, item, amount, slot, metadata)
local player = QBCore.Functions.GetPlayer(src) local player = Framework.GetPlayer(src)
if not player then return end if not player then return end
TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "add", item = item, count = amount, slot = slot, metadata = metadata}) TriggerClientEvent("community_bridge:client:inventory:updateInventory", src,
{ action = "add", item = item, count = amount, slot = slot, metadata = metadata })
return player.Functions.AddItem(item, amount, slot, metadata) return player.Functions.AddItem(item, amount, slot, metadata)
end end
-- Framework.RemoveItem(src, item, amount, slot, metadata) -- Framework.RemoveItem(src, item, amount, slot, metadata)
-- Removes the specified item from the player's inventory. -- Removes the specified item from the player's inventory.
Framework.RemoveItem = function(src, item, amount, slot, metadata) Framework.RemoveItem = function(src, item, amount, slot, metadata)
local player = QBCore.Functions.GetPlayer(src) local player = Framework.GetPlayer(src)
if not player then return end if not player then return end
TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "remove", item = item, count = amount, slot = slot, metadata = metadata}) TriggerClientEvent("community_bridge:client:inventory:updateInventory", src,
{ action = "remove", item = item, count = amount, slot = slot, metadata = metadata })
return player.Functions.RemoveItem(item, amount, slot or nil) return player.Functions.RemoveItem(item, amount, slot or nil)
end end
@@ -409,7 +432,7 @@ end
-- Sets the metadata for the specified item in the player's inventory. -- Sets the metadata for the specified item in the player's inventory.
-- Notes, this is kinda a jank workaround. with the framework aside from updating the entire table theres not really a better way -- Notes, this is kinda a jank workaround. with the framework aside from updating the entire table theres not really a better way
Framework.SetMetadata = function(src, item, slot, metadata) Framework.SetMetadata = function(src, item, slot, metadata)
local player = QBCore.Functions.GetPlayer(src) local player = Framework.GetPlayer(src)
if not player then return end if not player then return end
local slotFinder = Framework.GetPlayerInventory(src) local slotFinder = Framework.GetPlayerInventory(src)
local freeSlot = Table.FindFirstUnoccupiedSlot(slotFinder) local freeSlot = Table.FindFirstUnoccupiedSlot(slotFinder)
@@ -431,12 +454,13 @@ end
---@return table ---@return table
Framework.GetOwnedVehicles = function(src) Framework.GetOwnedVehicles = function(src)
local citizenId = Framework.GetPlayerIdentifier(src) local citizenId = Framework.GetPlayerIdentifier(src)
local result = MySQL.Sync.fetchAll("SELECT vehicle, plate FROM player_vehicles WHERE citizenid = '" .. citizenId .. "'") local result = MySQL.Sync.fetchAll("SELECT vehicle, plate FROM player_vehicles WHERE citizenid = '" ..
citizenId .. "'")
local vehicles = {} local vehicles = {}
for i=1, #result do for i = 1, #result do
local vehicle = result[i].vehicle local vehicle = result[i].vehicle
local plate = result[i].plate local plate = result[i].plate
table.insert(vehicles, {vehicle = vehicle, plate = plate}) table.insert(vehicles, { vehicle = vehicle, plate = plate })
end end
return vehicles return vehicles
end end
@@ -473,3 +497,4 @@ Framework.Commands.Add = function(name, help, arguments, argsrequired, callback,
QBCore.Commands.Add(name, help, arguments, argsrequired, callback, permission, ...) QBCore.Commands.Add(name, help, arguments, argsrequired, callback, permission, ...)
end end
return Framework
+12 -16
View File
@@ -3,7 +3,7 @@ if GetResourceState('qbx_core') ~= 'started' then return end
QBox = exports.qbx_core QBox = exports.qbx_core
Framework = {} Framework = Framework or {}
Framework.GetFrameworkName = function() Framework.GetFrameworkName = function()
return 'qbx_core' return 'qbx_core'
@@ -18,7 +18,7 @@ Framework.GetFrameworkJobs = function()
end end
Framework.GetPlayerDob = function() Framework.GetPlayerDob = function()
local playerData = QBox.GetPlayerData() local playerData = Framework.GetPlayerData()
return playerData.charinfo.birthdate return playerData.charinfo.birthdate
end end
@@ -37,26 +37,26 @@ Framework.HideHelpText = function()
end end
Framework.GetPlayerMetaData = function(metadata) Framework.GetPlayerMetaData = function(metadata)
local playerData = QBox.GetPlayerData() local playerData = Framework.GetPlayerData()
return playerData.metadata[metadata] return playerData.metadata[metadata]
end end
Framework.GetPlayerIdentifier = function() Framework.GetPlayerIdentifier = function()
return QBox.GetPlayerData().citizenid return Framework.GetPlayerData().citizenid
end end
Framework.GetPlayerName = function() Framework.GetPlayerName = function()
local playerData = QBox.GetPlayerData() local playerData = Framework.GetPlayerData()
return playerData.charinfo.firstname, playerData.charinfo.lastname return playerData.charinfo.firstname, playerData.charinfo.lastname
end end
Framework.GetPlayerJob = function() Framework.GetPlayerJob = function()
local playerData = QBox.GetPlayerData() local playerData = Framework.GetPlayerData()
return playerData.job.name, playerData.job.label, playerData.job.grade.name, playerData.job.grade.level return playerData.job.name, playerData.job.label, playerData.job.grade.name, playerData.job.grade.level
end end
Framework.GetPlayerInventory = function() Framework.GetPlayerInventory = function()
return QBox.GetPlayerData().items return Framework.GetPlayerData().items
end end
---comment ---comment
@@ -68,25 +68,21 @@ Framework.GetItemCount = function(item)
end end
Framework.GetIsPlayerDead = function() Framework.GetIsPlayerDead = function()
local platerData = QBox.GetPlayerData() local platerData = Framework.GetPlayerData()
return platerData.metadata["isdead"] or platerData.metadata["inlaststand"] return platerData.metadata["isdead"] or platerData.metadata["inlaststand"]
end end
RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function() RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function()
Wait(1500) Wait(1500)
FillBridgeTables()
TriggerEvent('community_bridge:Client:OnPlayerLoaded') TriggerEvent('community_bridge:Client:OnPlayerLoaded')
end) end)
RegisterNetEvent('QBCore:Client:OnPlayerUnload', function() RegisterNetEvent('QBCore:Client:OnPlayerUnload', function()
ClearClientSideVariables() TriggerEvent('community_bridge:Client:OnPlayerUnload')
TriggerEvent('community_bridge:Client:OnPlayerUnload')
end) end)
RegisterNetEvent('QBCore:Client:OnJobUpdate', function(data) RegisterNetEvent('QBCore:Client:OnJobUpdate', function(data)
PlayerJobName = data.name TriggerEvent('community_bridge:Client:OnPlayerJobUpdate', data.name, data.label, data.grade.name, data.grade.level)
PlayerJobLabel = data.label
PlayerJobGradeName = data.grade.name
PlayerJobGradeLevel = data.grade.level
TriggerEvent('community_bridge:Client:OnPlayerJobUpdate',PlayerJobName, PlayerJobLabel, PlayerJobGradeName, PlayerJobGradeLevel)
end) end)
return Framework
+59 -37
View File
@@ -3,7 +3,7 @@ if GetResourceState('qbx_core') ~= 'started' then return end
local QBox = exports.qbx_core local QBox = exports.qbx_core
Framework = {} Framework = Framework or {}
---Returns the name of the framework being used (if a supported framework). ---Returns the name of the framework being used (if a supported framework).
---@return string ---@return string
@@ -15,12 +15,21 @@ end
---@param src number ---@param src number
---@return string ---@return string
Framework.GetPlayerDob = function(src) Framework.GetPlayerDob = function(src)
local player = QBox:GetPlayer(src) local player = Framework.GetPlayer(src)
if not player then return end if not player then return end
local playerData = player.PlayerData local playerData = player.PlayerData
return playerData.charinfo.birthdate return playerData.charinfo.birthdate
end end
--- Returns the player data of the specified source.
---@param src any
---@return table | nil
Framework.GetPlayer = function(src)
local player = QBox:GetPlayer(src)
if not player then return end
return player
end
---Returns a table of the jobs in the framework. ---Returns a table of the jobs in the framework.
---@return table ---@return table
Framework.GetFrameworkJobs = function() Framework.GetFrameworkJobs = function()
@@ -29,9 +38,9 @@ end
---Returns the citizen ID of the player. ---Returns the citizen ID of the player.
---@param src number ---@param src number
---@return string | boolean ---@return string | boolean | nil
Framework.GetPlayerIdentifier = function(src) Framework.GetPlayerIdentifier = function(src)
local player = QBox:GetPlayer(src) local player = Framework.GetPlayer(src)
if not player then return end if not player then return end
local playerData = player.PlayerData local playerData = player.PlayerData
if not playerData then return false end if not playerData then return false end
@@ -52,8 +61,9 @@ end
---Returns the first and last name of the player. ---Returns the first and last name of the player.
---@param src number ---@param src number
---@return string | nil ---@return string | nil
---@return string | nil
Framework.GetPlayerName = function(src) Framework.GetPlayerName = function(src)
local player = QBox:GetPlayer(src) local player = Framework.GetPlayer(src)
if not player then return end if not player then return end
local playerData = player.PlayerData local playerData = player.PlayerData
return playerData.charinfo.firstname, playerData.charinfo.lastname return playerData.charinfo.firstname, playerData.charinfo.lastname
@@ -65,7 +75,7 @@ end
---@param metadata table ---@param metadata table
---@return table ---@return table
Framework.GetItem = function(src, item, metadata) Framework.GetItem = function(src, item, metadata)
local player = QBox:GetPlayer(src) local player = Framework.GetPlayer(src)
if not player then return end if not player then return end
local playerInventory = player.PlayerData.items local playerInventory = player.PlayerData.items
local repackedTable = {} local repackedTable = {}
@@ -86,9 +96,9 @@ end
---@param src number ---@param src number
---@param item string ---@param item string
---@param metadata table ---@param metadata table
---@return number ---@return number | nil
Framework.GetItemCount = function(src, item, metadata) Framework.GetItemCount = function(src, item, metadata)
local player = QBox:GetPlayer(src) local player = Framework.GetPlayer(src)
if not player then return end if not player then return end
local playerInventory = player.PlayerData.items local playerInventory = player.PlayerData.items
local count = 0 local count = 0
@@ -111,9 +121,9 @@ end
---Returns the entire inventory of the player as a table. ---Returns the entire inventory of the player as a table.
---@param src number ---@param src number
---@return table ---@return table | nil
Framework.GetPlayerInventory = function(src) Framework.GetPlayerInventory = function(src)
local player = QBox:GetPlayer(src) local player = Framework.GetPlayer(src)
if not player then return end if not player then return end
local playerItems = player.PlayerData.items local playerItems = player.PlayerData.items
local repackedTable = {} local repackedTable = {}
@@ -132,9 +142,9 @@ end
---@param src number ---@param src number
---@param metadata string ---@param metadata string
---@param value string ---@param value string
---@return boolean ---@return boolean | nil
Framework.SetPlayerMetadata = function(src, metadata, value) Framework.SetPlayerMetadata = function(src, metadata, value)
local player = QBox:GetPlayer(src) local player = Framework.GetPlayer(src)
if not player then return end if not player then return end
player.Functions.SetMetaData(metadata, value) player.Functions.SetMetaData(metadata, value)
return true return true
@@ -145,7 +155,7 @@ end
---@param metadata string ---@param metadata string
---@return string | boolean | nil ---@return string | boolean | nil
Framework.GetPlayerMetadata = function(src, metadata) Framework.GetPlayerMetadata = function(src, metadata)
local player = QBox:GetPlayer(src) local player = Framework.GetPlayer(src)
if not player then return end if not player then return end
local playerData = player.PlayerData local playerData = player.PlayerData
return playerData.metadata[metadata] or false return playerData.metadata[metadata] or false
@@ -156,7 +166,7 @@ end
---@param value number ---@param value number
---@return number | nil ---@return number | nil
Framework.AddStress = function(src, value) Framework.AddStress = function(src, value)
local player = QBox:GetPlayer(src) local player = Framework.GetPlayer(src)
if not player then return end if not player then return end
local playerData = player.PlayerData local playerData = player.PlayerData
local newStress = playerData.metadata.stress + value local newStress = playerData.metadata.stress + value
@@ -170,7 +180,7 @@ end
---@param value number ---@param value number
---@return number | nil ---@return number | nil
Framework.RemoveStress = function(src, value) Framework.RemoveStress = function(src, value)
local player = QBox:GetPlayer(src) local player = Framework.GetPlayer(src)
if not player then return end if not player then return end
local playerData = player.PlayerData local playerData = player.PlayerData
local newStress = (playerData.metadata.stress or 0) - value local newStress = (playerData.metadata.stress or 0) - value
@@ -184,7 +194,7 @@ end
---@param value number ---@param value number
---@return number | nil ---@return number | nil
Framework.AddHunger = function(src, value) Framework.AddHunger = function(src, value)
local player = QBox:GetPlayer(src) local player = Framework.GetPlayer(src)
if not player then return end if not player then return end
local playerData = player.PlayerData local playerData = player.PlayerData
local newHunger = (playerData.metadata.hunger or 0) + value local newHunger = (playerData.metadata.hunger or 0) + value
@@ -198,7 +208,7 @@ end
---@param value number ---@param value number
---@return number | nil ---@return number | nil
Framework.AddThirst = function(src, value) Framework.AddThirst = function(src, value)
local player = QBox:GetPlayer(src) local player = Framework.GetPlayer(src)
if not player then return end if not player then return end
local playerData = player.PlayerData local playerData = player.PlayerData
local newThirst = (playerData.metadata.thirst or 0) + value local newThirst = (playerData.metadata.thirst or 0) + value
@@ -211,7 +221,7 @@ end
---@param src number ---@param src number
---@return number | nil ---@return number | nil
Framework.GetHunger = function(src) Framework.GetHunger = function(src)
local player = QBox:GetPlayer(src) local player = Framework.GetPlayer(src)
if not player then return end if not player then return end
local playerData = player.PlayerData local playerData = player.PlayerData
local newHunger = (playerData.metadata.hunger or 0) local newHunger = (playerData.metadata.hunger or 0)
@@ -219,17 +229,24 @@ Framework.GetHunger = function(src)
end end
Framework.GetIsPlayerDead = function(src) Framework.GetIsPlayerDead = function(src)
local player = QBox:GetPlayer(src) local player = Framework.GetPlayer(src)
if not player then return end if not player then return end
local playerData = player.PlayerData local playerData = player.PlayerData
return playerData.metadata.isdead or false return playerData.metadata.isdead or false
end end
Framework.RevivePlayer = function(src)
src = tonumber(src)
if not src then return false end
TriggerClientEvent('hospital:client:Revive', src)
return true
end
---This will return the players thirst level. ---This will return the players thirst level.
---@param src number ---@param src number
---@return number ---@return number
Framework.GetThirst = function(src) Framework.GetThirst = function(src)
local player = QBox:GetPlayer(src) local player = Framework.GetPlayer(src)
if not player then return end if not player then return end
local playerData = player.PlayerData local playerData = player.PlayerData
local newThirst = (playerData.metadata.thirst or 0) local newThirst = (playerData.metadata.thirst or 0)
@@ -240,7 +257,7 @@ end
---@param src number ---@param src number
---@return string | nil ---@return string | nil
Framework.GetPlayerPhone = function(src) Framework.GetPlayerPhone = function(src)
local player = QBox:GetPlayer(src) local player = Framework.GetPlayer(src)
if not player then return end if not player then return end
local playerData = player.PlayerData local playerData = player.PlayerData
return playerData.charinfo.phone return playerData.charinfo.phone
@@ -250,7 +267,7 @@ end
---@param src number ---@param src number
---@return string | nil ---@return string | nil
Framework.GetPlayerGang = function(src) Framework.GetPlayerGang = function(src)
local player = QBox:GetPlayer(src).PlayerData local player = Framework.GetPlayer(src).PlayerData
return player.gang.name return player.gang.name
end end
@@ -275,7 +292,7 @@ end
---@return string | string | string | number | nil ---@return string | string | string | number | nil
---@return string | string | string | number | nil ---@return string | string | string | number | nil
Framework.GetPlayerJob = function(src) Framework.GetPlayerJob = function(src)
local player = QBox:GetPlayer(src).PlayerData local player = Framework.GetPlayer(src).PlayerData
if not player then return end if not player then return end
return player.job.name, player.job.label, player.job.grade.name, player.job.grade.level return player.job.name, player.job.label, player.job.grade.name, player.job.grade.level
end end
@@ -286,7 +303,7 @@ end
---@param grade string ---@param grade string
---@return boolean | nil ---@return boolean | nil
Framework.SetPlayerJob = function(src, name, grade) Framework.SetPlayerJob = function(src, name, grade)
local player = QBox:GetPlayer(src) local player = Framework.GetPlayer(src)
if not player then return end if not player then return end
return player.Functions.SetJob(name, grade) return player.Functions.SetJob(name, grade)
end end
@@ -295,7 +312,7 @@ end
---@param src number ---@param src number
---@param status boolean ---@param status boolean
Framework.SetPlayerDuty = function(src, status) Framework.SetPlayerDuty = function(src, status)
local player = QBox:GetPlayer(src) local player = Framework.GetPlayer(src)
if not player then return end if not player then return end
local playerData = player.PlayerData local playerData = player.PlayerData
QBox:SetJobDuty(playerData.citizenid, status) QBox:SetJobDuty(playerData.citizenid, status)
@@ -306,7 +323,7 @@ end
---@param src number ---@param src number
---@return boolean | nil ---@return boolean | nil
Framework.GetPlayerDuty = function(src) Framework.GetPlayerDuty = function(src)
local player = QBox:GetPlayer(src) local player = Framework.GetPlayer(src)
if not player then return end if not player then return end
local playerData = player.PlayerData local playerData = player.PlayerData
if not playerData.job.onduty then return false end if not playerData.job.onduty then return false end
@@ -319,7 +336,7 @@ end
---@param amount number ---@param amount number
---@return boolean | nil ---@return boolean | nil
Framework.AddAccountBalance = function(src, _type, amount) Framework.AddAccountBalance = function(src, _type, amount)
local player = QBox:GetPlayer(src) local player = Framework.GetPlayer(src)
if not player then return end if not player then return end
if _type == 'money' then _type = 'cash' end if _type == 'money' then _type = 'cash' end
return player.Functions.AddMoney(_type, amount) return player.Functions.AddMoney(_type, amount)
@@ -331,7 +348,7 @@ end
---@param amount number ---@param amount number
---@return boolean | nil ---@return boolean | nil
Framework.RemoveAccountBalance = function(src, _type, amount) Framework.RemoveAccountBalance = function(src, _type, amount)
local player = QBox:GetPlayer(src) local player = Framework.GetPlayer(src)
if not player then return end if not player then return end
if _type == 'money' then _type = 'cash' end if _type == 'money' then _type = 'cash' end
return player.Functions.RemoveMoney(_type, amount) return player.Functions.RemoveMoney(_type, amount)
@@ -342,7 +359,7 @@ end
---@param _type string ---@param _type string
---@return number | nil ---@return number | nil
Framework.GetAccountBalance = function(src, _type) Framework.GetAccountBalance = function(src, _type)
local player = QBox:GetPlayer(src) local player = Framework.GetPlayer(src)
if not player then return end if not player then return end
local playerData = player.PlayerData local playerData = player.PlayerData
if _type == 'money' then _type = 'cash' end if _type == 'money' then _type = 'cash' end
@@ -357,9 +374,10 @@ end
---@param metadata table ---@param metadata table
---@return boolean | nil ---@return boolean | nil
Framework.AddItem = function(src, item, amount, slot, metadata) Framework.AddItem = function(src, item, amount, slot, metadata)
local player = QBox:GetPlayer(src) local player = Framework.GetPlayer(src)
if not player then return end if not player then return end
TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "add", item = item, count = amount, slot = slot, metadata = metadata}) TriggerClientEvent("community_bridge:client:inventory:updateInventory", src,
{ action = "add", item = item, count = amount, slot = slot, metadata = metadata })
return player.Functions.AddItem(item, amount, slot, metadata) return player.Functions.AddItem(item, amount, slot, metadata)
end end
@@ -371,9 +389,10 @@ end
---@param metadata table ---@param metadata table
---@return boolean | nil ---@return boolean | nil
Framework.RemoveItem = function(src, item, amount, slot, metadata) Framework.RemoveItem = function(src, item, amount, slot, metadata)
local player = QBox:GetPlayer(src) local player = Framework.GetPlayer(src)
if not player then return end if not player then return end
TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "remove", item = item, count = amount, slot = slot, metadata = metadata}) TriggerClientEvent("community_bridge:client:inventory:updateInventory", src,
{ action = "remove", item = item, count = amount, slot = slot, metadata = metadata })
return player.Functions.RemoveItem(item, amount, slot) return player.Functions.RemoveItem(item, amount, slot)
end end
@@ -384,7 +403,7 @@ end
---@param metadata table ---@param metadata table
---@return boolean | nil ---@return boolean | nil
Framework.SetMetadata = function(src, item, slot, metadata) Framework.SetMetadata = function(src, item, slot, metadata)
local player = QBox:GetPlayer(src) local player = Framework.GetPlayer(src)
if not player then return end if not player then return end
player.Functions.RemoveItem(item, 1, slot) player.Functions.RemoveItem(item, 1, slot)
return player.Functions.AddItem(item, 1, slot, metadata) return player.Functions.AddItem(item, 1, slot, metadata)
@@ -395,12 +414,13 @@ end
---@return table ---@return table
Framework.GetOwnedVehicles = function(src) Framework.GetOwnedVehicles = function(src)
local citizenId = Framework.GetPlayerIdentifier(src) local citizenId = Framework.GetPlayerIdentifier(src)
local result = MySQL.Sync.fetchAll("SELECT vehicle, plate FROM player_vehicles WHERE citizenid = '" .. citizenId .. "'") local result = MySQL.Sync.fetchAll("SELECT vehicle, plate FROM player_vehicles WHERE citizenid = '" ..
citizenId .. "'")
local vehicles = {} local vehicles = {}
for i=1, #result do for i = 1, #result do
local vehicle = result[i].vehicle local vehicle = result[i].vehicle
local plate = result[i].plate local plate = result[i].plate
table.insert(vehicles, {vehicle = vehicle, plate = plate}) table.insert(vehicles, { vehicle = vehicle, plate = plate })
end end
return vehicles return vehicles
end end
@@ -433,3 +453,5 @@ AddEventHandler("playerDropped", function()
local src = source local src = source
TriggerEvent("community_bridge:Server:OnPlayerUnload", src) TriggerEvent("community_bridge:Server:OnPlayerUnload", src)
end) end)
return Framework
+2
View File
@@ -22,3 +22,5 @@ Fuel.SetFuel = function(vehicle, fuel)
if not DoesEntityExist(vehicle) then return end if not DoesEntityExist(vehicle) then return end
return SetVehicleFuelLevel(vehicle, fuel) return SetVehicleFuelLevel(vehicle, fuel)
end end
return Fuel
+2
View File
@@ -26,3 +26,5 @@ Fuel.SetFuel = function(vehicle, fuel)
if not DoesEntityExist(vehicle) then return end if not DoesEntityExist(vehicle) then return end
exports['BigDaddy-Fuel']:SetFuel(vehicle, fuel) exports['BigDaddy-Fuel']:SetFuel(vehicle, fuel)
end end
return Fuel
+2
View File
@@ -26,3 +26,5 @@ Fuel.SetFuel = function(vehicle, fuel)
if not DoesEntityExist(vehicle) then return end if not DoesEntityExist(vehicle) then return end
return exports['cdn-fuel']:SetFuel(vehicle, fuel) return exports['cdn-fuel']:SetFuel(vehicle, fuel)
end end
return Fuel
+2
View File
@@ -26,3 +26,5 @@ Fuel.SetFuel = function(vehicle, fuel)
if not DoesEntityExist(vehicle) then return end if not DoesEntityExist(vehicle) then return end
exports['esx-sna-fuel']:SetFuel(vehicle, fuel) exports['esx-sna-fuel']:SetFuel(vehicle, fuel)
end end
return Fuel
+3 -3
View File
@@ -1,3 +1,4 @@
---@diagnostic disable: duplicate-set-field
local resourceName = "lc_fuel" local resourceName = "lc_fuel"
local configValue = BridgeClientConfig.Fuel local configValue = BridgeClientConfig.Fuel
if (configValue == "auto" and GetResourceState(resourceName) ~= "started") or (configValue ~= "auto" and configValue ~= resourceName) then return end if (configValue == "auto" and GetResourceState(resourceName) ~= "started") or (configValue ~= "auto" and configValue ~= resourceName) then return end
@@ -6,7 +7,6 @@ Fuel = Fuel or {}
---This will get the name of the Fuel being used (if a supported Fuel). ---This will get the name of the Fuel being used (if a supported Fuel).
---@return string ---@return string
---@diagnostic disable-next-line: duplicate-set-field
Fuel.GetResourceName = function() Fuel.GetResourceName = function()
return resourceName return resourceName
end end
@@ -14,7 +14,6 @@ end
---This will get the fuel level of the vehicle. ---This will get the fuel level of the vehicle.
---@param vehicle number The vehicle entity ID. ---@param vehicle number The vehicle entity ID.
---@return number fuel The fuel level of the vehicle. ---@return number fuel The fuel level of the vehicle.
---@diagnostic disable-next-line: duplicate-set-field
Fuel.GetFuel = function(vehicle) Fuel.GetFuel = function(vehicle)
if not DoesEntityExist(vehicle) then return 0.0 end if not DoesEntityExist(vehicle) then return 0.0 end
return exports["lc_fuel"]:GetFuel(vehicle) return exports["lc_fuel"]:GetFuel(vehicle)
@@ -24,8 +23,9 @@ end
---@param vehicle number The vehicle entity ID. ---@param vehicle number The vehicle entity ID.
---@param fuel number The fuel level to set. ---@param fuel number The fuel level to set.
---@return nil ---@return nil
---@diagnostic disable-next-line: duplicate-set-field
Fuel.SetFuel = function(vehicle, fuel, type) Fuel.SetFuel = function(vehicle, fuel, type)
if not DoesEntityExist(vehicle) then return end if not DoesEntityExist(vehicle) then return end
return exports["lc_fuel"]:SetFuel(vehicle, fuel) return exports["lc_fuel"]:SetFuel(vehicle, fuel)
end end
return Fuel
+2
View File
@@ -26,3 +26,5 @@ Fuel.SetFuel = function(vehicle, fuel, type)
if not DoesEntityExist(vehicle) then return end if not DoesEntityExist(vehicle) then return end
return exports['LegacyFuel']:SetFuel(vehicle, fuel) return exports['LegacyFuel']:SetFuel(vehicle, fuel)
end end
return Fuel
+2
View File
@@ -26,3 +26,5 @@ Fuel.SetFuel = function(vehicle, fuel, type)
if not DoesEntityExist(vehicle) then return end if not DoesEntityExist(vehicle) then return end
return exports['okokGasStation']:SetFuel(vehicle, fuel) return exports['okokGasStation']:SetFuel(vehicle, fuel)
end end
return Fuel
+2
View File
@@ -28,3 +28,5 @@ Fuel.SetFuel = function(vehicle, fuel, type)
Entity(vehicle).state.fuel = currentFuel + fuel Entity(vehicle).state.fuel = currentFuel + fuel
return Entity(vehicle).state.fuel return Entity(vehicle).state.fuel
end end
return Fuel
+2
View File
@@ -26,3 +26,5 @@ Fuel.SetFuel = function(vehicle, fuel, type)
if not DoesEntityExist(vehicle) then return end if not DoesEntityExist(vehicle) then return end
return exports["ps-fuel"]:SetFuel(vehicle, fuel) return exports["ps-fuel"]:SetFuel(vehicle, fuel)
end end
return Fuel
+2
View File
@@ -26,3 +26,5 @@ Fuel.SetFuel = function(vehicle, fuel)
if not DoesEntityExist(vehicle) then return end if not DoesEntityExist(vehicle) then return end
return exports['qs-fuelstations']:SetFuel(vehicle, fuel) return exports['qs-fuelstations']:SetFuel(vehicle, fuel)
end end
return Fuel
+2
View File
@@ -26,3 +26,5 @@ Fuel.SetFuel = function(vehicle, fuel, type)
if not DoesEntityExist(vehicle) then return end if not DoesEntityExist(vehicle) then return end
return exports['Renewed-Fuel']:SetFuel(vehicle, fuel) return exports['Renewed-Fuel']:SetFuel(vehicle, fuel)
end end
return Fuel
+2
View File
@@ -27,3 +27,5 @@ Fuel.SetFuel = function(vehicle, fuel)
if not DoesEntityExist(vehicle) then return end if not DoesEntityExist(vehicle) then return end
return exports['ti_fuel']:setFuel(vehicle, fuel, "RON91") return exports['ti_fuel']:setFuel(vehicle, fuel, "RON91")
end end
return Fuel
+2
View File
@@ -27,3 +27,5 @@ Fuel.SetFuel = function(vehicle, fuel)
if not DoesEntityExist(vehicle) then return end if not DoesEntityExist(vehicle) then return end
return exports['x-fuel']:SetFuel(vehicle, fuel) return exports['x-fuel']:SetFuel(vehicle, fuel)
end end
return Fuel
+2
View File
@@ -23,3 +23,5 @@ end)
RegisterNetEvent('community_bridge:Client:HideHelpText', function() RegisterNetEvent('community_bridge:Client:HideHelpText', function()
HelpText.HideHelpText() HelpText.HideHelpText()
end) end)
return HelpText
+2
View File
@@ -15,3 +15,5 @@ end
HelpText.HideHelpText = function(src) HelpText.HideHelpText = function(src)
TriggerClientEvent('community_bridge:Client:HideHelpText', src) TriggerClientEvent('community_bridge:Client:HideHelpText', src)
end end
return HelpText
@@ -19,3 +19,5 @@ end
HelpText.HideHelpText = function() HelpText.HideHelpText = function()
return TriggerEvent('cd_drawtextui:HideUI') return TriggerEvent('cd_drawtextui:HideUI')
end end
return HelpText
+2
View File
@@ -18,3 +18,5 @@ end
HelpText.HideHelpText = function() HelpText.HideHelpText = function()
return exports['jg-textui']:HideText() return exports['jg-textui']:HideText()
end end
return HelpText
+2
View File
@@ -18,3 +18,5 @@ end
HelpText.HideHelpText = function() HelpText.HideHelpText = function()
return exports['lab-HintUI']:Hide() return exports['lab-HintUI']:Hide()
end end
return HelpText
+2
View File
@@ -18,3 +18,5 @@ end
HelpText.HideHelpText = function() HelpText.HideHelpText = function()
return exports['okokTextUI']:Close() return exports['okokTextUI']:Close()
end end
return HelpText
+2
View File
@@ -19,3 +19,5 @@ end
HelpText.HideHelpText = function() HelpText.HideHelpText = function()
return exports.ox_lib:hideTextUI() return exports.ox_lib:hideTextUI()
end end
return HelpText
+2
View File
@@ -1 +1,3 @@
Housing = Housing or {} Housing = Housing or {}
return Housing
+2
View File
@@ -10,3 +10,5 @@ RegisterNetEvent('community_bridge:Server:_OnPlayerInside', function(src, inside
local playerCoords = GetEntityCoords(playerEntity) local playerCoords = GetEntityCoords(playerEntity)
TriggerEvent('community_bridge:Client:OnPlayerInside', src, insideId, currentBucket, playerCoords) TriggerEvent('community_bridge:Client:OnPlayerInside', src, insideId, currentBucket, playerCoords)
end) end)
return Housing
+2
View File
@@ -9,3 +9,5 @@ end)
RegisterNetEvent("Housing:client:DeleteFurnitures", function() RegisterNetEvent("Housing:client:DeleteFurnitures", function()
TriggerServerEvent('community_bridge:Server:_OnPlayerInside', false) TriggerServerEvent('community_bridge:Server:_OnPlayerInside', false)
end) end)
return Housing
+2
View File
@@ -1,3 +1,5 @@
if GetResourceState('bcs-housing') ~= 'started' then return end if GetResourceState('bcs-housing') ~= 'started' then return end
Housing = Housing or {} Housing = Housing or {}
return Housing
+2
View File
@@ -1,3 +1,5 @@
if GetResourceState('esx_property') ~= 'started' then return end if GetResourceState('esx_property') ~= 'started' then return end
Housing = Housing or {} Housing = Housing or {}
return Housing
+2
View File
@@ -11,3 +11,5 @@ RegisterNetEvent('esx_property:leave', function(insideId)
local src = source local src = source
TriggerEvent('community_bridge:Server:_OnPlayerInside', src, insideId) TriggerEvent('community_bridge:Server:_OnPlayerInside', src, insideId)
end) end)
return Housing
+2
View File
@@ -1,3 +1,5 @@
if GetResourceState('ps-housing') ~= 'started' then return end if GetResourceState('ps-housing') ~= 'started' then return end
Housing = Housing or {} Housing = Housing or {}
return Housing
+2
View File
@@ -11,3 +11,5 @@ RegisterNetEvent('ps-housing:server:leaveProperty', function(insideId)
local src = source local src = source
TriggerEvent('community_bridge:Server:_OnPlayerInside', src, insideId) TriggerEvent('community_bridge:Server:_OnPlayerInside', src, insideId)
end) end)
return Housing
@@ -1,3 +1,5 @@
if GetResourceState('qb-appartments') ~= 'started' then return end if GetResourceState('qb-appartments') ~= 'started' then return end
Housing = Housing or {} Housing = Housing or {}
return Housing
@@ -7,3 +7,5 @@ RegisterNetEvent('qb-apartments:server:SetInsideMeta', function(house, insideId,
insideId = bool and house .. '-' .. insideId or nil insideId = bool and house .. '-' .. insideId or nil
TriggerEvent('community_bridge:Server:_OnPlayerInside', src, insideId) TriggerEvent('community_bridge:Server:_OnPlayerInside', src, insideId)
end) end)
return Housing
+2
View File
@@ -1,3 +1,5 @@
if GetResourceState('qb-houses') ~= 'started' then return end if GetResourceState('qb-houses') ~= 'started' then return end
Housing = Housing or {} Housing = Housing or {}
return Housing
+2
View File
@@ -7,3 +7,5 @@ RegisterNetEvent('qb-houses:server:SetInsideMeta', function(insideId, bool)
insideId = bool and insideId or nil insideId = bool and insideId or nil
TriggerEvent('community_bridge:Server:_OnPlayerInside', src, insideId) TriggerEvent('community_bridge:Server:_OnPlayerInside', src, insideId)
end) end)
return Housing
+3
View File
@@ -107,6 +107,9 @@ function Input.Open(title, data, isQBFormat, submitText)
return OpenInput(title, data, isQBFormat, submitText) return OpenInput(title, data, isQBFormat, submitText)
end end
return Input
--[[ --[[
-- Unit tests -- Unit tests
local thisIsQB = { local thisIsQB = {
+13 -4
View File
@@ -1,27 +1,34 @@
---@diagnostic disable: duplicate-set-field
Inventory = Inventory or {} Inventory = Inventory or {}
---This will fallback to framework add item functions when an inventory does not have the specifiec function. ---Return the item info in oxs format, {name, label, stack, weight, description, image}
---@param item string ---@param item string
---@return table ---@return table
Inventory.GetItemInfo = function(item) Inventory.GetItemInfo = function(item)
return Framework.GetItemInfo(item) return Framework.GetItemInfo(item)
end end
---This will fallback to framework add item functions when an inventory does not have the specifiec function. ---Will return boolean if the player has the item.
---@param item string ---@param item string
---@return boolean ---@return boolean
Inventory.HasItem = function(item) Inventory.HasItem = function(item)
return Framework.HasItem(item) return Framework.HasItem(item)
end end
---This will fallback to framework add item functions when an inventory does not have the specifiec function. ---This will return th count of the item in the players inventory, if not found will return 0.
---@param item string ---@param item string
---@return number ---@return number
Inventory.GetItemCount = function(item) Inventory.GetItemCount = function(item)
return Framework.GetItemCount(item) return Framework.GetItemCount(item)
end end
---This will provide a image of the community bridge logo if the inventory isnt bridged for the specific path. ---This will return the players inventory in the format of {name, label, count, slot, metadata}
---@return table
Inventory.GetPlayerInventory = function()
return Framework:GetPlayerInventory()
end
---This will get the image path for this item, if not found will return placeholder.
---@param item string ---@param item string
---@return string ---@return string
Inventory.GetImagePath = function(item) Inventory.GetImagePath = function(item)
@@ -34,3 +41,5 @@ Inventory.StripPNG = function(item)
end end
return item return item
end end
return Inventory
+77 -14
View File
@@ -1,36 +1,41 @@
---@diagnostic disable: duplicate-set-field
Inventory = Inventory or {} Inventory = Inventory or {}
---This will fallback to framework add item functions when an inventory does not have the specifiec function. ---This will add an item, and return true or false based on success
---@param src number ---@param src number
---@param item string ---@param item string
---@param count number ---@param count number
---@param slot number ---@param slot number
---@param metadata table ---@param metadata table
---@return boolean|nil ---@return boolean
Inventory.AddItem = function(src, item, count, slot, metadata) Inventory.AddItem = function(src, item, count, slot, metadata)
TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "add", item = item, count = count, slot = slot, metadata = metadata})
return Framework.AddItem(src, item, count, slot, metadata) return Framework.AddItem(src, item, count, slot, metadata)
end end
---This will fallback to framework add item functions when an inventory does not have the specifiec function. ---This will remove an item, and return true or false based on success
---@param src number ---@param src number
---@param item string ---@param item string
---@param count number ---@param count number
---@param slot number ---@param slot number
---@param metadata table ---@param metadata table
---@return boolean|nil ---@return boolean
Inventory.RemoveItem = function(src, item, count, slot, metadata) Inventory.RemoveItem = function(src, item, count, slot, metadata)
item = type(item) == "table" and item.name or item item = type(item) == "table" and item.name or item
TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "remove", item = item, count = count, slot = slot, metadata = metadata})
return Framework.RemoveItem(src, item, count, slot, metadata) return Framework.RemoveItem(src, item, count, slot, metadata)
end end
---This will fallback to framework add item functions when an inventory does not have the specifiec function. ---This will return a table with the item info, {name, label, stack, weight, description, image}
---@param item string ---@param item string
---@return table ---@return table
Inventory.GetItemInfo = function(item) Inventory.GetItemInfo = function(item)
return Framework.GetItemInfo(item) return Framework.GetItemInfo(item)
end end
---This will fallback to framework add item functions when an inventory does not have the specifiec function. ---This will return the count of the item in the players inventory, if not found will return 0.
---
---if metadata is passed it will find the matching items count.
---@param src number ---@param src number
---@param item string ---@param item string
---@param metadata table ---@param metadata table
@@ -39,14 +44,16 @@ Inventory.GetItemCount = function(src, item, metadata)
return Framework.GetItemCount(src, item, metadata) return Framework.GetItemCount(src, item, metadata)
end end
---This will fallback to framework add item functions when an inventory does not have the specifiec function. ---This wil return the players inventory.
---@param src number ---@param src number
---@return table ---@return table
Inventory.GetPlayerInventory = function(src) Inventory.GetPlayerInventory = function(src)
return Framework.GetPlayerInventory(src) return Framework.GetPlayerInventory(src)
end end
---This will fallback to framework add item functions when an inventory does not have the specifiec function. ---Returns the specified slot data as a table.
---
---format {weight, name, metadata, slot, label, count}
---@param src number ---@param src number
---@param slot number ---@param slot number
---@return table ---@return table
@@ -54,19 +61,32 @@ Inventory.GetItemBySlot = function(src, slot)
return Framework.GetItemBySlot(src, slot) return Framework.GetItemBySlot(src, slot)
end end
---This will fallback to framework add item functions when an inventory does not have the specifiec function. ---This will set the metadata of an item in the inventory.
---@param src number ---@param src number
---@param item string ---@param item string
---@param slot number ---@param slot number
---@param metadata table ---@param metadata table
---@return boolean ---@return nil
Inventory.SetMetadata = function(src, item, slot, metadata) Inventory.SetMetadata = function(src, item, slot, metadata)
return Framework.SetMetadata(src, item, slot, metadata) return Framework.SetMetadata(src, item, slot, metadata)
end end
---This will fallback to framework add item functions when an inventory does not have the specifiec function. ---This will open the specified stash for the src passed.
---@param src number ---@param src number
---@param id string||number ---@param id number||string
---@param label string
---@param slots number
---@param weight number
---@param owner string
---@param groups table
---@param coords table
---@return nil
Inventory.OpenStash = function(src, id, label, slots, weight, owner, groups, coords)
return false, Prints.Error("This Inventory Has Not Been Bridged For A Stash Feature.")
end
---This will register a stash
---@param id number||string
---@param label string ---@param label string
---@param slots number ---@param slots number
---@param weight number ---@param weight number
@@ -74,11 +94,52 @@ end
---@param groups table ---@param groups table
---@param coords table ---@param coords table
---@return boolean ---@return boolean
Inventory.OpenStash = function(src, id, label, slots, weight, owner, groups, coords) Inventory.RegisterStash = function(id, label, slots, weight, owner, groups, coords)
return false, Prints.Error("This Inventory Has Not Been Bridged For A Stash Feature.") return false, Prints.Error("This Inventory Has Not Been Bridged For A Stash Feature.")
end end
---This will provide a image of the community bridge logo if the inventory isnt bridged for the specific path. ---This will return a boolean if the player has the item.
---@param src number
---@param item string
---@return boolean
Inventory.HasItem = function(src, item)
return Framework.HasItem(src, item)
end
---This is to get if there is available space in the inventory, will return boolean.
---@param src number
---@param item string
---@param count number
---@return boolean
Inventory.CanCarryItem = function(src, item, count)
return false, Prints.Error("This Inventory Has Not Been Bridged For A CanCarryItem Feature.")
end
---This will update the plate to the vehicle inside the inventory. (It will also update with jg-mechanic if using it)
---@param oldplate string
---@param newplate string
---@return boolean
Inventory.UpdatePlate = function(oldplate, newplate)
return false, Prints.Error("This Inventory Has Not Been Bridged For A UpdatePlate Feature.")
end
-- This will open the specified shop for the src passed.
---@param src number
---@param shopTitle string
Inventory.OpenShop = function(src, shopTitle)
return false, Prints.Error("This Inventory Has Not Been Bridged For A OpenShop Feature.")
end
-- This will register a shop, if it already exists it will return true.
-- @param shopTitle string
-- @param shopInventory table
-- @param shopCoords table
-- @param shopGroups table
Inventory.CreateShop = function(shopTitle, shopInventory, shopCoords, shopGroups)
return false, Prints.Error("This Inventory Has Not Been Bridged For A CreateShop Feature.")
end
---This will get the image path for an item, it is an alternate option to GetItemInfo. If a image isnt found will revert to community_bridge logo (useful for menus)
---@param item string ---@param item string
---@return string ---@return string
Inventory.GetImagePath = function(item) Inventory.GetImagePath = function(item)
@@ -91,3 +152,5 @@ Inventory.StripPNG = function(item)
end end
return item return item
end end
return Inventory
+21 -13
View File
@@ -1,15 +1,17 @@
---@diagnostic disable: duplicate-set-field
if GetResourceState('codem-inventory') ~= 'started' then return end if GetResourceState('codem-inventory') ~= 'started' then return end
Inventory = Inventory or {} Inventory = Inventory or {}
local codem = exports['codem-inventory'] local codem = exports['codem-inventory']
---comment ---Return the item info in oxs format, {name, label, stack, weight, description, image}
---@param item string ---@param item string
---@return table ---@return table
Inventory.GetItemInfo = function(item) Inventory.GetItemInfo = function(item)
local itemData = codem:GetItemList(item) local itemData = codem:GetItemList(item)
if not itemData then return {} end
local image = itemData.image and Inventory.GetImagePath(itemData.image) or Inventory.GetImagePath(item) local image = itemData.image and Inventory.GetImagePath(itemData.image) or Inventory.GetImagePath(item)
local repackedTable = { return {
name = itemData.name or "Missing Name", name = itemData.name or "Missing Name",
label = itemData.label or "Missing Label", label = itemData.label or "Missing Label",
stack = itemData.unique or "false", stack = itemData.unique or "false",
@@ -17,10 +19,19 @@ Inventory.GetItemInfo = function(item)
description = itemData.description or "none", description = itemData.description or "none",
image = image, image = image,
} }
return repackedTable or {}
end end
---comment ---This will get the image path for this item, if not found will return placeholder.
---@param item string
---@return string
Inventory.GetImagePath = function(item)
item = Inventory.StripPNG(item)
local file = LoadResourceFile("codem-inventory", string.format("html/images/%s.png", item))
local imagePath = file and string.format("nui://codem-inventory/html/images/%s.png", item)
return imagePath or "https://avatars.githubusercontent.com/u/47620135"
end
---This will return the players inventory in the format of {name, label, count, slot, metadata}
---@return table ---@return table
Inventory.GetPlayerInventory = function() Inventory.GetPlayerInventory = function()
local items = {} local items = {}
@@ -40,12 +51,9 @@ Inventory.GetPlayerInventory = function()
return items return items
end end
---comment RegisterNetEvent('community_bridge:client:codem-inventory:openStash', function(id, data)
---@param item string if source ~= 65535 then return end
---@return string TriggerServerEvent('codem-inventory:server:openstash', id, data.slots, data.weight, data.label)
Inventory.GetImagePath = function(item) end)
item = Inventory.StripPNG(item)
local file = LoadResourceFile("codem-inventory", string.format("html/images/%s.png", item)) return Inventory
local imagePath = file and string.format("nui://codem-inventory/html/images/%s.png", item)
return imagePath or "https://avatars.githubusercontent.com/u/47620135"
end
+122 -40
View File
@@ -1,12 +1,41 @@
---@diagnostic disable: duplicate-set-field
if GetResourceState('codem-inventory') ~= 'started' then return end if GetResourceState('codem-inventory') ~= 'started' then return end
Inventory = Inventory or {} Inventory = Inventory or {}
local codem = exports['codem-inventory'] local codem = exports['codem-inventory']
---This will add an item, and return true or false based on success
---@param src number
---@param item string
---@param count number
---@param slot number
---@param metadata table
---@return boolean
Inventory.AddItem = function(src, item, count, slot, metadata)
TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "add", item = item, count = count, slot = slot, metadata = metadata})
return codem:AddItem(src, item, count, slot, metadata)
end
---This will remove an item, and return true or false based on success
---@param src number
---@param item string
---@param count number
---@param slot number
---@param metadata table
---@return boolean
Inventory.RemoveItem = function(src, item, count, slot, metadata)
TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "remove", item = item, count = count, slot = slot, metadata = metadata})
return codem:RemoveItem(src, item, count, slot)
end
---This will return a table with the item info, {name, label, stack, weight, description, image}
---@param item string
---@return table
Inventory.GetItemInfo = function(item) Inventory.GetItemInfo = function(item)
local itemData = codem:GetItemList(item) local itemData = codem:GetItemList(item)
local repackedTable = { if not itemData then return {} end
return {
name = itemData.name or "Missing Name", name = itemData.name or "Missing Name",
label = itemData.label or "Missing Label", label = itemData.label or "Missing Label",
stack = itemData.unique or "false", stack = itemData.unique or "false",
@@ -14,18 +43,11 @@ Inventory.GetItemInfo = function(item)
description = itemData.description or "none", description = itemData.description or "none",
image = itemData.image or Inventory.GetImagePath(item), image = itemData.image or Inventory.GetImagePath(item),
} }
return repackedTable or {}
end
Inventory.AddItem = function(src, item, count, slot, metadata)
TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "add", item = item, count = count, slot = slot, metadata = metadata})
return codem:AddItem(src, item, count, slot, metadata)
end
Inventory.GetItemBySlot = function(src, slot)
return codem:GetItemBySlot(src, slot)
end end
---This wil return the players inventory.
---@param src number
---@return table
Inventory.GetPlayerInventory = function(src) Inventory.GetPlayerInventory = function(src)
local identifier = Framework.GetPlayerIdentifier(src) local identifier = Framework.GetPlayerIdentifier(src)
local playerItems = codem:GetInventory(identifier, src) local playerItems = codem:GetInventory(identifier, src)
@@ -41,26 +63,65 @@ Inventory.GetPlayerInventory = function(src)
return repackedTable return repackedTable
end end
Inventory.RemoveItem = function(src, item, count, slot, metadata) ---Returns the specified slot data as a table.
if not slot and metadata then ---
local inv = Inventory.GetPlayerInventory(src) ---format {weight, name, metadata, slot, label, count}
if not inv then return false end ---@param src number
for _, v in pairs(inv) do ---@param slot number
if v.name == item and v.metadata == metadata then ---@return table
slot = v.slot Inventory.GetItemBySlot = function(src, slot)
break local slotData = codem:GetItemBySlot(src, slot)
end if not slotData then return {} end
end return {
end name = v.name,
TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "remove", item = item, count = count, slot = slot, metadata = metadata}) label = v.label or v.name,
return codem:RemoveItem(src, item, count, slot) weight = v.weight,
slot = v.slot,
count = v.amount or v.count,
metadata = v.info or v.metadata,
stack = v.unique,
description = v.description
}
end end
---This will set the metadata of an item in the inventory.
---@param src number
---@param item string
---@param slot number
---@param metadata table
---@return nil
Inventory.SetMetadata = function(src, item, slot, metadata) Inventory.SetMetadata = function(src, item, slot, metadata)
return codem:SetItemMetadata(src, slot, metadata) return codem:SetItemMetadata(src, slot, metadata)
end end
---comment ---This will open the specified stash for the src passed.
---@param src number
---@param id number||string
---@param label string
---@param slots number
---@param weight number
---@param owner string
---@param groups table
---@param coords table
---@return nil
Inventory.OpenStash = function(src, id, label, slots, weight, owner, groups, coords)
TriggerClientEvent('community_bridge:client:codem-inventory:openStash', src, id, { label = label, slots = slots, weight = weight })
end
---This will register a stash
---@param id number||string
---@param label string
---@param slots number
---@param weight number
---@param owner string
---@param groups table
---@param coords table
---@return boolean
Inventory.RegisterStash = function(id, label, slots, weight, owner, groups, coords)
return true
end
---This will return a boolean if the player has the item.
---@param src number ---@param src number
---@param item string ---@param item string
---@return boolean ---@return boolean
@@ -68,23 +129,26 @@ Inventory.HasItem = function(src, item)
return codem:HasItem(src, item, 1) return codem:HasItem(src, item, 1)
end end
Inventory.GetItemBySlot = function(src, slot) ---This is to get if there is available space in the inventory, will return boolean.
local slotData = codem:GetItemBySlot(src, slot) ---@param src number
if not slotData then return {} end ---@param item string
for _, v in pairs(slotData) do ---@param count number
return { ---@return boolean
name = v.name, Inventory.CanCarryItem = function(src, item, count)
label = v.name, return true
weight = v.weight,
slot = v.slot,
count = v.amount,
metadata = v.info,
stack = v.unique,
description = v.description
}
end
end end
---This will update the plate to the vehicle inside the inventory. (It will also update with jg-mechanic if using it)
---@param oldplate string
---@param newplate string
---@return boolean
Inventory.UpdatePlate = function(oldplate, newplate)
return false, print("Unable to update plate for codem-inventory, I do not have access to a copy of this inventory to bridge the feature.")
end
---This will get the image path for an item, it is an alternate option to GetItemInfo. If a image isnt found will revert to community_bridge logo (useful for menus)
---@param item string
---@return string
Inventory.GetImagePath = function(item) Inventory.GetImagePath = function(item)
item = Inventory.StripPNG(item) item = Inventory.StripPNG(item)
local file = LoadResourceFile("codem-inventory", string.format("html/images/%s.png", item)) local file = LoadResourceFile("codem-inventory", string.format("html/images/%s.png", item))
@@ -92,3 +156,21 @@ Inventory.GetImagePath = function(item)
return imagePath or "https://avatars.githubusercontent.com/u/47620135" return imagePath or "https://avatars.githubusercontent.com/u/47620135"
end end
-- This will open the specified shop for the src passed.
---@param src number
---@param shopTitle string
Inventory.OpenShop = function(src, shopTitle)
print("Unable to open shop for codem-inventory, I do not have access to a copy of this inventory to bridge the feature.")
end
-- This will register a shop, if it already exists it will return true.
-- @param shopTitle string
-- @param shopInventory table
-- @param shopCoords table
-- @param shopGroups table
Inventory.CreateShop = function(shopTitle, shopInventory, shopCoords, shopGroups)
return true, print("Unable to Create Shop for codem-inventory, I do not have access to a copy of this inventory to bridge the feature.")
end
return Inventory
+39 -33
View File
@@ -1,12 +1,44 @@
---@diagnostic disable: duplicate-set-field
if GetResourceState('core_inventory') ~= 'started' then return end if GetResourceState('core_inventory') ~= 'started' then return end
Inventory = Inventory or {}
local core = exports.core_inventory local core = exports.core_inventory
Inventory = Inventory or {} Inventory = Inventory or {}
---comment ---Return the item info in oxs format, {name, label, stack, weight, description, image}
---@param item string
---@return table
Inventory.GetItemInfo = function(item)
local frameworkName = Framework.GetFrameworkName()
if not frameworkName then return {} end
local dataRepack = {}
if frameworkName == 'es_extended' then
--<-- TODO swap to internal callback system
local callbackData = lib.callback.await('community_bridge:Callback:core_inventory', false)
-- really really wish this inventory allowed me to pull the item list client side....
dataRepack = callbackData[item]
if not dataRepack then return {} end
elseif frameworkName == 'qb-core' then
dataRepack = Framework.Shared.Items[item]
if not dataRepack then return {} end
end
return {name = dataRepack.name, label = dataRepack.label, stack = dataRepack.stack, weight = dataRepack.weight, description = dataRepack.description, image = Inventory.GetImagePath(dataRepack.name) }
end
---Will return boolean if the player has the item.
---@param item string
---@return boolean
Inventory.HasItem = function(item)
return core:hasItem(item, 1)
end
---This will return th count of the item in the players inventory, if not found will return 0.
---@param item string
---@return number
Inventory.GetItemCount = function(item)
return core:getItemCount(item)
end
---This will get the image path for this item, if not found will return placeholder.
---@param item string ---@param item string
---@return string ---@return string
Inventory.GetImagePath = function(item) Inventory.GetImagePath = function(item)
@@ -16,20 +48,8 @@ Inventory.GetImagePath = function(item)
return imagePath or "https://avatars.githubusercontent.com/u/47620135" return imagePath or "https://avatars.githubusercontent.com/u/47620135"
end end
---comment ---This will return the players inventory in the format of {name, label, count, slot, metadata}
---@param item string ---@return table
---@return boolean
Inventory.HasItem = function(item)
return core:hasItem(item, 1)
end
---comment
---@param item string
---@return number
Inventory.GetItemCount = function(item)
return core:getItemCount(item)
end
Inventory.GetPlayerInventory = function() Inventory.GetPlayerInventory = function()
local playerItems = core:getInventory() local playerItems = core:getInventory()
local repackedTable = {} local repackedTable = {}
@@ -44,18 +64,4 @@ Inventory.GetPlayerInventory = function()
return repackedTable return repackedTable
end end
Inventory.GetItemInfo = function(item) return Inventory
local frameworkName = Framework.GetFrameworkName()
if not frameworkName then return {} end
local dataRepack = {}
if frameworkName == 'es_extended' then
local callbackData = lib.callback.await('community_bridge:Callback:core_inventory', false)
-- really really wish this inventory allowed me to pull the item list client side....
dataRepack = callbackData[item]
if not dataRepack then return {} end
elseif frameworkName == 'qb-core' then
dataRepack = Framework.Shared.Items[item]
if not dataRepack then return {} end
end
return {name = dataRepack.name, label = dataRepack.label, stack = dataRepack.stack, weight = dataRepack.weight, description = dataRepack.description, image = Inventory.GetImagePath(dataRepack.name) }
end
+130 -57
View File
@@ -1,19 +1,10 @@
---@diagnostic disable: duplicate-set-field
if GetResourceState('core_inventory') ~= 'started' then return end if GetResourceState('core_inventory') ~= 'started' then return end
Inventory = Inventory or {} Inventory = Inventory or {}
local core = exports.core_inventory local core = exports.core_inventory
---comment
---@param item string
---@return string
Inventory.GetImagePath = function(item)
item = Inventory.StripPNG(item)
local file = LoadResourceFile("core_inventory", string.format("html/img/%s.png", item))
local imagePath = file and string.format("nui://core_inventory/html/img/%s.png", item)
return imagePath or "https://avatars.githubusercontent.com/u/47620135"
end
---This will add an item, and return true or false based on success ---This will add an item, and return true or false based on success
---@param src number ---@param src number
---@param item string ---@param item string
@@ -23,24 +14,16 @@ end
---@return boolean ---@return boolean
Inventory.AddItem = function(src, item, count, slot, metadata) Inventory.AddItem = function(src, item, count, slot, metadata)
TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "add", item = item, count = count, slot = slot, metadata = metadata}) TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "add", item = item, count = count, slot = slot, metadata = metadata})
local itemsAdd = core:addItem(src, item, count, metadata) return core:addItem(src, item, count, metadata)
return itemsAdd
end
Inventory.GetPlayerInventory = function(src)
local playerItems = core:getInventory(src)
local repackedTable = {}
for _, v in pairs(playerItems) do
table.insert(repackedTable, {
name = v.name,
count = v.count,
metadata = v.metadata,
slot = v.id,
})
end
return repackedTable
end end
---This will remove an item, and return true or false based on success
---@param src number
---@param item string
---@param count number
---@param slot number
---@param metadata table
---@return boolean
Inventory.RemoveItem = function(src, item, count, slot, metadata) Inventory.RemoveItem = function(src, item, count, slot, metadata)
if not slot and metadata then if not slot and metadata then
local inv = Inventory.GetPlayerInventory(src) local inv = Inventory.GetPlayerInventory(src)
@@ -68,28 +51,9 @@ Inventory.RemoveItem = function(src, item, count, slot, metadata)
-- I hate this inventory so much, I am so sorry for this. -- I hate this inventory so much, I am so sorry for this.
end end
---This will get the item from the specified slot. ---This will return the count of the item in the players inventory, if not found will return 0.
---@param src number ---
---@param slot number ---if metadata is passed it will find the matching items count.
---@return table
Inventory.GetItemBySlot = function(src, slot)
local inv = Inventory.GetPlayerInventory(src)
if not inv then return {} end
for _, v in pairs(inv) do
print(v.slot, slot)
if v.slot == slot then
return {
name = v.name,
count = v.count,
metadata = v.metadata,
slot = v.slot,
}
end
end
return {}
end
---Returns the total count of an item in the inventory.
---@param src number ---@param src number
---@param item string ---@param item string
---@param metadata table ---@param metadata table
@@ -110,13 +74,43 @@ Inventory.GetItemCount = function(src, item, metadata)
return count or 0 return count or 0
end end
---Returns boolean if the player has the item in their inventory. ---This wil return the players inventory.
---@param src number ---@param src number
---@param item string ---@return table
---@return boolean Inventory.GetPlayerInventory = function(src)
Inventory.HasItem = function(src, item) local playerItems = core:getInventory(src)
local count = core:getItemCount(src, item) local repackedTable = {}
return count > 0 for _, v in pairs(playerItems) do
table.insert(repackedTable, {
name = v.name,
count = v.count,
metadata = v.metadata,
slot = v.id,
})
end
return repackedTable
end
---Returns the specified slot data as a table.
---
---format {weight, name, metadata, slot, label, count}
---@param src number
---@param slot number
---@return table
Inventory.GetItemBySlot = function(src, slot)
local inv = Inventory.GetPlayerInventory(src)
if not inv then return {} end
for _, v in pairs(inv) do
if v.slot == slot then
return {
name = v.name,
count = v.count,
metadata = v.metadata,
slot = v.slot,
}
end
end
return {}
end end
---This will set the metadata of an item in the inventory. ---This will set the metadata of an item in the inventory.
@@ -129,7 +123,56 @@ Inventory.SetMetadata = function(src, item, slot, metadata)
core:setMetadata(src, slot, metadata) core:setMetadata(src, slot, metadata)
end end
---comment ---This will open the specified stash for the src passed.
---@param src number
---@param id number||string
---@param label string
---@param slots number
---@param weight number
---@param owner string
---@param groups table
---@param coords table
---@return nil
Inventory.OpenStash = function(src, id, label, slots, weight, owner, groups, coords)
if not slots then slots = 30 end
local mathyShit = slots / 2
core:openInventory(playerid, id, 'stash', mathyShit, mathyShit, true, nil, false)
end
---This will register a stash
---@param id number||string
---@param label string
---@param slots number
---@param weight number
---@param owner string
---@param groups table
---@param coords table
---@return boolean
Inventory.RegisterStash = function(id, label, slots, weight, owner, groups, coords)
if not slots then slots = 30 end
local mathyShit = slots / 2
core:openInventory(nil, id, 'stash', mathyShit, mathyShit, false, nil, false)
return true
end
---This will return a boolean if the player has the item.
---@param src number
---@param item string
---@return boolean
Inventory.HasItem = function(src, item)
return core:getItemCount(src, item) > 0
end
---This is to get if there is available space in the inventory, will return boolean.
---@param src number
---@param item string
---@param count number
---@return boolean
Inventory.CanCarryItem = function(src, item, count)
return true
end
---This will update the plate to the vehicle inside the inventory. (It will also update with jg-mechanic if using it)
---@param oldplate string ---@param oldplate string
---@param newplate string ---@param newplate string
---@return boolean ---@return boolean
@@ -148,11 +191,41 @@ Inventory.UpdatePlate = function(oldplate, newplate)
} }
MySQL.transaction.await(queries, values) MySQL.transaction.await(queries, values)
if GetResourceState('jg-mechanic') ~= 'started' then return true end if GetResourceState('jg-mechanic') ~= 'started' then return true end
exports["jg-mechanic"]:vehiclePlateUpdated(oldplate, newplate) return true, exports["jg-mechanic"]:vehiclePlateUpdated(oldplate, newplate)
return true
end end
---This will get the image path for an item, it is an alternate option to GetItemInfo. If a image isnt found will revert to community_bridge logo (useful for menus)
---@param item string
---@return string
Inventory.GetImagePath = function(item)
item = Inventory.StripPNG(item)
local file = LoadResourceFile("core_inventory", string.format("html/img/%s.png", item))
local imagePath = file and string.format("nui://core_inventory/html/img/%s.png", item)
return imagePath or "https://avatars.githubusercontent.com/u/47620135"
end
-- This will open the specified shop for the src passed.
---@param src number
---@param shopTitle string
Inventory.OpenShop = function(src, shopTitle)
return false, print("Unable to open shop for core_inventory, I do not have access to a copy of this inventory to bridge the feature.")
end
-- This will register a shop, if it already exists it will return true.
-- @param shopTitle string
-- @param shopInventory table
-- @param shopCoords table
-- @param shopGroups table
Inventory.CreateShop = function(shopTitle, shopInventory, shopCoords, shopGroups)
return false, print("Unable to open shop for core_inventory, I do not have access to a copy of this inventory to bridge the feature.")
end
--<-- TODO swap to internal callback system
-- This is used for the esx users, documentation doesnt show a client side available option for the inventory so we use jank callbacks to get this.
lib.callback.register('community_bridge:Callback:core_inventory', function(source) lib.callback.register('community_bridge:Callback:core_inventory', function(source)
local items = core:getItemsList() local items = core:getItemsList()
return items or {} return items or {}
end) end)
return Inventory
+26 -21
View File
@@ -1,22 +1,33 @@
---@diagnostic disable: duplicate-set-field
if GetResourceState('jpr-inventory') ~= 'started' then return end if GetResourceState('jpr-inventory') ~= 'started' then return end
local jpr = exports['jpr-inventory'] local jpr = exports['jpr-inventory']
Inventory = Inventory or {} Inventory = Inventory or {}
RegisterNetEvent('community_bridge:client:jpr-inventory:openStash', function(id, data) ---Return the item info in oxs format, {name, label, stack, weight, description, image}
if source ~= 65535 then return end ---@param item string
TriggerEvent("inventory:client:SetCurrentStash", id) ---@return table
TriggerServerEvent('inventory:server:OpenInventory', 'stash', id, { maxweight = data.weight, slots = data.slots }) Inventory.GetItemInfo = function(item)
end) local itemData = Framework.Shared.Items[item]
if not itemData then return {} end
return {
name = itemData.name,
label = itemData.label,
stack = itemData.unique,
weight = itemData.weight,
description = itemData.description,
image = Inventory.GetImagePath(itemData.name)
}
end
---comment ---Will return boolean if the player has the item.
---@param item string ---@param item string
---@return boolean ---@return boolean
Inventory.HasItem = function(item) Inventory.HasItem = function(item)
return jpr:HasItem(item) return jpr:HasItem(item)
end end
---comment ---This will get the image path for this item, if not found will return placeholder.
---@param item string ---@param item string
---@return string ---@return string
Inventory.GetImagePath = function(item) Inventory.GetImagePath = function(item)
@@ -26,16 +37,10 @@ Inventory.GetImagePath = function(item)
return imagePath or "https://avatars.githubusercontent.com/u/47620135" return imagePath or "https://avatars.githubusercontent.com/u/47620135"
end end
Inventory.GetItemInfo = function(item) RegisterNetEvent('community_bridge:client:jpr-inventory:openStash', function(id, data)
local itemData = Framework.Shared.Items[item] if source ~= 65535 then return end
if not itemData then return {} end TriggerEvent("inventory:client:SetCurrentStash", id)
local repackedTable = { TriggerServerEvent('inventory:server:OpenInventory', 'stash', id, { maxweight = data.weight, slots = data.slots })
name = itemData.name, end)
label = itemData.label,
stack = itemData.unique, return Inventory
weight = itemData.weight,
description = itemData.description,
image = Inventory.GetImagePath(itemData.name)
}
return repackedTable
end
+101 -41
View File
@@ -1,11 +1,81 @@
---@diagnostic disable: duplicate-set-field
if GetResourceState('jpr-inventory') ~= 'started' then return end if GetResourceState('jpr-inventory') ~= 'started' then return end
local jpr = exports['jpr-inventory'] local jpr = exports['jpr-inventory']
local registeredShops = {}
Inventory = Inventory or {} Inventory = Inventory or {}
---comment ---This will add an item, and return true or false based on success
---@param id string||number ---@param src number
---@param item string
---@param count number
---@param slot number
---@param metadata table
---@return boolean
Inventory.AddItem = function(src, item, count, slot, metadata)
TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "add", item = item, count = count, slot = slot, metadata = metadata})
return exports['jpr-inventory']:AddItem(src, item, count, slot, metadata, 'community_bridge Item added')
end
---This will remove an item, and return true or false based on success
---@param src number
---@param item string
---@param count number
---@param slot number
---@param metadata table
---@return boolean
Inventory.RemoveItem = function(src, item, count, slot, metadata)
TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "remove", item = item, count = count, slot = slot, metadata = metadata})
return exports['jpr-inventory']:RemoveItem(src, item, count, slot, 'community_bridge Item removed')
end
---This will return a table with the item info, {name, label, stack, weight, description, image}
---@param item string
---@return table
Inventory.GetItemInfo = function(item)
local itemTable = Framework.GetItemInfo(item)
itemTable.image = Inventory.GetImagePath(item)
return itemTable
end
---Returns the specified slot data as a table.
---
---format {weight, name, metadata, slot, label, count}
---@param src number
---@param slot number
---@return table
Inventory.GetItemBySlot = function(src, slot)
local slotData = jpr:GetItemBySlot(src, slot)
if not slotData then return {} end
return {
name = slotData.name,
label = slotData.label,
weight = slotData.weight,
slot = slot,
count = slotData.amount,
metadata = slotData.info,
stack = slotData.unique,
description = slotData.description
}
end
---This will open the specified stash for the src passed.
---@param src number
---@param id number||string
---@param label string
---@param slots number
---@param weight number
---@param owner string
---@param groups table
---@param coords table
---@return nil
Inventory.OpenStash = function(src, id, label, slots, weight, owner, groups, coords)
TriggerClientEvent('community_bridge:client:jpr-inventory:openStash', src, id, { weight = weight, slots = slots })
end
---This will register a stash
---@param id number||string
---@param label string ---@param label string
---@param slots number ---@param slots number
---@param weight number ---@param weight number
@@ -17,7 +87,7 @@ Inventory.RegisterStash = function(id, label, slots, weight, owner, groups, coor
return true return true
end end
---comment ---This will return a boolean if the player has the item.
---@param src number ---@param src number
---@param item string ---@param item string
---@return boolean ---@return boolean
@@ -25,41 +95,16 @@ Inventory.HasItem = function(src, item)
return jpr:HasItem(src, item, 1) return jpr:HasItem(src, item, 1)
end end
---comment ---This is to get if there is available space in the inventory, will return boolean.
---@param src number ---@param src number
---@param id string||number
---@param label string
---@param slots number
---@param weight number
---@param owner string
---@param groups table
---@param coords table
---@return nil
Inventory.OpenStash = function(src, id, label, slots, weight, owner, groups, coords)
TriggerClientEvent('community_bridge:client:qb-inventory:openStash', src, id, { weight = weight, slots = slots })
end
---comment
---@param item string ---@param item string
---@return string ---@param count number
Inventory.GetImagePath = function(item) ---@return boolean
item = Inventory.StripPNG(item) Inventory.CanCarryItem = function(src, item, count)
local file = LoadResourceFile("jpr-inventory", string.format("html/images/%s.png", item)) return true
local imagePath = file and string.format("nui://jpr-inventory/html/images/%s.png", item)
return imagePath or "https://avatars.githubusercontent.com/u/47620135"
end end
---comment ---This will update the plate to the vehicle inside the inventory. (It will also update with jg-mechanic if using it)
---@param src number
---@param slot number
---@return table
Inventory.GetItemBySlot = function(src, slot)
local slotData = jpr:GetItemBySlot(src, slot)
if not slotData then return {} end
return { name = slotData.name, label = slotData.label, weight = slotData.weight, slot = slot, count = slotData.amount, metadata = slotData.info, stack = slotData.unique, description = slotData.description }
end
---comment
---@param oldplate string ---@param oldplate string
---@param newplate string ---@param newplate string
---@return boolean ---@return boolean
@@ -71,18 +116,32 @@ Inventory.UpdatePlate = function(oldplate, newplate)
local values = { newplate = newplate, oldplate = oldplate } local values = { newplate = newplate, oldplate = oldplate }
MySQL.transaction.await(queries, values) MySQL.transaction.await(queries, values)
if GetResourceState('jg-mechanic') ~= 'started' then return true end if GetResourceState('jg-mechanic') ~= 'started' then return true end
exports["jg-mechanic"]:vehiclePlateUpdated(oldplate, newplate) return true, exports["jg-mechanic"]:vehiclePlateUpdated(oldplate, newplate)
return true
end end
---This will get the image path for an item, it is an alternate option to GetItemInfo. If a image isnt found will revert to community_bridge logo (useful for menus)
---@param item string
---@return string
Inventory.GetImagePath = function(item)
item = Inventory.StripPNG(item)
local file = LoadResourceFile("jpr-inventory", string.format("html/images/%s.png", item))
local imagePath = file and string.format("nui://jpr-inventory/html/images/%s.png", item)
return imagePath or "https://avatars.githubusercontent.com/u/47620135"
end
local registeredShops = {} -- This will open the specified shop for the src passed.
---@param src number
---@param shopTitle string
Inventory.OpenShop = function(src, shopTitle) Inventory.OpenShop = function(src, shopTitle)
return jpr:OpenShop(src, shopTitle) jpr:OpenShop(src, shopTitle)
end end
Inventory.CreateShop = function(src, shopTitle, shopInventory, shopCoords, shopGroups) -- This will register a shop, if it already exists it will return true.
-- @param shopTitle string
-- @param shopInventory table
-- @param shopCoords table
-- @param shopGroups table
Inventory.CreateShop = function(shopTitle, shopInventory, shopCoords, shopGroups)
if not shopTitle or not shopInventory or not shopCoords then return end if not shopTitle or not shopInventory or not shopCoords then return end
if registeredShops[shopTitle] then return true end if registeredShops[shopTitle] then return true end
@@ -94,6 +153,7 @@ Inventory.CreateShop = function(src, shopTitle, shopInventory, shopCoords, shopG
jpr:CreateShop(repackedShopItems) jpr:CreateShop(repackedShopItems)
registeredShops[shopTitle] = true registeredShops[shopTitle] = true
--Inventory.OpenShop(src, shopTitle)
return true return true
end end
return Inventory
+21 -18
View File
@@ -1,15 +1,15 @@
---@diagnostic disable: duplicate-set-field
if GetResourceState('origen_inventory') ~= 'started' then return end if GetResourceState('origen_inventory') ~= 'started' then return end
Inventory = Inventory or {} Inventory = Inventory or {}
local origin = exports.origen_inventory local origin = exports.origen_inventory
---comment ---Return the item info in oxs format, {name, label, stack, weight, description, image}
---@param item string ---@param item string
---@return table ---@return table
Inventory.GetItemInfo = function(item) Inventory.GetItemInfo = function(item)
local itemData = origin:Items(item) local itemData = origin:Items(item)
local repackedTable = { if not itemData then return {} end
return {
name = itemData.name or "Missing Name", name = itemData.name or "Missing Name",
label = itemData.label or "Missing Label", label = itemData.label or "Missing Label",
stack = itemData.unique or "false", stack = itemData.unique or "false",
@@ -17,29 +17,25 @@ Inventory.GetItemInfo = function(item)
description = itemData.description or "none", description = itemData.description or "none",
image = itemData.image or Inventory.GetImagePath(item), image = itemData.image or Inventory.GetImagePath(item),
} }
return repackedTable or {}
end end
---comment ---Will return boolean if the player has the item.
---@param item string ---@param item string
---@return boolean ---@return boolean
Inventory.HasItem = function(item) Inventory.HasItem = function(item)
return origin:HasItem(item) return origin:HasItem(item)
end end
---comment ---This will return th count of the item in the players inventory, if not found will return 0.
---@param item string ---@param item string
---@return number ---@return number
Inventory.GetItemCount = function(item) Inventory.GetItemCount = function(item)
local searchItem = origin:Search('slots', item) local inventory = origin:Search('count', item)
local count = 0 if not inventory then return 0 end
for _, v in pairs(searchItem) do return inventory.count
count = count + v.count
end
return count
end end
---comment ---This will get the image path for this item, if not found will return placeholder.
---@param item string ---@param item string
---@return string ---@return string
Inventory.GetImagePath = function(item) Inventory.GetImagePath = function(item)
@@ -49,13 +45,14 @@ Inventory.GetImagePath = function(item)
return imagePath or "https://avatars.githubusercontent.com/u/47620135" return imagePath or "https://avatars.githubusercontent.com/u/47620135"
end end
---comment ---This will return the players inventory in the format of {name, label, count, slot, metadata}
---@return table ---@return table
Inventory.GetPlayerInventory = function() Inventory.GetPlayerInventory = function()
local items = {} local repack = {}
local inventory = origin:GetInventory() local inventory = origin:GetInventory()
if not inventory then return {} end
for _, v in pairs(inventory) do for _, v in pairs(inventory) do
table.insert(items, { table.insert(repack, {
name = v.name, name = v.name,
label = v.label, label = v.label,
count = v.count, count = v.count,
@@ -66,5 +63,11 @@ Inventory.GetPlayerInventory = function()
weight = v.weight weight = v.weight
}) })
end end
return items return repack
end end
Inventory.OpenStash = function(id)
origin:openInventory('stash', id, { label = id, weight = 400000, slots = 100, })
end
return Inventory
+138 -74
View File
@@ -1,31 +1,41 @@
---@diagnostic disable: duplicate-set-field
if GetResourceState('origen_inventory') ~= 'started' then return end if GetResourceState('origen_inventory') ~= 'started' then return end
Inventory = Inventory or {} Inventory = Inventory or {}
local origen_inventory = exports.origen_inventory local origin = exports.origen_inventory
Inventory.AddItem = function(src, item, count, slot, metadata) ---This will add an item, and return true or false based on success
TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "add", item = item, count = count, slot = slot, metadata = metadata})
return origen_inventory:AddItem(src, item, count, metadata, slot, true)
end
Inventory.RemoveItem = function(src, item, count, slot, metadata)
TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "remove", item = item, count = count, slot = slot, metadata = metadata})
return origen_inventory:removeItem(src, item, count, metadata, slot, true)
end
---comment
---@param src number ---@param src number
---@param item string ---@param item string
---@param count number
---@param slot number
---@param metadata table
---@return boolean ---@return boolean
Inventory.HasItem = function(src, item) Inventory.AddItem = function(src, item, count, slot, metadata)
local count = origen_inventory:getItemCount(src , item) TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "add", item = item, count = count, slot = slot, metadata = metadata})
return count > 0 return origin:AddItem(src, item, count, metadata, slot, true)
end end
---This will remove an item, and return true or false based on success
---@param src number
---@param item string
---@param count number
---@param slot number
---@param metadata table
---@return boolean
Inventory.RemoveItem = function(src, item, count, slot, metadata)
TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "remove", item = item, count = count, slot = slot, metadata = metadata})
return origin:removeItem(src, item, count, metadata, slot, true)
end
---This will return a table with the item info, {name, label, stack, weight, description, image}
---@param item string
---@return table
Inventory.GetItemInfo = function(item) Inventory.GetItemInfo = function(item)
local itemData = origen_inventory:Items(item) local itemData = origin:Items(item)
local repackedTable = { if not itemData then return {} end
return {
name = itemData.name or "Missing Name", name = itemData.name or "Missing Name",
label = itemData.label or "Missing Label", label = itemData.label or "Missing Label",
stack = itemData.unique or "false", stack = itemData.unique or "false",
@@ -33,82 +43,108 @@ Inventory.GetItemInfo = function(item)
description = itemData.description or "none", description = itemData.description or "none",
image = itemData.image or Inventory.GetImagePath(item), image = itemData.image or Inventory.GetImagePath(item),
} }
return repackedTable or {}
end end
---This will return the count of the item in the players inventory, if not found will return 0.
---
---if metadata is passed it will find the matching items count.
---@param src number
---@param item string
---@param metadata table
---@return number
Inventory.GetItemCount = function(src, item, metadata) Inventory.GetItemCount = function(src, item, metadata)
if not metadata then return origin:getItemCount(src, item, metadata, false)
return origen_inventory:GetItemTotalAmount(src, item)
else
local items = origen_inventory:GetInventory(src)
local count = 0
for _, itemInfo in pairs(items) do
if itemInfo.name == item and itemInfo.info == metadata or itemInfo.metadata == metadata then
count = count + itemInfo.count
end
end
return count
end
end end
---This wil return the players inventory.
---@param src number
---@return table
Inventory.GetPlayerInventory = function(src) Inventory.GetPlayerInventory = function(src)
local playerItems = origen_inventory:GetInventory(src) return origin:GetInventory(src)
local repackedTable = {}
for _, v in pairs(playerItems.inventory) do
table.insert(repackedTable, {
name = v.name,
count = v.count,
metadata = v.metadata,
slot = v.slot,
})
end
return repackedTable
end end
---Returns the specified slot data as a table.
---
---format {weight, name, metadata, slot, label, count}
---@param src number
---@param slot number
---@return table
Inventory.GetItemBySlot = function(src, slot) Inventory.GetItemBySlot = function(src, slot)
-- This inventory got rid of almost all the great exports they had =( local inv = origin:getInventory(src)
local slotData = Inventory.GetInventoryItems(src) for k, v in pairs(inv) do
for _, item in pairs(slotData) do if v.slot == slot then
if item.slot == slot then
return { return {
name = item.name, weight = v.weight,
label = item.name, name = v.name,
weight = item.weight, metadata = v.metadata,
slot = slot, slot = v.slot,
count = item.amount, label = v.label,
metadata = item.metadata, count = v.count
stack = item.unique or false,
description = item.description
} }
end end
end end
return {} return {}
end end
Inventory.CanCarryItem = function(src, item, count) ---This will set the metadata of an item in the inventory.
return origen_inventory:CanCarryItems(src, item, count) ---@param src number
end ---@param item string
---@param slot number
Inventory.RegisterStash = function(id, label, slots, weight, owner, groups, coords) ---@param metadata table
return origen_inventory:RegisterStash(id, { label = label, slots = slots, weight = weight }) ---@return nil
end
Inventory.OpenStash = function(src, id, label, slots, weight, owner, groups, coords)
return origen_inventory:OpenInventory(src, 'stash', id)
end
Inventory.SetMetadata = function(src, item, slot, metadata) Inventory.SetMetadata = function(src, item, slot, metadata)
Inventory.RemoveItem (src, item, 1, slot, nil) origin:setMetadata(src, slot, metadata)
Inventory.AddItem(src, item, 1, slot, metadata)
end end
Inventory.GetImagePath = function(item) ---This will open the specified stash for the src passed.
item = Inventory.StripPNG(item) ---@param src number
local file = LoadResourceFile("origen_inventory", string.format("html/images/%s.png", item)) ---@param id number||string
local imagePath = file and string.format("nui://origen_inventory/html/images/%s.png", item) ---@param label string
return imagePath or "https://avatars.githubusercontent.com/u/47620135" ---@param slots number
---@param weight number
---@param owner string
---@param groups table
---@param coords table
---@return nil
Inventory.OpenStash = function(src, id, label, slots, weight, owner, groups, coords)
return origin:OpenInventory(src, 'stash', id)
end end
---This will register a stash
---@param id number||string
---@param label string
---@param slots number
---@param weight number
---@param owner string
---@param groups table
---@param coords table
---@return boolean
Inventory.RegisterStash = function(id, label, slots, weight, owner, groups, coords)
return origin:registerStash(id, label, slots, weight, owner, groups, coords)
end
---This will return a boolean if the player has the item.
---@param src number
---@param item string
---@return boolean
Inventory.HasItem = function(src, item)
return origin:getItemCount(src , item) > 0
end
---This is to get if there is available space in the inventory, will return boolean.
---@param src number
---@param item string
---@param count number
---@return boolean
Inventory.CanCarryItem = function(src, item, count)
return origin:canCarryItem(src, item, count)
end
---This will update the plate to the vehicle inside the inventory. (It will also update with jg-mechanic if using it)
---@param oldplate string
---@param newplate string
---@return boolean
Inventory.UpdatePlate = function(oldplate, newplate) Inventory.UpdatePlate = function(oldplate, newplate)
local queries = { local queries = {
'UPDATE gloveboxitems SET plate = @newplate WHERE plate = @oldplate', 'UPDATE gloveboxitems SET plate = @newplate WHERE plate = @oldplate',
@@ -117,6 +153,34 @@ Inventory.UpdatePlate = function(oldplate, newplate)
local values = { newplate = newplate, oldplate = oldplate } local values = { newplate = newplate, oldplate = oldplate }
MySQL.transaction.await(queries, values) MySQL.transaction.await(queries, values)
if GetResourceState('jg-mechanic') ~= 'started' then return true end if GetResourceState('jg-mechanic') ~= 'started' then return true end
exports["jg-mechanic"]:vehiclePlateUpdated(oldplate, newplate) return true, exports["jg-mechanic"]:vehiclePlateUpdated(oldplate, newplate)
return true
end end
---This will get the image path for an item, it is an alternate option to GetItemInfo. If a image isnt found will revert to community_bridge logo (useful for menus)
---@param item string
---@return string
Inventory.GetImagePath = function(item)
item = Inventory.StripPNG(item)
local file = LoadResourceFile("origin", string.format("html/images/%s.png", item))
local imagePath = file and string.format("nui://origen_inventory/html/images/%s.png", item)
return imagePath or "https://avatars.githubusercontent.com/u/47620135"
end
-- This will open the specified shop for the src passed.
---@param src number
---@param shopTitle string
Inventory.OpenShop = function(src, shopTitle)
print("Currently runtime shops are not supported in origen_inventory")
end
-- This will register a shop, if it already exists it will return true.
-- @param shopTitle string
-- @param shopInventory table
-- @param shopCoords table
-- @param shopGroups table
Inventory.CreateShop = function(shopTitle, shopInventory, shopCoords, shopGroups)
return true, print("Currently runtime shops are not supported in origen_inventory")
end
return Inventory
+10 -12
View File
@@ -1,15 +1,16 @@
---@diagnostic disable: duplicate-set-field
if GetResourceState('ox_inventory') ~= 'started' then return end if GetResourceState('ox_inventory') ~= 'started' then return end
local ox_inventory = exports.ox_inventory local ox_inventory = exports.ox_inventory
Inventory = Inventory or {} Inventory = Inventory or {}
---comment ---Return the item info in oxs format, {name, label, stack, weight, description, image}
---@param item string ---@param item string
---@return table ---@return table
Inventory.GetItemInfo = function(item) Inventory.GetItemInfo = function(item)
local itemData = ox_inventory:Items(item) local itemData = ox_inventory:Items(item)
if not itemData then return {} end if not itemData then return {} end
local repackedTable = { return {
name = itemData.name or "Missing Name", name = itemData.name or "Missing Name",
label = itemData.label or "Missing Label", label = itemData.label or "Missing Label",
stack = itemData.stack or "true", stack = itemData.stack or "true",
@@ -17,26 +18,23 @@ Inventory.GetItemInfo = function(item)
description = itemData.description or "none", description = itemData.description or "none",
image = (itemData.client and itemData.client.image) or Inventory.GetImagePath(item), image = (itemData.client and itemData.client.image) or Inventory.GetImagePath(item),
} }
return repackedTable
end end
---comment ---Will return boolean if the player has the item.
---@param item string ---@param item string
---@return boolean ---@return boolean
Inventory.HasItem = function(item) Inventory.HasItem = function(item)
local itemCount = ox_inventory:Search('count', item) return ox_inventory:Search('count', item) > 0
local hasItem = itemCount ~= 0
return hasItem
end end
---comment ---This will return th count of the item in the players inventory, if not found will return 0.
---@param item string ---@param item string
---@return number ---@return number
Inventory.GetItemCount = function(item) Inventory.GetItemCount = function(item)
return ox_inventory:GetItemCount(item, nil, false) return ox_inventory:GetItemCount(item, nil, false)
end end
---comment ---This will get the image path for this item, if not found will return placeholder.
---@param item string ---@param item string
---@return string ---@return string
Inventory.GetImagePath = function(item) Inventory.GetImagePath = function(item)
@@ -46,14 +44,14 @@ Inventory.GetImagePath = function(item)
return imagePath or "https://avatars.githubusercontent.com/u/47620135" return imagePath or "https://avatars.githubusercontent.com/u/47620135"
end end
---comment ---This will return the players inventory in the format of {name, label, count, slot, metadata}
---@return table ---@return table
Inventory.GetPlayerInventory = function() Inventory.GetPlayerInventory = function()
return exports.ox_inventory:GetPlayerItems() return ox_inventory:GetPlayerItems()
end end
Inventory.OpenShop = function(shopTitle, shopInventory) Inventory.OpenShop = function(shopTitle, shopInventory)
ox_inventory:openInventory("shop", { type = shopTitle, id = 1 }) ox_inventory:openInventory("shop", { type = shopTitle, id = 1 })
end end
--Bridge.RegisterModule("Inventory", Inventory) return Inventory
+87 -70
View File
@@ -1,6 +1,8 @@
---@diagnostic disable: duplicate-set-field
if GetResourceState('ox_inventory') ~= 'started' then return end if GetResourceState('ox_inventory') ~= 'started' then return end
local ox_inventory = exports.ox_inventory local ox_inventory = exports.ox_inventory
local registeredShops = {}
Inventory = Inventory or {} Inventory = Inventory or {}
@@ -16,24 +18,6 @@ Inventory.AddItem = function(src, item, count, slot, metadata)
return ox_inventory:AddItem(src, item, count, metadata) return ox_inventory:AddItem(src, item, count, metadata)
end end
Inventory.GetItemInfo = function(item)
local itemData = ox_inventory:Items(item)
if not itemData then return {} end
local repackedTable = {
name = itemData.name or "Missing Name",
label = itemData.label or "Missing Label",
stack = itemData.stack or "true",
weight = itemData.weight or "0",
description = itemData.description or "none",
image = string.format("nui://ox_inventory/web/images/%s", itemData.client
and itemData.client.image
or string.format("%s.png", item)
),
}
return repackedTable
end
-- string.format("nui://ox_inventory/web/images/%s.png", item)
---This will remove an item, and return true or false based on success ---This will remove an item, and return true or false based on success
---@param src number ---@param src number
---@param item string ---@param item string
@@ -46,24 +30,25 @@ Inventory.RemoveItem = function(src, item, count, slot, metadata)
return ox_inventory:RemoveItem(src, item, count, metadata, slot) return ox_inventory:RemoveItem(src, item, count, metadata, slot)
end end
---comment ---This will return a table with the item info, {name, label, stack, weight, description, image}
---@param src number
---@param item string ---@param item string
---@param metadata table
---@return table ---@return table
Inventory.GetItem = function(src, item, metadata) Inventory.GetItemInfo = function(item)
return ox_inventory:GetItem(src, item, metadata, false) local itemData = ox_inventory:Items(item)
if not itemData then return {} end
return {
name = itemData.name or "Missing Name",
label = itemData.label or "Missing Label",
stack = itemData.stack or "true",
weight = itemData.weight or "0",
description = itemData.description or "none",
image = string.format("nui://ox_inventory/web/images/%s", itemData.client and itemData.client.image or string.format("%s.png", item)),
}
end end
---This will get the item from the specified slot. ---This will return the count of the item in the players inventory, if not found will return 0.
---@param src number ---
---@param slot number ---if metadata is passed it will find the matching items count.
---@return table
Inventory.GetItemBySlot = function(src, slot)
return ox_inventory:GetSlot(src, slot)
end
---comment
---@param src number ---@param src number
---@param item string ---@param item string
---@param metadata table ---@param metadata table
@@ -72,15 +57,6 @@ Inventory.GetItemCount = function(src, item, metadata)
return ox_inventory:GetItemCount(src, item, metadata, false) return ox_inventory:GetItemCount(src, item, metadata, false)
end end
---comment
---@param src number
---@param item string
---@return boolean
Inventory.HasItem = function(src, item)
local count = ox_inventory:GetItemCount(src, item, nil, false)
return count > 0
end
---This wil return the players inventory. ---This wil return the players inventory.
---@param src number ---@param src number
---@return table ---@return table
@@ -88,13 +64,38 @@ Inventory.GetPlayerInventory = function(src)
return ox_inventory:GetInventoryItems(src, false) return ox_inventory:GetInventoryItems(src, false)
end end
---This is to get if there is available space in the inventory. ---Returns the specified slot data as a table.
---
---format {weight, name, metadata, slot, label, count}
---@param src number
---@param slot number
---@return table
Inventory.GetItemBySlot = function(src, slot)
return ox_inventory:GetSlot(src, slot)
end
---This will set the metadata of an item in the inventory.
---@param src number ---@param src number
---@param item string ---@param item string
---@param count number ---@param slot number
---@return boolean ---@param metadata table
Inventory.CanCarryItem = function(src, item, count) ---@return nil
return ox_inventory:CanCarryItem(src, item, count) Inventory.SetMetadata = function(src, item, slot, metadata)
ox_inventory:SetMetadata(src, slot, metadata)
end
---This will open the specified stash for the src passed.
---@param src number
---@param id number||string
---@param label string
---@param slots number
---@param weight number
---@param owner string
---@param groups table
---@param coords table
---@return nil
Inventory.OpenStash = function(src, id, label, slots, weight, owner, groups, coords)
TriggerClientEvent('ox_inventory:openInventory', src, 'stash', 'stash_' .. id)
end end
---This will register a stash ---This will register a stash
@@ -110,28 +111,21 @@ Inventory.RegisterStash = function(id, label, slots, weight, owner, groups, coor
return ox_inventory:RegisterStash(id, label, slots, weight, owner) return ox_inventory:RegisterStash(id, label, slots, weight, owner)
end end
---comment ---This will return a boolean if the player has the item.
---@param src number
---@param id number||string
---@param label string
---@param slots number
---@param weight number
---@param owner string
---@param groups table
---@param coords table
---@return nil
Inventory.OpenStash = function(src, id, label, slots, weight, owner, groups, coords)
TriggerClientEvent('ox_inventory:openInventory', src, 'stash', 'stash_' .. id)
end
---This will set the metadata of an item in the inventory.
---@param src number ---@param src number
---@param item string ---@param item string
---@param slot number ---@return boolean
---@param metadata table Inventory.HasItem = function(src, item)
---@return nil return ox_inventory:GetItemCount(src, item, nil, false) > 0
Inventory.SetMetadata = function(src, item, slot, metadata) end
ox_inventory:SetMetadata(src, slot, metadata)
---This is to get if there is available space in the inventory, will return boolean.
---@param src number
---@param item string
---@param count number
---@return boolean
Inventory.CanCarryItem = function(src, item, count)
return ox_inventory:CanCarryItem(src, item, count)
end end
---This will update the plate to the vehicle inside the inventory. (It will also update with jg-mechanic if using it) ---This will update the plate to the vehicle inside the inventory. (It will also update with jg-mechanic if using it)
@@ -141,8 +135,7 @@ end
Inventory.UpdatePlate = function(oldplate, newplate) Inventory.UpdatePlate = function(oldplate, newplate)
ox_inventory:UpdateVehicle(oldplate, newplate) ox_inventory:UpdateVehicle(oldplate, newplate)
if GetResourceState('jg-mechanic') ~= 'started' then return true end if GetResourceState('jg-mechanic') ~= 'started' then return true end
exports["jg-mechanic"]:vehiclePlateUpdated(oldplate, newplate) return true, exports["jg-mechanic"]:vehiclePlateUpdated(oldplate, newplate)
return true
end end
---This will get the image path for an item, it is an alternate option to GetItemInfo. If a image isnt found will revert to community_bridge logo (useful for menus) ---This will get the image path for an item, it is an alternate option to GetItemInfo. If a image isnt found will revert to community_bridge logo (useful for menus)
@@ -155,12 +148,18 @@ Inventory.GetImagePath = function(item)
return imagePath or "https://avatars.githubusercontent.com/u/47620135" return imagePath or "https://avatars.githubusercontent.com/u/47620135"
end end
local registeredShops = {} -- This will open the specified shop for the src passed.
---@param src number
---@param shopTitle string
Inventory.OpenShop = function(src, shopTitle) Inventory.OpenShop = function(src, shopTitle)
TriggerClientEvent('ox_inventory:openInventory', src, 'shop', {type = shopTitle}) TriggerClientEvent('ox_inventory:openInventory', src, 'shop', {type = shopTitle})
end end
-- This will register a shop, if it already exists it will return true.
-- @param shopTitle string
-- @param shopInventory table
-- @param shopCoords table
-- @param shopGroups table
Inventory.CreateShop = function(shopTitle, shopInventory, shopCoords, shopGroups) Inventory.CreateShop = function(shopTitle, shopInventory, shopCoords, shopGroups)
if registeredShops[shopTitle] then return true end if registeredShops[shopTitle] then return true end
registeredShops[shopTitle] = true registeredShops[shopTitle] = true
@@ -168,3 +167,21 @@ Inventory.CreateShop = function(shopTitle, shopInventory, shopCoords, shopGroups
--return Inventory.OpenShop(src, shopTitle) --return Inventory.OpenShop(src, shopTitle)
return true return true
end end
---UNUSED:
---This will return generic item data from the specified inventory, with the items total count.
---
---format without metadata { count, stack, name, weight, label }
---
---fortmat with metadata { count, stack, name, weight, label, metadata }
---@param src number
---@param item string
---@param metadata table
---@return table
Inventory.GetItem = function(src, item, metadata)
return ox_inventory:GetItem(src, item, metadata, false)
end
return Inventory
Loaded 100 of 168 files, more files were not shown because too many files have changed in this diff. Show more