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
+3486 -1305

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'
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.'
version '0.7.0'
version '0.8.0'
shared_scripts {
'@ox_lib/init.lua',
'lib/init.lua',
'settings/sharedConfig.lua',
'lib/init.lua',
'modules/math/*.lua',
'modules/locales/*.lua',
}
+24 -53
View File
@@ -8,7 +8,7 @@ function Bridge.RegisterModule(moduleName, moduleTable)
return
end
local wrappedModule = {}
local wrappedModule = Bridge[moduleName] or {}
if type(moduleTable) == 'function' then
Bridge[moduleName] = wrappedModule
exports(moduleName, moduleTable)
@@ -21,7 +21,8 @@ function Bridge.RegisterModule(moduleName, moduleTable)
print("^2 Registering module:", moduleName, "^0")
end
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()
return wrappedModule
@@ -55,24 +56,31 @@ Bridge.RegisterModule("Phone", Phone)
Bridge.RegisterModule("Dispatch", Dispatch)
Bridge.RegisterModule("Shops", Shops)
Bridge.RegisterModule("Housing", Housing)
Bridge.RegisterModule("Version", Version)
--lib
Bridge.RegisterModule("Tables", cLib.Tables)
Bridge.RegisterModule("Math", cLib.Math)
Bridge.RegisterModule("Prints", cLib.Prints)
Bridge.RegisterModule("Callback", cLib.Callback)
-- Bridge.RegisterModule("Tables", cLib.Tables)
-- Bridge.RegisterModule("Math", cLib.Math)
-- Bridge.RegisterModule("Prints", cLib.Prints)
-- Bridge.RegisterModule("Callback", cLib.Callback)
--new
-- --new
Bridge.RegisterModule("Require", Require)
Bridge.RegisterModule("Ids", cLib.Ids)
Bridge.RegisterModule("ReboundEntities", cLib.ReboundEntities)
Bridge.RegisterModule("LA", cLib.LA)
Bridge.RegisterModule("Perlin", cLib.Perlin)
Bridge.RegisterModule("Actions", cLib.Actions)
Bridge.RegisterModule("Cache", cLib.Cache)
Bridge.RegisterModule("Skills", Skills)
-- Bridge.RegisterModule("Ids", cLib.Ids)
-- Bridge.RegisterModule("ReboundEntities", cLib.ReboundEntities)
-- Bridge.RegisterModule("LA", cLib.LA)
-- Bridge.RegisterModule("Perlin", cLib.Perlin)
-- Bridge.RegisterModule("Actions", cLib.Actions)
-- Bridge.RegisterModule("Cache", cLib.Cache)
-- Bridge.RegisterModule("Skills", Skills)
for k, v in pairs(cLib) do
if v then
Bridge.RegisterModule(k, v)
end
end
exports('Bridge', function()
return Bridge
end)
@@ -80,14 +88,7 @@ end)
-- ▄▀▀ ██▀ █▀▄ █ █ ██▀ █▀▄
-- ▄█▀ █▄▄ █▀▄ ▀▄▀ █▄▄ █▀▄
if not IsDuplicityVersion() then goto client end
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)
Bridge.RegisterModule('Version', Version)
-- ▄▀▀ █ █ ██▀ █▄ █ ▀█▀
-- ▀▄▄ █▄▄ █ █▄▄ █ ▀█ █
@@ -104,34 +105,4 @@ Bridge.RegisterModule("Weather", Weather)
Bridge.RegisterModule("Target", Target)
Bridge.RegisterModule("Menu", Menu)
Bridge.RegisterModule("Dialogue", Dialogue)
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
Bridge.RegisterModule("Accessibility", Accessibility) -- new
+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))
end
if entity then
-- print(string.format("[ClientEntity] Spawned %s entity %s (GameID: %s)", entityData.entityType, entityData.id, entity))
entityData.spawned = entity
SetModelAsNoLongerNeeded(model)
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
entityData.OnSpawn(entityData)
end
@@ -49,17 +50,14 @@ local function SpawnEntity(entityData)
end
local function RemoveEntity(entityData)
entityData = entityData and entityData.args
if not entityData then return end -- Added safety check
ClientEntityActions.StopAction(entityData.id) -- Stop any ongoing action AND clear queue before despawning
entityData = entityData and entityData.args or entityData
if not entityData then return end
ClientEntityActions.StopAction(entityData.id)
if entityData.spawned and DoesEntityExist(entityData.spawned) then
local entityHandle = entityData.spawned
entityData.spawned = nil -- Clear handle first
SetEntityAsMissionEntity(entityHandle, false, false) -- Allow game engine to delete if needed, though we delete manually
entityData.spawned = nil
SetEntityAsMissionEntity(entityHandle, false, false)
DeleteEntity(entityHandle)
-- print(string.format("[ClientEntity] Removed %s entity %s (GameID: %s)", entityData.entityType, entityData.id, entityHandle))
end
if entityData.OnRemove and type(entityData.OnRemove) == 'function' then
entityData.OnRemove(entityData)
@@ -75,7 +73,7 @@ function ClientEntity.Register(entityData)
-- print(string.format("[ClientEntity] Registering %s entity %s", entityData.entityType, entityData.id))
-- 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)
end
@@ -85,9 +83,8 @@ function ClientEntity.Unregister(id)
local entityData = Entities[id]
if not entityData then return end
-- print(string.format("[ClientEntity] Unregistering entity %s", id))
Point.Remove(id) -- Remove from proximity checks (this will call RemoveEntity if currently in range)
RemoveEntity(entityData) -- Ensure it's removed even if Point.Remove didn't trigger it
Point.Remove(id)
RemoveEntity(entityData)
Entities[id] = nil
end
@@ -96,13 +93,13 @@ end
-- @param data table The data fields to update.
function ClientEntity.Update(id, data)
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
local needsPointUpdate = false
for key, value in pairs(data) do
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
end
if key == 'spawnDistance' and entityData.spawnDistance ~= value then
@@ -176,7 +173,6 @@ end)
-- New handler for entity actions
RegisterNetEvent("community_bridge:client:TriggerEntityAction", function(entityId, actionName, ...)
local entityData = Entities[entityId]
print("here", json.encode(entityData))
-- Check if entity exists locally (it doesn't need to be spawned to queue actions)
if entityData 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.
function ClientEntityActions.ProcessNextAction(entityId)
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]
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
local actionFunc = ClientEntityActions.RegisteredActions [nextAction.name]
print(string.format("[ClientEntityActions] Action '%s' dequeued for entity %s", nextAction.name, entityId))
if actionFunc then
-- print(string.format("[ClientEntityActions] Starting action '%s' for entity %s", nextAction.name, entityId))
ClientEntityActions.IsActionRunning [entityId] = true
@@ -4,7 +4,6 @@ LA = LA or Require("lib/utility/shared/la.lua")
--- Internal implementation for walking. Registered via RegisterAction.
function DefaultActions.WalkTo(entityData, coords, speed, timeout)
print("[ClientEntityActions] WalkTo action called", coords, speed, timeout)
local entity = entityData.spawned
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
end
--- Internal implementation for playing an animation. Registered via RegisterAction.
-- @param entityData table
-- @param animDict string
-- @param animName string
-- @param blendIn number (Optional, default 8.0)
-- @param blendOut number (Optional, default -8.0)
-- @param duration number (Optional, default -1 for loop/until stopped)
-- @param flag number (Optional, default 0)
-- @param playbackRate number (Optional, default 0.0)
--- @param entityData table
--- @param animDict string
--- @param animName string
--- @param blendIn number (Optional, default 8.0)
--- @param blendOut number (Optional, default -8.0)
--- @param duration number (Optional, default -1 for loop/until stopped)
--- @param flag number (Optional, default 0)
--- @param playbackRate number (Optional, default 0.0)
function DefaultActions.PlayAnim(entityData, animDict, animName, blendIn, blendOut, duration, flag, playbackRate)
local entity = entityData.spawned
local entityId = entityData.id
@@ -157,17 +156,17 @@ function DefaultActions.LerpTo(entityData, targetCoords, duration, easingType, e
ClientEntityActions.ActionThreads[entityId] = thread
end
--- Internal implementation for attaching a prop. Registered via RegisterAction.
-- This action completes immediately after attaching. Use DetachProp to remove.
-- @param entityData table
-- @param propModel string|number
-- @param boneIndex number (Optional, default -1 for root)
-- @param offsetPos vector3 (Optional, default vector3(0,0,0))
-- @param offsetRot vector3 (Optional, default vector3(0,0,0))
-- @param useSoftPinning boolean (Optional, default false)
-- @param collision boolean (Optional, default false)
-- @param isPed boolean (Optional, default false) - Seems unused in native?
-- @param vertexIndex number (Optional, default 2) - Seems unused in native?
-- @param fixedRot boolean (Optional, default true)
--- This action completes immediately after attaching. Use DetachProp to remove.
--- @param entityData table
--- @param propModel string|number
--- @param boneIndex number (Optional, default -1 for root)
--- @param offsetPos vector3 (Optional, default vector3(0,0,0))
--- @param offsetRot vector3 (Optional, default vector3(0,0,0))
--- @param useSoftPinning boolean (Optional, default false)
--- @param collision boolean (Optional, default false)
--- @param isPed boolean (Optional, default false) - Seems unused in native?
--- @param vertexIndex number (Optional, default 2) - Seems unused in native?
--- @param fixedRot boolean (Optional, default true)
function DefaultActions.AttachProp(entityData, propModel, boneName, offsetPos, offsetRot, useSoftPinning, collision, isPed, vertexIndex, fixedRot)
local entity = entityData.spawned
local entityId = entityData.id
@@ -179,9 +178,7 @@ function DefaultActions.AttachProp(entityData, propModel, boneName, offsetPos, o
end
local modelHash = Utility.GetEntityHashFromModel(propModel)
print(modelHash, propModel)
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.ProcessNextAction(entityId)
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
offsetPos = offsetPos 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)
entityData.props = entityData.props or {} -- Ensure props table exists
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)
end
--- Internal implementation for detaching a prop. Registered via RegisterAction.
-- @param entityData table
-- @param propModel string|number The model name/hash of the prop to detach.
--- @param entityData table
--- @param propModel string|number The model name/hash of the prop to detach.
function DefaultActions.DetachProp(entityData, propModel)
local entityId = entityData.id
@@ -268,7 +264,6 @@ function DefaultActions.GetInCar(entityData, vehicleData, seatIndex, timeout)
end
function DefaultActions.Freeze(entityData, freeze)
print("[ClientEntityActions] Freeze action called", freeze)
local entity = entityData.spawned
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
end
function DefaultActions.Collisions(entityData, enable, keepPhysics)
local entity = entityData.spawned
SetEntityCollision(entity, enable, keepPhysics)
end
for name, func in pairs(DefaultActions) do
ClientEntityActions.RegisterAction(name, func)
end
+10 -1
View File
@@ -35,6 +35,8 @@ function Require(modulePath, resourceName)
return result
end
cLib = {
Require = Require,
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.Cache = Cache or Require("lib/cache/shared/cache.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
::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.ClientEntityActions = ClientEntityActions or Require("lib/entities/client/client_entity_actions.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
+109 -76
View File
@@ -1,8 +1,10 @@
Marker = {
}
local Created = setmetatable({}, { __mode = "k" })
local id = Require("lib/utility/shared/ids")
---@diagnostic disable: duplicate-set-field
Marker = {}
local Created = setmetatable({}, { __mode = "k" }) --what is mode?
local Ids = Ids or Require("lib/utility/shared/ids.lua")
local point = Point or Require("lib/points/client/points.lua")
local loopRunning = false
local Drawing = {}
--- 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}
@@ -23,91 +25,122 @@ local function validateMarkerData(data)
return true
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.
--- @param data table{position: vector3, offset: vector3, rotation: vector3, size: vector3, color: vector3, alpha: number, bobUpAndDown: boolean, marker: number, interaction: function}
---@return number
function Marker.DrawMarker(data)
local _id = data.id or id.Random()
local position = data.position or vector3(0.0, 0.0, 0.0)
local offset = data.offset or vector3(0.0, 0.0, 0.0)
local marker = data.marker or 1
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 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,
--- @return string|nil
function Marker.Create(data)
local _id = data.id or Ids.CreateUniqueId(Created)
if not validateMarkerData(data) then return end
local basePosition = data.position or vector3(0.0, 0.0, 0.0)
local baseOffset = data.offset or vector3(0.0, 0.0, 0.0)
local data = {
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
end
function Marker.RemoveMarker(id)
if Created[id] then
--- This will remove a marker.
--- @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
return true
end
return false
end
end
function Marker.Draw()
while true do
Wait(0)
if not next(Created) then
Wait(1000) -- Reduce CPU usage when no markers are present
goto continue
end
for id, _ in pairs(Created) do
if Created[id] then
local data = Created[id]
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
-- This will loop through all marker(points) in range and draw them.
-- @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}
-- @return nil
function Marker.Run()
if loopRunning then return end
loopRunning = true
CreateThread(function()
while loopRunning do
if not next(Created) then
loopRunning = false
return
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
::continue::
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)
+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
print("Invalid marker position. Must be a vector3 with x, y, and z coordinates.")
return
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
print("Invalid marker size. Must be a vector3 with x, y, and z dimensions.")
return
end
TriggerClientEvent("community_bridge:client:marker", source, data)
local _id = data.id or id.CreateUniqueId(Created)
local data = {
id = _id,
position = data.position,
offset = data.offset or vector3(0.0, 0.0, 0.0),
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
RegisterNetEvent("community_bridge:server:createMarker", RegisterNewMarker)
exports("RegisterNewMarker", RegisterNewMarker)
function Marker.Create(data)
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 = {}
---@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.
---@param dict string
@@ -14,7 +18,6 @@ function LoadPtfxAsset(dict)
return HasNamedPtfxAssetLoaded(dict)
end
--- Create a particle effect at the specified position and rotation.
--- @param dict string
--- @param ptfx string
@@ -25,7 +28,7 @@ end
--- @param looped boolean
--- @param loopLength number|nil
--- @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)
UseParticleFxAssetNextCall(dict)
SetParticleFxNonLoopedColour(color.x, color.y, color.z)
@@ -45,14 +48,101 @@ function Particle.Create(dict, ptfx, pos, rot, scale, color, looped, loopLength)
return particle
end
function Particle.Remove(particle)
function Particle.Stop(particle)
if not particle then return end
StopParticleFxLooped(particle, false)
RemoveParticleFx(particle, false)
RemoveNamedPtfxAsset(particle)
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)
LoadPtfxAsset(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
+86 -35
View File
@@ -1,40 +1,84 @@
Scaleform = {}
---@class Scaleform
local Scaleform = {}
function SetupScaleform(scaleform, Buttons)
local scaleform = RequestScaleformMovie(scaleform)
local timeout = 5000
-- Constants
local SCALEFORM_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
timeout = timeout - 1
Wait(0)
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)
for i = 1,#Buttons do
PushScaleformMovieFunction(scaleform, Buttons[i].type)
if Buttons[i].int then PushScaleformMovieFunctionParameterInt(Buttons[i].int) end
if Buttons[i].keyIndex then
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()
-- Setup each button
for _, button in ipairs(buttons) do
setupButton(scaleform, button)
end
return scaleform
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)
buttons = buttons or {
-- Default button configuration commented out
-- Uncomment and modify as needed
-- {type = "CLEAR_ALL"},
-- {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},
@@ -46,34 +90,41 @@ function Scaleform.SetupInstructionalButtons(buttons)
-- {type = "DRAW_INSTRUCTIONAL_BUTTONS"},
-- {type = "SET_BACKGROUND_COLOUR"},
}
local scaleform = SetupScaleform("instructional_buttons", buttons)
return scaleform
return setupScaleform("instructional_buttons", buttons)
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)
if runningScaleform then return end
runningScaleform = scaleform
if activeScaleform then return end
activeScaleform = scaleform
CreateThread(function()
while runningScaleform do
while activeScaleform do
DrawScaleformMovieFullscreen(scaleform, 255, 255, 255, 255, 0)
if onUpdate then
shouldQuit = onUpdate()
if shouldQuit then
local shouldStop = onUpdate()
if shouldStop then
Scaleform.Stop()
break
end
end
Wait(2)
Wait(RENDER_WAIT_TIME)
end
end)
end
---Stops the currently running scaleform
function Scaleform.Stop()
runningScaleform = nil
activeScaleform = nil
end
exports("Scaleform", Scaleform)
return Scaleform
return Scaleform
+92
View File
@@ -404,6 +404,98 @@ function Utility.RemovePoint(pointID)
return Point.Remove(pointID)
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)
if resource ~= GetCurrentResourceName() then return end
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
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
+3 -3
View File
@@ -2,9 +2,9 @@ Ids = Ids or {}
---This will generate a unique id.
---@param tbl table
---@param len number
---@param pattern string
---@param tbl table | nil
---@param len number | nil
---@param pattern string | nil
---@return string
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
+3 -1
View File
@@ -207,4 +207,6 @@ Accessibility.getAdjustedColour = function(colourName, returnAsRGB)
Prints.Error("Invalid Colour Name^0] [^3"..colourName.."^0")
return "#FFFFFF" -- Default to white if the colour name is invalid
end
end
end
return Accessibility
+3 -3
View File
@@ -34,8 +34,6 @@ Clothing.ReloadSkin = function()
return true
end
Clothing.UpdateAppearanceBackup = function(data)
ClothingBackup = data
end
@@ -58,4 +56,6 @@ end)
RegisterNetEvent('community_bridge:client:ReloadSkin', function()
Clothing.ReloadSkin()
end)
end)
return Clothing
+3 -1
View File
@@ -29,4 +29,6 @@ end)
RegisterNetEvent('community_bridge:client:ReloadSkin', function()
Clothing.ReloadSkin()
end)
end)
return Clothing
+3 -1
View File
@@ -161,4 +161,6 @@ if BridgeSharedConfig.DebugLevel >= 1 then
end
end)
end)
end
end
return Dialogue
+3 -1
View File
@@ -26,4 +26,6 @@ RegisterNetEvent('community_bridge:Client:DispatchAlert', function(alert)
local blip = Bridge.Utility.CreateBlip(alert.coords, alert.sprite, alert.color, alert.scale, alert.code, true)
Wait(alert.time)
Bridge.Utility.RemoveBlip(blip)
end)
end)
return Dispatch
+3 -1
View File
@@ -8,4 +8,6 @@ RegisterNetEvent("community_bridge:Server:DispatchAlert", function(data)
TriggerClientEvent('community_bridge:Client:DispatchAlert', src, data)
end
end
end)
end)
return Dispatch
+3 -1
View File
@@ -12,4 +12,6 @@ Dispatch.SendAlert = function(data)
blipCoords = data.coords or cache.ped and GetEntityCoords(cache.ped) or { x = 0, y = 0},
}
exports["bub-mdt"]:CustomAlert(alertData)
end
end
return Dispatch
+3 -1
View File
@@ -1,2 +1,4 @@
if GetResourceState('bub-mdt') ~= 'started' then return end
Dispatch = Dispatch or {}
Dispatch = Dispatch or {}
return Dispatch
@@ -21,4 +21,6 @@ Dispatch.SendAlert = function(data)
radius = 0,
}
})
end
end
return Dispatch
@@ -1,2 +1,4 @@
if GetResourceState('cd_dispatch') ~= 'started' then return end
Dispatch = Dispatch or {}
return Dispatch
+3 -1
View File
@@ -37,4 +37,6 @@ Dispatch.SendAlert = function(data)
job = data.jobs,
}
TriggerServerEvent("community_bridge:server:dispatch:sendAlert", alertData)
end
end
return Dispatch
+3 -1
View File
@@ -3,4 +3,6 @@ Dispatch = Dispatch or {}
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.
end)
end)
return Dispatch
@@ -15,4 +15,6 @@ Dispatch.SendAlert = function(data)
caller = 'Anonymous',
coords = data.coords or GetEntityCoords(cache.ped)
})
end
end
return Dispatch
@@ -1,2 +1,4 @@
if GetResourceState('linden_outlawalert') ~= 'started' then return end
Dispatch = Dispatch or {}
Dispatch = Dispatch or {}
return Dispatch
@@ -27,4 +27,6 @@ Dispatch.SendAlert = function(data)
jobs = data.jobs
}
exports["ps-dispatch"]:CustomAlert(alertData)
end
end
return Dispatch
@@ -1,3 +1,5 @@
if GetResourceState('ps-dispatch') ~= 'started' then return end
if GetResourceState('lb-tablet') == 'started' then return end
Dispatch = Dispatch or {}
return Dispatch
@@ -35,4 +35,6 @@ Dispatch.SendAlert = function(data)
customData.image = image or customData.image
TriggerServerEvent('qs-dispatch:server:CreateDispatchCall', customData)
end)
end
end
return Dispatch
@@ -1,2 +1,4 @@
if GetResourceState('qs-dispatch') ~= 'started' then return end
Dispatch = Dispatch or {}
Dispatch = Dispatch or {}
return Dispatch
@@ -11,4 +11,6 @@ Dispatch.SendAlert = function(data)
coords = data.coords,
}
TriggerServerEvent("community_bridge:server:dispatch:sendAlert", alertData)
end
end
return Dispatch
@@ -9,4 +9,6 @@ RegisterNetEvent("community_bridge:server:dispatch:sendAlert", function(data)
duration = data.time,
coords = data.coords
})
end)
end)
return Dispatch
@@ -17,4 +17,6 @@ Dispatch.SendAlert = function(data)
},
jobs = data.jobs or {'police'},
})
end
end
return Dispatch
@@ -1,2 +1,4 @@
if GetResourceState('tk_dispatch') ~= 'started' then return end
Dispatch = Dispatch or {}
Dispatch = Dispatch or {}
return Dispatch
+4 -1
View File
@@ -1,3 +1,4 @@
---@diagnostic disable: duplicate-set-field
if GetResourceState('doors_creator') ~= 'started' then return end
Doorlock = Doorlock or {}
@@ -6,4 +7,6 @@ Doorlock = Doorlock or {}
---@return string | nil
Doorlock.GetClosestDoor = function()
return exports["doors_creator"]:getClosestActiveDoor()
end
end
return Doorlock
+4 -1
View File
@@ -1,3 +1,4 @@
---@diagnostic disable: duplicate-set-field
if GetResourceState('doors_creator') ~= 'started' then return end
Doorlock = Doorlock or {}
@@ -15,4 +16,6 @@ Doorlock.ToggleDoorLock = function(doorID, toggle)
exports["doors_creator"]:setDoorState(doorID, 0)
end
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
Doorlock = Doorlock or {}
@@ -5,5 +6,9 @@ Doorlock = Doorlock or {}
---This will get the closest door to the ped
---@return string | nil
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
return Doorlock
+4 -1
View File
@@ -1,3 +1,4 @@
---@diagnostic disable: duplicate-set-field
if GetResourceState('ox_doorlock') ~= 'started' then return end
Doorlock = Doorlock or {}
@@ -14,4 +15,6 @@ Doorlock.ToggleDoorLock = function(doorID, toggle)
exports.ox_doorlock:setDoorState(doorID, 0)
end
return true
end
end
return Doorlock
+4 -1
View File
@@ -1,3 +1,4 @@
---@diagnostic disable: duplicate-set-field
if GetResourceState('qb-doorlock') ~= 'started' then return end
Doorlock = Doorlock or {}
@@ -19,4 +20,6 @@ Doorlock.GetClosestDoor = function()
end
end
return door
end
end
return Doorlock
+4 -1
View File
@@ -1,3 +1,4 @@
---@diagnostic disable: duplicate-set-field
if GetResourceState('qb-doorlock') ~= 'started' then return end
Doorlock = Doorlock or {}
@@ -9,4 +10,6 @@ Doorlock = Doorlock or {}
Doorlock.ToggleDoorLock = function(doorID, toggle)
TriggerClientEvent('qb-doorlock:client:setState', -1, 0, doorID, toggle, false, false, false)
return true
end
end
return Doorlock
+4 -1
View File
@@ -1,3 +1,4 @@
---@diagnostic disable: duplicate-set-field
if GetResourceState('rcore_doorlock') ~= 'started' then return end
Doorlock = Doorlock or {}
@@ -17,4 +18,6 @@ Doorlock.GetClosestDoor = function()
end
end
return door
end
end
return Doorlock
+3 -1
View File
@@ -1,3 +1,4 @@
---@diagnostic disable: duplicate-set-field
if GetResourceState('rcore_doorlock') ~= 'started' then return end
Doorlock = Doorlock or {}
@@ -14,4 +15,5 @@ Doorlock.ToggleDoorLock = function(doorID, toggle)
exports.rcore_doorlock:changeDoorState(doorID, 1)
end
return true
end
end
return Doorlock
+3
View File
@@ -0,0 +1,3 @@
Framework = Framework or {}
return Framework
+15 -18
View File
@@ -3,7 +3,7 @@ if GetResourceState('es_extended') ~= 'started' then return end
ESX = exports["es_extended"]:getSharedObject()
Framework = {}
Framework = Framework or {}
Framework.GetFrameworkName = function()
return 'es_extended'
@@ -15,6 +15,7 @@ Framework.GetPlayerData = function()
return ESX.PlayerData
end
--<-- TODO swap to internal callback system
---This will return a table of all the jobs in the framework.
---@return table
Framework.GetFrameworkJobs = function()
@@ -25,7 +26,7 @@ end
---This will return the players birth date
---@return string
Framework.GetPlayerDob = function()
local playerData = ESX.GetPlayerData()
local playerData = Framework.GetPlayerData()
local dob = playerData.dateofbirth
return dob
end
@@ -34,7 +35,7 @@ end
---@param metadata string
---@return table | nil
Framework.GetPlayerMetaData = function(metadata)
return ESX.GetPlayerData().metadata[metadata]
return Framework.GetPlayerData().metadata[metadata]
end
---This will prompt the user with a notification message
@@ -63,7 +64,7 @@ end
---This will return the players identifier
---@return string
Framework.GetPlayerIdentifier = function()
local playerData = ESX.GetPlayerData()
local playerData = Framework.GetPlayerData()
return playerData.identifier
end
@@ -71,7 +72,7 @@ end
---@return string
---@return string
Framework.GetPlayerName = function()
local playerData = ESX.GetPlayerData()
local playerData = Framework.GetPlayerData()
return playerData.firstName, playerData.lastName
end
@@ -81,7 +82,7 @@ end
---@return string
---@return string
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
end
@@ -96,7 +97,7 @@ end
---This will return a table of the players inventory
---@return table
Framework.GetPlayerInventory = function()
local playerData = ESX.GetPlayerData()
local playerData = Framework.GetPlayerData()
return playerData.inventory
end
@@ -112,25 +113,21 @@ end
---This will return a boolean if the player is dead
---@return boolean
Framework.GetIsPlayerDead = function()
local playerData = ESX.GetPlayerData()
local playerData = Framework.GetPlayerData()
return playerData.dead
end
RegisterNetEvent('esx:playerLoaded', function(xPlayer)
Wait(1500)
FillBridgeTables()
TriggerEvent('community_bridge:Client:OnPlayerLoaded')
TriggerEvent('community_bridge:Client:OnPlayerLoaded')
end)
RegisterNetEvent('esx:onPlayerLogout', function()
ClearClientSideVariables()
TriggerEvent('community_bridge:Client:OnPlayerUnload')
TriggerEvent('community_bridge:Client:OnPlayerUnload')
end)
RegisterNetEvent('esx:setJob', function(data)
PlayerJobName = data.name
PlayerJobLabel = data.label
PlayerJobGradeName = data.grade_label
PlayerJobGradeLevel = data.grade
TriggerEvent('community_bridge:Client:OnPlayerJobUpdate',PlayerJobName, PlayerJobLabel, PlayerJobGradeName, PlayerJobGradeLevel)
end)
TriggerEvent('community_bridge:Client:OnPlayerJobUpdate', data.name, data.label, data.grade_label, data.grade)
end)
return Framework
+65 -40
View File
@@ -1,25 +1,37 @@
---@diagnostic disable: duplicate-set-field
if GetResourceState('es_extended') ~= 'started' then return end
Prints = Prints or Require("lib/utility/shared/prints.lua")
ESX = exports["es_extended"]:getSharedObject()
Framework = {}
Framework = Framework or {}
Framework.GetFrameworkName = function()
return 'es_extended'
end
Framework.GetPlayerDob = function(src)
local xPlayer = ESX.GetPlayerFromId(src)
local xPlayer = Framework.GetPlayer(src)
if not xPlayer then return end
local dob = xPlayer.get("dateofbirth")
return dob
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)
-- Returns the citizen ID of the player.
Framework.GetPlayerIdentifier = function(src)
local xPlayer = ESX.GetPlayerFromId(src)
local xPlayer = Framework.GetPlayer(src)
if not xPlayer then return end
return xPlayer.getIdentifier()
end
@@ -31,7 +43,7 @@ end
-- Framework.GetPlayerName(src)
-- Returns the first and last name of the player.
Framework.GetPlayerName = function(src)
local xPlayer = ESX.GetPlayerFromId(src)
local xPlayer = Framework.GetPlayer(src)
if not xPlayer then return end
return xPlayer.variables.firstName, xPlayer.variables.lastName
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 {name = v.name, count = v.amount, metadata = v.info, slot = v.slot}
Framework.GetItem = function(src, item, _)
local xPlayer = ESX.GetPlayerFromId(src)
local xPlayer = Framework.GetPlayer(src)
if not xPlayer then return end
local playerItems = xPlayer.getInventory()
local repackedTable = {}
@@ -71,7 +83,7 @@ end
-- Framework.GetItemCount(src, item, _)
-- Returns the count of items matching the specified name and if passed metadata from the player's inventory.
Framework.GetItemCount = function(src, item, _)
local xPlayer = ESX.GetPlayerFromId(src)
local xPlayer = Framework.GetPlayer(src)
if not xPlayer then return end
return xPlayer.getInventoryItem(item).count
end
@@ -89,19 +101,19 @@ end
-- Returns the entire inventory of the player as a table.
-- returns {name = v.name, count = v.amount, _, _}
Framework.GetPlayerInventory = function(src)
local xPlayer = ESX.GetPlayerFromId(src)
local xPlayer = Framework.GetPlayer(src)
if not xPlayer then return end
local playerItems = xPlayer.getInventory()
local repackedTable = {}
for _, v in pairs(playerItems) do
if v.count > 0 then
table.insert(repackedTable, {
name = v.name,
count = v.count,
--metadata = v.metadata,
--slot = v.slot,
})
end
if v.count > 0 then
table.insert(repackedTable, {
name = v.name,
count = v.count,
--metadata = v.metadata,
--slot = v.slot,
})
end
end
return repackedTable
end
@@ -109,7 +121,7 @@ end
-- Framework.SetMetadata(src, metadata, value)
-- Adds the specified metadata key and number value to the player's data.
Framework.SetPlayerMetadata = function(src, metadata, value)
local xPlayer = ESX.GetPlayerFromId(src)
local xPlayer = Framework.GetPlayer(src)
if not xPlayer then return end
xPlayer.setMeta(metadata, value, nil)
return true
@@ -118,28 +130,35 @@ end
-- Framework.GetMetadata(src, metadata)
-- Gets the specified metadata key and value to the player's data.
Framework.GetPlayerMetadata = function(src, metadata)
local xPlayer = ESX.GetPlayerFromId(src)
local xPlayer = Framework.GetPlayer(src)
if not xPlayer then return end
return xPlayer.getMeta(metadata) or false
end
-- defualt esx Available tables are
-- identifier, accounts, group, inventory, job, job_grade, loadout,
-- metadata, position, firstname, lastname, dateofbirth, sex, height,
-- skin, status, is_dead, id, disabled, last_property, created_at, last_seen,
-- identifier, accounts, group, inventory, job, job_grade, loadout,
-- metadata, position, firstname, lastname, dateofbirth, sex, height,
-- skin, status, is_dead, id, disabled, last_property, created_at, last_seen,
-- phone_number, pincode
Framework.GetStatus = function(src, column)
local xPlayer = ESX.GetPlayerFromId(src)
local xPlayer = Framework.GetPlayer(src)
if not xPlayer then return end
return xPlayer.get(column) or nil
end
Framework.GetIsPlayerDead = function(src)
local xPlayer = ESX.GetPlayerFromId(src)
local xPlayer = Framework.GetPlayer(src)
if not xPlayer then return end
return xPlayer.get("is_dead") or false
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)
-- Adds the specified value from the player's thirst level.
Framework.AddThirst = function(src, value)
@@ -173,7 +192,7 @@ end
-- Framework.GetPlayerPhone(src)
-- Returns the phone number of the player.
Framework.GetPlayerPhone = function(src)
local xPlayer = ESX.GetPlayerFromId(src)
local xPlayer = Framework.GetPlayer(src)
if not xPlayer then return end
return xPlayer.get("phone_number")
end
@@ -186,7 +205,7 @@ end
---@return string | nil
---@return string | nil
Framework.GetPlayerJob = function(src)
local xPlayer = ESX.GetPlayerFromId(src)
local xPlayer = Framework.GetPlayer(src)
if not xPlayer then return end
local job = xPlayer.getJob()
return job.name, job.label, job.grade_label, job.grade
@@ -196,7 +215,7 @@ end
---@param src number
---@return boolean
Framework.GetPlayerDuty = function(src)
local xPlayer = ESX.GetPlayerFromId(src)
local xPlayer = Framework.GetPlayer(src)
if not xPlayer then return false end
local job = xPlayer.getJob()
if not job.onDuty then return false end
@@ -208,7 +227,7 @@ end
---@param dutystatus boolean
---@return boolean
Framework.SetPlayerDuty = function(src, dutystatus)
local xPlayer = ESX.GetPlayerFromId(src)
local xPlayer = Framework.GetPlayer(src)
if not xPlayer then return false end
local job = xPlayer.getJob()
if not job.onDuty then return false end
@@ -221,7 +240,7 @@ Framework.GetPlayersByJob = function(job)
local players = GetPlayers()
local playerList = {}
for _, src in pairs(players) do
local xPlayer = ESX.GetPlayerFromId(src)
local xPlayer = Framework.GetPlayer(src)
if xPlayer.getJob().name == job then
table.insert(playerList, src)
end
@@ -232,16 +251,19 @@ end
-- Framework.SetPlayerJob(src, name, grade)
-- Sets the player's job to the specified name and 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 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)
end
-- Framework.AddAccountBalance(src, _type, amount)
-- Adds the specified amount to the player's account balance of the specified type.
Framework.AddAccountBalance = function(src, _type, amount)
local xPlayer = ESX.GetPlayerFromId(src)
local xPlayer = Framework.GetPlayer(src)
if not xPlayer then return end
if _type == 'cash' then _type = 'money' end
return xPlayer.addAccountMoney(_type, amount)
@@ -250,7 +272,7 @@ end
-- Framework.RemoveAccountBalance(src, _type, amount)
-- Removes the specified amount from the player's account balance of the specified type.
Framework.RemoveAccountBalance = function(src, _type, amount)
local xPlayer = ESX.GetPlayerFromId(src)
local xPlayer = Framework.GetPlayer(src)
if not xPlayer then return end
if _type == 'cash' then _type = 'money' end
xPlayer.removeAccountMoney(_type, amount)
@@ -260,7 +282,7 @@ end
-- Framework.GetAccountBalance(src, _type)
-- Returns the player's account balance of the specified type.
Framework.GetAccountBalance = function(src, _type)
local xPlayer = ESX.GetPlayerFromId(src)
local xPlayer = Framework.GetPlayer(src)
if not xPlayer then return end
if _type == 'cash' then _type = 'money' end
return xPlayer.getAccount(_type).money
@@ -269,7 +291,7 @@ end
-- Framework.AddItem(src, item, amount, _, _)
-- Adds the specified item to the player's inventory.
Framework.AddItem = function(src, item, amount, slot, metadata)
local xPlayer = ESX.GetPlayerFromId(src)
local xPlayer = Framework.GetPlayer(src)
if not xPlayer then return end
return xPlayer.addInventoryItem(item, amount)
end
@@ -277,7 +299,7 @@ end
-- Framework.RemoveItem(src, item, amount, _, _)
-- Removes the specified item from the player's inventory.
Framework.RemoveItem = function(src, item, amount, slot, metadata)
local xPlayer = ESX.GetPlayerFromId(src)
local xPlayer = Framework.GetPlayer(src)
if not xPlayer then return end
return xPlayer.removeInventoryItem(item, amount)
end
@@ -285,14 +307,14 @@ end
Framework.GetOwnedVehicles = function(src)
local citizenId = Framework.GetPlayerIdentifier(src)
local result = MySQL.Sync.fetchAll("SELECT vehicle, plate FROM owned_vehicles WHERE owner = '" .. citizenId .. "'")
local vehicles = {}
for i=1, #result do
local vehicles = {}
for i = 1, #result do
local vehicle = result[i].vehicle
local plate = result[i].plate
local model = json.decode(vehicle).model
table.insert(vehicles, {vehicle = model, plate = plate})
table.insert(vehicles, { vehicle = model, plate = plate })
end
return vehicles
return vehicles
end
-- Framework.RegisterUsableItem(item, cb)
@@ -322,8 +344,9 @@ AddEventHandler("playerDropped", function()
TriggerEvent("community_bridge:Server:OnPlayerUnload", src)
end)
--<-- TODO swap to internal callback system
lib.callback.register('community_bridge:Callback:GetFrameworkJobs', function(source)
return Framework.GetFrameworkJobs() or {}
return Framework.GetFrameworkJobs() or {}
end)
Framework.Commands = {}
@@ -334,4 +357,6 @@ Framework.Commands.Add = function(name, help, arguments, argsrequired, callback,
help = help,
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()
Framework = {}
Framework = Framework or {}
---This will get the name of the framework being used (if a supported framework).
---@return string
@@ -33,7 +33,7 @@ end
---This will get the players birth date
---@return string
Framework.GetPlayerDob = function()
local player = QBCore.Functions.GetPlayerData()
local player = Framework.GetPlayerData()
local playerData = player.PlayerData
return playerData.charinfo.birthdate
end
@@ -42,7 +42,7 @@ end
---@param metadata table | string
---@return table | string | number | boolean
Framework.GetPlayerMetaData = function(metadata)
return QBCore.Functions.GetPlayerData().metadata[metadata]
return Framework.GetPlayerData().metadata[metadata]
end
Framework.Notify = function(message, type, time)
@@ -80,14 +80,14 @@ end
---This will get the players identifier (citizenid) etc.
---@return string
Framework.GetPlayerIdentifier = function()
return QBCore.Functions.GetPlayerData().citizenid
return Framework.GetPlayerData().citizenid
end
---This will get the players name (first and last).
---@return string
---@return string
Framework.GetPlayerName = function()
local playerData = QBCore.Functions.GetPlayerData()
local playerData = Framework.GetPlayerData()
return playerData.charinfo.firstname, playerData.charinfo.lastname
end
@@ -97,7 +97,7 @@ end
---@return string
---@return string
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
end
@@ -109,7 +109,7 @@ end
---@param item string
---@return number
Framework.GetItemCount = function(item)
local frameworkInv = QBCore.Functions.GetPlayerData().items
local frameworkInv = Framework.GetPlayerData().items
local count = 0
for _, v in pairs(frameworkInv) do
if v.name == item then
@@ -121,7 +121,7 @@ end
Framework.GetPlayerInventory = function()
local items = {}
local frameworkInv = QBCore.Functions.GetPlayerData().items
local frameworkInv = Framework.GetPlayerData().items
for _, v in pairs(frameworkInv) do
table.insert(items, {
name = v.name,
@@ -140,7 +140,7 @@ end
---This will get a players dead status.
---@return boolean
Framework.GetIsPlayerDead = function()
local playerData = QBCore.Functions.GetPlayerData()
local playerData = Framework.GetPlayerData()
return playerData.metadata["isdead"] or playerData.metadata["inlaststand"]
end
@@ -148,21 +148,15 @@ Framework.Shared = QBCore.Shared
RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function()
Wait(1500)
FillBridgeTables()
TriggerEvent('community_bridge:Client:OnPlayerLoaded')
end)
RegisterNetEvent('QBCore:Client:OnPlayerUnload', function()
ClearClientSideVariables()
TriggerEvent('community_bridge:Client:OnPlayerUnload')
TriggerEvent('community_bridge:Client:OnPlayerUnload')
end)
RegisterNetEvent('QBCore:Client:OnJobUpdate', function(data)
PlayerJobName = data.name
PlayerJobLabel = data.label
PlayerJobGradeName = data.grade.name
PlayerJobGradeLevel = data.grade.level
TriggerEvent('community_bridge:Client:OnPlayerJobUpdate', PlayerJobName, PlayerJobLabel, PlayerJobGradeName, PlayerJobGradeLevel)
TriggerEvent('community_bridge:Client:OnPlayerJobUpdate', data.name, data.label, data.grade_label, data.grade)
end)
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)
--]]
end)
return Framework
+65 -40
View File
@@ -4,7 +4,7 @@ if GetResourceState('qbx_core') == 'started' then return end
QBCore = exports['qb-core']:GetCoreObject()
Framework = {}
Framework = Framework or {}
Framework.Shared = QBCore.Shared
Framework.GetFrameworkName = function()
return 'qb-core'
@@ -13,12 +13,21 @@ end
-- Framework.GetPlayerIdentifier(src)
-- Returns the citizen ID of the player.
Framework.GetPlayerIdentifier = function(src)
local player = QBCore.Functions.GetPlayer(src)
local player = Framework.GetPlayer(src)
if not player then return end
local playerData = player.PlayerData
return playerData.citizenid
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()
local jobs = {}
for k, v in pairs(QBCore.Shared.Jobs) do
@@ -35,7 +44,7 @@ end
-- Returns the first and last name of the player.
---@return string, string
Framework.GetPlayerName = function(src)
local player = QBCore.Functions.GetPlayer(src)
local player = Framework.GetPlayer(src)
if not player then return end
local playerData = player.PlayerData
return playerData.charinfo.firstname, playerData.charinfo.lastname
@@ -44,7 +53,7 @@ end
---This will get the players birth date
---@return string
Framework.GetPlayerDob = function(src)
local player = QBCore.Functions.GetPlayer(src)
local player = Framework.GetPlayer(src)
if not player then return end
local playerData = player.PlayerData
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 {name = v.name, count = v.amount, metadata = v.info, slot = v.slot}
Framework.GetItem = function(src, item, metadata)
local player = QBCore.Functions.GetPlayer(src)
local player = Framework.GetPlayer(src)
if not player then return end
local playerData = player.PlayerData
local playerInventory = playerData.items
@@ -72,7 +81,7 @@ Framework.GetItem = function(src, item, metadata)
return repackedTable
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
---@return table
Framework.GetItemInfo = function(item)
@@ -89,10 +98,15 @@ Framework.GetItemInfo = function(item)
return repackedTable
end
-- Framework.GetItemCount(src, item, metadata)
-- Returns the count of items matching the specified name and if passed metadata from the player's inventory.
---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
Framework.GetItemCount = function(src, item, metadata)
local player = QBCore.Functions.GetPlayer(src)
local player = Framework.GetPlayer(src)
if not player then return end
local playerData = player.PlayerData
local playerInventory = playerData.items
@@ -105,7 +119,7 @@ Framework.GetItemCount = function(src, item, metadata)
return count
end
---comment
---This will return a boolean if the player has the item.
---@param src number
---@param item string
---@return boolean
@@ -118,7 +132,7 @@ end
-- Returns the entire inventory of the player as a table.
-- returns {name = v.name, count = v.amount, metadata = v.info, slot = v.slot}
Framework.GetPlayerInventory = function(src)
local player = QBCore.Functions.GetPlayer(src)
local player = Framework.GetPlayer(src)
if not player then return end
local playerData = player.PlayerData
local playerInventory = playerData.items
@@ -146,7 +160,7 @@ Framework.GetPlayers = function()
end
Framework.GetItemBySlot = function(src, slot)
local player = QBCore.Functions.GetPlayer(src)
local player = Framework.GetPlayer(src)
if not player then return end
local playerData = player.PlayerData
local playerInventory = playerData.items
@@ -172,7 +186,7 @@ end
-- Adds the specified metadata key and number value to the player's data.
---@return boolean | nil
Framework.SetPlayerMetadata = function(src, metadata, value)
local player = QBCore.Functions.GetPlayer(src)
local player = Framework.GetPlayer(src)
if not player then return end
player.Functions.SetMetaData(metadata, value)
return true
@@ -181,7 +195,7 @@ end
-- Framework.GetMetadata(src, metadata)
-- Gets the specified metadata key to the player's data.
Framework.GetPlayerMetadata = function(src, metadata)
local player = QBCore.Functions.GetPlayer(src)
local player = Framework.GetPlayer(src)
if not player then return end
local playerData = player.PlayerData
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.
---@return number | nil
Framework.AddStress = function(src, value)
local player = QBCore.Functions.GetPlayer(src)
local player = Framework.GetPlayer(src)
if not player then return end
local playerData = player.PlayerData
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.
---@return number | nil
Framework.RemoveStress = function(src, value)
local player = QBCore.Functions.GetPlayer(src)
local player = Framework.GetPlayer(src)
if not player then return end
local playerData = player.PlayerData
local newStress = (playerData.metadata.stress or 0) - value
@@ -217,14 +231,14 @@ end
-- Adds the specified value from the player's hunger level.
---@return number | nil
Framework.AddHunger = function(src, value)
local player = QBCore.Functions.GetPlayer(src)
local player = Framework.GetPlayer(src)
if not player then return end
local playerData = player.PlayerData
local newHunger = (playerData.metadata.hunger or 0) + value
player.Functions.SetMetaData('hunger', Math.Clamp(newHunger, 0, 100))
TriggerClientEvent('hud:client:UpdateNeeds', src, newHunger, playerData.metadata.thirst)
--TriggerClientEvent('hud:client:UpdateStress', src, newStress)
return newHunger
end
@@ -232,7 +246,7 @@ end
-- Adds the specified value from the player's thirst level.
---@return number | nil
Framework.AddThirst = function(src, value)
local player = QBCore.Functions.GetPlayer(src)
local player = Framework.GetPlayer(src)
if not player then return end
local playerData = player.PlayerData
local newThirst = (playerData.metadata.thirst or 0) + value
@@ -246,7 +260,7 @@ end
---@param src any
---@return number | nil
Framework.GetHunger = function(src)
local player = QBCore.Functions.GetPlayer(src)
local player = Framework.GetPlayer(src)
if not player then return end
local playerData = player.PlayerData
local newHunger = (playerData.metadata.hunger or 0)
@@ -254,18 +268,25 @@ Framework.GetHunger = function(src)
end
Framework.GetIsPlayerDead = function(src)
local player = QBCore.Functions.GetPlayer(src)
local player = Framework.GetPlayer(src)
if not player then return end
local playerData = player.PlayerData
return playerData.metadata.isdead or playerData.metadata.inlaststand or false
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
---@param src any
---@return number | nil
Framework.GetThirst = function(src)
local player = QBCore.Functions.GetPlayer(src)
local player = Framework.GetPlayer(src)
if not player then return end
local playerData = player.PlayerData
local newThirst = (playerData.metadata.thirst or 0)
@@ -275,7 +296,7 @@ end
-- Framework.GetPlayerPhone(src)
-- Returns the phone number of the player.
Framework.GetPlayerPhone = function(src)
local player = QBCore.Functions.GetPlayer(src)
local player = Framework.GetPlayer(src)
if not player then return end
local playerData = player.PlayerData
return playerData.charinfo.phone
@@ -284,7 +305,7 @@ end
-- Framework.GetPlayerGang(src)
-- Returns the gang name of the player.
Framework.GetPlayerGang = function(src)
local player = QBCore.Functions.GetPlayer(src)
local player = Framework.GetPlayer(src)
if not player then return end
local playerData = player.PlayerData
return playerData.gang.name
@@ -297,7 +318,7 @@ Framework.GetPlayersByJob = function(job)
local playerList = {}
local players = QBCore.Functions.GetPlayers()
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
table.insert(playerList, src)
end
@@ -312,7 +333,7 @@ end
---@return string
---@return string
Framework.GetPlayerJob = function(src)
local player = QBCore.Functions.GetPlayer(src)
local player = Framework.GetPlayer(src)
if not player then return end
local playerData = player.PlayerData
return playerData.job.name, playerData.job.label, playerData.job.grade.name, playerData.job.grade.level
@@ -322,7 +343,7 @@ end
---@param src number
---@return boolean | nil
Framework.GetPlayerDuty = function(src)
local player = QBCore.Functions.GetPlayer(src)
local player = Framework.GetPlayer(src)
if not player then return end
local playerData = player.PlayerData
if not playerData.job.onduty then return false end
@@ -334,7 +355,7 @@ end
---@param status boolean
---@return nil
Framework.SetPlayerDuty = function(src, status)
local player = QBCore.Functions.GetPlayer(src)
local player = Framework.GetPlayer(src)
if not player then return end
player.Functions.SetJobDuty(status)
TriggerEvent('QBCore:Server:SetDuty', src, player.PlayerData.job.onduty)
@@ -346,7 +367,7 @@ end
---@param grade string
---@return nil
Framework.SetPlayerJob = function(src, name, grade)
local player = QBCore.Functions.GetPlayer(src)
local player = Framework.GetPlayer(src)
if not player then return end
return player.Functions.SetJob(name, grade)
end
@@ -357,7 +378,7 @@ end
---@param amount number
---@return boolean | nil
Framework.AddAccountBalance = function(src, _type, amount)
local player = QBCore.Functions.GetPlayer(src)
local player = Framework.GetPlayer(src)
if not player then return end
if _type == 'money' then _type = 'cash' end
return player.Functions.AddMoney(_type, amount)
@@ -369,7 +390,7 @@ end
---@param amount number
---@return boolean | nil
Framework.RemoveAccountBalance = function(src, _type, amount)
local player = QBCore.Functions.GetPlayer(src)
local player = Framework.GetPlayer(src)
if not player then return end
if _type == 'money' then _type = 'cash' end
return player.Functions.RemoveMoney(_type, amount)
@@ -380,7 +401,7 @@ end
---@param _type string
---@return string | nil
Framework.GetAccountBalance = function(src, _type)
local player = QBCore.Functions.GetPlayer(src)
local player = Framework.GetPlayer(src)
if not player then return end
local playerData = player.PlayerData
if _type == 'money' then _type = 'cash' end
@@ -390,18 +411,20 @@ end
-- Framework.AddItem(src, item, amount, slot, metadata)
-- Adds the specified item to the player's inventory.
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
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)
end
-- Framework.RemoveItem(src, item, amount, slot, metadata)
-- Removes the specified item from the player's inventory.
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
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)
end
@@ -409,7 +432,7 @@ end
-- 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
Framework.SetMetadata = function(src, item, slot, metadata)
local player = QBCore.Functions.GetPlayer(src)
local player = Framework.GetPlayer(src)
if not player then return end
local slotFinder = Framework.GetPlayerInventory(src)
local freeSlot = Table.FindFirstUnoccupiedSlot(slotFinder)
@@ -431,12 +454,13 @@ end
---@return table
Framework.GetOwnedVehicles = function(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 = {}
for i=1, #result do
for i = 1, #result do
local vehicle = result[i].vehicle
local plate = result[i].plate
table.insert(vehicles, {vehicle = vehicle, plate = plate})
table.insert(vehicles, { vehicle = vehicle, plate = plate })
end
return vehicles
end
@@ -473,3 +497,4 @@ Framework.Commands.Add = function(name, help, arguments, argsrequired, callback,
QBCore.Commands.Add(name, help, arguments, argsrequired, callback, permission, ...)
end
return Framework
+13 -17
View File
@@ -3,7 +3,7 @@ if GetResourceState('qbx_core') ~= 'started' then return end
QBox = exports.qbx_core
Framework = {}
Framework = Framework or {}
Framework.GetFrameworkName = function()
return 'qbx_core'
@@ -18,7 +18,7 @@ Framework.GetFrameworkJobs = function()
end
Framework.GetPlayerDob = function()
local playerData = QBox.GetPlayerData()
local playerData = Framework.GetPlayerData()
return playerData.charinfo.birthdate
end
@@ -37,26 +37,26 @@ Framework.HideHelpText = function()
end
Framework.GetPlayerMetaData = function(metadata)
local playerData = QBox.GetPlayerData()
local playerData = Framework.GetPlayerData()
return playerData.metadata[metadata]
end
Framework.GetPlayerIdentifier = function()
return QBox.GetPlayerData().citizenid
return Framework.GetPlayerData().citizenid
end
Framework.GetPlayerName = function()
local playerData = QBox.GetPlayerData()
local playerData = Framework.GetPlayerData()
return playerData.charinfo.firstname, playerData.charinfo.lastname
end
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
end
Framework.GetPlayerInventory = function()
return QBox.GetPlayerData().items
return Framework.GetPlayerData().items
end
---comment
@@ -68,25 +68,21 @@ Framework.GetItemCount = function(item)
end
Framework.GetIsPlayerDead = function()
local platerData = QBox.GetPlayerData()
local platerData = Framework.GetPlayerData()
return platerData.metadata["isdead"] or platerData.metadata["inlaststand"]
end
RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function()
Wait(1500)
FillBridgeTables()
TriggerEvent('community_bridge:Client:OnPlayerLoaded')
end)
RegisterNetEvent('QBCore:Client:OnPlayerUnload', function()
ClearClientSideVariables()
TriggerEvent('community_bridge:Client:OnPlayerUnload')
TriggerEvent('community_bridge:Client:OnPlayerUnload')
end)
RegisterNetEvent('QBCore:Client:OnJobUpdate', function(data)
PlayerJobName = data.name
PlayerJobLabel = data.label
PlayerJobGradeName = data.grade.name
PlayerJobGradeLevel = data.grade.level
TriggerEvent('community_bridge:Client:OnPlayerJobUpdate',PlayerJobName, PlayerJobLabel, PlayerJobGradeName, PlayerJobGradeLevel)
end)
TriggerEvent('community_bridge:Client:OnPlayerJobUpdate', data.name, data.label, data.grade.name, data.grade.level)
end)
return Framework
+60 -38
View File
@@ -3,7 +3,7 @@ if GetResourceState('qbx_core') ~= 'started' then return end
local QBox = exports.qbx_core
Framework = {}
Framework = Framework or {}
---Returns the name of the framework being used (if a supported framework).
---@return string
@@ -15,12 +15,21 @@ end
---@param src number
---@return string
Framework.GetPlayerDob = function(src)
local player = QBox:GetPlayer(src)
local player = Framework.GetPlayer(src)
if not player then return end
local playerData = player.PlayerData
return playerData.charinfo.birthdate
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.
---@return table
Framework.GetFrameworkJobs = function()
@@ -29,9 +38,9 @@ end
---Returns the citizen ID of the player.
---@param src number
---@return string | boolean
---@return string | boolean | nil
Framework.GetPlayerIdentifier = function(src)
local player = QBox:GetPlayer(src)
local player = Framework.GetPlayer(src)
if not player then return end
local playerData = player.PlayerData
if not playerData then return false end
@@ -52,8 +61,9 @@ end
---Returns the first and last name of the player.
---@param src number
---@return string | nil
---@return string | nil
Framework.GetPlayerName = function(src)
local player = QBox:GetPlayer(src)
local player = Framework.GetPlayer(src)
if not player then return end
local playerData = player.PlayerData
return playerData.charinfo.firstname, playerData.charinfo.lastname
@@ -65,7 +75,7 @@ end
---@param metadata table
---@return table
Framework.GetItem = function(src, item, metadata)
local player = QBox:GetPlayer(src)
local player = Framework.GetPlayer(src)
if not player then return end
local playerInventory = player.PlayerData.items
local repackedTable = {}
@@ -86,9 +96,9 @@ end
---@param src number
---@param item string
---@param metadata table
---@return number
---@return number | nil
Framework.GetItemCount = function(src, item, metadata)
local player = QBox:GetPlayer(src)
local player = Framework.GetPlayer(src)
if not player then return end
local playerInventory = player.PlayerData.items
local count = 0
@@ -111,9 +121,9 @@ end
---Returns the entire inventory of the player as a table.
---@param src number
---@return table
---@return table | nil
Framework.GetPlayerInventory = function(src)
local player = QBox:GetPlayer(src)
local player = Framework.GetPlayer(src)
if not player then return end
local playerItems = player.PlayerData.items
local repackedTable = {}
@@ -132,9 +142,9 @@ end
---@param src number
---@param metadata string
---@param value string
---@return boolean
---@return boolean | nil
Framework.SetPlayerMetadata = function(src, metadata, value)
local player = QBox:GetPlayer(src)
local player = Framework.GetPlayer(src)
if not player then return end
player.Functions.SetMetaData(metadata, value)
return true
@@ -145,7 +155,7 @@ end
---@param metadata string
---@return string | boolean | nil
Framework.GetPlayerMetadata = function(src, metadata)
local player = QBox:GetPlayer(src)
local player = Framework.GetPlayer(src)
if not player then return end
local playerData = player.PlayerData
return playerData.metadata[metadata] or false
@@ -156,7 +166,7 @@ end
---@param value number
---@return number | nil
Framework.AddStress = function(src, value)
local player = QBox:GetPlayer(src)
local player = Framework.GetPlayer(src)
if not player then return end
local playerData = player.PlayerData
local newStress = playerData.metadata.stress + value
@@ -170,7 +180,7 @@ end
---@param value number
---@return number | nil
Framework.RemoveStress = function(src, value)
local player = QBox:GetPlayer(src)
local player = Framework.GetPlayer(src)
if not player then return end
local playerData = player.PlayerData
local newStress = (playerData.metadata.stress or 0) - value
@@ -184,7 +194,7 @@ end
---@param value number
---@return number | nil
Framework.AddHunger = function(src, value)
local player = QBox:GetPlayer(src)
local player = Framework.GetPlayer(src)
if not player then return end
local playerData = player.PlayerData
local newHunger = (playerData.metadata.hunger or 0) + value
@@ -198,7 +208,7 @@ end
---@param value number
---@return number | nil
Framework.AddThirst = function(src, value)
local player = QBox:GetPlayer(src)
local player = Framework.GetPlayer(src)
if not player then return end
local playerData = player.PlayerData
local newThirst = (playerData.metadata.thirst or 0) + value
@@ -211,7 +221,7 @@ end
---@param src number
---@return number | nil
Framework.GetHunger = function(src)
local player = QBox:GetPlayer(src)
local player = Framework.GetPlayer(src)
if not player then return end
local playerData = player.PlayerData
local newHunger = (playerData.metadata.hunger or 0)
@@ -219,17 +229,24 @@ Framework.GetHunger = function(src)
end
Framework.GetIsPlayerDead = function(src)
local player = QBox:GetPlayer(src)
local player = Framework.GetPlayer(src)
if not player then return end
local playerData = player.PlayerData
return playerData.metadata.isdead or false
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.
---@param src number
---@return number
Framework.GetThirst = function(src)
local player = QBox:GetPlayer(src)
local player = Framework.GetPlayer(src)
if not player then return end
local playerData = player.PlayerData
local newThirst = (playerData.metadata.thirst or 0)
@@ -240,7 +257,7 @@ end
---@param src number
---@return string | nil
Framework.GetPlayerPhone = function(src)
local player = QBox:GetPlayer(src)
local player = Framework.GetPlayer(src)
if not player then return end
local playerData = player.PlayerData
return playerData.charinfo.phone
@@ -250,7 +267,7 @@ end
---@param src number
---@return string | nil
Framework.GetPlayerGang = function(src)
local player = QBox:GetPlayer(src).PlayerData
local player = Framework.GetPlayer(src).PlayerData
return player.gang.name
end
@@ -275,7 +292,7 @@ end
---@return string | string | string | number | nil
---@return string | string | string | number | nil
Framework.GetPlayerJob = function(src)
local player = QBox:GetPlayer(src).PlayerData
local player = Framework.GetPlayer(src).PlayerData
if not player then return end
return player.job.name, player.job.label, player.job.grade.name, player.job.grade.level
end
@@ -286,7 +303,7 @@ end
---@param grade string
---@return boolean | nil
Framework.SetPlayerJob = function(src, name, grade)
local player = QBox:GetPlayer(src)
local player = Framework.GetPlayer(src)
if not player then return end
return player.Functions.SetJob(name, grade)
end
@@ -295,7 +312,7 @@ end
---@param src number
---@param status boolean
Framework.SetPlayerDuty = function(src, status)
local player = QBox:GetPlayer(src)
local player = Framework.GetPlayer(src)
if not player then return end
local playerData = player.PlayerData
QBox:SetJobDuty(playerData.citizenid, status)
@@ -306,7 +323,7 @@ end
---@param src number
---@return boolean | nil
Framework.GetPlayerDuty = function(src)
local player = QBox:GetPlayer(src)
local player = Framework.GetPlayer(src)
if not player then return end
local playerData = player.PlayerData
if not playerData.job.onduty then return false end
@@ -319,7 +336,7 @@ end
---@param amount number
---@return boolean | nil
Framework.AddAccountBalance = function(src, _type, amount)
local player = QBox:GetPlayer(src)
local player = Framework.GetPlayer(src)
if not player then return end
if _type == 'money' then _type = 'cash' end
return player.Functions.AddMoney(_type, amount)
@@ -331,7 +348,7 @@ end
---@param amount number
---@return boolean | nil
Framework.RemoveAccountBalance = function(src, _type, amount)
local player = QBox:GetPlayer(src)
local player = Framework.GetPlayer(src)
if not player then return end
if _type == 'money' then _type = 'cash' end
return player.Functions.RemoveMoney(_type, amount)
@@ -342,7 +359,7 @@ end
---@param _type string
---@return number | nil
Framework.GetAccountBalance = function(src, _type)
local player = QBox:GetPlayer(src)
local player = Framework.GetPlayer(src)
if not player then return end
local playerData = player.PlayerData
if _type == 'money' then _type = 'cash' end
@@ -357,9 +374,10 @@ end
---@param metadata table
---@return boolean | nil
Framework.AddItem = function(src, item, amount, slot, metadata)
local player = QBox:GetPlayer(src)
local player = Framework.GetPlayer(src)
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)
end
@@ -371,9 +389,10 @@ end
---@param metadata table
---@return boolean | nil
Framework.RemoveItem = function(src, item, amount, slot, metadata)
local player = QBox:GetPlayer(src)
local player = Framework.GetPlayer(src)
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)
end
@@ -384,7 +403,7 @@ end
---@param metadata table
---@return boolean | nil
Framework.SetMetadata = function(src, item, slot, metadata)
local player = QBox:GetPlayer(src)
local player = Framework.GetPlayer(src)
if not player then return end
player.Functions.RemoveItem(item, 1, slot)
return player.Functions.AddItem(item, 1, slot, metadata)
@@ -395,12 +414,13 @@ end
---@return table
Framework.GetOwnedVehicles = function(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 = {}
for i=1, #result do
for i = 1, #result do
local vehicle = result[i].vehicle
local plate = result[i].plate
table.insert(vehicles, {vehicle = vehicle, plate = plate})
table.insert(vehicles, { vehicle = vehicle, plate = plate })
end
return vehicles
end
@@ -432,4 +452,6 @@ end)
AddEventHandler("playerDropped", function()
local src = source
TriggerEvent("community_bridge:Server:OnPlayerUnload", src)
end)
end)
return Framework
+3 -1
View File
@@ -21,4 +21,6 @@ end
Fuel.SetFuel = function(vehicle, fuel)
if not DoesEntityExist(vehicle) then return end
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
exports['BigDaddy-Fuel']:SetFuel(vehicle, fuel)
end
return Fuel
+3 -1
View File
@@ -25,4 +25,6 @@ end
Fuel.SetFuel = function(vehicle, fuel)
if not DoesEntityExist(vehicle) then return end
return exports['cdn-fuel']:SetFuel(vehicle, fuel)
end
end
return Fuel
+3 -1
View File
@@ -25,4 +25,6 @@ end
Fuel.SetFuel = function(vehicle, fuel)
if not DoesEntityExist(vehicle) then return end
exports['esx-sna-fuel']:SetFuel(vehicle, fuel)
end
end
return Fuel
+4 -4
View File
@@ -1,3 +1,4 @@
---@diagnostic disable: duplicate-set-field
local resourceName = "lc_fuel"
local configValue = BridgeClientConfig.Fuel
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).
---@return string
---@diagnostic disable-next-line: duplicate-set-field
Fuel.GetResourceName = function()
return resourceName
end
@@ -14,7 +14,6 @@ end
---This will get the fuel level of the vehicle.
---@param vehicle number The vehicle entity ID.
---@return number fuel The fuel level of the vehicle.
---@diagnostic disable-next-line: duplicate-set-field
Fuel.GetFuel = function(vehicle)
if not DoesEntityExist(vehicle) then return 0.0 end
return exports["lc_fuel"]:GetFuel(vehicle)
@@ -24,8 +23,9 @@ end
---@param vehicle number The vehicle entity ID.
---@param fuel number The fuel level to set.
---@return nil
---@diagnostic disable-next-line: duplicate-set-field
Fuel.SetFuel = function(vehicle, fuel, type)
if not DoesEntityExist(vehicle) then return end
return exports["lc_fuel"]:SetFuel(vehicle, fuel)
end
end
return Fuel
+3 -1
View File
@@ -25,4 +25,6 @@ end
Fuel.SetFuel = function(vehicle, fuel, type)
if not DoesEntityExist(vehicle) then return end
return exports['LegacyFuel']:SetFuel(vehicle, fuel)
end
end
return Fuel
+3 -1
View File
@@ -25,4 +25,6 @@ end
Fuel.SetFuel = function(vehicle, fuel, type)
if not DoesEntityExist(vehicle) then return end
return exports['okokGasStation']:SetFuel(vehicle, fuel)
end
end
return Fuel
+3 -1
View File
@@ -27,4 +27,6 @@ Fuel.SetFuel = function(vehicle, fuel, type)
local currentFuel = Entity(vehicle).state.fuel
Entity(vehicle).state.fuel = currentFuel + fuel
return Entity(vehicle).state.fuel
end
end
return Fuel
+3 -1
View File
@@ -25,4 +25,6 @@ end
Fuel.SetFuel = function(vehicle, fuel, type)
if not DoesEntityExist(vehicle) then return end
return exports["ps-fuel"]:SetFuel(vehicle, fuel)
end
end
return Fuel
+3 -1
View File
@@ -25,4 +25,6 @@ end
Fuel.SetFuel = function(vehicle, fuel)
if not DoesEntityExist(vehicle) then return end
return exports['qs-fuelstations']:SetFuel(vehicle, fuel)
end
end
return Fuel
+3 -1
View File
@@ -25,4 +25,6 @@ end
Fuel.SetFuel = function(vehicle, fuel, type)
if not DoesEntityExist(vehicle) then return end
return exports['Renewed-Fuel']:SetFuel(vehicle, fuel)
end
end
return Fuel
+3 -1
View File
@@ -26,4 +26,6 @@ end
Fuel.SetFuel = function(vehicle, fuel)
if not DoesEntityExist(vehicle) then return end
return exports['ti_fuel']:setFuel(vehicle, fuel, "RON91")
end
end
return Fuel
+3 -1
View File
@@ -26,4 +26,6 @@ end
Fuel.SetFuel = function(vehicle, fuel)
if not DoesEntityExist(vehicle) then return end
return exports['x-fuel']:SetFuel(vehicle, fuel)
end
end
return Fuel
+3 -1
View File
@@ -22,4 +22,6 @@ end)
RegisterNetEvent('community_bridge:Client:HideHelpText', function()
HelpText.HideHelpText()
end)
end)
return HelpText
+3 -1
View File
@@ -14,4 +14,6 @@ end
---@diagnostic disable-next-line: duplicate-set-field
HelpText.HideHelpText = function(src)
TriggerClientEvent('community_bridge:Client:HideHelpText', src)
end
end
return HelpText
+3 -1
View File
@@ -18,4 +18,6 @@ end
---@diagnostic disable-next-line: duplicate-set-field
HelpText.HideHelpText = function()
return TriggerEvent('cd_drawtextui:HideUI')
end
end
return HelpText
+3 -1
View File
@@ -17,4 +17,6 @@ end
---@diagnostic disable-next-line: duplicate-set-field
HelpText.HideHelpText = function()
return exports['jg-textui']:HideText()
end
end
return HelpText
+3 -1
View File
@@ -17,4 +17,6 @@ end
---@diagnostic disable-next-line: duplicate-set-field
HelpText.HideHelpText = function()
return exports['lab-HintUI']:Hide()
end
end
return HelpText
+3 -1
View File
@@ -17,4 +17,6 @@ end
---@diagnostic disable-next-line: duplicate-set-field
HelpText.HideHelpText = function()
return exports['okokTextUI']:Close()
end
end
return HelpText
+3 -1
View File
@@ -18,4 +18,6 @@ end
---@diagnostic disable-next-line: duplicate-set-field
HelpText.HideHelpText = function()
return exports.ox_lib:hideTextUI()
end
end
return HelpText
+3 -1
View File
@@ -1 +1,3 @@
Housing = Housing or {}
Housing = Housing or {}
return Housing
+3 -1
View File
@@ -9,4 +9,6 @@ RegisterNetEvent('community_bridge:Server:_OnPlayerInside', function(src, inside
local playerEntity = GetPlayerPed(src)
local playerCoords = GetEntityCoords(playerEntity)
TriggerEvent('community_bridge:Client:OnPlayerInside', src, insideId, currentBucket, playerCoords)
end)
end)
return Housing
+3 -1
View File
@@ -8,4 +8,6 @@ end)
RegisterNetEvent("Housing:client:DeleteFurnitures", function()
TriggerServerEvent('community_bridge:Server:_OnPlayerInside', false)
end)
end)
return Housing
+3 -1
View File
@@ -1,3 +1,5 @@
if GetResourceState('bcs-housing') ~= 'started' then return end
Housing = Housing or {}
Housing = Housing or {}
return Housing
+3 -1
View File
@@ -1,3 +1,5 @@
if GetResourceState('esx_property') ~= 'started' then return end
Housing = Housing or {}
Housing = Housing or {}
return Housing
+3 -1
View File
@@ -10,4 +10,6 @@ end)
RegisterNetEvent('esx_property:leave', function(insideId)
local src = source
TriggerEvent('community_bridge:Server:_OnPlayerInside', src, insideId)
end)
end)
return Housing
+3 -1
View File
@@ -1,3 +1,5 @@
if GetResourceState('ps-housing') ~= 'started' then return end
Housing = Housing or {}
Housing = Housing or {}
return Housing
+3 -1
View File
@@ -10,4 +10,6 @@ end)
RegisterNetEvent('ps-housing:server:leaveProperty', function(insideId)
local src = source
TriggerEvent('community_bridge:Server:_OnPlayerInside', src, insideId)
end)
end)
return Housing
+3 -1
View File
@@ -1,3 +1,5 @@
if GetResourceState('qb-appartments') ~= 'started' then return end
Housing = Housing or {}
Housing = Housing or {}
return Housing
+3 -1
View File
@@ -6,4 +6,6 @@ RegisterNetEvent('qb-apartments:server:SetInsideMeta', function(house, insideId,
local src = source
insideId = bool and house .. '-' .. insideId or nil
TriggerEvent('community_bridge:Server:_OnPlayerInside', src, insideId)
end)
end)
return Housing
+3 -1
View File
@@ -1,3 +1,5 @@
if GetResourceState('qb-houses') ~= 'started' then return end
Housing = Housing or {}
Housing = Housing or {}
return Housing
+3 -1
View File
@@ -6,4 +6,6 @@ RegisterNetEvent('qb-houses:server:SetInsideMeta', function(insideId, bool)
local src = source
insideId = bool and insideId or nil
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)
end
return Input
--[[
-- Unit tests
local thisIsQB = {
+14 -5
View File
@@ -1,27 +1,34 @@
---@diagnostic disable: duplicate-set-field
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
---@return table
Inventory.GetItemInfo = function(item)
return Framework.GetItemInfo(item)
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
---@return boolean
Inventory.HasItem = function(item)
return Framework.HasItem(item)
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
---@return number
Inventory.GetItemCount = function(item)
return Framework.GetItemCount(item)
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
---@return string
Inventory.GetImagePath = function(item)
@@ -33,4 +40,6 @@ Inventory.StripPNG = function(item)
item = string.gsub(item, ".png", "")
end
return item
end
end
return Inventory
+78 -15
View File
@@ -1,36 +1,41 @@
---@diagnostic disable: duplicate-set-field
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 item string
---@param count number
---@param slot number
---@param metadata table
---@return boolean|nil
---@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 Framework.AddItem(src, item, count, slot, metadata)
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 item string
---@param count number
---@param slot number
---@param metadata table
---@return boolean|nil
---@return boolean
Inventory.RemoveItem = function(src, item, count, slot, metadata)
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)
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
---@return table
Inventory.GetItemInfo = function(item)
return Framework.GetItemInfo(item)
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 item string
---@param metadata table
@@ -39,14 +44,16 @@ Inventory.GetItemCount = function(src, item, metadata)
return Framework.GetItemCount(src, item, metadata)
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
---@return table
Inventory.GetPlayerInventory = function(src)
return Framework.GetPlayerInventory(src)
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 slot number
---@return table
@@ -54,19 +61,32 @@ Inventory.GetItemBySlot = function(src, slot)
return Framework.GetItemBySlot(src, slot)
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 item string
---@param slot number
---@param metadata table
---@return boolean
---@return nil
Inventory.SetMetadata = function(src, item, slot, metadata)
return Framework.SetMetadata(src, item, slot, metadata)
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 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 slots number
---@param weight number
@@ -74,11 +94,52 @@ end
---@param groups table
---@param coords table
---@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.")
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
---@return string
Inventory.GetImagePath = function(item)
@@ -90,4 +151,6 @@ Inventory.StripPNG = function(item)
item = string.gsub(item, ".png", "")
end
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
Inventory = Inventory or {}
local codem = exports['codem-inventory']
---comment
---Return the item info in oxs format, {name, label, stack, weight, description, image}
---@param item string
---@return table
Inventory.GetItemInfo = function(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 repackedTable = {
return {
name = itemData.name or "Missing Name",
label = itemData.label or "Missing Label",
stack = itemData.unique or "false",
@@ -17,10 +19,19 @@ Inventory.GetItemInfo = function(item)
description = itemData.description or "none",
image = image,
}
return repackedTable or {}
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
Inventory.GetPlayerInventory = function()
local items = {}
@@ -40,12 +51,9 @@ Inventory.GetPlayerInventory = function()
return items
end
---comment
---@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
RegisterNetEvent('community_bridge:client:codem-inventory:openStash', function(id, data)
if source ~= 65535 then return end
TriggerServerEvent('codem-inventory:server:openstash', id, data.slots, data.weight, data.label)
end)
return Inventory
+122 -40
View File
@@ -1,12 +1,41 @@
---@diagnostic disable: duplicate-set-field
if GetResourceState('codem-inventory') ~= 'started' then return end
Inventory = Inventory or {}
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)
local itemData = codem:GetItemList(item)
local repackedTable = {
if not itemData then return {} end
return {
name = itemData.name or "Missing Name",
label = itemData.label or "Missing Label",
stack = itemData.unique or "false",
@@ -14,18 +43,11 @@ Inventory.GetItemInfo = function(item)
description = itemData.description or "none",
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
---This wil return the players inventory.
---@param src number
---@return table
Inventory.GetPlayerInventory = function(src)
local identifier = Framework.GetPlayerIdentifier(src)
local playerItems = codem:GetInventory(identifier, src)
@@ -41,26 +63,65 @@ Inventory.GetPlayerInventory = function(src)
return repackedTable
end
Inventory.RemoveItem = function(src, item, count, slot, metadata)
if not slot and metadata then
local inv = Inventory.GetPlayerInventory(src)
if not inv then return false end
for _, v in pairs(inv) do
if v.name == item and v.metadata == metadata then
slot = v.slot
break
end
end
end
TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "remove", item = item, count = count, slot = slot, metadata = metadata})
return codem:RemoveItem(src, item, count, slot)
---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 = codem:GetItemBySlot(src, slot)
if not slotData then return {} end
return {
name = v.name,
label = v.label or v.name,
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
---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)
return codem:SetItemMetadata(src, slot, metadata)
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 item string
---@return boolean
@@ -68,23 +129,26 @@ Inventory.HasItem = function(src, item)
return codem:HasItem(src, item, 1)
end
Inventory.GetItemBySlot = function(src, slot)
local slotData = codem:GetItemBySlot(src, slot)
if not slotData then return {} end
for _, v in pairs(slotData) do
return {
name = v.name,
label = v.name,
weight = v.weight,
slot = v.slot,
count = v.amount,
metadata = v.info,
stack = v.unique,
description = v.description
}
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 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)
item = Inventory.StripPNG(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"
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
Inventory = Inventory or {}
local core = exports.core_inventory
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
---@return string
Inventory.GetImagePath = function(item)
@@ -16,20 +48,8 @@ Inventory.GetImagePath = function(item)
return imagePath or "https://avatars.githubusercontent.com/u/47620135"
end
---comment
---@param item string
---@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
---This will return the players inventory in the format of {name, label, count, slot, metadata}
---@return table
Inventory.GetPlayerInventory = function()
local playerItems = core:getInventory()
local repackedTable = {}
@@ -44,18 +64,4 @@ Inventory.GetPlayerInventory = function()
return repackedTable
end
Inventory.GetItemInfo = function(item)
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
return Inventory
+131 -58
View File
@@ -1,19 +1,10 @@
---@diagnostic disable: duplicate-set-field
if GetResourceState('core_inventory') ~= 'started' then return end
Inventory = Inventory or {}
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
---@param src number
---@param item string
@@ -23,24 +14,16 @@ end
---@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})
local itemsAdd = 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
return core:addItem(src, item, count, 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)
if not slot and metadata then
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.
end
---This will get the item from the specified slot.
---@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
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.
---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
@@ -110,13 +74,43 @@ Inventory.GetItemCount = function(src, item, metadata)
return count or 0
end
---Returns boolean if the player has the item in their inventory.
---This wil return the players inventory.
---@param src number
---@param item string
---@return boolean
Inventory.HasItem = function(src, item)
local count = core:getItemCount(src, item)
return count > 0
---@return table
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
---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
---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)
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 newplate string
---@return boolean
@@ -148,11 +191,41 @@ Inventory.UpdatePlate = function(oldplate, newplate)
}
MySQL.transaction.await(queries, values)
if GetResourceState('jg-mechanic') ~= 'started' then return true end
exports["jg-mechanic"]:vehiclePlateUpdated(oldplate, newplate)
return true
return true, exports["jg-mechanic"]:vehiclePlateUpdated(oldplate, newplate)
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)
local items = core:getItemsList()
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
local jpr = exports['jpr-inventory']
Inventory = Inventory or {}
RegisterNetEvent('community_bridge:client:jpr-inventory:openStash', function(id, data)
if source ~= 65535 then return end
TriggerEvent("inventory:client:SetCurrentStash", id)
TriggerServerEvent('inventory:server:OpenInventory', 'stash', id, { maxweight = data.weight, slots = data.slots })
end)
---Return the item info in oxs format, {name, label, stack, weight, description, image}
---@param item string
---@return table
Inventory.GetItemInfo = function(item)
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
---@return boolean
Inventory.HasItem = function(item)
return jpr:HasItem(item)
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)
@@ -26,16 +37,10 @@ Inventory.GetImagePath = function(item)
return imagePath or "https://avatars.githubusercontent.com/u/47620135"
end
Inventory.GetItemInfo = function(item)
local itemData = Framework.Shared.Items[item]
if not itemData then return {} end
local repackedTable = {
name = itemData.name,
label = itemData.label,
stack = itemData.unique,
weight = itemData.weight,
description = itemData.description,
image = Inventory.GetImagePath(itemData.name)
}
return repackedTable
end
RegisterNetEvent('community_bridge:client:jpr-inventory:openStash', function(id, data)
if source ~= 65535 then return end
TriggerEvent("inventory:client:SetCurrentStash", id)
TriggerServerEvent('inventory:server:OpenInventory', 'stash', id, { maxweight = data.weight, slots = data.slots })
end)
return Inventory
+102 -42
View File
@@ -1,11 +1,81 @@
---@diagnostic disable: duplicate-set-field
if GetResourceState('jpr-inventory') ~= 'started' then return end
local jpr = exports['jpr-inventory']
local registeredShops = {}
Inventory = Inventory or {}
---comment
---@param id string||number
---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 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 slots number
---@param weight number
@@ -17,7 +87,7 @@ Inventory.RegisterStash = function(id, label, slots, weight, owner, groups, coor
return true
end
---comment
---This will return a boolean if the player has the item.
---@param src number
---@param item string
---@return boolean
@@ -25,41 +95,16 @@ Inventory.HasItem = function(src, item)
return jpr:HasItem(src, item, 1)
end
---comment
---This is to get if there is available space in the inventory, will return boolean.
---@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
---@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"
---@param count number
---@return boolean
Inventory.CanCarryItem = function(src, item, count)
return true
end
---comment
---@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
---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
@@ -71,18 +116,32 @@ Inventory.UpdatePlate = function(oldplate, newplate)
local values = { newplate = newplate, oldplate = oldplate }
MySQL.transaction.await(queries, values)
if GetResourceState('jg-mechanic') ~= 'started' then return true end
exports["jg-mechanic"]:vehiclePlateUpdated(oldplate, newplate)
return true
return true, exports["jg-mechanic"]:vehiclePlateUpdated(oldplate, newplate)
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)
return jpr:OpenShop(src, shopTitle)
jpr:OpenShop(src, shopTitle)
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 registeredShops[shopTitle] then return true end
@@ -94,6 +153,7 @@ Inventory.CreateShop = function(src, shopTitle, shopInventory, shopCoords, shopG
jpr:CreateShop(repackedShopItems)
registeredShops[shopTitle] = true
--Inventory.OpenShop(src, shopTitle)
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
Inventory = Inventory or {}
local origin = exports.origen_inventory
---comment
---Return the item info in oxs format, {name, label, stack, weight, description, image}
---@param item string
---@return table
Inventory.GetItemInfo = function(item)
local itemData = origin:Items(item)
local repackedTable = {
if not itemData then return {} end
return {
name = itemData.name or "Missing Name",
label = itemData.label or "Missing Label",
stack = itemData.unique or "false",
@@ -17,29 +17,25 @@ Inventory.GetItemInfo = function(item)
description = itemData.description or "none",
image = itemData.image or Inventory.GetImagePath(item),
}
return repackedTable or {}
end
---comment
---Will return boolean if the player has the item.
---@param item string
---@return boolean
Inventory.HasItem = function(item)
return origin:HasItem(item)
end
---comment
---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)
local searchItem = origin:Search('slots', item)
local count = 0
for _, v in pairs(searchItem) do
count = count + v.count
end
return count
local inventory = origin:Search('count', item)
if not inventory then return 0 end
return inventory.count
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)
@@ -49,13 +45,14 @@ Inventory.GetImagePath = function(item)
return imagePath or "https://avatars.githubusercontent.com/u/47620135"
end
---comment
---This will return the players inventory in the format of {name, label, count, slot, metadata}
---@return table
Inventory.GetPlayerInventory = function()
local items = {}
local repack = {}
local inventory = origin:GetInventory()
if not inventory then return {} end
for _, v in pairs(inventory) do
table.insert(items, {
table.insert(repack, {
name = v.name,
label = v.label,
count = v.count,
@@ -66,5 +63,11 @@ Inventory.GetPlayerInventory = function()
weight = v.weight
})
end
return items
return repack
end
Inventory.OpenStash = function(id)
origin:openInventory('stash', id, { label = id, weight = 400000, slots = 100, })
end
return Inventory
+139 -75
View File
@@ -1,31 +1,41 @@
---@diagnostic disable: duplicate-set-field
if GetResourceState('origen_inventory') ~= 'started' then return end
Inventory = Inventory or {}
local origen_inventory = exports.origen_inventory
local origin = exports.origen_inventory
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 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
---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.HasItem = function(src, item)
local count = origen_inventory:getItemCount(src , item)
return count > 0
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 origin:AddItem(src, item, count, metadata, slot, true)
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)
local itemData = origen_inventory:Items(item)
local repackedTable = {
local itemData = origin:Items(item)
if not itemData then return {} end
return {
name = itemData.name or "Missing Name",
label = itemData.label or "Missing Label",
stack = itemData.unique or "false",
@@ -33,82 +43,108 @@ Inventory.GetItemInfo = function(item)
description = itemData.description or "none",
image = itemData.image or Inventory.GetImagePath(item),
}
return repackedTable or {}
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)
if not metadata then
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
return origin:getItemCount(src, item, metadata, false)
end
---This wil return the players inventory.
---@param src number
---@return table
Inventory.GetPlayerInventory = function(src)
local playerItems = origen_inventory: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
return origin:GetInventory(src)
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)
-- This inventory got rid of almost all the great exports they had =(
local slotData = Inventory.GetInventoryItems(src)
for _, item in pairs(slotData) do
if item.slot == slot then
local inv = origin:getInventory(src)
for k, v in pairs(inv) do
if v.slot == slot then
return {
name = item.name,
label = item.name,
weight = item.weight,
slot = slot,
count = item.amount,
metadata = item.metadata,
stack = item.unique or false,
description = item.description
weight = v.weight,
name = v.name,
metadata = v.metadata,
slot = v.slot,
label = v.label,
count = v.count
}
end
end
return {}
end
Inventory.CanCarryItem = function(src, item, count)
return origen_inventory:CanCarryItems(src, item, count)
end
Inventory.RegisterStash = function(id, label, slots, weight, owner, groups, coords)
return origen_inventory:RegisterStash(id, { label = label, slots = slots, weight = weight })
end
Inventory.OpenStash = function(src, id, label, slots, weight, owner, groups, coords)
return origen_inventory:OpenInventory(src, 'stash', id)
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.RemoveItem (src, item, 1, slot, nil)
Inventory.AddItem(src, item, 1, slot, metadata)
origin:setMetadata(src, slot, metadata)
end
Inventory.GetImagePath = function(item)
item = Inventory.StripPNG(item)
local file = LoadResourceFile("origen_inventory", 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"
---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)
return origin:OpenInventory(src, 'stash', id)
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)
local queries = {
'UPDATE gloveboxitems SET plate = @newplate WHERE plate = @oldplate',
@@ -117,6 +153,34 @@ Inventory.UpdatePlate = function(oldplate, newplate)
local values = { newplate = newplate, oldplate = oldplate }
MySQL.transaction.await(queries, values)
if GetResourceState('jg-mechanic') ~= 'started' then return true end
exports["jg-mechanic"]:vehiclePlateUpdated(oldplate, newplate)
return true
end
return true, exports["jg-mechanic"]:vehiclePlateUpdated(oldplate, newplate)
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
local ox_inventory = exports.ox_inventory
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 itemData = ox_inventory:Items(item)
if not itemData then return {} end
local repackedTable = {
return {
name = itemData.name or "Missing Name",
label = itemData.label or "Missing Label",
stack = itemData.stack or "true",
@@ -17,26 +18,23 @@ Inventory.GetItemInfo = function(item)
description = itemData.description or "none",
image = (itemData.client and itemData.client.image) or Inventory.GetImagePath(item),
}
return repackedTable
end
---comment
---Will return boolean if the player has the item.
---@param item string
---@return boolean
Inventory.HasItem = function(item)
local itemCount = ox_inventory:Search('count', item)
local hasItem = itemCount ~= 0
return hasItem
return ox_inventory:Search('count', item) > 0
end
---comment
---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 ox_inventory:GetItemCount(item, nil, false)
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)
@@ -46,14 +44,14 @@ Inventory.GetImagePath = function(item)
return imagePath or "https://avatars.githubusercontent.com/u/47620135"
end
---comment
---This will return the players inventory in the format of {name, label, count, slot, metadata}
---@return table
Inventory.GetPlayerInventory = function()
return exports.ox_inventory:GetPlayerItems()
return ox_inventory:GetPlayerItems()
end
Inventory.OpenShop = function(shopTitle, shopInventory)
ox_inventory:openInventory("shop", { type = shopTitle, id = 1 })
end
--Bridge.RegisterModule("Inventory", Inventory)
return Inventory
+88 -71
View File
@@ -1,6 +1,8 @@
---@diagnostic disable: duplicate-set-field
if GetResourceState('ox_inventory') ~= 'started' then return end
local ox_inventory = exports.ox_inventory
local registeredShops = {}
Inventory = Inventory or {}
@@ -16,24 +18,6 @@ Inventory.AddItem = function(src, item, count, slot, metadata)
return ox_inventory:AddItem(src, item, count, metadata)
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
---@param src number
---@param item string
@@ -46,24 +30,25 @@ Inventory.RemoveItem = function(src, item, count, slot, metadata)
return ox_inventory:RemoveItem(src, item, count, metadata, slot)
end
---comment
---@param src number
---This will return a table with the item info, {name, label, stack, weight, description, image}
---@param item string
---@param metadata table
---@return table
Inventory.GetItem = function(src, item, metadata)
return ox_inventory:GetItem(src, item, metadata, false)
Inventory.GetItemInfo = function(item)
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
---This will get the item from the specified slot.
---@param src number
---@param slot number
---@return table
Inventory.GetItemBySlot = function(src, slot)
return ox_inventory:GetSlot(src, slot)
end
---comment
---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
@@ -72,15 +57,6 @@ Inventory.GetItemCount = function(src, item, metadata)
return ox_inventory:GetItemCount(src, item, metadata, false)
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.
---@param src number
---@return table
@@ -88,13 +64,38 @@ Inventory.GetPlayerInventory = function(src)
return ox_inventory:GetInventoryItems(src, false)
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 item string
---@param count number
---@return boolean
Inventory.CanCarryItem = function(src, item, count)
return ox_inventory:CanCarryItem(src, item, count)
---@param slot number
---@param metadata table
---@return nil
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
---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)
end
---comment
---@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.
---This will return a boolean if the player has the item.
---@param src number
---@param item string
---@param slot number
---@param metadata table
---@return nil
Inventory.SetMetadata = function(src, item, slot, metadata)
ox_inventory:SetMetadata(src, slot, metadata)
---@return boolean
Inventory.HasItem = function(src, item)
return ox_inventory:GetItemCount(src, item, nil, false) > 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 ox_inventory: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)
@@ -141,8 +135,7 @@ end
Inventory.UpdatePlate = function(oldplate, newplate)
ox_inventory:UpdateVehicle(oldplate, newplate)
if GetResourceState('jg-mechanic') ~= 'started' then return true end
exports["jg-mechanic"]:vehiclePlateUpdated(oldplate, newplate)
return true
return true, exports["jg-mechanic"]:vehiclePlateUpdated(oldplate, newplate)
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)
@@ -155,16 +148,40 @@ Inventory.GetImagePath = function(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)
TriggerClientEvent('ox_inventory:openInventory', src, 'shop', {type = shopTitle})
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)
if registeredShops[shopTitle] then return true end
registeredShops[shopTitle] = true
ox_inventory:RegisterShop(shopTitle, { name = shopTitle, inventory = shopInventory, groups = shopGroups, })
--return Inventory.OpenShop(src, shopTitle)
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