diff --git a/fxmanifest.lua b/fxmanifest.lua index 4668f29..9aaa255 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -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', } diff --git a/init.lua b/init.lua index 533efb5..2fc7e21 100644 --- a/init.lua +++ b/init.lua @@ -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 \ No newline at end of file diff --git a/lib/anim/client/client.lua b/lib/anim/client/client.lua new file mode 100644 index 0000000..b809317 --- /dev/null +++ b/lib/anim/client/client.lua @@ -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 \ No newline at end of file diff --git a/lib/batch/shared/events.lua b/lib/batch/shared/events.lua new file mode 100644 index 0000000..f88fb86 --- /dev/null +++ b/lib/batch/shared/events.lua @@ -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 \ No newline at end of file diff --git a/lib/cutscenes/client/cutscene.lua b/lib/cutscenes/client/cutscene.lua new file mode 100644 index 0000000..f192fbc --- /dev/null +++ b/lib/cutscenes/client/cutscene.lua @@ -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 = 10000 +local FADE_DURATION = 1000 +local CUTSCENE_WAIT = 1000 + +-- Character model definitions +local characterTags = { + { 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 = { + -- 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 diff --git a/lib/dui/client/dui.lua b/lib/dui/client/dui.lua new file mode 100644 index 0000000..7f0d7f0 --- /dev/null +++ b/lib/dui/client/dui.lua @@ -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 = 1280 +local DEFAULT_HEIGHT = 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 = { + 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 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 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 diff --git a/lib/entities/client/client_entity.lua b/lib/entities/client/client_entity.lua index 59af37b..d3764ff 100644 --- a/lib/entities/client/client_entity.lua +++ b/lib/entities/client/client_entity.lua @@ -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 diff --git a/lib/entities/client/client_entity_actions.lua b/lib/entities/client/client_entity_actions.lua index b8ffd67..31b66b3 100644 --- a/lib/entities/client/client_entity_actions.lua +++ b/lib/entities/client/client_entity_actions.lua @@ -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 diff --git a/lib/entities/client/client_entity_actions_ext.lua b/lib/entities/client/client_entity_actions_ext.lua index 73dc7b5..4033e29 100644 --- a/lib/entities/client/client_entity_actions_ext.lua +++ b/lib/entities/client/client_entity_actions_ext.lua @@ -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 diff --git a/lib/init.lua b/lib/init.lua index 3d3df81..7aa6a34 100644 --- a/lib/init.lua +++ b/lib/init.lua @@ -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 diff --git a/lib/markers/client/markers.lua b/lib/markers/client/markers.lua index c83dc60..a747e20 100644 --- a/lib/markers/client/markers.lua +++ b/lib/markers/client/markers.lua @@ -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) diff --git a/lib/markers/server/server.lua b/lib/markers/server/server.lua index c009c7d..62719dc 100644 --- a/lib/markers/server/server.lua +++ b/lib/markers/server/server.lua @@ -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 diff --git a/lib/particles/client/particles.lua b/lib/particles/client/particles.lua index 28da84b..d425163 100644 --- a/lib/particles/client/particles.lua +++ b/lib/particles/client/particles.lua @@ -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) diff --git a/lib/particles/server/particles.lua b/lib/particles/server/particles.lua new file mode 100644 index 0000000..f71ab68 --- /dev/null +++ b/lib/particles/server/particles.lua @@ -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 \ No newline at end of file diff --git a/lib/scaleform/client/scaleform.lua b/lib/scaleform/client/scaleform.lua index aeeb2fe..f59e659 100644 --- a/lib/scaleform/client/scaleform.lua +++ b/lib/scaleform/client/scaleform.lua @@ -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 \ No newline at end of file +return Scaleform diff --git a/lib/utility/client/utility.lua b/lib/utility/client/utility.lua index d9a87bd..3f410c3 100644 --- a/lib/utility/client/utility.lua +++ b/lib/utility/client/utility.lua @@ -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 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 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 diff --git a/lib/utility/shared/callbacks.lua b/lib/utility/shared/callbacks.lua index 97cab1e..196c86b 100644 --- a/lib/utility/shared/callbacks.lua +++ b/lib/utility/shared/callbacks.lua @@ -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 diff --git a/lib/utility/shared/ids.lua b/lib/utility/shared/ids.lua index f0ae840..e7cdba8 100644 --- a/lib/utility/shared/ids.lua +++ b/lib/utility/shared/ids.lua @@ -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 diff --git a/modules/accessibility/client.lua b/modules/accessibility/client.lua index a284ca6..5aa0851 100644 --- a/modules/accessibility/client.lua +++ b/modules/accessibility/client.lua @@ -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 \ No newline at end of file +end + +return Accessibility \ No newline at end of file diff --git a/modules/clothing/_default/client.lua b/modules/clothing/_default/client.lua index bd35793..47b89d4 100644 --- a/modules/clothing/_default/client.lua +++ b/modules/clothing/_default/client.lua @@ -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) \ No newline at end of file +end) + +return Clothing \ No newline at end of file diff --git a/modules/clothing/_default/server.lua b/modules/clothing/_default/server.lua index 8689800..d02f61f 100644 --- a/modules/clothing/_default/server.lua +++ b/modules/clothing/_default/server.lua @@ -29,4 +29,6 @@ end) RegisterNetEvent('community_bridge:client:ReloadSkin', function() Clothing.ReloadSkin() -end) \ No newline at end of file +end) + +return Clothing \ No newline at end of file diff --git a/modules/dialogue/_default/client/client.lua b/modules/dialogue/_default/client/client.lua index 97ce769..1f91e0e 100644 --- a/modules/dialogue/_default/client/client.lua +++ b/modules/dialogue/_default/client/client.lua @@ -161,4 +161,6 @@ if BridgeSharedConfig.DebugLevel >= 1 then end end) end) -end \ No newline at end of file +end + +return Dialogue \ No newline at end of file diff --git a/modules/dispatch/_default/client/client.lua b/modules/dispatch/_default/client/client.lua index eeffe67..16f4c99 100644 --- a/modules/dispatch/_default/client/client.lua +++ b/modules/dispatch/_default/client/client.lua @@ -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) \ No newline at end of file +end) + +return Dispatch \ No newline at end of file diff --git a/modules/dispatch/_default/server/server.lua b/modules/dispatch/_default/server/server.lua index 4296918..31d76e4 100644 --- a/modules/dispatch/_default/server/server.lua +++ b/modules/dispatch/_default/server/server.lua @@ -8,4 +8,6 @@ RegisterNetEvent("community_bridge:Server:DispatchAlert", function(data) TriggerClientEvent('community_bridge:Client:DispatchAlert', src, data) end end -end) \ No newline at end of file +end) + +return Dispatch \ No newline at end of file diff --git a/modules/dispatch/bub_mdt/client/client.lua b/modules/dispatch/bub_mdt/client/client.lua index 999ff62..f5850f2 100644 --- a/modules/dispatch/bub_mdt/client/client.lua +++ b/modules/dispatch/bub_mdt/client/client.lua @@ -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 \ No newline at end of file +end + +return Dispatch \ No newline at end of file diff --git a/modules/dispatch/bub_mdt/server/server.lua b/modules/dispatch/bub_mdt/server/server.lua index 13c866f..60cd14c 100644 --- a/modules/dispatch/bub_mdt/server/server.lua +++ b/modules/dispatch/bub_mdt/server/server.lua @@ -1,2 +1,4 @@ if GetResourceState('bub-mdt') ~= 'started' then return end -Dispatch = Dispatch or {} \ No newline at end of file +Dispatch = Dispatch or {} + +return Dispatch \ No newline at end of file diff --git a/modules/dispatch/cd_dispatch/client/client.lua b/modules/dispatch/cd_dispatch/client/client.lua index b9e0aa2..c37ff1e 100644 --- a/modules/dispatch/cd_dispatch/client/client.lua +++ b/modules/dispatch/cd_dispatch/client/client.lua @@ -21,4 +21,6 @@ Dispatch.SendAlert = function(data) radius = 0, } }) -end \ No newline at end of file +end + +return Dispatch \ No newline at end of file diff --git a/modules/dispatch/cd_dispatch/server/server.lua b/modules/dispatch/cd_dispatch/server/server.lua index 364e335..20f62c3 100644 --- a/modules/dispatch/cd_dispatch/server/server.lua +++ b/modules/dispatch/cd_dispatch/server/server.lua @@ -1,2 +1,4 @@ if GetResourceState('cd_dispatch') ~= 'started' then return end Dispatch = Dispatch or {} + +return Dispatch \ No newline at end of file diff --git a/modules/dispatch/lb-tablet/client/client.lua b/modules/dispatch/lb-tablet/client/client.lua index 83aabee..28483ab 100644 --- a/modules/dispatch/lb-tablet/client/client.lua +++ b/modules/dispatch/lb-tablet/client/client.lua @@ -37,4 +37,6 @@ Dispatch.SendAlert = function(data) job = data.jobs, } TriggerServerEvent("community_bridge:server:dispatch:sendAlert", alertData) -end \ No newline at end of file +end + +return Dispatch \ No newline at end of file diff --git a/modules/dispatch/lb-tablet/server/server.lua b/modules/dispatch/lb-tablet/server/server.lua index ec8befc..b4806d8 100644 --- a/modules/dispatch/lb-tablet/server/server.lua +++ b/modules/dispatch/lb-tablet/server/server.lua @@ -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) \ No newline at end of file +end) + +return Dispatch \ No newline at end of file diff --git a/modules/dispatch/linden_outlawalert/client/client.lua b/modules/dispatch/linden_outlawalert/client/client.lua index 3b936e0..eed7de0 100644 --- a/modules/dispatch/linden_outlawalert/client/client.lua +++ b/modules/dispatch/linden_outlawalert/client/client.lua @@ -15,4 +15,6 @@ Dispatch.SendAlert = function(data) caller = 'Anonymous', coords = data.coords or GetEntityCoords(cache.ped) }) -end \ No newline at end of file +end + +return Dispatch \ No newline at end of file diff --git a/modules/dispatch/linden_outlawalert/server/server.lua b/modules/dispatch/linden_outlawalert/server/server.lua index 1824ed4..4e58535 100644 --- a/modules/dispatch/linden_outlawalert/server/server.lua +++ b/modules/dispatch/linden_outlawalert/server/server.lua @@ -1,2 +1,4 @@ if GetResourceState('linden_outlawalert') ~= 'started' then return end -Dispatch = Dispatch or {} \ No newline at end of file +Dispatch = Dispatch or {} + +return Dispatch \ No newline at end of file diff --git a/modules/dispatch/ps-dispatch/client/client.lua b/modules/dispatch/ps-dispatch/client/client.lua index cbf06a3..a4eb7d8 100644 --- a/modules/dispatch/ps-dispatch/client/client.lua +++ b/modules/dispatch/ps-dispatch/client/client.lua @@ -27,4 +27,6 @@ Dispatch.SendAlert = function(data) jobs = data.jobs } exports["ps-dispatch"]:CustomAlert(alertData) -end \ No newline at end of file +end + +return Dispatch \ No newline at end of file diff --git a/modules/dispatch/ps-dispatch/server/server.lua b/modules/dispatch/ps-dispatch/server/server.lua index b75b55e..dde11f4 100644 --- a/modules/dispatch/ps-dispatch/server/server.lua +++ b/modules/dispatch/ps-dispatch/server/server.lua @@ -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 \ No newline at end of file diff --git a/modules/dispatch/qs_dispatch/client/client.lua b/modules/dispatch/qs_dispatch/client/client.lua index 3656cc7..f68f798 100644 --- a/modules/dispatch/qs_dispatch/client/client.lua +++ b/modules/dispatch/qs_dispatch/client/client.lua @@ -35,4 +35,6 @@ Dispatch.SendAlert = function(data) customData.image = image or customData.image TriggerServerEvent('qs-dispatch:server:CreateDispatchCall', customData) end) -end \ No newline at end of file +end + +return Dispatch \ No newline at end of file diff --git a/modules/dispatch/qs_dispatch/server/server.lua b/modules/dispatch/qs_dispatch/server/server.lua index 238df5e..46fa79a 100644 --- a/modules/dispatch/qs_dispatch/server/server.lua +++ b/modules/dispatch/qs_dispatch/server/server.lua @@ -1,2 +1,4 @@ if GetResourceState('qs-dispatch') ~= 'started' then return end -Dispatch = Dispatch or {} \ No newline at end of file +Dispatch = Dispatch or {} + +return Dispatch \ No newline at end of file diff --git a/modules/dispatch/redutzu-mdt/client/client.lua b/modules/dispatch/redutzu-mdt/client/client.lua index 2314a7d..895de7b 100644 --- a/modules/dispatch/redutzu-mdt/client/client.lua +++ b/modules/dispatch/redutzu-mdt/client/client.lua @@ -11,4 +11,6 @@ Dispatch.SendAlert = function(data) coords = data.coords, } TriggerServerEvent("community_bridge:server:dispatch:sendAlert", alertData) -end \ No newline at end of file +end + +return Dispatch \ No newline at end of file diff --git a/modules/dispatch/redutzu-mdt/server/server.lua b/modules/dispatch/redutzu-mdt/server/server.lua index e07d799..ea72477 100644 --- a/modules/dispatch/redutzu-mdt/server/server.lua +++ b/modules/dispatch/redutzu-mdt/server/server.lua @@ -9,4 +9,6 @@ RegisterNetEvent("community_bridge:server:dispatch:sendAlert", function(data) duration = data.time, coords = data.coords }) -end) \ No newline at end of file +end) + +return Dispatch \ No newline at end of file diff --git a/modules/dispatch/tk_dispatch/client/client.lua b/modules/dispatch/tk_dispatch/client/client.lua index 7d112fb..edfa708 100644 --- a/modules/dispatch/tk_dispatch/client/client.lua +++ b/modules/dispatch/tk_dispatch/client/client.lua @@ -17,4 +17,6 @@ Dispatch.SendAlert = function(data) }, jobs = data.jobs or {'police'}, }) -end \ No newline at end of file +end + +return Dispatch \ No newline at end of file diff --git a/modules/dispatch/tk_dispatch/server/server.lua b/modules/dispatch/tk_dispatch/server/server.lua index 43020fb..688895d 100644 --- a/modules/dispatch/tk_dispatch/server/server.lua +++ b/modules/dispatch/tk_dispatch/server/server.lua @@ -1,2 +1,4 @@ if GetResourceState('tk_dispatch') ~= 'started' then return end -Dispatch = Dispatch or {} \ No newline at end of file +Dispatch = Dispatch or {} + +return Dispatch \ No newline at end of file diff --git a/modules/doorlock/doors_creator/client.lua b/modules/doorlock/doors_creator/client.lua index 88b9745..26a691b 100644 --- a/modules/doorlock/doors_creator/client.lua +++ b/modules/doorlock/doors_creator/client.lua @@ -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 \ No newline at end of file +end + +return Doorlock \ No newline at end of file diff --git a/modules/doorlock/doors_creator/server.lua b/modules/doorlock/doors_creator/server.lua index b9ae565..ed9a0b1 100644 --- a/modules/doorlock/doors_creator/server.lua +++ b/modules/doorlock/doors_creator/server.lua @@ -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 \ No newline at end of file +end + +return Doorlock \ No newline at end of file diff --git a/modules/doorlock/ox_doorlock/client.lua b/modules/doorlock/ox_doorlock/client.lua index 3c25dd1..04a2d31 100644 --- a/modules/doorlock/ox_doorlock/client.lua +++ b/modules/doorlock/ox_doorlock/client.lua @@ -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 \ No newline at end of file diff --git a/modules/doorlock/ox_doorlock/server.lua b/modules/doorlock/ox_doorlock/server.lua index a0324ba..132efa1 100644 --- a/modules/doorlock/ox_doorlock/server.lua +++ b/modules/doorlock/ox_doorlock/server.lua @@ -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 \ No newline at end of file +end + +return Doorlock \ No newline at end of file diff --git a/modules/doorlock/qb-doorlock/client.lua b/modules/doorlock/qb-doorlock/client.lua index 11929e5..b5275b9 100644 --- a/modules/doorlock/qb-doorlock/client.lua +++ b/modules/doorlock/qb-doorlock/client.lua @@ -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 \ No newline at end of file +end + +return Doorlock \ No newline at end of file diff --git a/modules/doorlock/qb-doorlock/server.lua b/modules/doorlock/qb-doorlock/server.lua index 21648e3..5fd74c9 100644 --- a/modules/doorlock/qb-doorlock/server.lua +++ b/modules/doorlock/qb-doorlock/server.lua @@ -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 \ No newline at end of file +end + +return Doorlock \ No newline at end of file diff --git a/modules/doorlock/rcore_doorlock/client.lua b/modules/doorlock/rcore_doorlock/client.lua index efb90be..11860b1 100644 --- a/modules/doorlock/rcore_doorlock/client.lua +++ b/modules/doorlock/rcore_doorlock/client.lua @@ -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 \ No newline at end of file +end + +return Doorlock \ No newline at end of file diff --git a/modules/doorlock/rcore_doorlock/server.lua b/modules/doorlock/rcore_doorlock/server.lua index 9535aab..016f952 100644 --- a/modules/doorlock/rcore_doorlock/server.lua +++ b/modules/doorlock/rcore_doorlock/server.lua @@ -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 \ No newline at end of file +end +return Doorlock \ No newline at end of file diff --git a/modules/framework/_default/server.lua b/modules/framework/_default/server.lua new file mode 100644 index 0000000..5d895be --- /dev/null +++ b/modules/framework/_default/server.lua @@ -0,0 +1,3 @@ +Framework = Framework or {} + +return Framework \ No newline at end of file diff --git a/modules/framework/es_extended/client.lua b/modules/framework/es_extended/client.lua index ea14754..0704ac1 100644 --- a/modules/framework/es_extended/client.lua +++ b/modules/framework/es_extended/client.lua @@ -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) \ No newline at end of file + TriggerEvent('community_bridge:Client:OnPlayerJobUpdate', data.name, data.label, data.grade_label, data.grade) +end) + +return Framework \ No newline at end of file diff --git a/modules/framework/es_extended/server.lua b/modules/framework/es_extended/server.lua index 4a1cfea..83fee38 100644 --- a/modules/framework/es_extended/server.lua +++ b/modules/framework/es_extended/server.lua @@ -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 \ No newline at end of file +end + +return Framework \ No newline at end of file diff --git a/modules/framework/qb-core/client.lua b/modules/framework/qb-core/client.lua index f1ab2e9..1daa075 100644 --- a/modules/framework/qb-core/client.lua +++ b/modules/framework/qb-core/client.lua @@ -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 \ No newline at end of file diff --git a/modules/framework/qb-core/server.lua b/modules/framework/qb-core/server.lua index 1d81bc3..1a302da 100644 --- a/modules/framework/qb-core/server.lua +++ b/modules/framework/qb-core/server.lua @@ -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 \ No newline at end of file diff --git a/modules/framework/qbx_core/client.lua b/modules/framework/qbx_core/client.lua index da1b25c..bf1e9af 100644 --- a/modules/framework/qbx_core/client.lua +++ b/modules/framework/qbx_core/client.lua @@ -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) \ No newline at end of file + TriggerEvent('community_bridge:Client:OnPlayerJobUpdate', data.name, data.label, data.grade.name, data.grade.level) +end) + +return Framework \ No newline at end of file diff --git a/modules/framework/qbx_core/server.lua b/modules/framework/qbx_core/server.lua index aa614a6..b981b50 100644 --- a/modules/framework/qbx_core/server.lua +++ b/modules/framework/qbx_core/server.lua @@ -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) \ No newline at end of file +end) + +return Framework \ No newline at end of file diff --git a/modules/fuel/_default/client.lua b/modules/fuel/_default/client.lua index 681b2e4..731ace5 100644 --- a/modules/fuel/_default/client.lua +++ b/modules/fuel/_default/client.lua @@ -21,4 +21,6 @@ end Fuel.SetFuel = function(vehicle, fuel) if not DoesEntityExist(vehicle) then return end return SetVehicleFuelLevel(vehicle, fuel) -end \ No newline at end of file +end + +return Fuel \ No newline at end of file diff --git a/modules/fuel/bigDaddy-Fuel/client.lua b/modules/fuel/bigDaddy-Fuel/client.lua index daa86a6..00f8f75 100644 --- a/modules/fuel/bigDaddy-Fuel/client.lua +++ b/modules/fuel/bigDaddy-Fuel/client.lua @@ -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 \ No newline at end of file diff --git a/modules/fuel/cdn-fuel/client.lua b/modules/fuel/cdn-fuel/client.lua index 093987f..1dba7dd 100644 --- a/modules/fuel/cdn-fuel/client.lua +++ b/modules/fuel/cdn-fuel/client.lua @@ -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 \ No newline at end of file +end + +return Fuel \ No newline at end of file diff --git a/modules/fuel/esx-sna-fuel/client.lua b/modules/fuel/esx-sna-fuel/client.lua index 3309621..cc15388 100644 --- a/modules/fuel/esx-sna-fuel/client.lua +++ b/modules/fuel/esx-sna-fuel/client.lua @@ -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 \ No newline at end of file +end + +return Fuel \ No newline at end of file diff --git a/modules/fuel/lc_fuel/client.lua b/modules/fuel/lc_fuel/client.lua index ee85467..551aef2 100644 --- a/modules/fuel/lc_fuel/client.lua +++ b/modules/fuel/lc_fuel/client.lua @@ -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 \ No newline at end of file +end + +return Fuel \ No newline at end of file diff --git a/modules/fuel/legacyfuel/client.lua b/modules/fuel/legacyfuel/client.lua index 6c64d4f..4903687 100644 --- a/modules/fuel/legacyfuel/client.lua +++ b/modules/fuel/legacyfuel/client.lua @@ -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 \ No newline at end of file +end + +return Fuel \ No newline at end of file diff --git a/modules/fuel/okokGasStation/client.lua b/modules/fuel/okokGasStation/client.lua index 02c5ed0..42785fe 100644 --- a/modules/fuel/okokGasStation/client.lua +++ b/modules/fuel/okokGasStation/client.lua @@ -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 \ No newline at end of file +end + +return Fuel \ No newline at end of file diff --git a/modules/fuel/ox_fuel/client.lua b/modules/fuel/ox_fuel/client.lua index 16d7772..1001582 100644 --- a/modules/fuel/ox_fuel/client.lua +++ b/modules/fuel/ox_fuel/client.lua @@ -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 \ No newline at end of file +end + +return Fuel \ No newline at end of file diff --git a/modules/fuel/ps-fuel/client.lua b/modules/fuel/ps-fuel/client.lua index 8f28f7e..ee84b1a 100644 --- a/modules/fuel/ps-fuel/client.lua +++ b/modules/fuel/ps-fuel/client.lua @@ -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 \ No newline at end of file +end + +return Fuel \ No newline at end of file diff --git a/modules/fuel/qs-fuelstations/client.lua b/modules/fuel/qs-fuelstations/client.lua index 8b3827f..ab5c571 100644 --- a/modules/fuel/qs-fuelstations/client.lua +++ b/modules/fuel/qs-fuelstations/client.lua @@ -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 \ No newline at end of file +end + +return Fuel \ No newline at end of file diff --git a/modules/fuel/renewed-Fuel/client.lua b/modules/fuel/renewed-Fuel/client.lua index 262740e..8ed1f66 100644 --- a/modules/fuel/renewed-Fuel/client.lua +++ b/modules/fuel/renewed-Fuel/client.lua @@ -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 \ No newline at end of file +end + +return Fuel \ No newline at end of file diff --git a/modules/fuel/ti_fuel/client.lua b/modules/fuel/ti_fuel/client.lua index d0fdcef..54471e2 100644 --- a/modules/fuel/ti_fuel/client.lua +++ b/modules/fuel/ti_fuel/client.lua @@ -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 \ No newline at end of file +end + +return Fuel \ No newline at end of file diff --git a/modules/fuel/x-fuel/client.lua b/modules/fuel/x-fuel/client.lua index 1011e3b..b00f604 100644 --- a/modules/fuel/x-fuel/client.lua +++ b/modules/fuel/x-fuel/client.lua @@ -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 \ No newline at end of file +end + +return Fuel \ No newline at end of file diff --git a/modules/helptext/_default/client.lua b/modules/helptext/_default/client.lua index c1e4ea1..bfab021 100644 --- a/modules/helptext/_default/client.lua +++ b/modules/helptext/_default/client.lua @@ -22,4 +22,6 @@ end) RegisterNetEvent('community_bridge:Client:HideHelpText', function() HelpText.HideHelpText() -end) \ No newline at end of file +end) + +return HelpText \ No newline at end of file diff --git a/modules/helptext/_default/server.lua b/modules/helptext/_default/server.lua index 448e815..c670c93 100644 --- a/modules/helptext/_default/server.lua +++ b/modules/helptext/_default/server.lua @@ -14,4 +14,6 @@ end ---@diagnostic disable-next-line: duplicate-set-field HelpText.HideHelpText = function(src) TriggerClientEvent('community_bridge:Client:HideHelpText', src) -end \ No newline at end of file +end + +return HelpText \ No newline at end of file diff --git a/modules/helptext/cd_drawtextui/client.lua b/modules/helptext/cd_drawtextui/client.lua index 4ae1271..9d55f2e 100644 --- a/modules/helptext/cd_drawtextui/client.lua +++ b/modules/helptext/cd_drawtextui/client.lua @@ -18,4 +18,6 @@ end ---@diagnostic disable-next-line: duplicate-set-field HelpText.HideHelpText = function() return TriggerEvent('cd_drawtextui:HideUI') -end \ No newline at end of file +end + +return HelpText \ No newline at end of file diff --git a/modules/helptext/jg-textui/client.lua b/modules/helptext/jg-textui/client.lua index bd2d9d6..cc6d4f8 100644 --- a/modules/helptext/jg-textui/client.lua +++ b/modules/helptext/jg-textui/client.lua @@ -17,4 +17,6 @@ end ---@diagnostic disable-next-line: duplicate-set-field HelpText.HideHelpText = function() return exports['jg-textui']:HideText() -end \ No newline at end of file +end + +return HelpText \ No newline at end of file diff --git a/modules/helptext/lab-HintUI/client.lua b/modules/helptext/lab-HintUI/client.lua index c6e42bc..0ddccb9 100644 --- a/modules/helptext/lab-HintUI/client.lua +++ b/modules/helptext/lab-HintUI/client.lua @@ -17,4 +17,6 @@ end ---@diagnostic disable-next-line: duplicate-set-field HelpText.HideHelpText = function() return exports['lab-HintUI']:Hide() -end \ No newline at end of file +end + +return HelpText \ No newline at end of file diff --git a/modules/helptext/okokTextUI/client.lua b/modules/helptext/okokTextUI/client.lua index f2614d2..fec30be 100644 --- a/modules/helptext/okokTextUI/client.lua +++ b/modules/helptext/okokTextUI/client.lua @@ -17,4 +17,6 @@ end ---@diagnostic disable-next-line: duplicate-set-field HelpText.HideHelpText = function() return exports['okokTextUI']:Close() -end \ No newline at end of file +end + +return HelpText \ No newline at end of file diff --git a/modules/helptext/ox_lib/client.lua b/modules/helptext/ox_lib/client.lua index 171fe98..4fe01d3 100644 --- a/modules/helptext/ox_lib/client.lua +++ b/modules/helptext/ox_lib/client.lua @@ -18,4 +18,6 @@ end ---@diagnostic disable-next-line: duplicate-set-field HelpText.HideHelpText = function() return exports.ox_lib:hideTextUI() -end \ No newline at end of file +end + +return HelpText \ No newline at end of file diff --git a/modules/housing/_default/client.lua b/modules/housing/_default/client.lua index 4e660db..ae77287 100644 --- a/modules/housing/_default/client.lua +++ b/modules/housing/_default/client.lua @@ -1 +1,3 @@ -Housing = Housing or {} \ No newline at end of file +Housing = Housing or {} + +return Housing \ No newline at end of file diff --git a/modules/housing/_default/server.lua b/modules/housing/_default/server.lua index dcfb42b..4566d0a 100644 --- a/modules/housing/_default/server.lua +++ b/modules/housing/_default/server.lua @@ -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) \ No newline at end of file +end) + +return Housing \ No newline at end of file diff --git a/modules/housing/bcs-housing/client.lua b/modules/housing/bcs-housing/client.lua index d5d2396..398b713 100644 --- a/modules/housing/bcs-housing/client.lua +++ b/modules/housing/bcs-housing/client.lua @@ -8,4 +8,6 @@ end) RegisterNetEvent("Housing:client:DeleteFurnitures", function() TriggerServerEvent('community_bridge:Server:_OnPlayerInside', false) -end) \ No newline at end of file +end) + +return Housing \ No newline at end of file diff --git a/modules/housing/bcs-housing/server.lua b/modules/housing/bcs-housing/server.lua index f4263c0..7a8f747 100644 --- a/modules/housing/bcs-housing/server.lua +++ b/modules/housing/bcs-housing/server.lua @@ -1,3 +1,5 @@ if GetResourceState('bcs-housing') ~= 'started' then return end -Housing = Housing or {} \ No newline at end of file +Housing = Housing or {} + +return Housing \ No newline at end of file diff --git a/modules/housing/esx_property/client.lua b/modules/housing/esx_property/client.lua index 3d3238f..dc61c00 100644 --- a/modules/housing/esx_property/client.lua +++ b/modules/housing/esx_property/client.lua @@ -1,3 +1,5 @@ if GetResourceState('esx_property') ~= 'started' then return end -Housing = Housing or {} \ No newline at end of file +Housing = Housing or {} + +return Housing \ No newline at end of file diff --git a/modules/housing/esx_property/server.lua b/modules/housing/esx_property/server.lua index 5243ae7..118fa7a 100644 --- a/modules/housing/esx_property/server.lua +++ b/modules/housing/esx_property/server.lua @@ -10,4 +10,6 @@ end) RegisterNetEvent('esx_property:leave', function(insideId) local src = source TriggerEvent('community_bridge:Server:_OnPlayerInside', src, insideId) -end) \ No newline at end of file +end) + +return Housing \ No newline at end of file diff --git a/modules/housing/ps-housing/client.lua b/modules/housing/ps-housing/client.lua index a40ae1c..b7f5d8e 100644 --- a/modules/housing/ps-housing/client.lua +++ b/modules/housing/ps-housing/client.lua @@ -1,3 +1,5 @@ if GetResourceState('ps-housing') ~= 'started' then return end -Housing = Housing or {} \ No newline at end of file +Housing = Housing or {} + +return Housing \ No newline at end of file diff --git a/modules/housing/ps-housing/server.lua b/modules/housing/ps-housing/server.lua index d364c2e..52a2e48 100644 --- a/modules/housing/ps-housing/server.lua +++ b/modules/housing/ps-housing/server.lua @@ -10,4 +10,6 @@ end) RegisterNetEvent('ps-housing:server:leaveProperty', function(insideId) local src = source TriggerEvent('community_bridge:Server:_OnPlayerInside', src, insideId) -end) \ No newline at end of file +end) + +return Housing \ No newline at end of file diff --git a/modules/housing/qb-appartments/client.lua b/modules/housing/qb-appartments/client.lua index 5d6b7f8..2ce29c9 100644 --- a/modules/housing/qb-appartments/client.lua +++ b/modules/housing/qb-appartments/client.lua @@ -1,3 +1,5 @@ if GetResourceState('qb-appartments') ~= 'started' then return end -Housing = Housing or {} \ No newline at end of file +Housing = Housing or {} + +return Housing \ No newline at end of file diff --git a/modules/housing/qb-appartments/server.lua b/modules/housing/qb-appartments/server.lua index 6c5f6c5..cfd0982 100644 --- a/modules/housing/qb-appartments/server.lua +++ b/modules/housing/qb-appartments/server.lua @@ -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) \ No newline at end of file +end) + +return Housing \ No newline at end of file diff --git a/modules/housing/qb-houses/client.lua b/modules/housing/qb-houses/client.lua index e1e61cf..4208627 100644 --- a/modules/housing/qb-houses/client.lua +++ b/modules/housing/qb-houses/client.lua @@ -1,3 +1,5 @@ if GetResourceState('qb-houses') ~= 'started' then return end -Housing = Housing or {} \ No newline at end of file +Housing = Housing or {} + +return Housing \ No newline at end of file diff --git a/modules/housing/qb-houses/server.lua b/modules/housing/qb-houses/server.lua index 7fac010..a06d537 100644 --- a/modules/housing/qb-houses/server.lua +++ b/modules/housing/qb-houses/server.lua @@ -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) \ No newline at end of file +end) + +return Housing \ No newline at end of file diff --git a/modules/input/client.lua b/modules/input/client.lua index a5b86d1..1650cce 100644 --- a/modules/input/client.lua +++ b/modules/input/client.lua @@ -107,6 +107,9 @@ function Input.Open(title, data, isQBFormat, submitText) return OpenInput(title, data, isQBFormat, submitText) end +return Input + + --[[ -- Unit tests local thisIsQB = { diff --git a/modules/inventory/_default/client.lua b/modules/inventory/_default/client.lua index 21991ad..7f460c5 100644 --- a/modules/inventory/_default/client.lua +++ b/modules/inventory/_default/client.lua @@ -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 \ No newline at end of file +end + +return Inventory \ No newline at end of file diff --git a/modules/inventory/_default/server.lua b/modules/inventory/_default/server.lua index 2d42c54..ebde24c 100644 --- a/modules/inventory/_default/server.lua +++ b/modules/inventory/_default/server.lua @@ -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 \ No newline at end of file +end + +return Inventory \ No newline at end of file diff --git a/modules/inventory/codem-inventory/client.lua b/modules/inventory/codem-inventory/client.lua index 11be4c5..ffe00a5 100644 --- a/modules/inventory/codem-inventory/client.lua +++ b/modules/inventory/codem-inventory/client.lua @@ -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 \ No newline at end of file +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 \ No newline at end of file diff --git a/modules/inventory/codem-inventory/server.lua b/modules/inventory/codem-inventory/server.lua index cbf6847..0718c83 100644 --- a/modules/inventory/codem-inventory/server.lua +++ b/modules/inventory/codem-inventory/server.lua @@ -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 \ No newline at end of file diff --git a/modules/inventory/core_inventory/client.lua b/modules/inventory/core_inventory/client.lua index f59f174..95a5d27 100644 --- a/modules/inventory/core_inventory/client.lua +++ b/modules/inventory/core_inventory/client.lua @@ -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 \ No newline at end of file +return Inventory \ No newline at end of file diff --git a/modules/inventory/core_inventory/server.lua b/modules/inventory/core_inventory/server.lua index 65792dc..43f1a25 100644 --- a/modules/inventory/core_inventory/server.lua +++ b/modules/inventory/core_inventory/server.lua @@ -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) \ No newline at end of file +end) + +return Inventory \ No newline at end of file diff --git a/modules/inventory/jpr-inventory/client.lua b/modules/inventory/jpr-inventory/client.lua index f7deebc..34fc32d 100644 --- a/modules/inventory/jpr-inventory/client.lua +++ b/modules/inventory/jpr-inventory/client.lua @@ -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 \ No newline at end of file +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 \ No newline at end of file diff --git a/modules/inventory/jpr-inventory/server.lua b/modules/inventory/jpr-inventory/server.lua index 9c7cf01..81f4dc0 100644 --- a/modules/inventory/jpr-inventory/server.lua +++ b/modules/inventory/jpr-inventory/server.lua @@ -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 \ No newline at end of file +end + +return Inventory \ No newline at end of file diff --git a/modules/inventory/origen_inventory/client.lua b/modules/inventory/origen_inventory/client.lua index a7f8359..fe44011 100644 --- a/modules/inventory/origen_inventory/client.lua +++ b/modules/inventory/origen_inventory/client.lua @@ -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 \ No newline at end of file diff --git a/modules/inventory/origen_inventory/server.lua b/modules/inventory/origen_inventory/server.lua index f567fb9..19ec807 100644 --- a/modules/inventory/origen_inventory/server.lua +++ b/modules/inventory/origen_inventory/server.lua @@ -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 \ No newline at end of file + 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 \ No newline at end of file diff --git a/modules/inventory/ox_inventory/client.lua b/modules/inventory/ox_inventory/client.lua index 766c571..17bbcd6 100644 --- a/modules/inventory/ox_inventory/client.lua +++ b/modules/inventory/ox_inventory/client.lua @@ -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 \ No newline at end of file diff --git a/modules/inventory/ox_inventory/server.lua b/modules/inventory/ox_inventory/server.lua index e2eb791..6e3ec45 100644 --- a/modules/inventory/ox_inventory/server.lua +++ b/modules/inventory/ox_inventory/server.lua @@ -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 \ No newline at end of file +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 \ No newline at end of file diff --git a/modules/inventory/ps-inventory/client.lua b/modules/inventory/ps-inventory/client.lua index 6d37dd6..fa55848 100644 --- a/modules/inventory/ps-inventory/client.lua +++ b/modules/inventory/ps-inventory/client.lua @@ -1,24 +1,33 @@ +---@diagnostic disable: duplicate-set-field if GetResourceState('ps-inventory') ~= 'started' then return end - local ps = exports['ps-inventory'] Inventory = Inventory or {} -RegisterNetEvent('community_bridge:client:ps-inventory:openStash', function(id, data) - if source ~= 65535 then return end - TriggerEvent('ps-inventory:client:SetCurrentStash', id) - TriggerServerEvent('ps-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 ps: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) @@ -28,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 \ No newline at end of file +RegisterNetEvent('community_bridge:client:ps-inventory:openStash', function(id, data) + if source ~= 65535 then return end + TriggerEvent('ps-inventory:client:SetCurrentStash', id) + TriggerServerEvent('ps-inventory:server:OpenInventory', 'stash', id, { maxweight = data.weight, slots = data.slots }) +end) + +return Inventory \ No newline at end of file diff --git a/modules/inventory/ps-inventory/server.lua b/modules/inventory/ps-inventory/server.lua index ff95702..2dc105c 100644 --- a/modules/inventory/ps-inventory/server.lua +++ b/modules/inventory/ps-inventory/server.lua @@ -1,26 +1,90 @@ +---@diagnostic disable: duplicate-set-field if GetResourceState('ps-inventory') ~= 'started' then return end - local sloth = exports['ps-inventory'] +local registeredShops = {} Inventory = Inventory or {} - ----comment ----@param id string||number ----@param label string ----@param slots number ----@param weight number ----@param owner string ----@param groups table ----@param coords table +---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.RegisterStash = function(id, label, slots, weight, owner, groups, coords) - return true +Inventory.AddItem = function(src, item, count, slot, metadata) + TriggerClientEvent('ps-inventory:client:ItemBox', src, QBCore.Shared.Items[item], 'add', count) + TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "add", item = item, count = count, slot = slot, metadata = metadata}) + return sloth:AddItem(src, item, count, slot, metadata, 'community_bridge') end ----comment +---This will remove an item, and return true or false based on success ---@param src number ----@param id string||number +---@param item string +---@param count number +---@param slot number +---@param metadata table +---@return boolean +Inventory.RemoveItem = function(src, item, count, slot, metadata) + TriggerClientEvent('ps-inventory:client:ItemBox', src, QBCore.Shared.Items[item], 'remove', count) + TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "remove", item = item, count = count, slot = slot, metadata = metadata}) + return sloth:RemoveItem(src, item, count, slot, 'community_bridge') +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 = QBCore.Shared.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 = Inventory.GetImagePath(item), + } +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 = sloth:GetItemBySlot(src, slot) + if not slotData then return {} end + return { + name = slotData.name, + label = slotData.label or slotData.name, + weight = slotData.weight, + slot = slot, + count = slotData.amount, + metadata = slotData.info, + stack = slotData.unique, + description = slotData.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) + local itemData = Inventory.GetItemBySlot(src, slot) + if not itemData then return end + if itemData.count > 1 then return print("Items with more than 1 count cannot be set with metadata plase adjust item to unique in the qb shared item name : "..item) end + Inventory.RemoveItem(src, item, 1, slot) + return Inventory.AddItem(src, item, 1, 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 @@ -32,17 +96,20 @@ Inventory.OpenStash = function(src, id, label, slots, weight, owner, groups, coo TriggerClientEvent('community_bridge:client:ps-inventory:openStash', src, id, { label = label, maxweight = weight, slots = slots, }) end ----comment ----@param item string ----@return string -Inventory.GetImagePath = function(item) - item = Inventory.StripPNG(item) - local file = LoadResourceFile("ps-inventory", string.format("html/images/%s.png", item)) - local imagePath = file and string.format("nui://ps-inventory/html/images/%s.png", item) - return imagePath or "https://avatars.githubusercontent.com/u/47620135" +---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 ----comment +---This will return a boolean if the player has the item. ---@param src number ---@param item string ---@return boolean @@ -50,43 +117,16 @@ Inventory.HasItem = function(src, item) return sloth:HasItem(src, item, 1) end ----comment ----@param src number ----@param slot number ----@return table -Inventory.GetItemBySlot = function(src, slot) - local slotData = sloth:GetItemBySlot(src, slot) - if not slotData then return {} end - return {name = slotData.name, label = slotData.name, weight = slotData.weight, slot = slot, count = slotData.amount, metadata = slotData.info, stack = slotData.unique, description = slotData.description} -end - ----comment +---This is to get if there is available space in the inventory, will return boolean. ---@param src number ---@param item string ----@param amount number ----@param slot number ----@param metadata table +---@param count number ---@return boolean -Inventory.AddItem = function(src, item, amount, slot, metadata) - TriggerClientEvent('ps-inventory:client:ItemBox', src, QBCore.Shared.Items[item], 'add', amount) - TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "add", item = item, count = amount, slot = slot, metadata = metadata}) - return sloth:AddItem(src, item, amount, slot, metadata, 'community_bridge') +Inventory.CanCarryItem = function(src, item, count) + return true end ----comment ----@param src number ----@param item string ----@param amount number ----@param slot number ----@param metadata table ----@return boolean -Inventory.RemoveItem = function(src, item, amount, slot, metadata) - TriggerClientEvent('ps-inventory:client:ItemBox', src, QBCore.Shared.Items[item], 'remove', amount) - TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "remove", item = item, count = amount, slot = slot, metadata = metadata}) - return sloth:RemoveItem(src, item, amount, slot, 'community_bridge') -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 @@ -98,16 +138,31 @@ 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 -local registeredShops = {} +---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("ps-inventory", string.format("html/images/%s.png", item)) + local imagePath = file and string.format("nui://ps-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) return sloth:OpenShop(src, 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(src, shopTitle, shopInventory, shopCoords, shopGroups) if not shopTitle or not shopInventory or not shopCoords then return end if registeredShops[shopTitle] then return true end @@ -120,6 +175,7 @@ Inventory.CreateShop = function(src, shopTitle, shopInventory, shopCoords, shopG sloth:CreateShop(repackedShopItems) registeredShops[shopTitle] = true - --Inventory.OpenShop(src, shopTitle) return true -end \ No newline at end of file +end + +return Inventory \ No newline at end of file diff --git a/modules/inventory/qb-inventory/client.lua b/modules/inventory/qb-inventory/client.lua index 0818f4f..6870be1 100644 --- a/modules/inventory/qb-inventory/client.lua +++ b/modules/inventory/qb-inventory/client.lua @@ -1,23 +1,33 @@ +---@diagnostic disable: duplicate-set-field if GetResourceState('qb-inventory') ~= 'started' then return end - local qb = exports['qb-inventory'] Inventory = Inventory or {} -RegisterNetEvent('community_bridge:client:qb-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.image or itemData.name) + } +end ----This will return a boolean if the player has the item in their inventory +---Will return boolean if the player has the item. ---@param item string ---@return boolean Inventory.HasItem = function(item) return qb:HasItem(item) end ----This will return a string of the image path for the item +---This will get the image path for this item, if not found will return placeholder. ---@param item string ---@return string Inventory.GetImagePath = function(item) @@ -27,17 +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.image or itemData.name) - } - return repackedTable -end +RegisterNetEvent('community_bridge:client:qb-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 \ No newline at end of file diff --git a/modules/inventory/qb-inventory/server.lua b/modules/inventory/qb-inventory/server.lua index ba70836..8df9850 100644 --- a/modules/inventory/qb-inventory/server.lua +++ b/modules/inventory/qb-inventory/server.lua @@ -1,49 +1,50 @@ +---@diagnostic disable: duplicate-set-field if GetResourceState('qb-inventory') ~= 'started' then return end - local qbInventory = exports['qb-inventory'] Inventory = Inventory or {} +local registeredShops = {} +local v1ShopData = {} + local function getInventoryNewVersion() - if tonumber(string.sub(GetResourceMetadata("qb-inventory", "version", 0), 1, 1)) >= 2 then - return true - else - return false - end + if tonumber(string.sub(GetResourceMetadata("qb-inventory", "version", 0), 1, 1)) >= 2 then return true end + return false end ----comment ----@param id 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 - ----comment +---This will add an item, and return true or false based on success ---@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:qb-inventory:openStash', src, id, { weight = weight, slots = slots }) +---@param item string +---@param count number +---@param slot number +---@param metadata table +---@return boolean +Inventory.AddItem = function(src, item, count, slot, metadata) + TriggerClientEvent('qb-inventory:client:ItemBox', src, QBCore.Shared.Items[item], 'add', count) + TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "add", item = item, count = count, slot = slot, metadata = metadata}) + return exports['qb-inventory']:AddItem(src, item, count, slot, metadata, 'community_bridge') 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('qb-inventory:client:ItemBox', src, QBCore.Shared.Items[item], 'remove', count) + TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "remove", item = item, count = count, slot = slot, metadata = metadata}) + return exports['qb-inventory']:RemoveItem(src, item, count, slot, 'community_bridge') +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 = Framework.Shared.Items[item] if not itemData then return {} end - local repackedTable = { + return { name = itemData.name, label = itemData.label, stack = itemData.unique, @@ -51,29 +52,11 @@ Inventory.GetItemInfo = function(item) description = itemData.description, image = Inventory.GetImagePath(itemData.image or itemData.name) } - return repackedTable end ----comment ----@param item string ----@return string -Inventory.GetImagePath = function(item) - -- check if contains.png and remove it if it does - item = Inventory.StripPNG(item) - local file = LoadResourceFile("qb-inventory", string.format("html/images/%s.png", item)) - local imagePath = file and string.format("nui://qb-inventory/html/images/%s.png", item) - return imagePath or "https://avatars.githubusercontent.com/u/47620135" -end - ----comment ----@param src number ----@param item string ----@return boolean -Inventory.HasItem = function(src, item) - return qbInventory:HasItem(src, item, 1) -end - ----comment +---Returns the specified slot data as a table. +--- +---format {weight, name, metadata, slot, label, count} ---@param src number ---@param slot number ---@return table @@ -92,7 +75,61 @@ Inventory.GetItemBySlot = function(src, slot) } 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:qb-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 +---@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 +Inventory.HasItem = function(src, item) + return qbInventory:HasItem(src, item, 1) +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 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("qb-inventory", string.format("html/images/%s.png", item)) + local imagePath = file and string.format("nui://qb-inventory/html/images/%s.png", item) + return imagePath or "https://avatars.githubusercontent.com/u/47620135" +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 @@ -119,25 +156,12 @@ Inventory.UpdatePlate = function(oldplate, newplate) MySQL.transaction.await(queries, values) end 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 -Inventory.AddItem = function(src, item, amount, slot, metadata) - TriggerClientEvent('qb-inventory:client:ItemBox', src, QBCore.Shared.Items[item], 'add', amount) - TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "add", item = item, count = amount, slot = slot, metadata = metadata}) - return exports['qb-inventory']:AddItem(src, item, amount, slot, metadata, 'community_bridge') -end - -Inventory.RemoveItem = function(src, item, amount, slot, metadata) - TriggerClientEvent('qb-inventory:client:ItemBox', src, QBCore.Shared.Items[item], 'remove', amount) - TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "remove", item = item, count = amount, slot = slot, metadata = metadata}) - return exports['qb-inventory']:RemoveItem(src, item, amount, slot, 'community_bridge') -end - -local registeredShops = {} -local v1ShopData = {} - +-- This will open the specified shop for the src passed. +---@param src number +---@param shopTitle string Inventory.OpenShop = function(src, shopTitle) local newVersion = getInventoryNewVersion() if newVersion then @@ -149,6 +173,11 @@ Inventory.OpenShop = function(src, shopTitle) end end +-- This will register a shop, if it already exists it will return true. +-- @param shopTitle string +-- @param shopInventory table +-- @param shopCoords table +-- @param shopGroups table Inventory.CreateShop = function(src, shopTitle, shopInventory, shopCoords, shopGroups) if not shopTitle or not shopInventory or not shopCoords then return end if registeredShops[shopTitle] then return true end @@ -173,4 +202,6 @@ Inventory.CreateShop = function(src, shopTitle, shopInventory, shopCoords, shopG v1ShopData[shopTitle] = shopData print("QB-INVENTORY: You are using an outdated version of qb-inventory, please update to the latest version. Stuff will still work but you are using litterally the most exploitable inventory in fivem.") end -end \ No newline at end of file +end + +return Inventory \ No newline at end of file diff --git a/modules/inventory/qs-inventory/client.lua b/modules/inventory/qs-inventory/client.lua index 9a0f0d1..d309ddd 100644 --- a/modules/inventory/qs-inventory/client.lua +++ b/modules/inventory/qs-inventory/client.lua @@ -1,15 +1,10 @@ +---@diagnostic disable: duplicate-set-field if GetResourceState('qs-inventory') ~= 'started' then return end local quasar = exports["qs-inventory"] + Inventory = Inventory or {} ----comment ----@param id any ----@return nil -Inventory.OpenStash = function(id) - quasar:RegisterStash(id, 50, 50000) -end - ----comment +---Return the item info in oxs format, {name, label, stack, weight, description, image} ---@param item string ---@return table Inventory.GetItemInfo = function(item) @@ -17,7 +12,7 @@ Inventory.GetItemInfo = function(item) if not itemsData then return {} end local itemData = itemsData[item] if not itemData then return {} end - local repackedTable = { + return { name = itemData.name or "Missing Name", label = itemData.label or "Missing Label", stack = itemData.unique or "false", @@ -25,10 +20,9 @@ Inventory.GetItemInfo = function(item) description = itemData.description or "none", image = itemData.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) @@ -36,7 +30,15 @@ Inventory.HasItem = function(item) return check and true or false 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 = quasar:Search(item) + return searchItem or 0 +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) @@ -46,15 +48,7 @@ Inventory.GetImagePath = function(item) return imagePath or "https://avatars.githubusercontent.com/u/47620135" end ----comment ----@param item string ----@return number -Inventory.GetItemCount = function(item) - local searchItem = quasar:Search(item) - return searchItem or 0 -end - ----comment +---This will return the players inventory in the format of {name, label, count, slot, metadata} ---@return table Inventory.GetPlayerInventory = function() local items = {} @@ -74,3 +68,11 @@ Inventory.GetPlayerInventory = function() return items end +---comment +---@param id any +---@return nil +Inventory.OpenStash = function(id) + quasar:RegisterStash(id, 50, 50000) +end + +return Inventory \ No newline at end of file diff --git a/modules/inventory/qs-inventory/server.lua b/modules/inventory/qs-inventory/server.lua index 0cbc1a8..ddb2d3b 100644 --- a/modules/inventory/qs-inventory/server.lua +++ b/modules/inventory/qs-inventory/server.lua @@ -1,10 +1,11 @@ +---@diagnostic disable: duplicate-set-field if GetResourceState('qs-inventory') ~= 'started' then return end local quasar = exports['qs-inventory'] Inventory = Inventory or {} ----This will add the item if found and return a boolean on success +---This will add an item, and return true or false based on success ---@param src number ---@param item string ---@param count number @@ -17,7 +18,7 @@ Inventory.AddItem = function(src, item, count, slot, metadata) return quasar:AddItem(src, item, count, slot, metadata) end ----This will remove the item if found and return a boolean on success +---This will remove an item, and return true or false based on success ---@param src number ---@param item string ---@param count number @@ -29,7 +30,27 @@ Inventory.RemoveItem = function(src, item, count, slot, metadata) return quasar:RemoveItem(src, item, count, slot, metadata) end ----This will return a number of the items count in the inventory +---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 itemsData = quasar:GetItemList() + if not itemsData then return {} end + local itemData = itemsData[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", + weight = itemData.weight or "0", + description = itemData.description or "none", + image = itemData.image or Inventory.GetImagePath(item), + } +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 @@ -38,7 +59,7 @@ Inventory.GetItemCount = function(src, item, metadata) return quasar:GetItemTotalAmount(src, item) end ----This will return the player inventory in a table following ox_inventory format +---This wil return the players inventory. ---@param src number ---@return table Inventory.GetPlayerInventory = function(src) @@ -55,20 +76,12 @@ Inventory.GetPlayerInventory = function(src) return repackedTable end ----This will return a boolean of if the player has the item in the inventory ----@param src number ----@param item string ----@return boolean -Inventory.HasItem = function(src, item) - local count = quasar:GetItemTotalAmount(src, item) - if not count then return false end - return count > 0 -end - ----This will return the item data in the inventory based on the slot if not found will return nil +---Returns the specified slot data as a table. +--- +---format {weight, name, metadata, slot, label, count} ---@param src number ---@param slot number ----@return table | nil +---@return table Inventory.GetItemBySlot = function(src, slot) local playerItems = quasar:GetInventory(src) for _, item in pairs(playerItems) do @@ -85,32 +98,22 @@ Inventory.GetItemBySlot = function(src, slot) } end end - return nil + return {} end ----This will return a boolean if the player can carry the item +---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 quasar:CanCarryItem(src, item, count) -end - ----@param id 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 +---@param slot number +---@param metadata table +---@return nil +Inventory.SetMetadata = function(src, item, slot, metadata) + return quasar:SetItemMetadata(src, slot, metadata) end +---This will open the specified stash for the src passed. ---@param src number ----@param id string +---@param id number||string ---@param label string ---@param slots number ---@param weight number @@ -123,44 +126,40 @@ Inventory.OpenStash = function(src, id, label, slots, weight, owner, groups, coo TriggerClientEvent("inventory:client:SetCurrentStash",src, id) end ----This will return the data to an item ----@param item string ----@return table -Inventory.GetItemInfo = function(item) - local itemsData = quasar:GetItemList() - if not itemsData then return {} end - local itemData = itemsData[item] - if not itemData then return {} end - local repackedTable = { - name = itemData.name or "Missing Name", - label = itemData.label or "Missing Label", - stack = itemData.unique or "false", - weight = itemData.weight or "0", - description = itemData.description or "none", - image = itemData.image or Inventory.GetImagePath(item), - } - return repackedTable +---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) + --exports['qs-inventory']:RegisterStash(src, id, stashSlots, stashWeight) -- this needs to pass source to register, need to plan around this. + return true end - +---This will return a boolean if the player has the item. ---@param src number ---@param item string ----@param slot number ----@param metadata table ---@return boolean -Inventory.SetMetadata = function(src, item, slot, metadata) - return quasar:SetItemMetadata(src, slot, metadata) +Inventory.HasItem = function(src, item) + local count = quasar:GetItemTotalAmount(src, item) + if not count then return false end + return count > 0 end +---This is to get if there is available space in the inventory, will return boolean. +---@param src number ---@param item string ----@return string -Inventory.GetImagePath = function(item) - item = Inventory.StripPNG(item) - local file = LoadResourceFile("qs-inventory", string.format("html/images/%s.png", item)) - local imagePath = file and string.format("nui://qs-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 quasar: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 @@ -172,6 +171,33 @@ 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 \ No newline at end of file + 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("qs-inventory", string.format("html/images/%s.png", item)) + local imagePath = file and string.format("nui://qs-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 qs shop is not bridged") +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("Currently qs shop is not bridged") +end + +return Inventory \ No newline at end of file diff --git a/modules/inventory/tgiann-inventory/client.lua b/modules/inventory/tgiann-inventory/client.lua index 5ddcee4..cc230c3 100644 --- a/modules/inventory/tgiann-inventory/client.lua +++ b/modules/inventory/tgiann-inventory/client.lua @@ -1,20 +1,16 @@ +---@diagnostic disable: duplicate-set-field if GetResourceState('tgiann-inventory') ~= 'started' then return end local tgiann = exports["tgiann-inventory"] Inventory = Inventory or {} ----@param id any ----@return nil -Inventory.OpenStash = function(id) - -- open stash export... not sure what it is yet. -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 = tgiann:GetItemList() if not itemData[item] then return {} end - local repackedTable = { + return { name = itemData.name or "Missing Name", label = itemData.label or "Missing Label", stack = itemData.unique or "false", @@ -22,10 +18,16 @@ Inventory.GetItemInfo = function(item) description = itemData.description or "none", image = itemData.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) + return tgiann:HasItem(item) +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) @@ -33,14 +35,7 @@ Inventory.GetItemCount = function(item) return searchItem or 0 end ----This will return a boolean if the player has the item in the inventory ----@param item string ----@return boolean -Inventory.HasItem = function(item) - return tgiann:HasItem(item) -end - --- This will return the image path, it is incredibley useful for menus etc +---This will get the image path for this item, if not found will return placeholder. ---@param item string ---@return string Inventory.GetImagePath = function(item) @@ -51,7 +46,7 @@ Inventory.GetImagePath = function(item) return imagePath or "https://avatars.githubusercontent.com/u/47620135" end ----This will return the player inventory in a table +---This will return the players inventory in the format of {name, label, count, slot, metadata} ---@return table Inventory.GetPlayerInventory = function() local items = {} @@ -70,3 +65,11 @@ Inventory.GetPlayerInventory = function() end return items end + +---@param id any +---@return nil +Inventory.OpenStash = function(id) + tgiann:OpenInventory('stash', id, { maxweight = 400000, slots = 100 }) +end + +return Inventory \ No newline at end of file diff --git a/modules/inventory/tgiann-inventory/server.lua b/modules/inventory/tgiann-inventory/server.lua index 6219a5e..f72cff6 100644 --- a/modules/inventory/tgiann-inventory/server.lua +++ b/modules/inventory/tgiann-inventory/server.lua @@ -1,10 +1,11 @@ +---@diagnostic disable: duplicate-set-field if GetResourceState('tgiann-inventory') ~= 'started' then return end local tgiann = exports["tgiann-inventory"] Inventory = Inventory or {} ----This Will add the item if found and return boolean on success +---This will add an item, and return true or false based on success ---@param src number ---@param item string ---@param count number @@ -12,12 +13,11 @@ Inventory = Inventory or {} ---@param metadata table ---@return boolean Inventory.AddItem = function(src, item, count, slot, metadata) - if not tgiann:CanCarryItem(src, item, count) then return false end TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "add", item = item, count = count, slot = slot, metadata = metadata}) return tgiann:AddItem(src, item, count, slot, metadata, false) end ----This Will remove the item if found and return boolean on success +---This will remove an item, and return true or false based on success ---@param src number ---@param item string ---@param count number @@ -29,37 +29,35 @@ Inventory.RemoveItem = function(src, item, count, slot, metadata) return tgiann:RemoveItem(src, item, count, slot, metadata) 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 = tgiann:GetItemList() + if not itemData[item] then return {} end + return { + name = itemData.name or "Missing Name", + label = itemData.label or "Missing Label", + stack = itemData.unique or "false", + weight = itemData.weight or "0", + description = itemData.description or "none", + image = itemData.image or Inventory.GetImagePath(item), + } +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 table -Inventory.GetItem = function(src, item, metadata) - local item = tgiann:GetItemByName(src, item, metadata) - item.count = item.amount - item.metadata = item.info - return item -end - ----This will return a boolean if the player has the item in their inventory ----@param src number ----@param item string ----@return boolean -Inventory.HasItem = function(src, item) - return tgiann:HasItem(src, item, 1) -end - ----This will return the count of the item in the players inventory ----@param src number ----@param item string ----@param metadata optional table ---@return number Inventory.GetItemCount = function(src, item, metadata) local _item = tgiann:GetItemByName(src, item, metadata) return _item.amount or 0 end ----This will return the players inventory in a table in the format ox_inventory uses +---This wil return the players inventory. ---@param src number ---@return table Inventory.GetPlayerInventory = function(src) @@ -73,55 +71,28 @@ Inventory.GetPlayerInventory = function(src) return items end ----This will return a boolean if the player can carry the item ----@param src number ----@param item string ----@param count number ----@return boolean -Inventory.CanCarryItem = function(src, item, count) - return tgiann:CanCarryItem(src, item, count) -end - ----comment ----@param id string or number ----@param label string ----@param slots number ----@param weight number ----@param owner string ----@return boolean -Inventory.RegisterStash = function(id, label, slots, weight, owner) - return tgiann:CreateCustomStashWithItem(id, {}) -end - ----This will return the item data in the slot the item is found +---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 item = tgiann:GetItemBySlot(src, slot) if not item then return {} end - return {name = item.name, label = item.label, weight = item.weight, slot = slot, count = item.amount, metadata = item.info, stack = item.unique or false, description = item.description} -end - ----This will return a table of the item data including the image (very useful for menus etc) ----@param item string ----@return table -Inventory.GetItemInfo = function(item) - local itemData = tgiann:GetItemList() - if not itemData[item] then return {} end - local repackedTable = { - name = itemData.name or "Missing Name", - label = itemData.label or "Missing Label", - stack = itemData.unique or "false", - weight = itemData.weight or "0", - description = itemData.description or "none", - image = itemData.image or Inventory.GetImagePath(item), + return { + name = item.name, + label = item.label, + weight = item.weight, + slot = slot, + count = item.amount, + metadata = item.info, + stack = item.unique or false, + description = item.description } - return repackedTable end ----This will update the item metadata for an item with the provided slot and metadata, its best to get the item first ----And then set the metadata +---This will set the metadata of an item in the inventory. ---@param src number ---@param item string ---@param slot number @@ -131,18 +102,51 @@ Inventory.SetMetadata = function(src, item, slot, metadata) tgiann:UpdateItemMetadata(src, item, slot, metadata) end ----This will return the image path for the item ----@param item string ----@return string -Inventory.GetImagePath = function(item) - item = Inventory.StripPNG(item) - local pngPath = LoadResourceFile("inventory_images", string.format("html/images/%s.png", item)) - local webpPath = LoadResourceFile("inventory_images", string.format("html/images/%s.webp", item)) - local imagePath = pngPath and string.format("nui://inventory_images/html/images/%s.png", item) or webpPath and string.format("nui://inventory_images/html/images/%s.webp", 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) + print("Currently not bridged for stashes") end ----This will update the plate to a vehicle in the inventory +---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 false, print("Currently not bridged for stashes") +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 tgiann:HasItem(src, item, 1) +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 tgiann: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 @@ -154,6 +158,52 @@ 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 \ No newline at end of file + 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 pngPath = LoadResourceFile("inventory_images", string.format("html/images/%s.png", item)) + local webpPath = LoadResourceFile("inventory_images", string.format("html/images/%s.webp", item)) + local imagePath = pngPath and string.format("nui://inventory_images/html/images/%s.png", item) or webpPath and string.format("nui://inventory_images/html/images/%s.webp", 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 tgiann-inventory is not bridged for shops") +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("Currently tgiann-inventory is not bridged for shops") +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) + local item = tgiann:GetItemByName(src, item, metadata) + item.count = item.amount + item.metadata = item.info + return item +end + +return Inventory \ No newline at end of file diff --git a/modules/managment/Renewed-Banking/server.lua b/modules/managment/Renewed-Banking/server.lua index 3c4bf5b..a4683fb 100644 --- a/modules/managment/Renewed-Banking/server.lua +++ b/modules/managment/Renewed-Banking/server.lua @@ -22,4 +22,6 @@ end ---@return boolean Managment.RemoveAccountMoney = function(account, amount) return exports['Renewed-Banking']:removeAccountMoney(account, amount) -end \ No newline at end of file +end + +return Managment \ No newline at end of file diff --git a/modules/managment/_default/server.lua b/modules/managment/_default/server.lua index 26593d6..80cf953 100644 --- a/modules/managment/_default/server.lua +++ b/modules/managment/_default/server.lua @@ -10,4 +10,6 @@ end Managment.RemoveAccountMoney = function(account, amount) return false, print("The resource you are using does not support this function.") -end \ No newline at end of file +end + +return Managment \ No newline at end of file diff --git a/modules/managment/okokBanking/server.lua b/modules/managment/okokBanking/server.lua index 34582c3..60a32b4 100644 --- a/modules/managment/okokBanking/server.lua +++ b/modules/managment/okokBanking/server.lua @@ -22,4 +22,6 @@ end ---@return boolean Managment.RemoveAccountMoney = function(account, amount) return exports['okokBanking']:RemoveMoney(account, amount) -end \ No newline at end of file +end + +return Managment \ No newline at end of file diff --git a/modules/managment/qb-banking/server.lua b/modules/managment/qb-banking/server.lua index 25d168a..da26df1 100644 --- a/modules/managment/qb-banking/server.lua +++ b/modules/managment/qb-banking/server.lua @@ -22,4 +22,6 @@ end ---@return boolean Managment.RemoveAccountMoney = function(account, amount) return exports['qb-banking']:RemoveMoney(account, amount) -end \ No newline at end of file +end + +return Managment \ No newline at end of file diff --git a/modules/math/computation.lua b/modules/math/computation.lua index 1e6ef28..f007806 100644 --- a/modules/math/computation.lua +++ b/modules/math/computation.lua @@ -66,3 +66,5 @@ end function Math.Map(value, inMin, inMax, outMin, outMax) return (value - inMin) / (inMax - inMin) * (outMax - outMin) + outMin end + +return Math \ No newline at end of file diff --git a/modules/menu/client.lua b/modules/menu/client.lua index dbb41f9..26b2713 100644 --- a/modules/menu/client.lua +++ b/modules/menu/client.lua @@ -23,6 +23,7 @@ RegisterNetEvent('community_bridge:client:MenuCallback', function(_args) onSelect(args) end) +return Menu --[[ diff --git a/modules/notify/_default/client.lua b/modules/notify/_default/client.lua index c016d61..72a5c40 100644 --- a/modules/notify/_default/client.lua +++ b/modules/notify/_default/client.lua @@ -35,4 +35,6 @@ end ---@diagnostic disable-next-line: duplicate-set-field Notify.ShowHelpText = function(message, position) return HelpText.ShowHelpText(message, position) -end \ No newline at end of file +end + +return Notify \ No newline at end of file diff --git a/modules/notify/_default/server.lua b/modules/notify/_default/server.lua index a299eae..a6f5d41 100644 --- a/modules/notify/_default/server.lua +++ b/modules/notify/_default/server.lua @@ -30,4 +30,6 @@ end ---@diagnostic disable-next-line: duplicate-set-field Notify.HideHelpText = function(src) return HelpText.HideHelpText(src) -end \ No newline at end of file +end + +return Notify \ No newline at end of file diff --git a/modules/notify/mythic_notify/client.lua b/modules/notify/mythic_notify/client.lua index 378ce39..b276ef5 100644 --- a/modules/notify/mythic_notify/client.lua +++ b/modules/notify/mythic_notify/client.lua @@ -17,4 +17,6 @@ end Notify.SendNotify = function(message, _type, time) time = time or 3000 return exports['mythic_notify']:SendAlert('inform', message, time) -end \ No newline at end of file +end + +return Notify \ No newline at end of file diff --git a/modules/notify/okokNotify/client.lua b/modules/notify/okokNotify/client.lua index 78c28a5..6375bab 100644 --- a/modules/notify/okokNotify/client.lua +++ b/modules/notify/okokNotify/client.lua @@ -17,4 +17,6 @@ end Notify.SendNotify = function(message, _type, time) time = time or 3000 return exports['okokNotify']:Alert('Notification', message, time, _type, false) -end \ No newline at end of file +end + +return Notify \ No newline at end of file diff --git a/modules/notify/ox_lib/client.lua b/modules/notify/ox_lib/client.lua index fe28910..037dc95 100644 --- a/modules/notify/ox_lib/client.lua +++ b/modules/notify/ox_lib/client.lua @@ -18,4 +18,6 @@ end Notify.SendNotify = function(message, _type, time) time = time or 3000 return exports.ox_lib:notify({ description = message, type = _type, position = 'center-left' }) -end \ No newline at end of file +end + +return Notify \ No newline at end of file diff --git a/modules/notify/pNotify/client.lua b/modules/notify/pNotify/client.lua index e5ee328..7cbf356 100644 --- a/modules/notify/pNotify/client.lua +++ b/modules/notify/pNotify/client.lua @@ -17,4 +17,6 @@ end Notify.SendNotify = function(message, _type, time) time = time or 3000 return exports['pNotify']:SendNotification({ text = message, type = _type, timeout = time, layout = 'centerRight' }) -end \ No newline at end of file +end + +return Notify \ No newline at end of file diff --git a/modules/notify/r_notify/client.lua b/modules/notify/r_notify/client.lua index a3dc5b6..4b12e9e 100644 --- a/modules/notify/r_notify/client.lua +++ b/modules/notify/r_notify/client.lua @@ -17,4 +17,6 @@ end Notify.SendNotify = function(message, _type, time) time = time or 3000 return exports.r_notify:notify({title = 'Notification', content = message, type = _type, icon = "fas fa-check", duration = time, position = 'top-right', sound = false}) -end \ No newline at end of file +end + +return Notify \ No newline at end of file diff --git a/modules/notify/t-notify/client.lua b/modules/notify/t-notify/client.lua index f11e863..0dcc4c4 100644 --- a/modules/notify/t-notify/client.lua +++ b/modules/notify/t-notify/client.lua @@ -17,4 +17,6 @@ end Notify.SendNotify = function(message, _type, time) time = time or 3000 return exports['t-notify']:Alert({ style = 'info', message = message, duration = time, }) -end \ No newline at end of file +end + +return Notify \ No newline at end of file diff --git a/modules/notify/wasabi_notify/client.lua b/modules/notify/wasabi_notify/client.lua index 52998c8..f4d83f5 100644 --- a/modules/notify/wasabi_notify/client.lua +++ b/modules/notify/wasabi_notify/client.lua @@ -17,4 +17,6 @@ end Notify.SendNotify = function(message, _type, time) time = time or 3000 return exports.wasabi_notify:notify(_type, message, time, _type) -end \ No newline at end of file +end + +return Notify \ No newline at end of file diff --git a/modules/phone/_default/client.lua b/modules/phone/_default/client.lua index 3337b0c..b05bde5 100644 --- a/modules/phone/_default/client.lua +++ b/modules/phone/_default/client.lua @@ -3,4 +3,6 @@ Phone = Phone or {} ---@diagnostic disable-next-line: duplicate-set-field Phone.SendEmail = function(email, title, message) return false, Print.Error('There Is No Phone Bridged.') -end \ No newline at end of file +end + +return Phone \ No newline at end of file diff --git a/modules/phone/_default/server.lua b/modules/phone/_default/server.lua index 51b2402..899d30e 100644 --- a/modules/phone/_default/server.lua +++ b/modules/phone/_default/server.lua @@ -8,4 +8,6 @@ end ---@diagnostic disable-next-line: duplicate-set-field Phone.SendEmail = function(src, email, title, message) return false, Print.Error('There Is No Phone Bridged.') -end \ No newline at end of file +end + +return Phone \ No newline at end of file diff --git a/modules/phone/gksphone/client.lua b/modules/phone/gksphone/client.lua index 7bae1cb..ead89bb 100644 --- a/modules/phone/gksphone/client.lua +++ b/modules/phone/gksphone/client.lua @@ -12,4 +12,6 @@ Phone = Phone or {} ---@diagnostic disable-next-line: duplicate-set-field Phone.SendEmail = function(email, title, message) return exports["gksphone"]:SendNewMail({ sender = email, image = '/html/static/img/icons/mail.png', subject = title, message = message }) -end \ No newline at end of file +end + +return Phone \ No newline at end of file diff --git a/modules/phone/gksphone/server.lua b/modules/phone/gksphone/server.lua index 828696b..8d72d62 100644 --- a/modules/phone/gksphone/server.lua +++ b/modules/phone/gksphone/server.lua @@ -26,4 +26,6 @@ Phone.SendEmail = function(src, email, title, message) data.message = message exports["gksphone"]:SendNewMail(src, data) return true -end \ No newline at end of file +end + +return Phone \ No newline at end of file diff --git a/modules/phone/lb-phone/client.lua b/modules/phone/lb-phone/client.lua index 2964856..450f364 100644 --- a/modules/phone/lb-phone/client.lua +++ b/modules/phone/lb-phone/client.lua @@ -11,4 +11,6 @@ Phone = Phone or {} ---@diagnostic disable-next-line: duplicate-set-field Phone.SendEmail = function(email, title, message) TriggerServerEvent('community_bridge:Server:genericEmail', {email = email, title = title, message = message}) -end \ No newline at end of file +end + +return Phone \ No newline at end of file diff --git a/modules/phone/lb-phone/server.lua b/modules/phone/lb-phone/server.lua index 748741f..6545f23 100644 --- a/modules/phone/lb-phone/server.lua +++ b/modules/phone/lb-phone/server.lua @@ -33,4 +33,6 @@ RegisterNetEvent('community_bridge:Server:genericEmail', function(data) local src = source Prints.Debug('community_bridge:Server:genericEmail Hit') return Phone.SendEmail(src, data.email, data.title, data.message) -end) \ No newline at end of file +end) + +return Phone \ No newline at end of file diff --git a/modules/phone/okokPhone/client.lua b/modules/phone/okokPhone/client.lua index 623b01a..c6fd86d 100644 --- a/modules/phone/okokPhone/client.lua +++ b/modules/phone/okokPhone/client.lua @@ -11,6 +11,9 @@ Phone = Phone or {} ---@return boolean ---@diagnostic disable-next-line: duplicate-set-field Phone.SendEmail = function(email, title, message) + --<-- TODO swap to internal callback system local success = lib.callback.await('community_bridge:Callback:okokPhone:sendEmail', false, email, title, message) --[[ @as boolean ]] return success end + +return Phone \ No newline at end of file diff --git a/modules/phone/okokPhone/server.lua b/modules/phone/okokPhone/server.lua index 67643cb..d493309 100644 --- a/modules/phone/okokPhone/server.lua +++ b/modules/phone/okokPhone/server.lua @@ -49,7 +49,9 @@ Phone.SendEmail = function(src, email, title, message) return success end - +--<-- TODO swap to internal callback system lib.callback.registry('community_bridge:Callback:okokPhone:sendEmail', function(src, email, title, message) return Phone.SendEmail(src, email, title, message) end) + +return Phone \ No newline at end of file diff --git a/modules/phone/qs-smartphone/client.lua b/modules/phone/qs-smartphone/client.lua index 2f797e6..f0466a3 100644 --- a/modules/phone/qs-smartphone/client.lua +++ b/modules/phone/qs-smartphone/client.lua @@ -15,4 +15,6 @@ end RegisterNetEvent('community_bridge:Server:genericEmail', function(data) TriggerServerEvent('qs-smartphone:server:sendNewMail', { sender = data.email, subject = data.title, message = data.message, button = {} }) -end) \ No newline at end of file +end) + +return Phone \ No newline at end of file diff --git a/modules/phone/qs-smartphone/server.lua b/modules/phone/qs-smartphone/server.lua index 167bacc..792674a 100644 --- a/modules/phone/qs-smartphone/server.lua +++ b/modules/phone/qs-smartphone/server.lua @@ -20,4 +20,6 @@ end Phone.SendEmail = function(src, email, title, message) TriggerClientEvent('community_bridge:Server:genericEmail', src, { sender = email, subject = title, message = message, button = {} }) return true -end \ No newline at end of file +end + +return Phone \ No newline at end of file diff --git a/modules/progressbar/ox_lib/client.lua b/modules/progressbar/ox_lib/client.lua index 080e067..c7bdb21 100644 --- a/modules/progressbar/ox_lib/client.lua +++ b/modules/progressbar/ox_lib/client.lua @@ -62,6 +62,8 @@ function ProgressBar.Open(options, cb, isQBInput) return success end +return ProgressBar + --[[ RegisterCommand("progressbar", function() ProgressBar.Open({ diff --git a/modules/progressbar/qb-progressbar/client.lua b/modules/progressbar/qb-progressbar/client.lua index 73dd034..4908ff1 100644 --- a/modules/progressbar/qb-progressbar/client.lua +++ b/modules/progressbar/qb-progressbar/client.lua @@ -60,6 +60,8 @@ function ProgressBar.Open(options, cb, qbFormat) return Citizen.Await(prom) end +return ProgressBar + -- Example usage: --[[ diff --git a/modules/shops/_default/client.lua b/modules/shops/_default/client.lua index 02e774d..c8512db 100644 --- a/modules/shops/_default/client.lua +++ b/modules/shops/_default/client.lua @@ -76,3 +76,5 @@ Shops.OpenShop = function(title, shopData) end Menu.Open({ id = generatedID, title = title, options = buildMenu }, false) end + +return Shops \ No newline at end of file diff --git a/modules/shops/_default/server.lua b/modules/shops/_default/server.lua index 09a84fa..a4ac7b4 100644 --- a/modules/shops/_default/server.lua +++ b/modules/shops/_default/server.lua @@ -60,4 +60,6 @@ RegisterNetEvent("community_bridge:completeCheckout", function(shopName, item, a if not shopName and not item and not paymentType then return end if not paymentType == "money" or not paymentType == "bank" then return end Shops.CompleteCheckout(src, shopName, item, amount, paymentType) -end) \ No newline at end of file +end) + +return Shops \ No newline at end of file diff --git a/modules/skills/OT_skills/client.lua b/modules/skills/OT_skills/client.lua index cac7757..4d0e9f1 100644 --- a/modules/skills/OT_skills/client.lua +++ b/modules/skills/OT_skills/client.lua @@ -12,4 +12,6 @@ end Skills.GetSkillLevel = function(skillName) local skillData = exports.OT_skills:getSkill(skillName) return skillData.level or 0 -end \ No newline at end of file +end + +return Skills \ No newline at end of file diff --git a/modules/skills/OT_skills/server.lua b/modules/skills/OT_skills/server.lua index c5be3f1..7685012 100644 --- a/modules/skills/OT_skills/server.lua +++ b/modules/skills/OT_skills/server.lua @@ -26,4 +26,6 @@ Skills.RemoveXp = function(src, skillName, amount) if not skillData then return false, print("Skill not found") end exports.OT_skills:removeXP(src, skillName, amount) return true -end \ No newline at end of file +end + +return Skills \ No newline at end of file diff --git a/modules/skills/_default/client.lua b/modules/skills/_default/client.lua index 9b26b0a..74f9d3e 100644 --- a/modules/skills/_default/client.lua +++ b/modules/skills/_default/client.lua @@ -12,4 +12,6 @@ end ---@diagnostic disable-next-line: duplicate-set-field Skills.GetSkillLevel = function(skillName) return 0, warnUser() -end \ No newline at end of file +end + +return Skills \ No newline at end of file diff --git a/modules/skills/_default/server.lua b/modules/skills/_default/server.lua index a5ae846..e1b2302 100644 --- a/modules/skills/_default/server.lua +++ b/modules/skills/_default/server.lua @@ -22,4 +22,6 @@ end ---@diagnostic disable-next-line: duplicate-set-field Skills.RemoveXp = function(src, skillName, amount) return false, warnUser() -end \ No newline at end of file +end + +return Skills \ No newline at end of file diff --git a/modules/skills/evolent_skills/client.lua b/modules/skills/evolent_skills/client.lua index 7ee1e0f..745b5a8 100644 --- a/modules/skills/evolent_skills/client.lua +++ b/modules/skills/evolent_skills/client.lua @@ -12,4 +12,6 @@ end Skills.GetSkillLevel = function(skillName) local skillData = exports.evolent_skills:getSkillLevel(skillName) return skillData or 0 -end \ No newline at end of file +end + +return Skills \ No newline at end of file diff --git a/modules/skills/evolent_skills/server.lua b/modules/skills/evolent_skills/server.lua index 05f960a..935a184 100644 --- a/modules/skills/evolent_skills/server.lua +++ b/modules/skills/evolent_skills/server.lua @@ -28,4 +28,6 @@ Skills.RemoveXp = function(src, skillName, amount) if not skillData then return false, print("Skill not found") end exports.evolent_skills:removeXp(src, skillName, amount) return true -end \ No newline at end of file +end + +return Skills \ No newline at end of file diff --git a/modules/skills/pickle_xp/client.lua b/modules/skills/pickle_xp/client.lua index c21f010..4692acc 100644 --- a/modules/skills/pickle_xp/client.lua +++ b/modules/skills/pickle_xp/client.lua @@ -12,4 +12,6 @@ end Skills.GetSkillLevel = function(skillName) local skillData = exports.OT_skills:GetLevel(skillName) return skillData or 0 -end \ No newline at end of file +end + +return Skills \ No newline at end of file diff --git a/modules/skills/pickle_xp/server.lua b/modules/skills/pickle_xp/server.lua index b7234f3..82ef781 100644 --- a/modules/skills/pickle_xp/server.lua +++ b/modules/skills/pickle_xp/server.lua @@ -26,4 +26,6 @@ Skills.RemoveXp = function(src, skillName, amount) if not skillData then return false, print("Skill not found") end exports.pickle_xp:RemovePlayerXP(src, skillName, amount) return true -end \ No newline at end of file +end + +return Skills \ No newline at end of file diff --git a/modules/target/_default/client.lua b/modules/target/_default/client.lua index 710c524..37581d7 100644 --- a/modules/target/_default/client.lua +++ b/modules/target/_default/client.lua @@ -135,4 +135,6 @@ end Target.RemoveZone = function(name) warnUser() -end \ No newline at end of file +end + +return Target \ No newline at end of file diff --git a/modules/target/ox_target/client.lua b/modules/target/ox_target/client.lua index fb06fd0..d65b7e6 100644 --- a/modules/target/ox_target/client.lua +++ b/modules/target/ox_target/client.lua @@ -157,3 +157,5 @@ AddEventHandler('onResourceStop', function(resource) end targetZones = {} end) + +return Target \ No newline at end of file diff --git a/modules/target/qb-target/client.lua b/modules/target/qb-target/client.lua index dccdb64..516b4e8 100644 --- a/modules/target/qb-target/client.lua +++ b/modules/target/qb-target/client.lua @@ -170,4 +170,6 @@ AddEventHandler('onResourceStop', function(resource) end end targetZones = {} -end) \ No newline at end of file +end) + +return Target \ No newline at end of file diff --git a/modules/target/sleepless_interact/client.lua b/modules/target/sleepless_interact/client.lua index c3cc9f0..0e924b2 100644 --- a/modules/target/sleepless_interact/client.lua +++ b/modules/target/sleepless_interact/client.lua @@ -139,3 +139,5 @@ AddEventHandler('onResourceStop', function(resource) targetZones = {} end end) + +return Target \ No newline at end of file diff --git a/modules/vehicleKey/F_RealCarKeysSystem/client/client.lua b/modules/vehicleKey/F_RealCarKeysSystem/client/client.lua index 6013011..5ba0f96 100644 --- a/modules/vehicleKey/F_RealCarKeysSystem/client/client.lua +++ b/modules/vehicleKey/F_RealCarKeysSystem/client/client.lua @@ -12,3 +12,5 @@ end VehicleKey.RemoveKeys = function(vehicle, plate) return true end + +return VehicleKey \ No newline at end of file diff --git a/modules/vehicleKey/MrNewbVehicleKeys/client/client.lua b/modules/vehicleKey/MrNewbVehicleKeys/client/client.lua index 7cf6df9..2790419 100644 --- a/modules/vehicleKey/MrNewbVehicleKeys/client/client.lua +++ b/modules/vehicleKey/MrNewbVehicleKeys/client/client.lua @@ -12,4 +12,6 @@ end VehicleKey.RemoveKeys = function(vehicle, plate) if not plate then return false end return exports.MrNewbVehicleKeys:RemoveKeysByPlate(plate) -end \ No newline at end of file +end + +return VehicleKey \ No newline at end of file diff --git a/modules/vehicleKey/Renewed-Vehiclekeys/client/client.lua b/modules/vehicleKey/Renewed-Vehiclekeys/client/client.lua index 4344bb7..baf44c4 100644 --- a/modules/vehicleKey/Renewed-Vehiclekeys/client/client.lua +++ b/modules/vehicleKey/Renewed-Vehiclekeys/client/client.lua @@ -12,4 +12,6 @@ end VehicleKey.RemoveKeys = function(vehicle, plate) if not plate then return false end return exports['Renewed-Vehiclekeys']:removeKey(plate) -end \ No newline at end of file +end + +return VehicleKey \ No newline at end of file diff --git a/modules/vehicleKey/_default/client/client.lua b/modules/vehicleKey/_default/client/client.lua index df07dc4..283a143 100644 --- a/modules/vehicleKey/_default/client/client.lua +++ b/modules/vehicleKey/_default/client/client.lua @@ -13,4 +13,6 @@ end ---@return boolean | nil VehicleKey.RemoveKeys = function(vehicle, plate) return true, Prints.Error("There Is No Vehicle Key System Installed") -end \ No newline at end of file +end + +return VehicleKey \ No newline at end of file diff --git a/modules/vehicleKey/cd_garage/client/client.lua b/modules/vehicleKey/cd_garage/client/client.lua index 936e1d0..7250703 100644 --- a/modules/vehicleKey/cd_garage/client/client.lua +++ b/modules/vehicleKey/cd_garage/client/client.lua @@ -11,4 +11,6 @@ end VehicleKey.RemoveKeys = function(vehicle, plate) return true -end \ No newline at end of file +end + +return VehicleKey \ No newline at end of file diff --git a/modules/vehicleKey/jacksam/client.lua b/modules/vehicleKey/jacksam/client.lua index 2b2f643..4259aa4 100644 --- a/modules/vehicleKey/jacksam/client.lua +++ b/modules/vehicleKey/jacksam/client.lua @@ -13,4 +13,6 @@ end VehicleKey.RemoveKeys = function(vehicle, plate) if not plate then return false end return TriggerServerEvent("vehicles_keys:selfRemoveKeys", plate) -end \ No newline at end of file +end + +return VehicleKey \ No newline at end of file diff --git a/modules/vehicleKey/mk_vehiclekeys/client/client.lua b/modules/vehicleKey/mk_vehiclekeys/client/client.lua index c39def4..58227de 100644 --- a/modules/vehicleKey/mk_vehiclekeys/client/client.lua +++ b/modules/vehicleKey/mk_vehiclekeys/client/client.lua @@ -12,4 +12,6 @@ end VehicleKey.RemoveKeys = function(vehicle, plate) if not vehicle and not DoesEntityExist(vehicle) then return false end return exports["mk_vehiclekeys"]:RemoveKey(vehicle) -end \ No newline at end of file +end + +return VehicleKey \ No newline at end of file diff --git a/modules/vehicleKey/mono_carkeys/client/client.lua b/modules/vehicleKey/mono_carkeys/client/client.lua index 03790d3..793bd5a 100644 --- a/modules/vehicleKey/mono_carkeys/client/client.lua +++ b/modules/vehicleKey/mono_carkeys/client/client.lua @@ -12,3 +12,5 @@ VehicleKey.RemoveKeys = function(vehicle, plate) if not plate then return false end TriggerServerEvent('mono_carkeys:DeleteKey', 1, plate) end + +return VehicleKey \ No newline at end of file diff --git a/modules/vehicleKey/okokGarage/client/client.lua b/modules/vehicleKey/okokGarage/client/client.lua index 3d62e22..27dba9a 100644 --- a/modules/vehicleKey/okokGarage/client/client.lua +++ b/modules/vehicleKey/okokGarage/client/client.lua @@ -11,4 +11,6 @@ end VehicleKey.RemoveKeys = function(vehicle, plate) return true -end \ No newline at end of file +end + +return VehicleKey \ No newline at end of file diff --git a/modules/vehicleKey/qb-vehiclekeys/client/client.lua b/modules/vehicleKey/qb-vehiclekeys/client/client.lua index 3ab78a2..f553cea 100644 --- a/modules/vehicleKey/qb-vehiclekeys/client/client.lua +++ b/modules/vehicleKey/qb-vehiclekeys/client/client.lua @@ -12,4 +12,6 @@ end VehicleKey.RemoveKeys = function(vehicle, plate) if not plate then return false end TriggerEvent("qb-vehiclekeys:client:RemoveKeys", plate) -end \ No newline at end of file +end + +return VehicleKey \ No newline at end of file diff --git a/modules/vehicleKey/qbx_vehiclekeys/client/client.lua b/modules/vehicleKey/qbx_vehiclekeys/client/client.lua index 8e554a8..a815939 100644 --- a/modules/vehicleKey/qbx_vehiclekeys/client/client.lua +++ b/modules/vehicleKey/qbx_vehiclekeys/client/client.lua @@ -11,4 +11,6 @@ end VehicleKey.RemoveKeys = function(vehicle, plate) return true -end \ No newline at end of file +end + +return VehicleKey \ No newline at end of file diff --git a/modules/vehicleKey/qs-vehiclekeys/client/client.lua b/modules/vehicleKey/qs-vehiclekeys/client/client.lua index d9a4423..6f8c3e0 100644 --- a/modules/vehicleKey/qs-vehiclekeys/client/client.lua +++ b/modules/vehicleKey/qs-vehiclekeys/client/client.lua @@ -16,4 +16,6 @@ VehicleKey.RemoveKeys = function(vehicle, plate) local model = GetDisplayNameFromVehicleModel(GetEntityModel(vehicle)) local verifiedPlate = GetVehicleNumberPlateText(vehicle) return exports['qs-vehiclekeys']:RemoveKeys(verifiedPlate, model) -end \ No newline at end of file +end + +return VehicleKey \ No newline at end of file diff --git a/modules/vehicleKey/t1ger_keys/client/client.lua b/modules/vehicleKey/t1ger_keys/client/client.lua index 23dd224..e2107b4 100644 --- a/modules/vehicleKey/t1ger_keys/client/client.lua +++ b/modules/vehicleKey/t1ger_keys/client/client.lua @@ -12,4 +12,6 @@ end VehicleKey.RemoveKeys = function(vehicle, plate) -end \ No newline at end of file +end + +return VehicleKey \ No newline at end of file diff --git a/modules/vehicleKey/wasabi_carlock/client/client.lua b/modules/vehicleKey/wasabi_carlock/client/client.lua index 8f03b0f..a66377a 100644 --- a/modules/vehicleKey/wasabi_carlock/client/client.lua +++ b/modules/vehicleKey/wasabi_carlock/client/client.lua @@ -12,4 +12,6 @@ end VehicleKey.RemoveKeys = function(vehicle, plate) if not plate and vehicle then plate = GetVehicleNumberPlateText(vehicle) end exports.wasabi_carlock:RemoveKey(plate) -end \ No newline at end of file +end + +return VehicleKey \ No newline at end of file diff --git a/modules/version/server/VersionChecker.lua b/modules/version/server/VersionChecker.lua index acf583c..35ea71a 100644 --- a/modules/version/server/VersionChecker.lua +++ b/modules/version/server/VersionChecker.lua @@ -1,44 +1,36 @@ Version = Version or {} ---Pass a github username and repo name to check for the latest version of the resource. +--- ---Tebex is a optional boolean to determine if the message should be for a escrowed resource or not. ----Example Version.VersionChecker("The-Order-Of-The-Sacred-Framework/community_bridge") +--- +---Example Version.VersionChecker("The-Order-Of-The-Sacred-Framework/community_bridge", false) ---@param repoPath string ---@param tebex boolean | nil ---@return nil function Version.VersionChecker(repoPath, tebex) - local resource = repoPath:match("([^/]+)$") - if not resource then return Prints.Error('^1Invalid repository format. Expected format: "username/reponame"^0') end - - local version = GetResourceMetadata(resource, "version", 0) - if not version then return Prints.Error(('^1Unable to determine current resource version for %s ^0'):format(resource)) end - - version = version:match('%d+%.%d+%.%d+') - if not version then return Prints.Error(('^1Invalid version format for %s ^0'):format(resource)) end - local username, reponame = repoPath:match("([^/]+)/([^/]+)") - if not username or not reponame then return Prints.Error('^1Invalid repository format. Expected format: "username/reponame"^0') end + local resource = reponame and repoPath:match("([^/]+)$") + if not username or not reponame or not resource then + return Prints.Error('^1Invalid repository format. Expected format: "username/reponame"^0') + end + + local version = GetResourceMetadata(resource, "version", 0):match('%d+%.%d+%.%d+') + if not version then return end + PerformHttpRequest(('https://api.github.com/repos/%s/%s/releases/latest'):format(username, reponame), function(status, response) - if status ~= 200 then return end - response = json.decode(response) + local latest = json.decode(response).tag_name:match('%d+%.%d+%.%d+') + if not latest or latest == version or version:gsub('%D', '') >= latest:gsub('%D', '') then return end - local latest = response.tag_name:match('%d+%.%d+%.%d+') - if not latest then return end - - if latest == version then return end - local currentVersion, latestVersion = version:gsub('%D', ''), latest:gsub('%D', '') - - if currentVersion < latestVersion then - if tebex then - return print(('^1An update is available for %s (current version: %s)\r\n - ^5Please download the latest version from the portal/keymaster.^7\r\n%s'):format(resource, version, "https://portal.cfx.re/assets/granted-assets")) - end - return print(('^1An update is available for %s (current version: %s)\r\n - ^5Please download the latest version from the GitHub release page.^7\r\n%s'):format(resource, version, response.html_url)) - end + local url = tebex and "https://portal.cfx.re/assets/granted-assets" or json.decode(response).html_url + print(('^1An update is available for %s (current version: %s)\r\n - ^5Please download the latest version from %s^7'):format(resource, version, url)) end, 'GET') end AddEventHandler('onResourceStart', function(resourceName) if GetCurrentResourceName() ~= resourceName then return end Version.VersionChecker("The-Order-Of-The-Sacred-Framework/community_bridge") -end) \ No newline at end of file +end) + +return Version \ No newline at end of file diff --git a/modules/weather/_default/client.lua b/modules/weather/_default/client.lua index 93a508a..095bf46 100644 --- a/modules/weather/_default/client.lua +++ b/modules/weather/_default/client.lua @@ -5,4 +5,6 @@ Weather = Weather or {} ---@return nil Weather.ToggleSync = function(toggle) -end \ No newline at end of file +end + +return Weather \ No newline at end of file diff --git a/modules/weather/cd_easytime/client.lua b/modules/weather/cd_easytime/client.lua index e3740dc..7808160 100644 --- a/modules/weather/cd_easytime/client.lua +++ b/modules/weather/cd_easytime/client.lua @@ -5,4 +5,6 @@ Weather = Weather or {} ---@param toggle boolean Weather.ToggleSync = function(toggle) TriggerEvent('cd_easytime:PauseSync', toggle) -end \ No newline at end of file +end + +return Weather \ No newline at end of file diff --git a/modules/weather/qb-weathersync/client/client.lua b/modules/weather/qb-weathersync/client/client.lua index d6eb030..df628c7 100644 --- a/modules/weather/qb-weathersync/client/client.lua +++ b/modules/weather/qb-weathersync/client/client.lua @@ -9,4 +9,6 @@ Weather.ToggleSync = function(toggle) else TriggerEvent("qb-weathersync:client:DisableSync") end -end \ No newline at end of file +end + +return Weather \ No newline at end of file diff --git a/modules/weather/renewed-weathersync/client/client.lua b/modules/weather/renewed-weathersync/client/client.lua index 66bb585..d531bee 100644 --- a/modules/weather/renewed-weathersync/client/client.lua +++ b/modules/weather/renewed-weathersync/client/client.lua @@ -5,4 +5,6 @@ Weather = Weather or {} ---@param toggle boolean Weather.ToggleSync = function(toggle) LocalPlayer.state.syncWeather = toggle -end \ No newline at end of file +end + +return Weather \ No newline at end of file