diff --git a/Attributions.md b/Attributions.md index 4273fd1..05b2092 100644 --- a/Attributions.md +++ b/Attributions.md @@ -4,14 +4,14 @@ This project incorporates code from several libraries and resources licensed und ## r_bridge - **Purpose**: Code for codem-inventory bridging, targeting, and framework item registration. -- **Modifications to the code**: Code was used for codem/tgian inventory bridge & targeting, the idea of native helper functions came from that entirely. Targeting code still remains as is and is used as well as the method of registering usables. +- **Modifications to the code**: Code was used for codem/tgian inventory bridge & targeting, the idea of native helper functions came from that entirely. Targeting code has been altered to allow both formats, the item registration has been simplified to fit this use case. - **Credit**: **r_bridge** inventory bridging code for codem-inventory is used in this. Targeting code still remains as is and is used. [\[r_bridge\]](https://github.com/rumaier/r_bridge) ## clean_lib -- **Purpose**: Vehicle fuel, vehicle key bridging and the loading and saving methods of json files. +- **Purpose**: Vehicle fuel, vehicle key bridging. - **Modifications to the code**: None. -- **Credit**: **clean_lib** code is used to manage vehicle fuel and keys, bridging these systems seamlessly. +- **Credit**: **clean_lib** client side code is used to manage vehicle fuel and keys, bridging these systems. [\[clean_lib\]](https://github.com/Clean-Server-Pack/clean_lib) ## ox_lib @@ -34,4 +34,4 @@ This project incorporates code from several libraries and resources licensed und -Thank you to the creators and maintainers of these libraries/bridges/internet points for their hard work and contributions to the FiveM community. +Thank you to the creators and maintainers of these libraries/bridges/internet points for their hard work and contributions to the FiveM community. \ No newline at end of file diff --git a/fxmanifest.lua b/fxmanifest.lua index 2fa8cc8..83aa11b 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -4,13 +4,12 @@ lua54 'yes' use_experimental_fxv2_oal 'yes' author 'The Order of the Sacred Framework' description 'A bridge made for the community to use as a base for their own projects. This bridge will allow a single format to work with nearly all commonly used systems while still offering expandability.' -version '0.2.2' +version '0.2.6' shared_scripts { '@ox_lib/init.lua', + 'lib/init.lua', 'settings/sharedConfig.lua', - 'use/*.lua', - 'modules/utility/shared/*.lua', 'modules/math/*.lua', 'modules/locales/*.lua', } @@ -24,20 +23,22 @@ server_scripts { 'modules/inventory/**/server.lua', 'modules/doorlock/**/server.lua', 'modules/phone/**/server.lua', - 'modules/notify/server.lua', 'modules/managment/**/server.lua', + 'modules/dispatch/**/server.lua', + 'modules/clothing/**/server.lua', + 'modules/weather/**/server.lua', + 'modules/vehicleKey/**/server.lua', + 'modules/notify/**/server.lua', 'init.lua', } client_scripts { 'settings/clientConfig.lua', 'modules/locales/shared.lua', - 'modules/utility/client/*.lua', 'modules/framework/**/client.lua', 'modules/inventory/**/client.lua', 'modules/doorlock/**/client.lua', 'modules/phone/**/client.lua', - 'modules/notify/client.lua', 'modules/weather/**/client.lua', 'modules/vehicleKey/**/client.lua', 'modules/fuel/**/client.lua', @@ -47,12 +48,16 @@ client_scripts { 'modules/clothing/**/client.lua', 'modules/input/*.lua', 'modules/menu/*.lua', + 'modules/notify/**/client.lua', 'init.lua', } files { 'locales/*.json', - 'components/*.lua', + 'lib/client/*.lua', + 'lib/shared/*.lua', + 'lib/server/*.lua', + 'lib/init.lua', } dependencies { diff --git a/init.lua b/init.lua index df4016b..533b065 100644 --- a/init.lua +++ b/init.lua @@ -2,39 +2,68 @@ Bridge = {} function Bridge.RegisterModule(moduleName, moduleTable) if not moduleTable then - print("No moduleTable provided for module and no defaultsTable found: ", moduleName) - return - end - if Bridge[moduleName] then - print("Module already registered:", moduleName) + if BridgeSharedConfig.DebugLevel ~= 0 then + print("^6 No moduleTable provided for module: ", moduleName, "^0") + end return end local wrappedModule = {} + if type(moduleTable) == 'function' then + Bridge[moduleName] = wrappedModule + return + end for functionName, func in pairs(moduleTable) do wrappedModule[functionName] = func end - print("Registering module:", moduleName) + if BridgeSharedConfig.DebugLevel ~= 0 then + print("^2 Registering module:", moduleName, "^0") + end Bridge[moduleName] = wrappedModule + --trigger update object event + TriggerEvent("Bridge:Refresh", moduleName, wrappedModule) end +exports("RegisterModule", Bridge.RegisterModule) --TODO: Create a way to overide functions or create a new functions for module +function Bridge.RegisterModuleFunction(moduleName, functionName, func) + assert(moduleName and functionName and func, string.format("Bridge.RegisterModuleFunction(%s, %s, %s) - Invalid arguments", moduleName, functionName, func)) + Bridge[moduleName] = Bridge[moduleName] or {} + Bridge[moduleName][functionName] = func + --trigger update object event + TriggerEvent("Bridge:Refresh", moduleName, Bridge[moduleName]) +end + + +--Bridge Bridge.RegisterModule("Framework", Framework) Bridge.RegisterModule("Inventory", Inventory) Bridge.RegisterModule("Notify", Notify) -Bridge.RegisterModule("Utility", Utility) Bridge.RegisterModule("Clothing", Clothing) Bridge.RegisterModule("Language", Language) Bridge.RegisterModule("Doorlock", Doorlock) Bridge.RegisterModule("Phone", Phone) -Bridge.RegisterModule("Table", Table) -Bridge.RegisterModule("Math", Math) -Bridge.RegisterModule("Prints", Prints) -Bridge.RegisterModule("Callback", Callback) +Bridge.RegisterModule("Dispatch", Dispatch) +Bridge.RegisterModule("VehicleKey", VehicleKey) +Bridge.RegisterModule("Weather", Weather) +--lib +Bridge.RegisterModule("Tables", cLib.Tables) +Bridge.RegisterModule("Math", cLib.Math) +Bridge.RegisterModule("Prints", cLib.Prints) +Bridge.RegisterModule("Callback", cLib.Callback) + +--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) CreateThread(function() + Wait(100) for moduleName, moduleFunction in pairs(Bridge) do if type(moduleFunction) == 'table' then exports(moduleName, function() @@ -50,17 +79,35 @@ exports('Bridge', function() return Bridge end) +-- ▄▀▀ ██▀ █▀▄ █ █ ██▀ █▀▄ +-- ▄█▀ █▄▄ █▀▄ ▀▄▀ █▄▄ █▀▄ +if not IsDuplicityVersion() then goto client end +Bridge.RegisterModule("SQL", cLib.SQL) +Bridge.RegisterModule("Logs", cLib.Logs) +Bridge.RegisterModule("LootTables", cLib.LootTables) + + +-- ▄▀▀ █ █ ██▀ █▄ █ ▀█▀ +-- ▀▄▄ █▄▄ █ █▄▄ █ ▀█ █ if IsDuplicityVersion() then return end +::client:: + -Bridge.RegisterModule("Dispatch", Dispatch) Bridge.RegisterModule("Fuel", Fuel) Bridge.RegisterModule("Input", Input) Bridge.RegisterModule("Progressbar", Progressbar) -Bridge.RegisterModule("VehicleKey", VehicleKey) -Bridge.RegisterModule("Weather", Weather) + Bridge.RegisterModule("Target", Target) Bridge.RegisterModule("Menu", Menu) +Bridge.RegisterModule("Utility", cLib.Utility) +Bridge.RegisterModule("Placeable", cLib.Placeable) +--new +-- Bridge.RegisterModule("Gizmo", cLib.Gizmo) +-- Bridge.RegisterModule("Scaleform", cLib.Scaleform) +-- Bridge.RegisterModule("PlaceableObject", cLib.PlaceableObject) +-- + -- Fill the bridge tables with player data. function FillBridgeTables() diff --git a/lib/client/markers.lua b/lib/client/markers.lua new file mode 100644 index 0000000..f587da3 --- /dev/null +++ b/lib/client/markers.lua @@ -0,0 +1,26 @@ +Marker = {} + +function Marker.DrawMarker(data) + 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 + DrawMarker( + marker, + pos.x, pos.y, pos.z, + 0.0, 0.0, 0.0, + rotation.x, rotation.y, rotation.z, + size.x, size.y, size.z, + color.r, color.g, color.b, alpha, + bobUpAndDown, false, false + ) +end + +exports("Marker", Marker) + +return Marker diff --git a/modules/utility/client/object_Placer.lua b/lib/client/object_Placer.lua similarity index 93% rename from modules/utility/client/object_Placer.lua rename to lib/client/object_Placer.lua index 73fd0c2..5a59a7a 100644 --- a/modules/utility/client/object_Placer.lua +++ b/lib/client/object_Placer.lua @@ -1,4 +1,5 @@ -Utility = Utility or {} +Placeable = Placeable or {} +Utility = Utility or Require("lib/client/utility.lua") local activePlacementProp = nil lib.locale() @@ -18,7 +19,7 @@ local function finishPlacing() activePlacementProp = nil end -Utility.PlaceObject = function(object, distance, snapToGround, allowedMats, offset) +Placeable.PlaceObject = function(object, distance, snapToGround, allowedMats, offset) if activePlacementProp then return end if not object then Prints.Error('no_prop_defined') end @@ -100,9 +101,10 @@ Utility.PlaceObject = function(object, distance, snapToGround, allowedMats, offs end end -Utility.StopPlacing = function() +Placeable.StopPlacing = function() if not activePlacementProp then return end finishPlacing() end +return Placeable -- This is derrived and slightly altered from its creator and licensed under GPL-3.0 license Author:Zoo, the original is located here https://github.com/Renewed-Scripts/Renewed-Lib/tree/main \ No newline at end of file diff --git a/lib/client/scaleform.lua b/lib/client/scaleform.lua new file mode 100644 index 0000000..31763cd --- /dev/null +++ b/lib/client/scaleform.lua @@ -0,0 +1,53 @@ +Scaleform = {} +local function SetupScaleform(scaleform, Buttons) + local scaleform = RequestScaleformMovie(scaleform) + local timeout = 5000 + while not HasScaleformMovieLoaded(scaleform) and timeout > 0 do + timeout = timeout - 1 + Wait(0) + end + assert(timeout > 0, 'Scaleform failed to load') + + 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() + end + return scaleform +end + +function Scaleform.SetupInstructionalButtons(buttons) + buttons = buttons or { + -- {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}, + -- {type = "SET_DATA_SLOT", name = config?.cancel_placement?.name or 'Cancel Placement:', keyIndex = config?.cancel_placement?.key or {222}, int = 4}, + -- {type = "SET_DATA_SLOT", name = config?.snap_to_ground?.name or 'Snap to Ground:', keyIndex = config?.snap_to_ground?.key or {19}, int = 1}, + -- {type = "SET_DATA_SLOT", name = config?.rotate?.name or 'Rotate:', keyIndex = config?.rotate?.key or {14, 15}, int = 2}, + -- {type = "SET_DATA_SLOT", name = config?.distance?.name or 'Distance:', keyIndex = config?.distance?.key or {14,15,36}, int = 3}, + -- {type = "SET_DATA_SLOT", name = config?.toggle_placement?.name or 'Toggle Placement:', keyIndex = config?.toggle_placement?.key or {199}, int = 0}, + -- {type = "DRAW_INSTRUCTIONAL_BUTTONS"}, + -- {type = "SET_BACKGROUND_COLOUR"}, + } + local scaleform = SetupScaleform("instructional_buttons", buttons) + return scaleform +end + +exports("Scaleform", Scaleform) +return Scaleform \ No newline at end of file diff --git a/modules/utility/client/utility.lua b/lib/client/utility.lua similarity index 91% rename from modules/utility/client/utility.lua rename to lib/client/utility.lua index 8bd9fd9..63d6fb3 100644 --- a/modules/utility/client/utility.lua +++ b/lib/client/utility.lua @@ -2,7 +2,16 @@ Utility = Utility or {} local blipIDs = {} local spawnedPeds = {} local ActivePoints = {} -lib.locale() + +Utility.CreateProp = function(model, coords, heading, networked) + if networked == nil then networked = true end + Utility.LoadModel(model) + if not HasModelLoaded(model) then return Prints.Error("Model Has Not Loaded") end + local propEntity = CreateObject(model, coords.x, coords.y, coords.z, networked, false, false) + SetEntityHeading(propEntity, heading) + SetModelAsNoLongerNeeded(model) + return propEntity +end Utility.CreateVehicle = function(model, coords, heading, networked) if networked == nil then networked = true end @@ -16,6 +25,24 @@ Utility.CreateVehicle = function(model, coords, heading, networked) return vehicle, { networkid = NetworkGetNetworkIdFromEntity(vehicle) or 0, coords = GetEntityCoords(vehicle), heading = GetEntityHeading(vehicle), } end +Utility.CreatePed = function(model, coords, heading, networked, clothing) + if networked == nil then networked = true end + Utility.LoadModel(model) + if not HasModelLoaded(model) then return Prints.Error("Model Has Not Loaded") end + local spawnedEntity = CreatePed(0, model, coords.x, coords.y, coords.z, heading, networked, false) + if clothing then + for componentID, v in pairs(clothing) do + SetPedComponentVariation(spawnedEntity, componentID, v[1], v[2], 0) + end + end + FreezeEntityPosition(spawnedEntity, true) + SetEntityInvincible(spawnedEntity, true) + SetBlockingOfNonTemporaryEvents(spawnedEntity, true) + SetModelAsNoLongerNeeded(model) + table.insert(spawnedPeds, spawnedEntity) + return spawnedEntity +end + Utility.StartBusySpinner = function(text) AddTextEntry(text, text) BeginTextCommandBusyString(text) @@ -27,16 +54,6 @@ Utility.StopBusySpinner = function() if BusyspinnerIsOn() then BusyspinnerOff() end end -Utility.CreateProp = function(model, coords, heading, networked) - if networked == nil then networked = true end - Utility.LoadModel(model) - if not HasModelLoaded(model) then return Prints.Error("Model Has Not Loaded") end - local propEntity = CreateObject(model, coords.x, coords.y, coords.z, networked, false, false) - SetEntityHeading(propEntity, heading) - SetModelAsNoLongerNeeded(model) - return propEntity -end - Utility.CreateBlip = function(coords, sprite, color, scale, label, shortRange) local blip = AddBlipForCoord(coords.x, coords.y, coords.z) SetBlipSprite(blip, sprite or 8) @@ -75,22 +92,14 @@ Utility.LoadModel = function(model) return HasModelLoaded(model) end -Utility.CreatePed = function(model, coords, heading, networked, clothing) - if networked == nil then networked = true end - Utility.LoadModel(model) - if not HasModelLoaded(model) then return Prints.Error("Model Has Not Loaded") end - local spawnedEntity = CreatePed(0, model, coords.x, coords.y, coords.z, heading, networked, false) - if clothing then - for componentID, v in pairs(clothing) do - SetPedComponentVariation(spawnedEntity, componentID, v[1], v[2], 0) - end +Utility.RequestAnimDict = function(dict) + RequestAnimDict(dict) + local count = 0 + while not HasAnimDictLoaded(dict) and count < 30000 do + Wait(0) + count = count + 1 end - FreezeEntityPosition(spawnedEntity, true) - SetEntityInvincible(spawnedEntity, true) - SetBlockingOfNonTemporaryEvents(spawnedEntity, true) - SetModelAsNoLongerNeeded(model) - table.insert(spawnedPeds, spawnedEntity) - return spawnedEntity + return HasAnimDictLoaded(dict) end Utility.RemovePed = function(entity) @@ -124,10 +133,12 @@ end Utility.GetEntitySkinData = function(entity) local skinData = {} - skinData.clothing = {} for i = 0, 11 do skinData.clothing[i] = {GetPedDrawableVariation(entity, i), GetPedTextureVariation(entity, i)} end + for i = 0, 13 do + skinData.props[i] = {GetPedPropIndex(entity, i), GetPedPropTextureIndex(entity, i)} + end return skinData end @@ -135,18 +146,12 @@ Utility.SetEntitySkinData = function(entity, skinData) for i = 0, 11 do SetPedComponentVariation(entity, i, skinData.clothing[i][1], skinData.clothing[i][2], 0) end + for i = 0, 13 do + SetPedPropIndex(entity, i, skinData.props[i][1], skinData.props[i][2], 0) + end return true end -Utility.NativeAlert = function(data) - local message = data.message or 'No message provided' - local coords = data.coords or GetEntityCoords(cache.ped) - local job = data.job - local scale = data.scale or 0.8 - local sprite = data.sprite or 1 - TriggerServerEvent('community_bridge:server:alert', {message = message, coords = coords, job = job, scale = scale, sprite = sprite}) -end - Utility.ReloadSkin = function() local skinData = Utility.GetEntitySkinData(cache.ped) Utility.SetEntitySkinData(cache.ped, skinData) @@ -160,10 +165,6 @@ Utility.ReloadSkin = function() return true end -Utility.RestoreAppearance = function(data) - return Utility.SetEntitySkinData(cache.ped, data) -end - Utility.HelpText = function(text, duration) AddTextEntry(text, text) BeginTextCommandDisplayHelp(text) @@ -176,16 +177,6 @@ Utility.NotifyText = function(text) DrawNotification(false, true) end -Utility.RequestAnimDict = function(dict) - RequestAnimDict(dict) - local count = 0 - while not HasAnimDictLoaded(dict) and count < 30000 do - Wait(0) - count = count + 1 - end - return HasAnimDictLoaded(dict) -end - Utility.TeleportPlayer = function(coords, conditionFunction, afterTeleportFunction) if conditionFunction ~= nil then if not conditionFunction() then @@ -251,7 +242,7 @@ Utility.RegisterPoint = function(pointCoords, pointDistance, pointOnEnter, point pointOnExit(self) end, }) - local pointID = Utility.CreateUniqueId(nil, 5, nil) + local pointID = Bridge.Ids.RandomLower(nil, 8) ActivePoints[pointID] = enterZone return enterZone, pointID end @@ -290,9 +281,6 @@ AddEventHandler('onResourceStop', function(resource) end end) -RegisterNetEvent('community_bridge:client:alert', function(data) - local blip = Utility.CreateBlip(data.coords, data.sprite, 3, data.scale, data.message, true) - SetTimeout(40000, function() - Utility.RemoveBlip(blip) - end) -end) \ No newline at end of file +exports('Utility', Utility) + +return Utility \ No newline at end of file diff --git a/lib/client/wip_gizmo.lua b/lib/client/wip_gizmo.lua new file mode 100644 index 0000000..2348b1c --- /dev/null +++ b/lib/client/wip_gizmo.lua @@ -0,0 +1,458 @@ +-- Credit: https://github.com/citizenfx/lua/blob/luaglm-dev/cfx/libs/scripts/examples/dataview.lua +local dataView = setmetatable({ + EndBig = ">", + EndLittle = "<", + Types = { + Int8 = { code = "i1" }, + Uint8 = { code = "I1" }, + Int16 = { code = "i2" }, + Uint16 = { code = "I2" }, + Int32 = { code = "i4" }, + Uint32 = { code = "I4" }, + Int64 = { code = "i8" }, + Uint64 = { code = "I8" }, + Float32 = { code = "f", size = 4 }, -- a float (native size) + Float64 = { code = "d", size = 8 }, -- a double (native size) + + LuaInt = { code = "j" }, -- a lua_Integer + UluaInt = { code = "J" }, -- a lua_Unsigned + LuaNum = { code = "n" }, -- a lua_Number + String = { code = "z", size = -1, }, -- zero terminated string + }, + + FixedTypes = { + String = { code = "c" }, -- a fixed-sized string with n bytes + Int = { code = "i" }, -- a signed int with n bytes + Uint = { code = "I" }, -- an unsigned int with n bytes + }, +}, { + __call = function(_, length) + return dataView.ArrayBuffer(length) + end +}) +dataView.__index = dataView + +--[[ Create an ArrayBuffer with a size in bytes --]] +function dataView.ArrayBuffer(length) + return setmetatable({ + blob = string.blob(length), + length = length, + offset = 1, + cangrow = true, + }, dataView) +end + +--[[ Wrap a non-internalized string --]] +function dataView.Wrap(blob) + return setmetatable({ + blob = blob, + length = blob:len(), + offset = 1, + cangrow = true, + }, dataView) +end + +--[[ Return the underlying bytebuffer --]] +function dataView:Buffer() return self.blob end +function dataView:ByteLength() return self.length end +function dataView:ByteOffset() return self.offset end +function dataView:SubView(offset, length) + return setmetatable({ + blob = self.blob, + length = length or self.length, + offset = 1 + offset, + cangrow = false, + }, dataView) +end + +--[[ Return the Endianness format character --]] +local function ef(big) return (big and dataView.EndBig) or dataView.EndLittle end + +--[[ Helper function for setting fixed datatypes within a buffer --]] +local function packblob(self, offset, value, code) + -- If cangrow is false the dataview represents a subview, i.e., a subset + -- of some other string view. Ensure the references are the same before + -- updating the subview + local packed = self.blob:blob_pack(offset, code, value) + if self.cangrow or packed == self.blob then + self.blob = packed + self.length = packed:len() + return true + else + return false + end +end + +--[[ + Create the API by using dataView.Types +--]] +for label,datatype in pairs(dataView.Types) do + if not datatype.size then -- cache fixed encoding size + datatype.size = string.packsize(datatype.code) + elseif datatype.size >= 0 and string.packsize(datatype.code) ~= datatype.size then + local msg = "Pack size of %s (%d) does not match cached length: (%d)" + error(msg:format(label, string.packsize(datatype.code), datatype.size)) + return nil + end + + dataView["Get" .. label] = function(self, offset, endian) + offset = offset or 0 + if offset >= 0 then + local o = self.offset + offset + local v,_ = self.blob:blob_unpack(o, ef(endian) .. datatype.code) + return v + end + return nil + end + + dataView["Set" .. label] = function(self, offset, value, endian) + if offset >= 0 and value then + local o = self.offset + offset + local v_size = (datatype.size < 0 and value:len()) or datatype.size + if self.cangrow or ((o + (v_size - 1)) <= self.length) then + if not packblob(self, o, value, ef(endian) .. datatype.code) then + error("cannot grow subview") + end + else + error("cannot grow dataview") + end + end + return self + end +end + +for label,datatype in pairs(dataView.FixedTypes) do + datatype.size = -1 -- Ensure cached encoding size is invalidated + + dataView["GetFixed" .. label] = function(self, offset, typelen, endian) + if offset >= 0 then + local o = self.offset + offset + if (o + (typelen - 1)) <= self.length then + local code = ef(endian) .. "c" .. tostring(typelen) + local v,_ = self.blob:blob_unpack(o, code) + return v + end + end + return nil -- Out of bounds + end + + dataView["SetFixed" .. label] = function(self, offset, typelen, value, endian) + if offset >= 0 and value then + local o = self.offset + offset + if self.cangrow or ((o + (typelen - 1)) <= self.length) then + local code = ef(endian) .. "c" .. tostring(typelen) + if not packblob(self, o, value, code) then + error("cannot grow subview") + end + else + error("cannot grow dataview") + end + end + return self + end +end + + +-- CREDITS +-- Andyyy7666: https://github.com/overextended/ox_lib/pull/453 +-- AvarianKnight: https://forum.cfx.re/t/allow-drawgizmo-to-be-used-outside-of-fxdk/5091845/8?u=demi-automatic +local dataview = dataView +local enableScale = false -- allow scaling mode. doesnt scale collisions and resets when physics are applied it seems +local gizmoEnabled = false +local currentMode = 'translate' +local isRelative = false +local currentEntity + +-- FUNCTIONS + +local function normalize(x, y, z) + local length = math.sqrt(x * x + y * y + z * z) + if length == 0 then + return 0, 0, 0 + end + return x / length, y / length, z / length +end + +local identityMatrix = { + vector3(1, 0, 0), + vector3(0, 1, 0), + vector3(0, 0, 1) +} +local function makeEntityMatrix(entity) + local f, r, u, a = GetEntityMatrix(entity) + local view = dataview.ArrayBuffer(60) + + view:SetFloat32(0, r[1]) + :SetFloat32(4, r[2]) + :SetFloat32(8, r[3]) + :SetFloat32(12, 0) + :SetFloat32(16, f[1]) + :SetFloat32(20, f[2]) + :SetFloat32(24, f[3]) + :SetFloat32(28, 0) + :SetFloat32(32, u[1]) + :SetFloat32(36, u[2]) + :SetFloat32(40, u[3]) + :SetFloat32(44, 0) + :SetFloat32(48, a[1]) + :SetFloat32(52, a[2]) + :SetFloat32(56, a[3]) + :SetFloat32(60, 1) + + return view +end + +local function applyEntityMatrix(entity, view) + local x1, y1, z1 = view:GetFloat32(16), view:GetFloat32(20), view:GetFloat32(24) + local x2, y2, z2 = view:GetFloat32(0), view:GetFloat32(4), view:GetFloat32(8) + local x3, y3, z3 = view:GetFloat32(32), view:GetFloat32(36), view:GetFloat32(40) + local tx, ty, tz = view:GetFloat32(48), view:GetFloat32(52), view:GetFloat32(56) + + if not enableScale then + x1, y1, z1 = normalize(x1, y1, z1) + x2, y2, z2 = normalize(x2, y2, z2) + x3, y3, z3 = normalize(x3, y3, z3) + end + + SetEntityMatrix(entity, + x1, y1, z1, + x2, y2, z2, + x3, y3, z3, + tx, ty, tz + ) +end + +-- LOOPS + +function RegisterButtonHandler(button, onPressed, onReleased) + onPressed = onPressed and type(onPressed) == 'function' and onPressed + onReleased = onReleased and type(onReleased) == 'function' and onReleased + DisableControlAction(0, button, true) + local pressed = IsDisabledControlJustPressed(0, button) + local released = IsDisabledControlJustReleased(0, button) + return (pressed and onPressed and onPressed()) or (released and onReleased and onReleased()) +end + + +local function gizmoLoop(entity, onConfirm, onUpdate, onCancel) + entity = tonumber(entity) + EnterCursorMode() + + if IsEntityAPed(entity) then + SetEntityAlpha(entity, 200) + else + SetEntityDrawOutline(entity, true) + end + + while gizmoEnabled and DoesEntityExist(entity) do + Wait(0) + + DisableControlAction(0, 24, true) -- lmb + DisableControlAction(0, 25, true) -- rmb + DisableControlAction(0, 140, true) -- r + DisableControlAction(0, 245, true) --t + DisablePlayerFiring(PlayerId(), true) + SetEntityCollision(entity, false, false) + FreezeEntityPosition(entity, false) + local matrixBuffer = makeEntityMatrix(entity) + local changed = DrawGizmo(matrixBuffer:Buffer(), 'Editor1') + if changed then + print(GetEntityCoords(entity)) + applyEntityMatrix(entity, matrixBuffer) + SetEntityCoords(entity, GetEntityCoords(entity)) + end + + if onUpdate and type(onUpdate) == 'function' then onUpdate(entity, GetEntityCoords(entity), GetEntityRotation(entity)) end + --controles + --frontend confirm 18 [ENTER] + RegisterButtonHandler(191, function() + if not gizmoEnabled then return end + gizmoEnabled = false + if onConfirm and type(onConfirm) == 'function' then onConfirm(entity, GetEntityCoords(entity), GetEntityRotation(entity)) end + end) + --frontend cancel 202 [BACKSPACE] + RegisterButtonHandler(202, function() + if not gizmoEnabled then return end + gizmoEnabled = false + if onCancel and type(onCancel) == 'function' then onCancel(entity, GetEntityCoords(entity), GetEntityRotation(entity)) end + CreateThread(function() + local timeout = 100 + while timeout > 0 do + DisableFrontendThisFrame() + timeout = timeout - 1 + Wait(1) + end + end) + end) + --register e + RegisterButtonHandler(38, function() + if not gizmoEnabled then return end + gizmoEnabled = false + local playerPos = GetEntityCoords(PlayerPedId()) + local entityPos = GetFinalRenderedCamCoord() + local depth = #(playerPos - entityPos) -- Vector3 distance + PlaceableObject.Create({spawned = entity}, nil, onConfirm, onUpdate, onCancel, {depth = depth}) + end) + + --ctrl + RegisterButtonHandler(36, function() + if not gizmoEnabled then return end + LeaveCursorMode() + end, function() + EnterCursorMode() + end) + + RegisterButtonHandler(19, function() + if not gizmoEnabled then return end + PlaceObjectOnGroundProperly_2(currentEntity) + end) + FreezeEntityPosition(entity, false) + end + + LeaveCursorMode() + + if DoesEntityExist(entity) then + if IsEntityAPed(entity) then SetEntityAlpha(entity, 255) end + SetEntityDrawOutline(entity, false) + end + + gizmoEnabled = false + currentEntity = nil + return true +end + +-- local function textUILoop() +-- CreateThread(function() +-- while gizmoEnabled do +-- Wait(100) +-- local scaleText = (enableScale and '[S] - Scale Mode \n') or '' +-- lib.showTextUI( +-- ('Current Mode: %s | %s \n'):format(currentMode, (isRelative and 'Relative') or 'World') .. +-- '[W] - Translate Mode \n' .. +-- '[R] - Rotate Mode \n' .. +-- scaleText .. +-- '[Q] - Relative/World \n' .. +-- '[LALT] - Snap To Ground \n' .. +-- '[ENTER] - Done Editing \n' +-- ) +-- end +-- lib.hideTextUI() +-- end) +-- end + +-- EXPORTS + + +local function useGizmo(entity, onConfirm, onUpdate, onCancel) + gizmoEnabled = true + currentEntity = entity + -- textUILoop() + gizmoLoop(entity, onConfirm, onUpdate, onCancel) + + return { + handle = entity, + position = GetEntityCoords(entity), + rotation = GetEntityRotation(entity) + } +end + +exports("useGizmo", useGizmo) + +Gizmo = {} +local running = false +function Gizmo.UseGizmo(obj, onConfirm, onUpdate, onCancel) + if running then return end + running = true + + --instructional buttons + local scaleform = Scaleform.SetupInstructionalButtons({ + {type = "CLEAR_ALL"}, + {type = "SET_CLEAR_SPACE", int = 200}, + {type = "SET_DATA_SLOT", name = 'Translate:', keyIndex = {245}, int = 1}, + {type = "SET_DATA_SLOT", name = 'Scale:', keyIndex = {33}, int = 2}, + {type = "SET_DATA_SLOT", name = 'Rotate:', keyIndex = {45}, int = 3}, + {type = "SET_DATA_SLOT", name = 'Snap to Ground:', keyIndex = {19}, int = 4}, + {type = "SET_DATA_SLOT", name = 'Toggle Camera:', keyIndex = {36}, int = 5}, + {type = "SET_DATA_SLOT", name = 'Cancel Placement:', keyIndex = {202}, int = 6}, + {type = "SET_DATA_SLOT", name = 'Toggle Gizmo:', keyIndex = {38}, int = 7}, + {type = "DRAW_INSTRUCTIONAL_BUTTONS"}, + {type = "SET_BACKGROUND_COLOUR"}, + }) + local quit = false + CreateThread(function() + while not quit do + DrawScaleformMovieFullscreen(scaleform, 255, 255, 255, 255, 0) + Wait(0) + end + running = false + end) + + quit = useGizmo(obj, onConfirm, onUpdate, onCancel) + running = false +end +exports("UseGizmo", Gizmo.UseGizmo) + + +--got rid of the cancer +-- lib.addKeybind({ +-- name = '_gizmoLocal', +-- description = 'toggle gizmo to be local to the entity instead of world', +-- defaultKey = 'Q', +-- onPressed = function(self) +-- if not gizmoEnabled then return end +-- isRelative = not isRelative +-- ExecuteCommand('+gizmoLocal') +-- end, +-- onReleased = function (self) +-- ExecuteCommand('-gizmoLocal') +-- end +-- }) + +-- lib.addKeybind({ +-- name = 'gizmoclose', +-- description = 'close gizmo', +-- defaultKey = 'RETURN', +-- onPressed = function(self) +-- if not gizmoEnabled then return end +-- gizmoEnabled = false +-- end, +-- }) + +-- lib.addKeybind({ +-- name = 'gizmoSnapToGround', +-- description = 'snap current gizmo object to floor/surface', +-- defaultKey = 'LMENU', +-- onPressed = function(self) +-- if not gizmoEnabled then return end +-- PlaceObjectOnGroundProperly_2(currentEntity) +-- end, +-- }) + +-- if enableScale then +-- lib.addKeybind({ +-- name = '_gizmoScale', +-- description = 'Sets mode for the gizmo to scale', +-- defaultKey = 'S', +-- onPressed = function(self) +-- if not gizmoEnabled then return end +-- currentMode = 'Scale' +-- ExecuteCommand('+gizmoScale') +-- end, +-- onReleased = function (self) +-- ExecuteCommand('-gizmoScale') +-- end +-- }) +-- end + + +--onreousrcestop + +AddEventHandler('onResourceStop', function(resource) + if resource == GetCurrentResourceName() then + if not gizmoEnabled then return end + gizmoEnabled = false + LeaveCursorMode() + end +end) + +return Gizmo \ No newline at end of file diff --git a/lib/client/wip_object_placer.lua b/lib/client/wip_object_placer.lua new file mode 100644 index 0000000..a849e6c --- /dev/null +++ b/lib/client/wip_object_placer.lua @@ -0,0 +1,168 @@ +Scaleform = Scaleform or Require("client/scaleform.lua") +Utility = Utility or Require("client/utility.lua") +Gizmo = Gizmo or Require("client/gizmo.lua") + +PlaceableObject = PlaceableObject or {} +local data = { + entity = nil, + placing = false, +} + +function PlaceableObject.Eyetrace(depth, disableSphere) + local screenX = GetDisabledControlNormal(0, 239) + local screenY = GetDisabledControlNormal(0, 240) + + local world, normal = GetWorldCoordFromScreenCoord(screenX, screenY) + local playerPos = GetEntityCoords(PlayerPedId()) + local target = playerPos + normal * depth + if not disableSphere then + DrawSphere(target.x, target.y, target.z, 0.5, 255, 0, 0, 0.5) + end + return target +end + +-- Creates a placeable object in the game world. +-- @param model (string) The model of the object to create. +-- @param onConfirm (function) [optional] The callback function to execute when the object is confirmed. +-- @param onUpdate (function) [optional] The callback function to execute when the object is moved. +-- @param onCancel (function) [optional] The callback function to execute when the object is canceled. +-- @param settings (table) [optional] Additional settings for the placeable object. +-- - depthMin (number) The minimum depth for the object placement. Default is 2.0. +-- - depthMax (number) The maximum depth for the object placement. Default is 10.0. +-- - rotationStep (number) The rotation step for the object. Default is 15.0. +-- - depthStep (number) The depth step for the object. Default is 1.0. +function PlaceableObject.Create(data, model, onConfirm, onUpdate, onCancel, settings, config) + local settings = settings or {} + local depthMin = settings.depthMin or 2.0 + depthMax = settings.depthMax or 10.0 + rotationStep = settings.rotationStep or 15.0 + depthStep = settings.depthStep or 1.0 + local depth = settings.depth or 10.0 + print(depth) + data.placing = true + data.paused = false + local initialPos = nil + local placeOnGround = true + + --scaleform + local scaleform = Scaleform.SetupInstructionalButtons({ + {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}, + {type = "SET_DATA_SLOT", name = config?.cancel_placement?.name or 'Cancel Placement:', keyIndex = config?.cancel_placement?.key or {222}, int = 4}, + {type = "SET_DATA_SLOT", name = config?.snap_to_ground?.name or 'Snap to Ground:', keyIndex = config?.snap_to_ground?.key or {19}, int = 1}, + {type = "SET_DATA_SLOT", name = config?.rotate?.name or 'Rotate:', keyIndex = config?.rotate?.key or {14, 15}, int = 2}, + {type = "SET_DATA_SLOT", name = config?.distance?.name or 'Distance:', keyIndex = config?.distance?.key or {14,15,36}, int = 3}, + {type = "SET_DATA_SLOT", name = config?.toggle_placement?.name or 'Toggle Placement:', keyIndex = config?.toggle_placement?.key or {199}, int = 0}, + {type = "SET_DATA_SLOT", name = config?.gizmo?.name or 'Toggle Gizmo:', keyIndex = config?.gizmo?.key or {38}, int = 6}, + {type = "DRAW_INSTRUCTIONAL_BUTTONS"}, + {type = "SET_BACKGROUND_COLOUR"}, + }) + CreateThread(function() + local heading = -GetEntityHeading(PlayerPedId()) + + local pos = PlaceableObject.Eyetrace(depth) + if not data.spawned and model then + --get player heading + local obj = Utility.CreateProp(model, pos, vector3(0, 0, heading), nil) + data.spawned = obj + end + assert(data.spawned, "Failed to create object") + SetEntityCollision(data.spawned, false, false) + SetEntityAlpha(data.spawned, 150, false) + + SetPedConfigFlag(PlayerPedId(), 146, true) + SetCanClimbOnEntity(data.spawned, false) + SetEntityCompletelyDisableCollision(data.spawned, true, false) + SetEntityNoCollisionEntity(PlayerPedId(), data.spawned, false) + + while data.placing do + if data.paused then goto continue end + DrawScaleformMovieFullscreen(scaleform, 255, 255, 255, 255, 0) + DisableControlAction(0, 24, true) -- Attack + DisableControlAction(0, 25, true) -- Aim + DisableControlAction(0, 36, true) -- INPUT_DUCK. + + if IsControlJustPressed(0, 223) then -- left click + if onConfirm and type(onConfirm) == 'function' then onConfirm(data.spawned, pos, heading) end + data.placing = false + end + + if IsControlJustPressed(0, 222) then -- right click + data.placing = false + if onCancel and type(onCancel) == 'function' then + onCancel(data.spawned, pos, heading) + else + DeleteEntity(data.spawned) + end + return + end + + if IsControlPressed(0,19) then + placeOnGround = not (placeOnGround or false) + end + + if IsControlJustPressed(0, 38) then -- TAB key to switch to gizmo + data.placing = false + return Gizmo.UseGizmo(data.spawned, onConfirm, onUpdate, onCancel) + end + + if IsControlPressed(0,224) then -- left ctrl + if IsControlJustPressed(0, 261) then -- scroll up + depth = depth + depthStep + if depth > depthMax then + depth = depthMax + end + end + + if IsControlJustPressed(0, 262) then -- scroll down + depth = depth - depthStep + if depth < depthMin then + depth = depthMin + end + end + else + if IsControlJustPressed(0, 261) then -- scroll up + heading = heading + rotationStep + if heading > 360 then + heading = 0 + end + end + if IsControlJustPressed(0, 262) then -- scroll down + heading = heading - rotationStep + if heading < 0 then + heading = 360 + end + end + end + + pos = PlaceableObject.Eyetrace(depth) + if data.spawned then + SetEntityCoords(data.spawned, pos.x, pos.y, pos.z) + SetEntityHeading(data.spawned, heading) + if placeOnGround then + PlaceObjectOnGroundProperly(data.spawned) + pos = GetEntityCoords(data.spawned) + end + end + if onUpdate and type(onUpdate) == 'function' then onUpdate(data.spawned, pos, heading) end + ::continue:: + if IsControlJustPressed(0, 199) then -- home + data.paused = not data.paused + end + Wait(1) + end + end) +end + + + +RegisterCommand("testers", function() + PlaceableObject.Create({}, "prop_beachflag_01", function(entity, pos, heading) + + end, function(entity, pos, heading) + + end, function(entity, pos, heading) + + end) +end) diff --git a/lib/init.lua b/lib/init.lua new file mode 100644 index 0000000..91a1c9d --- /dev/null +++ b/lib/init.lua @@ -0,0 +1,69 @@ +loadedModules = {} + +function Require(modulePath, resourceName) + if resourceName and type(resourceName) ~= "string" then + resourceName = GetCurrentResourceName() + end + + if not resourceName then + resourceName = "community_bridge" + end + + local id = resourceName .. ":" .. modulePath + if loadedModules[id] then + if BridgeSharedConfig.DebugLevel ~= 0 then + print("^2 Returning cached module [" .. id .. "] ^0") + end + return loadedModules[id] + end + + local file = LoadResourceFile(resourceName, modulePath) + if not file then + error("Error loading file [" .. id .. "]") + end + + local chunk, loadErr = load(file, id) + if not chunk then + error("Error wrapping module [" .. id .. "] Message: " .. loadErr) + end + + local success, result = pcall(chunk) + if not success then + error("Error executing module [" .. id .. "] Message: " .. result) + end + loadedModules[id] = result + return result +end + +cLib = { + Require = Require, + Callback = Callback or Require("lib/shared/callbacks.lua"), + Ids = Ids or Require("lib/shared/ids.lua"), + ReboundEntities = ReboundEntities or Require("lib/shared/rebound_entities.lua"), + Tables = Tables or Require("lib/shared/tables.lua"), + Prints = Prints or Require("lib/shared/prints.lua"), + Math = Math or Require("lib/shared/math.lua"), + LA = LA or Require("lib/shared/la.lua"), + Perlin = Perlin or Require("lib/shared/perlin.lua"), + Actions = Actions or Require("lib/shared/actions.lua"), +} + +exports('cLib', cLib) + +if not IsDuplicityVersion() then goto client end + +cLib.SQL = SQL or Require("lib/server/sqlHandler.lua") +cLib.Logs = Logs or Require("lib/server/logs.lua") +cLib.LootTables = LootTables or Require("lib/server/lootTables.lua") + +if IsDuplicityVersion() then return cLib end +::client:: + +-- cLib.Gizmo = Gizmo or Require("lib/client/gizmo.lua") +-- cLib.Scaleform = Scaleform or Require("lib/client/scaleform.lua") +cLib.Placeable = Placeable or Require("lib/client/object_placer.lua") +cLib.Utility = Utility or Require("lib/client/utility.lua") +-- cLib.PlaceableObject = PlaceableObject or Require("lib/client/object_placer.lua") + + +return cLib \ No newline at end of file diff --git a/modules/utility/server/logs.lua b/lib/server/logs.lua similarity index 77% rename from modules/utility/server/logs.lua rename to lib/server/logs.lua index e8c8d8d..843881c 100644 --- a/modules/utility/server/logs.lua +++ b/lib/server/logs.lua @@ -1,15 +1,15 @@ -Utility = Utility or {} +Logs = Logs or {} -local WebhookURL = BridgeServerConfig.WebhookURL -local LogoForEmbed = BridgeServerConfig.WebhookImage +local WebhookURL = "" +local LogoForEmbed = "" -Utility.SendLog = function(src, message) +Logs.Send = function(src, message) if not src or not message then return end if BridgeServerConfig.LogSystem == "builtin" then PerformHttpRequest(WebhookURL, function(err, text, headers) end, 'POST', json.encode( { username = "Community_Bridge's Logger", - avatar_url = 'https://cdn.discordapp.com/avatars/299410129982455808/31ce635662206e8bd0132c34ce9ce683?size=1024', + avatar_url = 'https://avatars.githubusercontent.com/u/192999457?s=400&u=da632e8f64c85def390cfd1a73c3b664d6882b38&v=4', embeds = { { color = "15769093", @@ -36,8 +36,8 @@ Utility.SendLog = function(src, message) }, timestamp = os.date('!%Y-%m-%dT%H:%M:%S'), footer = { - text = "Community_Bridge | "..GetCurrentResourceName(), - icon_url = 'https://cdn.discordapp.com/avatars/299410129982455808/31ce635662206e8bd0132c34ce9ce683?size=1024', + text = "Community_Bridge | ", + icon_url = 'https://avatars.githubusercontent.com/u/192999457?s=400&u=da632e8f64c85def390cfd1a73c3b664d6882b38&v=4', }, } } @@ -47,4 +47,7 @@ Utility.SendLog = function(src, message) elseif BridgeServerConfig.LogSystem == "ox" then return exports.ox_lib:logger(src, GetCurrentResourceName(), message) end -end \ No newline at end of file +end + +exports('Logs', Logs) +return Logs \ No newline at end of file diff --git a/modules/utility/server/lootTables.lua b/lib/server/lootTables.lua similarity index 81% rename from modules/utility/server/lootTables.lua rename to lib/server/lootTables.lua index 9244c54..9adc49d 100644 --- a/modules/utility/server/lootTables.lua +++ b/lib/server/lootTables.lua @@ -1,8 +1,8 @@ -Utility = Utility or {} +LootTable = LootTable or {} local lootTables = {} -Utility.RegisterLootTable = function(name, items) +LootTable.Register = function(name, items) local repackedTable = {} for k, v in pairs(items) do table.insert(repackedTable, { @@ -19,12 +19,12 @@ Utility.RegisterLootTable = function(name, items) return lootTables[name] end -Utility.GetLootTable = function(name) +LootTable.Get = function(name) assert(name, "No Name Passed For Loot Table") return lootTables[name] or {} end -Utility.GetRandomItem = function(name, tier, randomNumber) +LootTable.GetRandomItem = function(name, tier, randomNumber) assert(name, "No Name Passed For Loot Table") if tier == nil then tier = 1 end local lootTable = lootTables[name] or {} @@ -37,10 +37,10 @@ Utility.GetRandomItem = function(name, tier, randomNumber) end end -Utility.GetRandomItems = function(name, tier, randomNumber) +LootTable.GetRandomItems = function(name, tier, randomNumber) assert(name, "No Name Passed For Loot Table") if tier == nil then tier = 1 end - local lootTable = Utility.GetLootTable(name) + local lootTable = LootTable.Get(name) math.randomseed(GetGameTimer()) local chance = randomNumber or math.random(1, 100) local items = {} @@ -52,10 +52,10 @@ Utility.GetRandomItems = function(name, tier, randomNumber) return items end -Utility.GetRandomItemsWithLimit = function(name, tier, randomNumber) +LootTable.GetRandomItemsWithLimit = function(name, tier, randomNumber) assert(name, "No Name Passed For Loot Table") if tier == nil then tier = 1 end - local lootTable = Utility.GetLootTable(name) + local lootTable = LootTable.Get(name) math.randomseed(GetGameTimer()) local chance = randomNumber or math.random(1, 100) local items = {} @@ -67,4 +67,8 @@ Utility.GetRandomItemsWithLimit = function(name, tier, randomNumber) end end return items -end \ No newline at end of file +end +-- + +exports('LootTable', LootTable) +return LootTable \ No newline at end of file diff --git a/lib/server/sqlHandler.lua b/lib/server/sqlHandler.lua new file mode 100644 index 0000000..aa329c7 --- /dev/null +++ b/lib/server/sqlHandler.lua @@ -0,0 +1,66 @@ +SQL = {} + +Require("lib/MySQL.lua", "oxmysql") + +function SQL.Create(tableName, columns) + assert(MySQL, "Tried using module SQL without MySQL being loaded") + local columnsList = {} + for i, column in pairs(columns) do + table.insert(columnsList, string.format("%s %s", column.name, column.type)) + end + + local query = string.format("CREATE TABLE IF NOT EXISTS %s (%s);", + tableName, + table.concat(columnsList, ", ") + ) + + MySQL.query.await(query) +end + +-- insert if not exist otherwise update +function SQL.InsertOrUpdate(tableName, data) + assert(MySQL, "Tried using module SQL without MySQL being loaded") + local columns = {} + local values = {} + local updates = {} + + for column, value in pairs(data) do + table.insert(columns, column) + table.insert(values, "'" .. value .. "'") -- Ensure values are properly quoted + table.insert(updates, column .. " = VALUES(" .. column .. ")") -- Use VALUES() for update + end + + local query = string.format( + "INSERT INTO %s (%s) VALUES (%s) ON DUPLICATE KEY UPDATE %s;", + tableName, + table.concat(columns, ", "), + table.concat(values, ", "), + table.concat(updates, ", ") + ) + + MySQL.query.await(query) +end + +function SQL.Get(tableName, where) + assert(MySQL, "Tried using module SQL without MySQL being loaded") + local query = string.format("SELECT * FROM %s WHERE %s;", tableName, where) + local result = MySQL.query.await(query) + return result +end + +function SQL.GetAll(tableName) + assert(MySQL, "Tried using module SQL without MySQL being loaded") + local query = string.format("SELECT * FROM %s;", tableName) + local result = MySQL.query.await(query) + return result +end + +function SQL.Delete(tableName, where) + assert(MySQL, "Tried using module SQL without MySQL being loaded") + local query = string.format("DELETE FROM %s WHERE %s;", tableName, where) + MySQL.query.await(query) +end + +exports('SQL', SQL) + +return SQL \ No newline at end of file diff --git a/lib/shared/actions.lua b/lib/shared/actions.lua new file mode 100644 index 0000000..1725820 --- /dev/null +++ b/lib/shared/actions.lua @@ -0,0 +1,49 @@ +local Actions = {} +Action = {} + + +if not IsDuplicityVersion() then goto client end + +function Action.Fire(id, players, ...) + local action = Actions[id] + if not action then return end + if type(players) == "table" then + for _, player in ipairs(players) do + TriggerClientEvent(GetCurrentResourceName() .. "client:Action", tonumber(player), id, ...) + end + return + end + TriggerClientEvent(GetCurrentResourceName() .. "client:Action", tonumber(players or -1), id, ...) +end + +if IsDuplicityVersion() then return Actions end +::client:: + +function Action.Create(id, action) + assert(type(id) == "string", "id must be a string") + assert(type(action) == "function", "action must be a function") + Actions[id] = action +end + +function Action.Remove(id) + Actions[id] = nil +end + +function Action.Get(id) + return Actions[id] +end + +function Action.GetAll() + return Actions +end + +RegisterNetEvent(GetCurrentResourceName() .. "client:Action", function(id, ...) + local action = Actions[id] + if not action then return end + action(...) +end) + +exports("Action", Action) +return Action + + diff --git a/modules/utility/shared/callbacks.lua b/lib/shared/callbacks.lua similarity index 97% rename from modules/utility/shared/callbacks.lua rename to lib/shared/callbacks.lua index 72977c9..7b23e0e 100644 --- a/modules/utility/shared/callbacks.lua +++ b/lib/shared/callbacks.lua @@ -12,10 +12,10 @@ local serverToClientName = resource .. ':client:SC:TriggerCallback' local serverToClientBackToServerName = resource .. ':server:SCS:TriggerCallback' +exports('Callback', Callback) + if not IsDuplicityVersion() then goto client end - - -- -- -- -- -- -- -- -- -- -- -- ▄▀▀ ██▀ █▀▄ █ █ ██▀ █▀▄ -- ▄█▀ █▄▄ █▀▄ ▀▄▀ █▄▄ █▀▄ @@ -79,7 +79,7 @@ exports('TriggerCallback', Callback.Trigger) -- ▄▀▀ █ █ ██▀ █▄ █ ▀█▀ -- ▀▄▄ █▄▄ █ █▄▄ █ ▀█ █ -- -- -- -- -- -- -- -- -- -- -if IsDuplicityVersion() then return end +if IsDuplicityVersion() then return Callback end ::client:: @@ -143,3 +143,4 @@ exports('RegisterCallback', Callback.Register) exports('RegisterRebound', Callback.RegisterRebound) exports('TriggerCallback', Callback.Trigger) +return Callback \ No newline at end of file diff --git a/lib/shared/ids.lua b/lib/shared/ids.lua new file mode 100644 index 0000000..17a3099 --- /dev/null +++ b/lib/shared/ids.lua @@ -0,0 +1,44 @@ +Ids = Ids or {} +-- for unique ids +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 + len = len or 8 + + local id = "" + for i = 1, len do + local char = "" + if pattern then + char = pattern:sub(math.random(1, #pattern), math.random(1, #pattern)) + else + char = math.random(1, 2) == 1 and string.char(math.random(65, 90)) or math.random(0, 9) -- CAP letter and number + end + id = id .. char + end + if tbl[id] then + return Ids.CreateUniqueId(tbl, len, pattern) + end + return id +end + +Ids.RandomUpper = function(tbl, len) + return Ids.CreateUniqueId(tbl, len, "ABCDEFGHIJKLMNOPQRSTUVWXYZ") +end + +Ids.RandomLower = function(tbl, len) + return Ids.CreateUniqueId(tbl, len, "abcdefghijklmnopqrstuvwxyz") +end + +Ids.RandomString = function(tbl, len) + return Ids.CreateUniqueId(tbl, len, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") +end + +Ids.RandomNumber = function(tbl, len) + return Ids.CreateUniqueId(tbl, len, "0123456789") +end + +Ids.Random = function(tbl, len) + return Ids.CreateUniqueId(tbl, len) +end + +exports("Ids", Ids) +return Ids \ No newline at end of file diff --git a/use/linear_algebra.lua b/lib/shared/la.lua similarity index 98% rename from use/linear_algebra.lua rename to lib/shared/la.lua index a391a0a..20b0987 100644 --- a/use/linear_algebra.lua +++ b/lib/shared/la.lua @@ -1,4 +1,5 @@ LA = LA or {} + --https://easings.net LA.Lerp = function(a, b, t) return a + (b - a) * t @@ -355,6 +356,10 @@ LA.Circle = function(t, radius, center) return vector3(x, y, center.z) end +LA.Clamp = function(value, min, max) + return math.min(math.max(value, min), max) +end + LA.CrossProduct = function(a, b) local x = a.y * b.z - a.z * b.y local y = a.z * b.x - a.x * b.z @@ -397,6 +402,8 @@ LA.MultiplyMatrixByVector = function(m, v) return result end +exports('LA', LA) +return LA -- local easingTypes = { -- "linear", diff --git a/lib/shared/math.lua b/lib/shared/math.lua new file mode 100644 index 0000000..196e749 --- /dev/null +++ b/lib/shared/math.lua @@ -0,0 +1,50 @@ +Math = {} + +function Math.Clamp(value, min, max) + return math.min(math.max(value, min), max) +end + +function Math.Remap(value, min, max, newMin, newMax) + return newMin + (value - min) / (max - min) * (newMax - newMin) +end + +function Math.PointInRadius(radius) + local angle = math.rad(math.random(0, 360)) + return vector2(radius * math.cos(angle), radius * math.sin(angle)) +end + +function Math.Normalize(value, min, max) + if max == min then return 0 end -- Avoid division by zero + return (value - min) / (max - min) +end + +function Math.Normalize2D(x, y) + if type(x) == "vector2" then + x, y = x.x, x.y + end + local length = math.sqrt(x*x + y*y) + return length ~= 0 and vector2(x / length, y / length) or vector2(0, 0) +end + +function Math.Normalize3D(x, y, z) + if type(x) == "vector3" then + x, y, z = x.x, x.y, x.z + end + local length = math.sqrt(x*x + y*y + z*z) + return length ~= 0 and vector3(x / length, y / length, z / length) or vector3(0, 0, 0) +end + +function Math.Normalize4D(x, y, z, w) + if type(x) == "vector4" then + x, y, z, w = x.x, x.y, x.z, x.w + end + local length = math.sqrt(x*x + y*y + z*z + w*w) + return length ~= 0 and vector4(x / length, y / length, z / length, w / length) or vector4(0, 0, 0, 0) +end + +function Math.DirectionToTarget(fromV3, toV3) + return Math.Normalize3D(toV3.x - fromV3.x, toV3.y - fromV3.y, toV3.z - fromV3.z) +end + +exports('Math', Math) +return Math \ No newline at end of file diff --git a/lib/shared/perlin.lua b/lib/shared/perlin.lua new file mode 100644 index 0000000..36ff967 --- /dev/null +++ b/lib/shared/perlin.lua @@ -0,0 +1,110 @@ +local Perlin = {} + +-- Permutation table for random gradients +local perm = {} +local grad3 = { + {1,1,0}, {-1,1,0}, {1,-1,0}, {-1,-1,0}, + {1,0,1}, {-1,0,1}, {1,0,-1}, {-1,0,-1}, + {0,1,1}, {0,-1,1}, {0,1,-1}, {0,-1,-1} +} + +-- Initialize permutation table +local function ShufflePermutation() + local p = {} + for i = 0, 255 do + p[i] = i + end + for i = 255, 1, -1 do + local j = math.random(i + 1) - 1 + p[i], p[j] = p[j], p[i] + end + for i = 0, 255 do + perm[i] = p[i] + perm[i + 256] = p[i] -- Repeat for wrapping + end +end + +ShufflePermutation() -- Randomize on load + +-- Dot product helper +local function Dot(g, x, y, z) + return g[1] * x + g[2] * y + (z and g[3] * z or 0) +end + +-- Fade function (smootherstep) +local function Fade(t) + return t * t * t * (t * (t * 6 - 15) + 10) +end + +-- Linear interpolation +local function Lerp(a, b, t) + return a + (b - a) * t +end + +-- **Perlin Noise 1D** +function Perlin.Noise1D(x) + local X = math.floor(x) & 255 + x = x - math.floor(x) + local u = Fade(x) + + local a = perm[X] + local b = perm[X + 1] + + return Lerp(a, b, u) * (2 / 255) - 1 +end + +-- **Perlin Noise 2D** +function Perlin.Noise2D(x, y) + local X = math.floor(x) & 255 + local Y = math.floor(y) & 255 + x, y = x - math.floor(x), y - math.floor(y) + + local u, v = Fade(x), Fade(y) + + local aa = perm[X] + Y + local ab = perm[X] + Y + 1 + local ba = perm[X + 1] + Y + local bb = perm[X + 1] + Y + 1 + + return Lerp( + Lerp(Dot(grad3[perm[aa] % 12 + 1], x, y), Dot(grad3[perm[ba] % 12 + 1], x - 1, y), u), + Lerp(Dot(grad3[perm[ab] % 12 + 1], x, y - 1), Dot(grad3[perm[bb] % 12 + 1], x - 1, y - 1), u), + v + ) +end + +-- **Perlin Noise 3D** +function Perlin.Noise3D(x, y, z) + local X = math.floor(x) & 255 + local Y = math.floor(y) & 255 + local Z = math.floor(z) & 255 + x, y, z = x - math.floor(x), y - math.floor(y), z - math.floor(z) + + local u, v, w = Fade(x), Fade(y), Fade(z) + + local aaa = perm[X] + Y + Z + local aba = perm[X] + Y + Z + 1 + local aab = perm[X] + Y + 1 + Z + local abb = perm[X] + Y + 1 + Z + 1 + local baa = perm[X + 1] + Y + Z + local bba = perm[X + 1] + Y + Z + 1 + local bab = perm[X + 1] + Y + 1 + Z + local bbb = perm[X + 1] + Y + 1 + Z + 1 + + return Lerp( + Lerp( + Lerp(Dot(grad3[perm[aaa] % 12 + 1], x, y, z), Dot(grad3[perm[baa] % 12 + 1], x - 1, y, z), u), + Lerp(Dot(grad3[perm[aab] % 12 + 1], x, y - 1, z), Dot(grad3[perm[bab] % 12 + 1], x - 1, y - 1, z), u), + v + ), + Lerp( + Lerp(Dot(grad3[perm[aba] % 12 + 1], x, y, z - 1), Dot(grad3[perm[bba] % 12 + 1], x - 1, y, z - 1), u), + Lerp(Dot(grad3[perm[abb] % 12 + 1], x, y - 1, z - 1), Dot(grad3[perm[bbb] % 12 + 1], x - 1, y - 1, z - 1), u), + v + ), + w + ) +end + +exports('Perlin', Perlin) +return Perlin diff --git a/modules/utility/shared/prints.lua b/lib/shared/prints.lua similarity index 96% rename from modules/utility/shared/prints.lua rename to lib/shared/prints.lua index a3198ac..2fc00ef 100644 --- a/modules/utility/shared/prints.lua +++ b/lib/shared/prints.lua @@ -1,5 +1,4 @@ Prints = Prints or {} - local function printMessage(level, color, message) if type(message) == 'table' then message = json.encode(message) @@ -21,4 +20,6 @@ end Prints.Debug = function(message) printMessage('DEBUG', '^2', message) -end \ No newline at end of file +end + +return Prints \ No newline at end of file diff --git a/lib/shared/rebound_entities.lua b/lib/shared/rebound_entities.lua new file mode 100644 index 0000000..b75ecc6 --- /dev/null +++ b/lib/shared/rebound_entities.lua @@ -0,0 +1,469 @@ +-- -- -- -- -- -- -- -- -- -- +-- ▄▀▀ █▄█ ▄▀▄ █▀▄ ██▀ █▀▄ -- +-- ▄█▀ █ █ █▀█ █▀▄ █▄▄ █▄▀ -- +-- -- -- -- -- -- -- -- -- -- +local Entities = {} +local isServer = IsDuplicityVersion() + +local registeredFunctions = {} +ReboundEntities = {} + +--- Global Add function which fire when an entity is registered +--- @param func function = function(entityData: table) +--- @return number = ID +function ReboundEntities.AddFunction(func) + assert(func, "Func is nil") + table.insert(registeredFunctions, func) + return #registeredFunctions +end + +--- Remove a registered function +--- @param id number +function ReboundEntities.RemoveFunction(id) + assert(id, "ID is nil") + assert(registeredFunctions[id], "ID not found") + registeredFunctions[id] = false +end + +--- Internal: Fire all registered functions +--- @vararg any +local function FireFunctions(...) + for k, v in pairs(registeredFunctions) do + if v then + v(...) + end + end +end + +--- Convert a table to an entityData object +--- @param entityData table = {model: string, position: vector3, id: string || nil} +--- @return table = {model: string, position: vector3, id: string, entity: number, isServer: boolean || nil} +function ReboundEntities.Register(entityData) + assert(entityData, "Entity data is nil") + local position = entityData.position + assert(position, "Position is nil") + local id = entityData.id or Ids.CreateUniqueId(Entities) + entityData.isServer = isServer + entityData.id = tostring(id) + local entityData = setmetatable(entityData, { + __tostring = function() + return entityData.id + end + }) + Entities[id] = entityData + FireFunctions(entityData) + return entityData +end + +-- Internal +local function Unregister(id) + Entities[id] = nil +end + +function ReboundEntities.GetSyncData(entityData, key) + return entityData[key] +end + +--- Get all entityDatas registered +--- @return table = {entityData: table} +function ReboundEntities.GetAll() + return Entities +end + +--- Get an entityData by its id +--- @param id string +--- @return table = {model: string, position: vector3, id: string, entity: number, isServer: boolean} +function ReboundEntities.GetById(id) + id = tostring(id) + return Entities[id] +end + +--- Get all entities by their model +--- @param model string +--- @return table = {entityData: table} +function ReboundEntities.GetByModel(model) + local entities = {} + for k, v in pairs(Entities) do + if v.model == model then + table.insert(entities, v) + end + end + return entities +end + +--- Get the closest entityData to a position +--- @param pos vector3 +--- @return table = {model: string, position: vector3, id: string, entity: number, isServer: boolean} +function ReboundEntities.GetClosest(pos) + local closest = nil + local closestDist = 9999 + for k, v in pairs(Entities) do + local dist = #(pos - v.pos) + if dist < closestDist then + closest = v + closestDist = dist + end + end + return closest +end + +--- Get all entities within a radius of a position +--- @param pos vector3 +--- @param radius number +--- @return table = {entityData: table} +function ReboundEntities.GetWithinRadius(pos, radius) + local entities = {} + for k, v in pairs(Entities) do + local dist = #(pos - v.pos) + if dist < radius then + table.insert(entities, v) + end + end + return entities +end + +function ReboundEntities.SetOnSyncKeyChange(entityData, cb) + print("SetOnSyncKeyChange", entityData, cb) + local id = entityData.id or entityData + local data = ReboundEntities.GetById(id) + assert(data, "Entity not found") + data.onSyncKeyChange = cb +end + +exports('ReboundEntities', ReboundEntities) + +if not isServer then goto client end +-- -- -- -- -- -- -- -- -- -- +-- ▄▀▀ ██▀ █▀▄ █ █ ██▀ █▀▄ -- +-- ▄█▀ █▄▄ █▀▄ ▀▄▀ █▄▄ █▀▄ -- +-- -- -- -- -- -- -- -- -- -- + +--- Create a rebound entity +--- @param entityData object = {model: string, position: vector3, rotation: vector3 || nil} +--- @param src number = Who to send to. Defaults: -1 +--- @return table = {model: string, position: vector3, rotation: vector3, id: string, entity: number, isServer: boolean} +function ReboundEntities.Create(entityData, src) + local entity = ReboundEntities.Register(entityData) + assert(entity, "Failed to register entity") + assert(entity.position, "Entity position is nil") + entity.rotation = entity.rotation or vector3(0, 0, 0) + src = src and tonumber(src) or -1 + TriggerClientEvent(GetCurrentResourceName() ..":client:CreateReboundEntity", src, entity) + return entity +end + +function ReboundEntities.SetCheckRestricted(entityData, cb) + assert(type(cb) == "function", "Check restricted is not a function") + entityData.restricted = cb +end + +function ReboundEntities.CheckRestricted(src, entityData) + src = tonumber(src) + if not entityData.restricted then return false end + if src == -1 then return true end + return entityData.restricted(src, entityData) or false +end + +function ReboundEntities.Refresh(src) + src= tonumber(src) + local list = ReboundEntities.GetAccessibleList(src) + TriggerClientEvent(GetCurrentResourceName() ..":client:CreateReboundEntities", src, list) +end + +--- Delete a rebound entity +--- @param id string = The entity id: string || entityData: object +--- @return boolean +function ReboundEntities.Delete(id) + Unregister(id) + TriggerClientEvent(GetCurrentResourceName() ..":client:DeleteReboundEntity", -1, id) +end + +-- Create multiple rebound entities +--- @param entityDatas table = {entityData: object} +--- @param src number = Who to send to. Defaults: -1 +--- @return table = {entityData: object} +function ReboundEntities.CreateMultiple(entityDatas, src, restricted) + src = src and tonumber(src) or -1 + local _entityDatas = {} + for k, v in pairs(entityDatas) do + local entity = ReboundEntities.Register(v) + assert(entity, "Failed to register entity") + assert(entity.position, "Entity position is nil") + entity.rotation = entity.rotation or vector3(0, 0, 0) + + if restricted then + ReboundEntities.SetCheckRestricted(entity, restricted) + end + if not ReboundEntities.CheckRestricted(src, entity) then + _entityDatas[entity.id] = entity + end + end + + TriggerClientEvent(GetCurrentResourceName() ..":client:CreateReboundEntities", src, _entityDatas) + return _entityDatas +end + +--- Sets data to be synced to clients for a rebound entity +--- @param entityData object = {model: string, position: vector3, rotation: vector3, id: string, entity: number, isServer: boolean} +--- @param key string +--- @param value any +function ReboundEntities.SetSyncData(entityData, key, value) + entityData[key] = value + if entityData.onSyncKeyChange then + entityData.onSyncKeyChange(entityData, key, value) + end + TriggerClientEvent(GetCurrentResourceName() ..":client:SetReboundSyncData", -1, entityData.id, key, value) +end + +function ReboundEntities.GetAccessibleList(src) + src = tonumber(src) + local list = {} + for k, data in pairs(ReboundEntities.GetAll()) do + if not ReboundEntities.CheckRestricted(src, data) then + list[data.id] = data + end + end + return list +end + +RegisterNetEvent("playerJoining", function(src, _) + ReboundEntities.Refresh(src) +end) + +AddEventHandler('onResourceStart', function(resource) + if resource == GetCurrentResourceName() then + Wait(1000) + local players = GetPlayers() + for k, src in pairs(players) do + ReboundEntities.Refresh(src) + end + end +end) + +::client:: +if isServer then return ReboundEntities end +-- -- -- -- -- -- -- -- -- -- +-- ▄▀▀ █ █ ██▀ █▄ █ ▀█▀ -- +-- ▀▄▄ █▄▄ █ █▄▄ █ ▀█ █ -- +-- -- -- -- -- -- -- -- -- -- + +--- Loads a model into memory +--- @param model : Model name || Model hash +--- @return modelHash : number +function ReboundEntities.LoadModel(model) + assert(model, "Model is nil") + model = type(model) == "number" and model or GetHashKey(model) + local timeout = 100 + RequestModel(model) + while not HasModelLoaded(model) and timeout > 0 do + timeout = timeout - 1 + Wait(100) + end + assert(timeout > 0, string.format("Failed to load model %s", model)) + return model +end + +--- Spawns an entity +--- @param entityData : table = {model: string, position: vector3, rotation: vector3 || nil, onSpawn: function || nil} +--- @return entity : number +function ReboundEntities.Spawn(entityData) + local model = entityData.model + local position = entityData.position + assert(position, "Position is nil") + local rotation = entityData.rotation or vector3(0, 0, 0) + local entity = nil + if model then + model = ReboundEntities.LoadModel(model) + entity = CreateObject(model, position.x, position.y, position.z, false, false, false) + SetEntityRotation(entity, rotation.x, rotation.y, rotation.z) + end + + local onSpawn = entityData.onSpawn + print(onSpawn) + if onSpawn then + onSpawn(entityData, entity) + end + -- dont forget to save the entity to the entityData table in the spawn loop + return entity, true +end + +--- Set the onSpawn callback for an entity. Triggered after the entity is created. +--- @param id : string || entityData : object +--- @param cb : function(entityData: object, entity: number) +--- @return success : boolean +function ReboundEntities.SetOnSpawn(id, cb) + id = tostring(id) + local entity = ReboundEntities.GetById(id) + assert(entity, "Entity not found") + entity.onSpawn = cb + return true +end + +--- Despawns an entity +--- @param entityData : entity || table = {entity: number, onDespawn: function || nil} +function ReboundEntities.Despawn(entityData) + assert(entityData, "Entity data is nil") + local entity = entityData.entity + local onDespawn = entityData.onDespawn + if onDespawn and type(onDespawn) == "function" then + onDespawn(entityData, entity) + end + if entity and DoesEntityExist(entity) then + DeleteEntity(entity) + end + return nil, nil +end + +--- Set the onDespawn callback for an entity. Triggered before the entity is deleted. +--- @param id : string || entityData : object +--- @param cb : function(entityData: object, entity: number) +--- @return success : boolean +function ReboundEntities.SetOnDespawn(id, cb) + id = tostring(id) + local entity = ReboundEntities.GetById(id) + assert(entity, "Entity not found") + entity.onDespawn = cb + return true +end + +local spawnLoopRunning = false + +--- Internal function to spawn entities in a loop +--- @param distanceToCheck : number || nil +--- @param waitTime : number || nil +function ReboundEntities.SpawnLoop(distanceToCheck, waitTime) + if spawnLoopRunning then return end + spawnLoopRunning = true + distanceToCheck = distanceToCheck or 50 + waitTime = waitTime or 2500 + CreateThread(function() + while spawnLoopRunning do + for k, v in pairs(Entities) do + + if not v.restricted then + local pos = GetEntityCoords(PlayerPedId()) + local dist = #(pos - v.position) + if dist <= distanceToCheck and (not v.entity and not v.inRange) then + v.entity, v.inRange = ReboundEntities.Spawn(v) + elseif dist > distanceToCheck and (v.entity or v.inRange) then + v.entity, v.inRange = ReboundEntities.Despawn(v) + end + elseif v.entity then + v.entity = ReboundEntities.Despawn(v) + end + end + Wait(waitTime) + end + end) +end + +--- Get an entity by its entity number +--- @param entity : number +--- @return entityData : table +function ReboundEntities.GetByEntity(entity) + for k, v in pairs(Entities) do + if v.entity == entity then + return v + end + end +end + +--- Create a client side only, rebound entity +--- @param entityData : table = {model: string, position: vector3, rotation: vector3 || nil} +--- @return entity : table +function ReboundEntities.CreateClient(entityData) + local entity = ReboundEntities.Register(entityData) + if not entity then return end + ReboundEntities.SpawnLoop() + return entity +end + +--- Delete a client side only, rebound entity +--- @param id : string || entityData : table +--- @return success : boolean +function ReboundEntities.DeleteClient(id) + id = tostring(id) + local entityData = ReboundEntities.GetById(id) + local isServer = entityData.isServer + assert(not isServer, "Cannot delete server entity from client") + local entity = entityData.entity + if entity then + ReboundEntities.Despawn(entityData) + end + Unregister(id) + return true +end + +--- Create multiple client only, rebound entities +--- @param entityDatas : table = {entityData: table = {model: string, position: vector3, rotation: vector3 || nil}} +--- @return _entityDatas : objects +function ReboundEntities.CreateMultipleClient(entityDatas) + local _entityDatas = {} + for k, v in pairs(entityDatas) do + local entityData = ReboundEntities.CreateClient(v) + entityDatas[entityData.id] = entityData + end + return _entityDatas +end + +--- Delete multiple client only, rebound entities +--- @param ids : table = {string || entityData: table} +function ReboundEntities.DeleteMultipleClient(ids) + for k, v in pairs(ids) do + ReboundEntities.DeleteClient(v) + end +end + +-- -- -- -- internal -- -- -- -- +local function DeleteFromServer(id) + id = tostring(id) + local entityData = ReboundEntities.GetById(id) + if not entityData then return end + entityData.isServer = nil + ReboundEntities.DeleteClient(id) +end + +local function DeleteMultipleFromServer(ids) + for k, v in pairs(ids) do + DeleteFromServer(v) + end +end +-- -- -- -- -- -- -- -- -- -- + +RegisterNetEvent(GetCurrentResourceName() ..":client:CreateReboundEntity", function(entityData) + ReboundEntities.CreateClient(entityData) +end) + +RegisterNetEvent(GetCurrentResourceName() ..":client:DeleteReboundEntity", function(id) + DeleteFromServer(id) +end) + +RegisterNetEvent(GetCurrentResourceName() ..":client:CreateReboundEntities", function(entityDatas) + ReboundEntities.CreateMultipleClient(entityDatas) +end) + +RegisterNetEvent(GetCurrentResourceName() ..":client:DeleteReboundEntities", function(ids) + DeleteMultipleFromServer(ids) +end) + +RegisterNetEvent(GetCurrentResourceName() ..":client:SetReboundSyncData", function(id, key, value) + local entityData = ReboundEntities.GetById(id) + if not entityData then return end + entityData[key] = value + if entityData.onSyncKeyChange then + entityData.onSyncKeyChange(entityData, key, value) + end +end) + +AddEventHandler('onResourceStop', function(resource) + if resource == GetCurrentResourceName() then + spawnLoopRunning = false + for k, v in pairs(Entities) do + if v.entity then + DeleteEntity(tonumber(v.entity)) + end + end + end +end) + +return ReboundEntities diff --git a/lib/shared/rebound_entitiy_actions.lua b/lib/shared/rebound_entitiy_actions.lua new file mode 100644 index 0000000..ba45e1f --- /dev/null +++ b/lib/shared/rebound_entitiy_actions.lua @@ -0,0 +1,35 @@ +local ReboundEntities = ReboundEntities or Require("shared/rebound_entities.lua") +local Actions = Actions or Require("shared/actions.lua") +local LA = LA or Require("shared/la.lua") + +REA = {} + +if not IsDuplicityVersion() then goto client end + + + +if IsDuplicityVersion() then return end +::client:: + +local ActionsInProgress = {} + + +Action.Create("LerpToPosition", function(reboundId, start, position, duration, shouldRepeat, overrideStartTime) + local re = ReboundEntities.Get(reboundId) + assert(re, "Rebound entity not found") + local entity = re and re.entity + if not entity then return end + local startTime = GetGameTimer() + local endTime = overrideStartTime or startTime + duration + ActionsInProgress[reboundId] = {reboundId, start, position, duration, shouldRepeat, startTime} + local t = 0 + CreateThread(function() + while shouldRepeat or t < 1 do + t = (GetGameTimer() - startTime) / duration + local lerpPosition = LA.LerpVector(start, position, t) + SetEntityCoords(entity, lerpPosition) + Wait(0) + + end + end) +end) diff --git a/modules/utility/shared/tables.lua b/lib/shared/tables.lua similarity index 98% rename from modules/utility/shared/tables.lua rename to lib/shared/tables.lua index af69c64..148db7f 100644 --- a/modules/utility/shared/tables.lua +++ b/lib/shared/tables.lua @@ -105,4 +105,5 @@ Table.Shuffle = function(tbl) return tbl end +exports("Table", Table) return Table \ No newline at end of file diff --git a/modules/clothing/_default/client.lua b/modules/clothing/_default/client.lua new file mode 100644 index 0000000..9d72391 --- /dev/null +++ b/modules/clothing/_default/client.lua @@ -0,0 +1,49 @@ +Clothing = Clothing or {} + +ClothingBackup = {} + +Clothing.SetAppearance = function(data) + ClothingBackup = Clothing.GetAppearance() + Utility.SetEntitySkinData(cache.ped, data) + return true +end + +Clothing.GetAppearance = function() + return Utility.GetEntitySkinData(cache.ped) +end + +Clothing.RestoreAppearance = function() + Utility.SetEntitySkinData(cache.ped, ClothingBackup) + return true +end + +Clothing.ReloadSkin = function() + Utility.SetEntitySkinData(cache.ped, ClothingBackup) + return true +end + + + +Clothing.UpdateAppearanceBackup = function(data) + ClothingBackup = data +end + +RegisterNetEvent('community_bridge:client:updateClothingBackup', function(skindata) + ClothingBackup = skindata +end) + +RegisterNetEvent('community_bridge:client:SetAppearance', function(data) + Clothing.SetAppearance(data) +end) + +RegisterNetEvent('community_bridge:client:GetAppearance', function() + Clothing.GetAppearance() +end) + +RegisterNetEvent('community_bridge:client:RestoreAppearance', function() + Clothing.RestoreAppearance() +end) + +RegisterNetEvent('community_bridge:client:ReloadSkin', function() + Clothing.ReloadSkin() +end) \ No newline at end of file diff --git a/modules/clothing/_default/server.lua b/modules/clothing/_default/server.lua new file mode 100644 index 0000000..2ec1460 --- /dev/null +++ b/modules/clothing/_default/server.lua @@ -0,0 +1,32 @@ +Clothing = Clothing or {} + +Clothing.SetAppearance = function(src, data) + TriggerClientEvent('community_bridge:client:SetAppearance', src, data) +end + +Clothing.RestoreAppearance = function(src) + TriggerClientEvent('community_bridge:client:RestoreAppearance', src) +end + +Clothing.ReloadSkin = function(src) + TriggerClientEvent('community_bridge:client:ReloadSkin', src) +end + + + + +RegisterNetEvent('community_bridge:client:SetAppearance', function(data) + Clothing.SetAppearance(data) +end) + +RegisterNetEvent('community_bridge:client:GetAppearance', function() + Clothing.GetAppearance() +end) + +RegisterNetEvent('community_bridge:client:RestoreAppearance', function() + Clothing.RestoreAppearance() +end) + +RegisterNetEvent('community_bridge:client:ReloadSkin', function() + Clothing.ReloadSkin() +end) \ No newline at end of file diff --git a/modules/clothing/esx_skin/client.lua b/modules/clothing/esx_skin/client.lua index da941c3..d3261e0 100644 --- a/modules/clothing/esx_skin/client.lua +++ b/modules/clothing/esx_skin/client.lua @@ -1,12 +1,6 @@ if GetResourceState('esx_skin') ~= 'started' then return end -Clothing = {} - -StoredOldClothing = {} - -RegisterNetEvent('community_bridge:client:updateStoredClothing', function(skindata) - StoredOldClothing = skindata -end) +Clothing = Clothing or {} local clothingData = { male = { diff --git a/modules/clothing/esx_skin/server.lua b/modules/clothing/esx_skin/server.lua deleted file mode 100644 index d0330af..0000000 --- a/modules/clothing/esx_skin/server.lua +++ /dev/null @@ -1,6 +0,0 @@ -if GetResourceState('esx_skin') ~= 'started' then return end - -RegisterNetEvent("esx_skin:save", function(skin) - local src = source - TriggerClientEvent('community_bridge:client:updateStoredClothing', src, skin) -end) \ No newline at end of file diff --git a/modules/clothing/fivem-appearance/client.lua b/modules/clothing/fivem-appearance/client.lua index 5c998e7..96dc98f 100644 --- a/modules/clothing/fivem-appearance/client.lua +++ b/modules/clothing/fivem-appearance/client.lua @@ -1,17 +1,15 @@ if GetResourceState('fivem-appearance') ~= 'started' then return end +Clothing = Clothing or {} -Clothing = {} - -StoredOldClothing = {} - -Clothing.SetAppearance = function(clothingData) +Clothing.SetAppearance = function(data) + local clothing = {} if GetEntityModel(cache.ped) == `mp_m_freemode_01` then - clothingData = clothingData.male + clothing = data.male else - clothingData = clothingData.female + clothing = data.female end - StoredOldClothing = exports['fivem-appearance']:getPedAppearance(cache.ped) - exports['fivem-appearance']:setPedAppearance(cache.ped, clothingData) + ClothingBackup = exports['fivem-appearance']:getPedAppearance(cache.ped) + exports['fivem-appearance']:setPedAppearance(cache.ped, clothing) return true end @@ -20,9 +18,14 @@ Clothing.GetAppearance = function() end Clothing.RestoreAppearance = function() - return exports['fivem-appearance']:setPedAppearance(cache.ped, StoredOldClothing) + if not next(ClothingBackup) then + return false + end + exports['fivem-appearance']:setPedAppearance(cache.ped, ClothingBackup) + return true end Clothing.ReloadSkin = function() TriggerEvent("fivem-appearance:client:reloadSkin", true) + return true end \ No newline at end of file diff --git a/modules/clothing/illenium-appearance/client.lua b/modules/clothing/illenium-appearance/client.lua index ee3c32e..92736ab 100644 --- a/modules/clothing/illenium-appearance/client.lua +++ b/modules/clothing/illenium-appearance/client.lua @@ -1,8 +1,5 @@ if GetResourceState('illenium-appearance') ~= 'started' then return end - -Clothing = {} - -StoredOldClothing = {} +Clothing = Clothing or {} Clothing.SetAppearance = function(clothingData) local clothing = {} @@ -15,7 +12,7 @@ Clothing.SetAppearance = function(clothingData) clothing.props = exports['illenium-appearance']:getPedProps(cache.ped) Prints.Debug(json.encode(clothingData, {indent = true})) - StoredOldClothing = clothing + ClothingBackup = clothing exports['illenium-appearance']:setPedComponents(cache.ped, clothingData.components) exports['illenium-appearance']:setPedProp(cache.ped, clothingData.props) return true @@ -35,8 +32,8 @@ Clothing.GetAppearance = function() end Clothing.RestoreAppearance = function() - exports['illenium-appearance']:setPedComponents(cache.ped, StoredOldClothing.components) - exports['illenium-appearance']:setPedProp(cache.ped, StoredOldClothing.props) + exports['illenium-appearance']:setPedComponents(cache.ped, ClothingBackup.components) + exports['illenium-appearance']:setPedProp(cache.ped, ClothingBackup.props) return true end diff --git a/modules/clothing/qb-clothing/client.lua b/modules/clothing/qb-clothing/client.lua index 0245f28..6d96122 100644 --- a/modules/clothing/qb-clothing/client.lua +++ b/modules/clothing/qb-clothing/client.lua @@ -1,21 +1,16 @@ if GetResourceState('qb-clothing') ~= 'started' then return end -Clothing = {} +Clothing = Clothing or {} -StoredOldClothing = {} - -RegisterNetEvent('community_bridge:client:updateStoredClothing', function(skindata) - StoredOldClothing = skindata -end) - -Clothing.SetAppearance = function(clothingData) - if GetEntityModel(cache.ped) == `mp_m_freemode_01` then - clothingData = clothingData.male - else - clothingData = clothingData.female - end +Clothing.SetAppearance = function(data) + local clothingData = {} local repackedTable = {} - StoredOldClothing = Clothing.GetAppearance + if GetEntityModel(cache.ped) == `mp_m_freemode_01` then + clothingData = data.male + else + clothingData = data.female + end + ClothingBackup = Clothing.GetAppearance local componentMap = { [1] = 'mask', [3] = 'arms', @@ -45,21 +40,21 @@ Clothing.SetAppearance = function(clothingData) face_id = 'face' } - for _, data in pairs(clothingData) do - if componentMap[data.component_id] then - repackedTable[componentMap[data.component_id]] = {drawable = data.drawable, texture = data.texture} - elseif propMap[data.prop_id] then - repackedTable[propMap[data.prop_id]] = {drawable = data.drawable, texture = data.texture} - elseif specialMap[data.eye_color_id] then - repackedTable[specialMap[data.eye_color_id]] = {drawable = data.drawable, texture = data.texture} - elseif specialMap[data.moles_id] then - repackedTable[specialMap[data.moles_id]] = {drawable = data.drawable, texture = data.texture} - elseif specialMap[data.ageing_id] then - repackedTable[specialMap[data.ageing_id]] = {drawable = data.drawable, texture = data.texture} - elseif specialMap[data.hair_id] then - repackedTable[specialMap[data.hair_id]] = {drawable = data.drawable, texture = data.texture} - elseif specialMap[data.face_id] then - repackedTable[specialMap[data.face_id]] = {drawable = data.drawable, texture = data.texture} + for _, v in pairs(clothingData) do + if componentMap[v.component_id] then + repackedTable[componentMap[v.component_id]] = {drawable = v.drawable, texture = v.texture} + elseif propMap[v.prop_id] then + repackedTable[propMap[v.prop_id]] = {drawable = v.drawable, texture = v.texture} + elseif specialMap[v.eye_color_id] then + repackedTable[specialMap[v.eye_color_id]] = {drawable = v.drawable, texture = v.texture} + elseif specialMap[v.moles_id] then + repackedTable[specialMap[v.moles_id]] = {drawable = v.drawable, texture = v.texture} + elseif specialMap[v.ageing_id] then + repackedTable[specialMap[v.ageing_id]] = {drawable = v.drawable, texture = v.texture} + elseif specialMap[v.hair_id] then + repackedTable[specialMap[v.hair_id]] = {drawable = v.drawable, texture = v.texture} + elseif specialMap[v.face_id] then + repackedTable[specialMap[v.face_id]] = {drawable = v.drawable, texture = v.texture} end end TriggerEvent('qb-clothing:client:loadOutfit', repackedTable) @@ -67,12 +62,12 @@ Clothing.SetAppearance = function(clothingData) end Clothing.GetAppearance = function() - StoredOldClothing = Utility.GetEntitySkinData(cache.ped) + ClothingBackup = Utility.GetEntitySkinData(cache.ped) return Utility.GetEntitySkinData(cache.ped) end Clothing.RestoreAppearance = function() - return Utility.SetEntitySkinData(cache.ped, StoredOldClothing) + return Utility.SetEntitySkinData(cache.ped, ClothingBackup) end Clothing.ReloadSkin = function() diff --git a/modules/clothing/qb-clothing/server.lua b/modules/clothing/qb-clothing/server.lua index 5083d20..c95f1bc 100644 --- a/modules/clothing/qb-clothing/server.lua +++ b/modules/clothing/qb-clothing/server.lua @@ -2,7 +2,7 @@ if GetResourceState('qb-clothing') ~= 'started' then return end RegisterNetEvent('qb-clothing:saveSkin', function(model, skin) local src = source - if model ~= nil and skin ~= nil then - TriggerClientEvent('community_bridge:client:updateStoredClothing', src, skin) + if model and skin then + TriggerClientEvent('community_bridge:client:updateClothingBackup', src, skin) end end) \ No newline at end of file diff --git a/modules/dispatch/_default/client/client.lua b/modules/dispatch/_default/client/client.lua new file mode 100644 index 0000000..ddb3718 --- /dev/null +++ b/modules/dispatch/_default/client/client.lua @@ -0,0 +1,51 @@ +Dispatch = Dispatch or {} + +Dispatch.SendAlert = function(data) + TriggerServerEvent('community_bridge:Server:DispatchAlert', { + sprite = data.blipData.sprite or 161, + color = data.blipData.color or 1, + scale = data.blipData.scale or 0.8, + vehicle = data.vehicle or nil, + plate = data.vehicle and GetVehicleNumberPlateText(data.vehicle) or nil, + ped = data.ped or cache.ped, + pedCoords = data.pedCoords or GetEntityCoords(cache.ped), + coords = data.coords or GetEntityCoords(cache.ped), + message = data.message or "An Alert Has Been Made", + code = data.code or '10-80', + icon = data.icon or 'fas fa-question', + jobs = data.jobs or {'police'}, + time = data.time or 100000 + }) +end + +RegisterNetEvent('community_bridge:Client:DispatchAlert', function(alert) + Notify.SendNotify(alert.message, "success", 15000) + local blip = Bridge.Utility.CreateBlip(alert.coords, alert.blipData.sprite, alert.blipData.color, alert.blipData.scale, alert.code, true) + Wait(alert.time) + Bridge.Utility.RemoveBlip(blip) +end) + +--[[ +RegisterCommand('testalert', function(source, args) + print('sending alert') + local ped = cache.ped + local vehicle = cache.vehicle + Dispatch.SendAlert({ + vehicle = vehicle or nil, + plate = vehicle and GetVehicleNumberPlateText(vehicle) or nil, + ped = ped, + pedCoords = ped and GetEntityCoords(ped), + coords = GetEntityCoords(ped), + blipData = { + sprite = 161, + color = 1, + scale = 0.8, + }, + message = "Vehicle is being stolen", + code = '10-80', + icon = 'fas fa-question', + jobs = {'police'}, + alertTime = 10 + }) +end, false) +--]] \ No newline at end of file diff --git a/modules/dispatch/_default/server/server.lua b/modules/dispatch/_default/server/server.lua new file mode 100644 index 0000000..4296918 --- /dev/null +++ b/modules/dispatch/_default/server/server.lua @@ -0,0 +1,11 @@ +Dispatch = Dispatch or {} + +RegisterNetEvent("community_bridge:Server:DispatchAlert", function(data) + local jobs = data.jobs + for _, name in pairs(jobs) do + local activeJobPlayers = Bridge.Framework.GetPlayersByJob(name) + for src, _ in pairs(activeJobPlayers) do + TriggerClientEvent('community_bridge:Client:DispatchAlert', src, data) + end + end +end) \ No newline at end of file diff --git a/modules/dispatch/bub_mdt/client/client.lua b/modules/dispatch/bub_mdt/client/client.lua new file mode 100644 index 0000000..999ff62 --- /dev/null +++ b/modules/dispatch/bub_mdt/client/client.lua @@ -0,0 +1,15 @@ +if GetResourceState('bub-mdt') ~= 'started' then return end +Dispatch = Dispatch or {} + +Dispatch.SendAlert = function(data) + local alertData = { + code = data.code or '10-80', + offense = data.message, + coords = data.coords or GetEntityCoords(cache.ped), + info = { label = data.code or '10-80', icon = data.icon or 'fas fa-question' }, + blip = data.blipData.sprite or 1, + isEmergency = data.priority == 1 and true or false, + 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 diff --git a/modules/dispatch/bub_mdt/server/server.lua b/modules/dispatch/bub_mdt/server/server.lua new file mode 100644 index 0000000..13c866f --- /dev/null +++ b/modules/dispatch/bub_mdt/server/server.lua @@ -0,0 +1,2 @@ +if GetResourceState('bub-mdt') ~= 'started' then return end +Dispatch = Dispatch or {} \ No newline at end of file diff --git a/modules/dispatch/cd_dispatch/client.lua b/modules/dispatch/cd_dispatch/client.lua deleted file mode 100644 index 4547a3d..0000000 --- a/modules/dispatch/cd_dispatch/client.lua +++ /dev/null @@ -1,18 +0,0 @@ -if GetResourceState('cd_dispatch') ~= 'started' then return end - -Dispatch = {} - -Dispatch.SendAlert = function(data) - local playerData = exports['cd_dispatch']:GetPlayerInfo() - local randomID = Utility.CreateUniqueId(nil, 14, nil) - TriggerServerEvent('cd_dispatch:AddNotification', { - job_table = data.job, - coords = data.coords or playerData.coords, - title = data.code or '10-80', - message = data.message, - flash = 0, - unique_id = randomID, - sound = 1, - blip = { sprite = 431, scale = 1.2, colour = 3, flashes = false, text = data.message, time = 10000, radius = 0, } - }) -end \ No newline at end of file diff --git a/modules/dispatch/linden_outlawalert/client.lua b/modules/dispatch/linden_outlawalert/client.lua deleted file mode 100644 index 4007d99..0000000 --- a/modules/dispatch/linden_outlawalert/client.lua +++ /dev/null @@ -1,21 +0,0 @@ -if GetResourceState('linden_outlawalert') ~= 'started' then return end - -Dispatch = {} - -Dispatch.SendAlert = function(data) - local formattedData = { - displayCode = data.code or '10-80', - description = data.message, - isImportant = data.priority or 0, - recipientList = data.job, - length = '10000', - infoM = data.icon or 'fas fa-question', - info = data.message - } - local dispatchData = { - dispatchData = formattedData, - caller = 'Anonymous', - coords = GetEntityCoords(cache.ped) - } - TriggerServerEvent('wf-alerts:svNotify', dispatchData) -end \ No newline at end of file diff --git a/modules/dispatch/linden_outlawalert/client/client.lua b/modules/dispatch/linden_outlawalert/client/client.lua new file mode 100644 index 0000000..1d19ea2 --- /dev/null +++ b/modules/dispatch/linden_outlawalert/client/client.lua @@ -0,0 +1,18 @@ +if GetResourceState('linden_outlawalert') ~= 'started' then return end +Dispatch = Dispatch or {} + +Dispatch.SendAlert = function(data) + TriggerServerEvent('wf-alerts:svNotify', { + dispatchData = { + displayCode = data.code or '211', + description = data.message or "Alert", + isImportant = 0, + recipientList = data.jobs or {'police'}, + length = (data.alertTime * 1000) or '10000', + infoM = data.icon or 'fas fa-question', + info = data.message or "Alert" + }, + caller = 'Anonymous', + coords = data.coords or GetEntityCoords(cache.ped) + }) +end \ No newline at end of file diff --git a/modules/dispatch/linden_outlawalert/server/server.lua b/modules/dispatch/linden_outlawalert/server/server.lua new file mode 100644 index 0000000..1824ed4 --- /dev/null +++ b/modules/dispatch/linden_outlawalert/server/server.lua @@ -0,0 +1,2 @@ +if GetResourceState('linden_outlawalert') ~= 'started' then return end +Dispatch = Dispatch or {} \ No newline at end of file diff --git a/modules/dispatch/ps-dispatch/client.lua b/modules/dispatch/ps-dispatch/client.lua deleted file mode 100644 index 69dad7a..0000000 --- a/modules/dispatch/ps-dispatch/client.lua +++ /dev/null @@ -1,75 +0,0 @@ -if GetResourceState('ps-dispatch') ~= 'started' then return end - -Dispatch = {} - -Dispatch.SendAlert = function(data) - local customData = { - message = data.message, - code = data.code or '10-80', - icon = data.icon or 'fas fa-question', - priority = data.priority or 2, - coords = data.coords or vec3(0.0, 0.0, 0.0), - gender = data.gender or nil, - camId = data.camId or nil, - color = data.firstColor or nil, - callsign = data.callsign or nil, - name = data.name or nil, - vehicle = data.model or nil, - plate = data.plate or nil, - alertTime = data.alertTime or nil, - doorCount = data.doorCount or nil, - automaticGunfire = data.automaticGunfire or false, - alert = { - radius = data.radius or 0, - recipientList = data.job or { 'leo' }, - sprite = data.sprite or 1, - color = data.color or 1, - scale = data.scale or 0.5, - length = data.length or 2, - sound = data.sound or "Lose_1st", - sound2 = data.sound2 or "GTAO_FM_Events_Soundset", - offset = data.offset or false, - flash = data.flash or false - }, - jobs = { data.job or 'leo' } - } - exports["ps-dispatch"]:CustomAlert(customData) -end - ---[[ --- tested, it worked -CreateThread(function() - local data = { - message = "Fart", - code = '10-80', - icon = 'fas fa-question', - priority = 2, - coords = vec3(0.0, 0.0, 0.0), - gender = nil, - camId = nil, - color = nil, - callsign = nil, - name = "Test Name", - vehicle = nil, - plate = nil, - alertTime = 30000, - doorCount = nil, - automaticGunfire = false, - alert = { - radius = 0, - recipientList = { 'leo' }, - sprite = 1, - color = 1, - scale = 0.5, - length = 2, - sound = "Lose_1st", - sound2 = "GTAO_FM_Events_Soundset", - offset = false, - flash = false - }, - jobs = { 'leo' } - } - Dispatch.SendAlert(data) - Prints.Debug("Dispatched") -end) ---]] \ No newline at end of file diff --git a/modules/dispatch/ps-dispatch/client/client.lua b/modules/dispatch/ps-dispatch/client/client.lua new file mode 100644 index 0000000..7a27093 --- /dev/null +++ b/modules/dispatch/ps-dispatch/client/client.lua @@ -0,0 +1,29 @@ +if GetResourceState('ps-dispatch') ~= 'started' then return end +Dispatch = Dispatch or {} + +Dispatch.SendAlert = function(data) + local alertData = { + message = data.message, + code = data.code or '10-80', + icon = data.icon or 'fas fa-question', + priority = 2, + coords = data.coords, + vehicle = data.vehicle, + plate = data.plate, + alertTime = (data.time or 10000) / 1000, + alert = { + radius = 0, + recipientList = data.jobs, + sprite = data.blipData.sprite, + color = data.blipData.color, + scale = data.blipData.scale, + length = 2, + sound = "Lose_1st", + sound2 = "GTAO_FM_Events_Soundset", + offset = false, + flash = false + }, + jobs = data.jobs + } + exports["ps-dispatch"]:CustomAlert(alertData) +end \ No newline at end of file diff --git a/modules/dispatch/ps-dispatch/server/server.lua b/modules/dispatch/ps-dispatch/server/server.lua new file mode 100644 index 0000000..b19a475 --- /dev/null +++ b/modules/dispatch/ps-dispatch/server/server.lua @@ -0,0 +1,2 @@ +if GetResourceState('ps-dispatch') ~= 'started' then return end +Dispatch = Dispatch or {} diff --git a/modules/dispatch/qs_dispatch/client.lua b/modules/dispatch/qs_dispatch/client.lua deleted file mode 100644 index e336fd7..0000000 --- a/modules/dispatch/qs_dispatch/client.lua +++ /dev/null @@ -1,42 +0,0 @@ -if GetResourceState('qs-dispatch') ~= 'started' then return end - -Dispatch = {} - -Dispatch.SendAlert = function(data) - local playerData = exports['qs-dispatch']:GetPlayerInfo() - if not playerData then - print("Error getting player data") - return - end - - local customData = { - job = data.job or { 'police', 'sheriff', 'traffic', 'patrol' }, -- Job Names - callLocation = data.coords or vec3(0.0, 0.0, 0.0), - callCode = { - code = data.code or '10-80', - snippet = data.snippet or 'General Alert' - }, - message = data.message or "No message provided.", - flashes = data.flash or false, - image = data.image or nil, - blip = { - sprite = data.sprite or 1, - scale = data.scale or 1.0, - colour = data.color or 1, - flashes = data.flash or false, - text = data.blipText or "Alert", - time = data.length and (data.length * 1000) or 20000 -- Default to 20 seconds - }, - otherData = { - { - text = data.name or 'N/A', - icon = data.icon or 'fas fa-question' - } - } - } - - exports['qs-dispatch']:getSSURL(function(image) - customData.image = image or customData.image - TriggerServerEvent('qs-dispatch:server:CreateDispatchCall', customData) - end) -end \ No newline at end of file diff --git a/modules/dispatch/qs_dispatch/client/client.lua b/modules/dispatch/qs_dispatch/client/client.lua new file mode 100644 index 0000000..3656cc7 --- /dev/null +++ b/modules/dispatch/qs_dispatch/client/client.lua @@ -0,0 +1,38 @@ +if GetResourceState('qs-dispatch') ~= 'started' then return end +Dispatch = Dispatch or {} + +Dispatch.SendAlert = function(data) + local playerData = exports['qs-dispatch']:GetPlayerInfo() + if not playerData then return print("Error getting player data") end + + local customData = { + job = data.jobs or { 'police'}, + callLocation = data.coords or vec3(0.0, 0.0, 0.0), + callCode = { + code = data.code or '10-80', + snippet = data.snippet or 'General Alert' + }, + message = data.message, + flashes = false, + image = nil, + blip = { + sprite = data.blipData.sprite or 1, + scale = data.blipData.scale or 1.0, + colour = data.blipData.color or 1, + flashes = false, + text = data.message or "Alert", + time = data.length and (data.time * 1000) or 20000 + }, + otherData = { + { + text = data.name or 'N/A', + icon = data.icon or 'fas fa-question' + } + } + } + + exports['qs-dispatch']:getSSURL(function(image) + customData.image = image or customData.image + TriggerServerEvent('qs-dispatch:server:CreateDispatchCall', customData) + end) +end \ No newline at end of file diff --git a/modules/dispatch/qs_dispatch/server/server.lua b/modules/dispatch/qs_dispatch/server/server.lua new file mode 100644 index 0000000..238df5e --- /dev/null +++ b/modules/dispatch/qs_dispatch/server/server.lua @@ -0,0 +1,2 @@ +if GetResourceState('qs-dispatch') ~= 'started' then return end +Dispatch = Dispatch or {} \ No newline at end of file diff --git a/modules/dispatch/rcore_dispatch/client.lua b/modules/dispatch/rcore_dispatch/client.lua deleted file mode 100644 index 358c9c0..0000000 --- a/modules/dispatch/rcore_dispatch/client.lua +++ /dev/null @@ -1,16 +0,0 @@ -if GetResourceState('rcore_dispatch') ~= 'started' then return end - -Dispatch = {} - -Dispatch.SendAlert = function(data) - local playerData = exports['rcore_dispatch']:GetPlayerData() - TriggerEvent('rcore_dispatch:server:sendAlert', { - code = data.code or '10-80', - default_priority = 'low', - coords = data.coords or playerData.coords, - job = data.job, - text = data.message or 'No message provided', - type = 'alerts', - blip = { sprite = 54, colour = 3, scale = 0.7, text = data.message or "No Message", flashes = false, radius = 0 } - }) -end \ No newline at end of file diff --git a/modules/framework/es_extended/client.lua b/modules/framework/es_extended/client.lua index 05f7d8e..eb92eaf 100644 --- a/modules/framework/es_extended/client.lua +++ b/modules/framework/es_extended/client.lua @@ -16,6 +16,10 @@ Framework.GetPlayerMetaData = function(metadata) return ESX.GetPlayerData().metadata[metadata] end +Framework.Notify = function(message, type, time) + return ESX.ShowNotification(message, type, time) +end + Framework.GetPlayerIdentifier = function() return ESX.GetPlayerData().identifier end diff --git a/modules/framework/ox_core/client.lua b/modules/framework/ox_core/client.lua new file mode 100644 index 0000000..cb054e4 --- /dev/null +++ b/modules/framework/ox_core/client.lua @@ -0,0 +1,58 @@ +if GetResourceState('ox_core') ~= 'started' then return end + +local Ox = require '@ox_core.lib.init' + +Framework = {} + +Framework.GetPlayerData = function() + -- wip +end + +Framework.GetPlayerMetaData = function(metadata) + -- wip +end + +Framework.GetPlayerIdentifier = function() + local player = Ox.GetPlayer() + return player.stateId +end + +Framework.GetPlayerName = function() + local player = Ox.GetPlayer() + local first = player.get('firstName') + local last = player.get('lastName') + return first, last +end + +Framework.GetPlayerJob = function() + local group, grade, title = Ox.getGroupInfo() + return group, title, title, grade +end + +Framework.GetPlayerInventory = function() + return exports.ox_inventory:GetPlayerItems() +end + +Framework.GetIsPlayerDead = function() + -- wip +end + +RegisterNetEvent('ox:playerLoaded', function() + Wait(1500) + FillBridgeTables() + TriggerEvent('community_bridge:Client:OnPlayerLoaded') +end) + + +RegisterNetEvent('ox:playerLogout', function() + ClearClientSideVariables() + TriggerEvent('community_bridge:Client:OnPlayerUnload') +end) + +RegisterNetEvent('ox:setGroup', function(name, grade) + PlayerJobName = name + PlayerJobLabel = name + PlayerJobGradeName = grade + PlayerJobGradeLevel = grade + TriggerEvent('community_bridge:Client:OnPlayerJobUpdate',PlayerJobName, PlayerJobLabel, PlayerJobGradeName, PlayerJobGradeLevel) +end) \ No newline at end of file diff --git a/modules/framework/ox_core/server.lua b/modules/framework/ox_core/server.lua new file mode 100644 index 0000000..26735c0 --- /dev/null +++ b/modules/framework/ox_core/server.lua @@ -0,0 +1,147 @@ +if GetResourceState('ox_core') ~= 'started' then return end + +local Ox = require '@ox_core.lib.init' + +Framework = {} + +-- Framework.GetPlayerIdentifier(src) +-- Returns the citizen ID of the player. +Framework.GetPlayerIdentifier = function(src) + -- wip +end + +-- Framework.GetPlayerName(src) +-- Returns the first and last name of the player. +Framework.GetPlayerName = function(src) + -- wip +end + +-- Framework.GetItem(src, item, metadata) +-- 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, _) + -- wip +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, _) + -- wip +end + +-- Framework.GetPlayerInventory(src) +-- Returns the entire inventory of the player as a table. +-- returns {name = v.name, count = v.amount, _, _} +Framework.GetPlayerInventory = function(src) + -- wip +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) + -- wip +end + +-- Framework.GetMetadata(src, metadata) +-- Gets the specified metadata key and value to the player's data. +Framework.GetPlayerMetadata = function(src, metadata) + -- wip +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, +-- phone_number, pincode +Framework.GetStatus = function(src, column) + -- wip +end + +-- Framework.AddThirst(src, value) +-- Adds the specified value from the player's thirst level. +Framework.AddThirst = function(src, value) + -- wip +end + +-- Framework.AddHunger(src, value) +-- Adds the specified value from the player's hunger level. +Framework.AddHunger = function(src, value) + -- wip +end + +Framework.GetHunger = function(src) + -- wip +end + +Framework.GetThirst = function(src) + -- wip +end + +-- Framework.GetPlayerPhone(src) +-- Returns the phone number of the player. +Framework.GetPlayerPhone = function(src) + -- wip +end + +-- Framework.GetPlayerJob(src) +-- Returns the job name, label, grade name, and grade level of the player. +Framework.GetPlayerJob = function(src) + -- wip +end + +-- Framework.GetPlayersByJob(jobname) +-- returns a table of player sources that have the specified job name. +Framework.GetPlayersByJob = function(job) + -- wip +end + +-- Framework.SetPlayerJob(src, name, grade) +-- Sets the player's job to the specified name and grade. +Framework.SetPlayerJob = function(src, name, grade) + -- wip +end + +Framework.ToggleDuty = function(src, status) + -- wip +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) + -- wip +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) + -- wip +end + +-- Framework.GetAccountBalance(src, _type) +-- Returns the player's account balance of the specified type. +Framework.GetAccountBalance = function(src, _type) + -- wip +end + +-- Framework.AddItem(src, item, amount, _, _) +-- Adds the specified item to the player's inventory. +Framework.AddItem = function(src, item, amount, slot, metadata) + -- wip +end + +-- Framework.RemoveItem(src, item, amount, _, _) +-- Removes the specified item from the player's inventory. +Framework.RemoveItem = function(src, item, amount, slot, metadata) + -- wip +end + +-- Framework.RegisterUsableItem(item, cb) +-- Registers a usable item with a callback function. +Framework.RegisterUsableItem = function(itemName, cb) + exports(itemName, function(event, item, inventory, slot, data) + local slotData = exports.ox_inventory:GetSlot(inventory.id, slot) + if event == 'usingItem' then + cb(inventory.id, item, slotData) + end + end) +end \ No newline at end of file diff --git a/modules/framework/qb-core/client.lua b/modules/framework/qb-core/client.lua index b7dd1f8..3b8291b 100644 --- a/modules/framework/qb-core/client.lua +++ b/modules/framework/qb-core/client.lua @@ -17,6 +17,18 @@ Framework.GetPlayerMetaData = function(metadata) return QBCore.Functions.GetPlayerData().metadata[metadata] end +Framework.Notify = function(message, type, time) + TriggerEvent('QBCore:Notify', message, 'primary', time) +end + +Framework.ShowHelpText = function(message, _position) + return exports['qb-core']:DrawText(message, _position) +end + +Framework.HideHelpText = function() + return exports['qb-core']:HideText() +end + Framework.GetItemInfo = function(item) local itemData = QBCore.Shared.Items[item] if not itemData then return {} end diff --git a/modules/fuel/BigDaddy-Fuel/client.lua b/modules/fuel/BigDaddy-Fuel/client.lua new file mode 100644 index 0000000..6c6d435 --- /dev/null +++ b/modules/fuel/BigDaddy-Fuel/client.lua @@ -0,0 +1,12 @@ +if GetResourceState('BigDaddy-Fuel') ~= 'started' then return end +Fuel = {} + +Fuel.GetFuel = function(vehicle) + if not DoesEntityExist(vehicle) then return 0.0 end + return exports['BigDaddy-Fuel']:GetFuel(vehicle) +end + +Fuel.SetFuel = function(vehicle, fuel) + if not DoesEntityExist(vehicle) then return end + exports['BigDaddy-Fuel']:SetFuel(vehicle, fuel) +end diff --git a/modules/fuel/esx-sna-fuel/client.lua b/modules/fuel/esx-sna-fuel/client.lua new file mode 100644 index 0000000..9ca3a17 --- /dev/null +++ b/modules/fuel/esx-sna-fuel/client.lua @@ -0,0 +1,12 @@ +if GetResourceState('esx-sna-fuel') ~= 'started' then return end +Fuel = {} + +Fuel.GetFuel = function(vehicle) + if not DoesEntityExist(vehicle) then return 0.0 end + return exports['esx-sna-fuel']:GetFuel(vehicle) +end + +Fuel.SetFuel = function(vehicle, fuel) + if not DoesEntityExist(vehicle) then return end + exports['esx-sna-fuel']:SetFuel(vehicle, fuel) +end diff --git a/modules/fuel/qs-fuelstations/client.lua b/modules/fuel/qs-fuelstations/client.lua new file mode 100644 index 0000000..02bdada --- /dev/null +++ b/modules/fuel/qs-fuelstations/client.lua @@ -0,0 +1,13 @@ +if GetResourceState('qs-fuelstations') ~= 'started' then return end + +Fuel = {} + +Fuel.GetFuel = function(vehicle) + if not DoesEntityExist(vehicle) then return 0.0 end + return exports['qs-fuelstations']:GetFuel(vehicle) +end + +Fuel.SetFuel = function(vehicle, fuel) + if not DoesEntityExist(vehicle) then return end + return exports['qs-fuelstations']:SetFuel(vehicle, fuel) +end diff --git a/modules/input/_oxlib.lua b/modules/input/_oxlib.lua index 8b52b20..c376a23 100644 --- a/modules/input/_oxlib.lua +++ b/modules/input/_oxlib.lua @@ -1,7 +1,5 @@ if GetResourceState('ox_lib') ~= 'started' or (BridgeClientConfig.InputSystem ~= "ox" and BridgeClientConfig.InputSystem ~= "auto") then return end - - function QBTypeToOxType(_type) if _type == "text" then return "input" @@ -18,7 +16,6 @@ function QBTypeToOxType(_type) end end - function QBToOxInput(data) local returnData = {} for i, v in pairs(data) do @@ -44,7 +41,6 @@ function QBToOxInput(data) return returnData end - function OpenInput(title, data, isQBFormat, submitText) local inputs = data.inputs if isQBFormat then diff --git a/modules/input/_qb-input.lua b/modules/input/_qb-input.lua index 933fe0e..43809d0 100644 --- a/modules/input/_qb-input.lua +++ b/modules/input/_qb-input.lua @@ -1,8 +1,6 @@ if GetResourceState('qb-input') ~= 'started' or (BridgeClientConfig.InputSystem ~= "qb" and BridgeClientConfig.InputSystem ~= "auto") then return end - --- ox to Qb function OxTypeToQBType(_type) if _type == "input" then return "text" @@ -65,5 +63,5 @@ function OpenInput(title, data, isQBFormat, submitText) header = title, submitText = submitText or "Submit", inputs = input - }) + }) end \ No newline at end of file diff --git a/modules/input/client.lua b/modules/input/client.lua index e3067ac..a5b86d1 100644 --- a/modules/input/client.lua +++ b/modules/input/client.lua @@ -78,14 +78,7 @@ if GetResourceState('ox_lib') ~= 'started' and GetResourceState('qb-menu') ~= 's -- "input", "number", "checkbox", "select", "multi-select", "slider", "color", "date", "date-range", "time", "textarea", Input = {} - - - - - - -- qb to ox - --Open menu function Input.Open(title, data, isQBFormat, submitText) diff --git a/modules/notify/client.lua b/modules/notify/_default/client.lua similarity index 66% rename from modules/notify/client.lua rename to modules/notify/_default/client.lua index 23308ef..a796cb9 100644 --- a/modules/notify/client.lua +++ b/modules/notify/_default/client.lua @@ -1,25 +1,25 @@ Notify = Notify or {} +local notifyType = BridgeClientConfig.NotifySystem +local helptextType = BridgeClientConfig.ShowHelpText -Notify.SendNotify = function(message, type, time) - if BridgeClientConfig == nil or BridgeClientConfig.NotifySystem == nil then return Prints.error("You have not configured a compatable notify in community_bridge") end - local notifyType = BridgeClientConfig.NotifySystem +Notify.SendNotify = function(message, _type, time) time = time or 3000 if notifyType == 'qb' then - return TriggerEvent('QBCore:Notify', message, 'primary', time) + return Framework.Notify(message, nil, time) elseif notifyType == 'mythic' then return exports['mythic_notify']:SendAlert('inform', message, time) elseif notifyType == 'pNotify' then - return exports['pNotify']:SendNotification({ text = message, type = type, timeout = time, layout = 'centerRight' }) + return exports['pNotify']:SendNotification({ text = message, type = _type, timeout = time, layout = 'centerRight' }) elseif notifyType == 'esx' then - return ESX.ShowNotification(message, type, time) + return Framework.Notify(message, _type, time) elseif notifyType == 'ox' then - return exports.ox_lib:notify({ description = message, type = type, position = 'center-left' }) + return exports.ox_lib:notify({ description = message, type = _type, position = 'center-left' }) + elseif notifyType == 'okok' then + return exports['okokNotify']:Alert('Notification', message, time, _type, false) elseif notifyType == 't-notify' then return exports['t-notify']:Alert({ style = 'info', message = message, duration = time, }) elseif notifyType == 'wasabi' then - return exports.wasabi_notify:notify(type, message, time, type) - elseif notifyType == 'lab' then - return exports['swe-notify']:SendNotification(message, time, type) + return exports.wasabi_notify:notify(_type, message, time, _type) elseif notifyType == 'custom' then return Prints.Error("You have not set up a custom notify in community_bridge") else @@ -28,8 +28,6 @@ Notify.SendNotify = function(message, type, time) end Notify.ShowHelpText = function(message, _position) - if BridgeClientConfig == nil or BridgeClientConfig.ShowHelpText == nil then return Prints.error("You have not configured a compatable helptext in community_bridge") end - local helptextType = BridgeClientConfig.ShowHelpText if helptextType == 'ox' then if _position == nil then _position = 'left-center' end return exports.ox_lib:showTextUI(message, { position = _position }) @@ -37,7 +35,12 @@ Notify.ShowHelpText = function(message, _position) return exports['jg-textui']:DrawText(message) elseif helptextType == 'qb' then if _position == nil then _position = 'left' end - return exports['qb-core']:DrawText(message, 'left') + return Framework.ShowHelpText(message, _position) + elseif helptextType == 'okok' then + if _position == nil then _position = 'left' end + return exports['okokTextUI']:Open(message, 'darkblue', _position, false) + elseif helptextType == 'cd' then + return TriggerEvent('cd_drawtextui:ShowUI', 'show', message) elseif helptextType == 'lab' then return exports['lab-HintUI']:Show(message, "Hint Text") elseif helptextType == 'custom' then @@ -48,14 +51,16 @@ Notify.ShowHelpText = function(message, _position) end Notify.HideHelpText = function() - if BridgeClientConfig == nil or BridgeClientConfig.ShowHelpText == nil then return Prints.error("You have not configured a compatable helptext in community_bridge") end - local helptextType = BridgeClientConfig.ShowHelpText if helptextType == 'ox' then return exports.ox_lib:hideTextUI() elseif helptextType == 'jg' then return exports['jg-textui']:HideText() elseif helptextType == 'qb' then - return exports['qb-core']:HideText() + return Framework.HideHelpText() + elseif helptextType == 'okok' then + return exports['okokTextUI']:Close() + elseif helptextType == 'cd' then + return TriggerEvent('cd_drawtextui:HideUI') elseif helptextType == 'lab' then return exports['lab-HintUI']:Hide() elseif helptextType == 'custom' then diff --git a/modules/notify/server.lua b/modules/notify/_default/server.lua similarity index 100% rename from modules/notify/server.lua rename to modules/notify/_default/server.lua diff --git a/modules/target/ox_target/client.lua b/modules/target/ox_target/client.lua index bcb2a75..f3c955e 100644 --- a/modules/target/ox_target/client.lua +++ b/modules/target/ox_target/client.lua @@ -14,38 +14,42 @@ local targetZones = {} Target = {} -Target.AddGlobalPlayer = function(options) +Target.FixOptions = function(options) for k, v in pairs(options) do - options[k].onSelect = v.onSelect or v.action + local action = v.onSelect or v.action + local select = function(entityOrData) + if type(entityOrData) == 'table' then + return action(entityOrData.entity) + end + return action(entityOrData) + end + options[k].onSelect = action end + return options +end + +Target.AddGlobalPlayer = function(options) + options = Target.FixOptions(options) ox_target:addGlobalPlayer(options) end Target.AddGlobalVehicle = function(options) - for k, v in pairs(options) do - options[k].onSelect = v.onSelect or v.action - end + options = Target.FixOptions(options) ox_target:addGlobalVehicle(options) end Target.AddLocalEntity = function(entities, options) - for k, v in pairs(options) do - options[k].onSelect = v.onSelect or v.action - end + options = Target.FixOptions(options) ox_target:addLocalEntity(entities, options) end Target.AddModel = function(models, options) - for k, v in pairs(options) do - options[k].onSelect = v.onSelect or v.action - end + options = Target.FixOptions(options) ox_target:addModel(models, options) end Target.AddBoxZone = function(name, coords, size, heading, options) - for k, v in pairs(options) do - options[k].onSelect = v.onSelect or v.action - end + options = Target.FixOptions(options) local target = ox_target:addBoxZone({ coords = coords, size = size, diff --git a/modules/target/qb-target/client.lua b/modules/target/qb-target/client.lua index cefff29..ec54bde 100644 --- a/modules/target/qb-target/client.lua +++ b/modules/target/qb-target/client.lua @@ -13,10 +13,22 @@ local targetZones = {} Target = {} -Target.AddGlobalPlayer = function(options) +Target.FixOptions = function(options) for k, v in pairs(options) do - options[k].action = v.action or v.onSelect + local action = v.onSelect or v.action + local select = function(entityOrData) + if type(entityOrData) == 'table' then + return action(entityOrData.entity) + end + return action(entityOrData) + end + options[k].onSelect = action end + return options +end + +Target.AddGlobalPlayer = function(options) + options = Target.FixOptions(options) exports['qb-target']:AddGlobalPlayer({ options = options, distance = options.distance or 1.5 @@ -25,9 +37,7 @@ end Target.AddGlobalVehicle = function(options) - for k, v in pairs(options) do - options[k].action = v.action or v.onSelect - end + options = Target.FixOptions(options) exports['qb-target']:AddGlobalVehicle({ options = options, distance = options.distance or 1.5 @@ -35,9 +45,7 @@ Target.AddGlobalVehicle = function(options) end Target.AddLocalEntity = function(entities, options) - for k, v in pairs(options) do - options[k].action = v.action or v.onSelect - end + options = Target.FixOptions(options) exports['qb-target']:AddTargetEntity(entities, { options = options, distance = options.distance or 1.5 @@ -45,9 +53,7 @@ Target.AddLocalEntity = function(entities, options) end Target.AddModel = function(models, options) - for k, v in pairs(options) do - options[k].action = v.action or v.onSelect - end + options = Target.FixOptions(options) exports['qb-target']:AddTargetModel(models, { options = options, distance = options.distance or 1.5, @@ -55,9 +61,7 @@ Target.AddModel = function(models, options) end Target.AddBoxZone = function(name, coords, size, heading, options) - for k, v in pairs(options) do - options[k].action = v.action or v.onSelect - end + options = Target.FixOptions(options) exports['qb-target']:AddBoxZone(name, coords, size.x, size.y, { name = name, debugPoly = targetDebug, diff --git a/modules/utility/server/supplement_events.lua b/modules/utility/server/supplement_events.lua deleted file mode 100644 index 11181c0..0000000 --- a/modules/utility/server/supplement_events.lua +++ /dev/null @@ -1,6 +0,0 @@ -RegisterNetEvent("community_bridge:server:alert", function(data) - local playersByJob = Framework.GetPlayersByJob(data.job) - for _, src in pairs(playersByJob) do - TriggerClientEvent("community_bridge:client:alert", src, data) - end -end) \ No newline at end of file diff --git a/modules/utility/shared/uniqueids.lua b/modules/utility/shared/uniqueids.lua deleted file mode 100644 index f950b30..0000000 --- a/modules/utility/shared/uniqueids.lua +++ /dev/null @@ -1,25 +0,0 @@ -Utility = Utility or {} --- for unique ids -Utility.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 - len = len or 8 - - local id = "" - for i = 1, len do - local char = "" - if pattern then - char = pattern:sub(math.random(1, #pattern), math.random(1, #pattern)) - else - char = math.random(1, 2) == 1 and string.char(math.random(65, 90)) or math.random(0, 9) -- CAP letter and number - end - id = id .. char - end - if tbl[id] then - return Utility.CreateUniqueId(tbl, len, pattern) - end - return id -end - -Utility.RandomString = function() - return Utility.CreateUniqueId(nil, 14, nil) -end \ No newline at end of file diff --git a/modules/vehicleKey/F_RealCarKeysSystem/client.lua b/modules/vehicleKey/F_RealCarKeysSystem/client.lua new file mode 100644 index 0000000..d780704 --- /dev/null +++ b/modules/vehicleKey/F_RealCarKeysSystem/client.lua @@ -0,0 +1,10 @@ +if GetResourceState('F_RealCarKeysSystem') ~= 'started' then return end +VehicleKey = VehicleKey or {} + +VehicleKey.GiveKeys = function(vehicle, plate) + TriggerServerEvent('F_RealCarKeysSystem:generateVehicleKeys', plate) +end + +VehicleKey.RemoveKeys = function(vehicle, plate) + return +end diff --git a/modules/vehicleKey/MrNewbVehicleKeys/client.lua b/modules/vehicleKey/MrNewbVehicleKeys/client/client.lua similarity index 94% rename from modules/vehicleKey/MrNewbVehicleKeys/client.lua rename to modules/vehicleKey/MrNewbVehicleKeys/client/client.lua index 75778f6..7b17541 100644 --- a/modules/vehicleKey/MrNewbVehicleKeys/client.lua +++ b/modules/vehicleKey/MrNewbVehicleKeys/client/client.lua @@ -1,5 +1,5 @@ if GetResourceState('MrNewbVehicleKeys') ~= 'started' then return end -VehicleKey = {} +VehicleKey = VehicleKey or {} VehicleKey.GiveKeys = function(vehicle, plate) if not DoesEntityExist(vehicle) then return false end diff --git a/modules/vehicleKey/MrNewbVehicleKeys/server/server.lua b/modules/vehicleKey/MrNewbVehicleKeys/server/server.lua new file mode 100644 index 0000000..f8d74ae --- /dev/null +++ b/modules/vehicleKey/MrNewbVehicleKeys/server/server.lua @@ -0,0 +1,10 @@ +if GetResourceState('MrNewbVehicleKeys') ~= 'started' then return end +VehicleKey = VehicleKey or {} + +VehicleKey.GiveKeys = function(src, vehicle, plate) + --wip +end + +VehicleKey.RemoveKeys = function(src, vehicle, plate) + -- wip +end \ No newline at end of file diff --git a/modules/vehicleKey/Renewed-Vehiclekeys/client.lua b/modules/vehicleKey/Renewed-Vehiclekeys/client/client.lua similarity index 93% rename from modules/vehicleKey/Renewed-Vehiclekeys/client.lua rename to modules/vehicleKey/Renewed-Vehiclekeys/client/client.lua index 6d502de..0682798 100644 --- a/modules/vehicleKey/Renewed-Vehiclekeys/client.lua +++ b/modules/vehicleKey/Renewed-Vehiclekeys/client/client.lua @@ -1,5 +1,5 @@ if GetResourceState('Renewed-Vehiclekeys') ~= 'started' then return end -VehicleKey = {} +VehicleKey = VehicleKey or {} VehicleKey.GiveKeys = function(vehicle, plate) if not DoesEntityExist(vehicle) then return false end diff --git a/modules/vehicleKey/Renewed-Vehiclekeys/server/server.lua b/modules/vehicleKey/Renewed-Vehiclekeys/server/server.lua new file mode 100644 index 0000000..ed5552d --- /dev/null +++ b/modules/vehicleKey/Renewed-Vehiclekeys/server/server.lua @@ -0,0 +1,10 @@ +if GetResourceState('Renewed-Vehiclekeys') ~= 'started' then return end +VehicleKey = VehicleKey or {} + +VehicleKey.GiveKeys = function(src, vehicle, plate) + --wip +end + +VehicleKey.RemoveKeys = function(src, vehicle, plate) + -- wip +end \ No newline at end of file diff --git a/modules/vehicleKey/_default/client/client.lua b/modules/vehicleKey/_default/client/client.lua new file mode 100644 index 0000000..af15d71 --- /dev/null +++ b/modules/vehicleKey/_default/client/client.lua @@ -0,0 +1,9 @@ +VehicleKey = VehicleKey or {} + +VehicleKey.GiveKeys = function(vehicle, plate) + -- wip +end + +VehicleKey.RemoveKeys = function(vehicle, plate) + -- wip +end \ No newline at end of file diff --git a/modules/vehicleKey/_default/server/server.lua b/modules/vehicleKey/_default/server/server.lua new file mode 100644 index 0000000..26b525d --- /dev/null +++ b/modules/vehicleKey/_default/server/server.lua @@ -0,0 +1,9 @@ +VehicleKey = VehicleKey or {} + +VehicleKey.GiveKeys = function(src, vehicle, plate) + --wip +end + +VehicleKey.RemoveKeys = function(src, vehicle, plate) + -- wip +end \ No newline at end of file diff --git a/modules/vehicleKey/cd_garage/client.lua b/modules/vehicleKey/cd_garage/client/client.lua similarity index 87% rename from modules/vehicleKey/cd_garage/client.lua rename to modules/vehicleKey/cd_garage/client/client.lua index 310b9eb..7651f69 100644 --- a/modules/vehicleKey/cd_garage/client.lua +++ b/modules/vehicleKey/cd_garage/client/client.lua @@ -1,5 +1,5 @@ if GetResourceState('cd_garage') ~= 'started' then return end -VehicleKey = {} +VehicleKey = VehicleKey or {} VehicleKey.GiveKeys = function(vehicle, plate) TriggerEvent('cd_garage:AddKeys', plate) diff --git a/modules/vehicleKey/cd_garage/server/server.lua b/modules/vehicleKey/cd_garage/server/server.lua new file mode 100644 index 0000000..96a29e5 --- /dev/null +++ b/modules/vehicleKey/cd_garage/server/server.lua @@ -0,0 +1,10 @@ +if GetResourceState('cd_garage') ~= 'started' then return end +VehicleKey = VehicleKey or {} + +VehicleKey.GiveKeys = function(src, vehicle, plate) + --wip +end + +VehicleKey.RemoveKeys = function(src, vehicle, plate) + -- wip +end \ No newline at end of file diff --git a/modules/vehicleKey/mk_vehiclekeys/client.lua b/modules/vehicleKey/mk_vehiclekeys/client/client.lua similarity index 92% rename from modules/vehicleKey/mk_vehiclekeys/client.lua rename to modules/vehicleKey/mk_vehiclekeys/client/client.lua index 82d7f4c..d2ca909 100644 --- a/modules/vehicleKey/mk_vehiclekeys/client.lua +++ b/modules/vehicleKey/mk_vehiclekeys/client/client.lua @@ -1,5 +1,5 @@ if GetResourceState('mk_vehiclekeys') ~= 'started' then return end -VehicleKey = {} +VehicleKey = VehicleKey or {} VehicleKey.GiveKeys = function(vehicle, plate) if not DoesEntityExist(vehicle) then return false end diff --git a/modules/vehicleKey/mk_vehiclekeys/server/server.lua b/modules/vehicleKey/mk_vehiclekeys/server/server.lua new file mode 100644 index 0000000..54e50e8 --- /dev/null +++ b/modules/vehicleKey/mk_vehiclekeys/server/server.lua @@ -0,0 +1,10 @@ +if GetResourceState('mk_vehiclekeys') ~= 'started' then return end +VehicleKey = VehicleKey or {} + +VehicleKey.GiveKeys = function(src, vehicle, plate) + -- wip +end + +VehicleKey.RemoveKeys = function(src, vehicle, plate) + --wip +end \ No newline at end of file diff --git a/modules/vehicleKey/mono_carkeys/client.lua b/modules/vehicleKey/mono_carkeys/client.lua new file mode 100644 index 0000000..63e4b72 --- /dev/null +++ b/modules/vehicleKey/mono_carkeys/client.lua @@ -0,0 +1,12 @@ +if GetResourceState('mono_carkeys') ~= 'started' then return end + +VehicleKey = VehicleKey or {} +VehicleKey.GiveKeys = function(vehicle, plate) + if type(plate) ~= 'string' then return end + TriggerServerEvent('mono_carkeys:CreateKey', plate) +end + +VehicleKey.RemoveKeys = function(vehicle, plate) + if type(plate) ~= 'string' then return end + TriggerServerEvent('mono_carkeys:DeleteKey', 1, plate) +end diff --git a/modules/vehicleKey/okokGarage/client.lua b/modules/vehicleKey/okokGarage/client/client.lua similarity index 88% rename from modules/vehicleKey/okokGarage/client.lua rename to modules/vehicleKey/okokGarage/client/client.lua index 88543e4..5338e6a 100644 --- a/modules/vehicleKey/okokGarage/client.lua +++ b/modules/vehicleKey/okokGarage/client/client.lua @@ -1,5 +1,5 @@ if GetResourceState('okokGarage') ~= 'started' then return end -VehicleKey = {} +VehicleKey = VehicleKey or {} VehicleKey.GiveKeys = function(vehicle, plate) TriggerServerEvent('okokGarage:GiveKeys', plate) diff --git a/modules/vehicleKey/okokGarage/server/server.lua b/modules/vehicleKey/okokGarage/server/server.lua new file mode 100644 index 0000000..0669b0a --- /dev/null +++ b/modules/vehicleKey/okokGarage/server/server.lua @@ -0,0 +1,10 @@ +if GetResourceState('okokGarage') ~= 'started' then return end +VehicleKey = VehicleKey or {} + +VehicleKey.GiveKeys = function(src, vehicle, plate) + --wip +end + +VehicleKey.RemoveKeys = function(src, vehicle, plate) + -- wip +end \ No newline at end of file diff --git a/modules/vehicleKey/qb-vehiclekeys/client.lua b/modules/vehicleKey/qb-vehiclekeys/client/client.lua similarity index 91% rename from modules/vehicleKey/qb-vehiclekeys/client.lua rename to modules/vehicleKey/qb-vehiclekeys/client/client.lua index 226200e..fda29d8 100644 --- a/modules/vehicleKey/qb-vehiclekeys/client.lua +++ b/modules/vehicleKey/qb-vehiclekeys/client/client.lua @@ -1,6 +1,6 @@ if GetResourceState('qb-vehiclekeys') ~= 'started' then return end if GetResourceState('qbx_vehiclekeys') == 'started' then return end -VehicleKey = {} +VehicleKey = VehicleKey or {} VehicleKey.GiveKeys = function(vehicle, plate) TriggerServerEvent('qb-vehiclekeys:server:AcquireVehicleKeys', plate) diff --git a/modules/vehicleKey/qb-vehiclekeys/server/server.lua b/modules/vehicleKey/qb-vehiclekeys/server/server.lua new file mode 100644 index 0000000..6f07ac6 --- /dev/null +++ b/modules/vehicleKey/qb-vehiclekeys/server/server.lua @@ -0,0 +1,11 @@ +if GetResourceState('qb-vehiclekeys') ~= 'started' then return end +if GetResourceState('qbx_vehiclekeys') == 'started' then return end +VehicleKey = VehicleKey or {} + +VehicleKey.GiveKeys = function(src, vehicle, plate) + --wip +end + +VehicleKey.RemoveKeys = function(src, vehicle, plate) + -- wip +end \ No newline at end of file diff --git a/modules/vehicleKey/qbx_vehiclekeys/client.lua b/modules/vehicleKey/qbx_vehiclekeys/client/client.lua similarity index 89% rename from modules/vehicleKey/qbx_vehiclekeys/client.lua rename to modules/vehicleKey/qbx_vehiclekeys/client/client.lua index f46158c..8de11a0 100644 --- a/modules/vehicleKey/qbx_vehiclekeys/client.lua +++ b/modules/vehicleKey/qbx_vehiclekeys/client/client.lua @@ -1,5 +1,5 @@ if GetResourceState('qbx_vehiclekeys') ~= 'started' then return end -VehicleKey = {} +VehicleKey = VehicleKey or {} VehicleKey.GiveKeys = function(vehicle, plate) TriggerServerEvent('qb-vehiclekeys:server:AcquireVehicleKeys', plate) diff --git a/modules/vehicleKey/qbx_vehiclekeys/server/server.lua b/modules/vehicleKey/qbx_vehiclekeys/server/server.lua new file mode 100644 index 0000000..ae9ec98 --- /dev/null +++ b/modules/vehicleKey/qbx_vehiclekeys/server/server.lua @@ -0,0 +1,10 @@ +if GetResourceState('qbx_vehiclekeys') ~= 'started' then return end +VehicleKey = VehicleKey or {} + +VehicleKey.GiveKeys = function(src, vehicle, plate) + --wip +end + +VehicleKey.RemoveKeys = function(src, vehicle, plate) + -- wip +end \ No newline at end of file diff --git a/modules/vehicleKey/qs-vehiclekeys/client.lua b/modules/vehicleKey/qs-vehiclekeys/client/client.lua similarity index 92% rename from modules/vehicleKey/qs-vehiclekeys/client.lua rename to modules/vehicleKey/qs-vehiclekeys/client/client.lua index aca4377..aa85802 100644 --- a/modules/vehicleKey/qs-vehiclekeys/client.lua +++ b/modules/vehicleKey/qs-vehiclekeys/client/client.lua @@ -1,5 +1,5 @@ if GetResourceState('qs-vehiclekeys') ~= 'started' then return end -VehicleKey = {} +VehicleKey = VehicleKey or {} VehicleKey.GiveKeys = function(vehicle, plate) local model = GetDisplayNameFromVehicleModel(GetEntityModel(vehicle)) diff --git a/modules/vehicleKey/qs-vehiclekeys/server/server.lua b/modules/vehicleKey/qs-vehiclekeys/server/server.lua new file mode 100644 index 0000000..5a07ae3 --- /dev/null +++ b/modules/vehicleKey/qs-vehiclekeys/server/server.lua @@ -0,0 +1,10 @@ +if GetResourceState('qs-vehiclekeys') ~= 'started' then return end +VehicleKey = VehicleKey or {} + +VehicleKey.GiveKeys = function(src, vehicle, plate) + --wip +end + +VehicleKey.RemoveKeys = function(src, vehicle, plate) + -- wip +end \ No newline at end of file diff --git a/modules/vehicleKey/t1ger_keys/client.lua b/modules/vehicleKey/t1ger_keys/client/client.lua similarity index 93% rename from modules/vehicleKey/t1ger_keys/client.lua rename to modules/vehicleKey/t1ger_keys/client/client.lua index 112e14b..6f34b03 100644 --- a/modules/vehicleKey/t1ger_keys/client.lua +++ b/modules/vehicleKey/t1ger_keys/client/client.lua @@ -1,5 +1,5 @@ if GetResourceState('t1ger_keys') ~= 'started' then return end -VehicleKey = {} +VehicleKey = VehicleKey or {} VehicleKey.GiveKeys = function(vehicle, plate) if not DoesEntityExist(vehicle) then return false end diff --git a/modules/vehicleKey/t1ger_keys/server/server.lua b/modules/vehicleKey/t1ger_keys/server/server.lua new file mode 100644 index 0000000..569b2f3 --- /dev/null +++ b/modules/vehicleKey/t1ger_keys/server/server.lua @@ -0,0 +1,10 @@ +if GetResourceState('t1ger_keys') ~= 'started' then return end +VehicleKey = VehicleKey or {} + +VehicleKey.GiveKeys = function(src, vehicle, plate) + --wip +end + +VehicleKey.RemoveKeys = function(src, vehicle, plate) + -- wip +end \ No newline at end of file diff --git a/modules/vehicleKey/wasabi_carlock/client.lua b/modules/vehicleKey/wasabi_carlock/client/client.lua similarity index 89% rename from modules/vehicleKey/wasabi_carlock/client.lua rename to modules/vehicleKey/wasabi_carlock/client/client.lua index d71e8a6..7f5704b 100644 --- a/modules/vehicleKey/wasabi_carlock/client.lua +++ b/modules/vehicleKey/wasabi_carlock/client/client.lua @@ -1,5 +1,5 @@ if GetResourceState('wasabi_carlock') ~= 'started' then return end -VehicleKey = {} +VehicleKey = VehicleKey or {} VehicleKey.GiveKeys = function(vehicle, plate) exports.wasabi_carlock:GiveKey(plate) diff --git a/modules/vehicleKey/wasabi_carlock/server/server.lua b/modules/vehicleKey/wasabi_carlock/server/server.lua new file mode 100644 index 0000000..55c7838 --- /dev/null +++ b/modules/vehicleKey/wasabi_carlock/server/server.lua @@ -0,0 +1,10 @@ +if GetResourceState('wasabi_carlock') ~= 'started' then return end +VehicleKey = VehicleKey or {} + +VehicleKey.GiveKeys = function(src, vehicle, plate) + --wip +end + +VehicleKey.RemoveKeys = function(src, vehicle, plate) + -- wip +end \ No newline at end of file diff --git a/modules/weather/qb-weathersync/client.lua b/modules/weather/qb-weathersync/client/client.lua similarity index 100% rename from modules/weather/qb-weathersync/client.lua rename to modules/weather/qb-weathersync/client/client.lua diff --git a/modules/weather/qb-weathersync/server/server.lua b/modules/weather/qb-weathersync/server/server.lua new file mode 100644 index 0000000..b03d4c5 --- /dev/null +++ b/modules/weather/qb-weathersync/server/server.lua @@ -0,0 +1,6 @@ +if GetResourceState('qb-weathersync') ~= 'started' then return end +Weather = {} + +Weather.ToggleSync = function(src, toggle) + -- wip +end \ No newline at end of file diff --git a/modules/weather/renewed-weathersync/client.lua b/modules/weather/renewed-weathersync/client/client.lua similarity index 100% rename from modules/weather/renewed-weathersync/client.lua rename to modules/weather/renewed-weathersync/client/client.lua diff --git a/modules/weather/renewed-weathersync/server/server.lua b/modules/weather/renewed-weathersync/server/server.lua new file mode 100644 index 0000000..dc6adfc --- /dev/null +++ b/modules/weather/renewed-weathersync/server/server.lua @@ -0,0 +1,6 @@ +if GetResourceState('Renewed-Weathersync') ~= 'started' then return end +Weather = {} + +Weather.ToggleSync = function(src, toggle) + -- wip +end \ No newline at end of file diff --git a/modules/weather/vSync/client.lua b/modules/weather/vSync/client/client.lua similarity index 100% rename from modules/weather/vSync/client.lua rename to modules/weather/vSync/client/client.lua diff --git a/modules/weather/vSync/server/server.lua b/modules/weather/vSync/server/server.lua new file mode 100644 index 0000000..b03d4c5 --- /dev/null +++ b/modules/weather/vSync/server/server.lua @@ -0,0 +1,6 @@ +if GetResourceState('qb-weathersync') ~= 'started' then return end +Weather = {} + +Weather.ToggleSync = function(src, toggle) + -- wip +end \ No newline at end of file diff --git a/settings/clientConfig.lua b/settings/clientConfig.lua index 7183189..f977d4c 100644 --- a/settings/clientConfig.lua +++ b/settings/clientConfig.lua @@ -1,6 +1,7 @@ BridgeClientConfig = {} BridgeClientConfig.DebugLevel = 2 -- Debug level, 0 for none, 1 for some, 2 for all data BridgeClientConfig.NotifySystem = "ox" -- [ ox | qb | esx | mythic | pNotify | t-notify | wasabi | lab | custom ] +BridgeClientConfig.HelpTextSystem = "auto" BridgeClientConfig.ShowHelpText = "ox" -- [ox | jg | qb | lab | custom ] BridgeClientConfig.InputSystem = "auto" -- [ auto | ox | qb ] BridgeClientConfig.MenuSystem = "auto" -- [ auto | ox | qb ] diff --git a/use/ids.lua b/use/ids.lua deleted file mode 100644 index a12eec4..0000000 --- a/use/ids.lua +++ /dev/null @@ -1,22 +0,0 @@ -Ids = {} -function Ids.CreateUniqueId(tbl, len, pattern) -- both optional - tbl = tbl or {} -- table to check uniqueness. Ids to check against must be the key to the tables value - len = len or 8 - - local id = "" - for i = 1, len do - local char = "" - if pattern then - char = pattern:sub(math.random(1, #pattern), math.random(1, #pattern)) - else - char = math.random(1, 2) == 1 and string.char(math.random(65, 90)) or math.random(0, 9) -- CAP letter and number - end - id = id .. char - end - if tbl[id] then - return Ids.CreateUniqueId(tbl, len, pattern) - end - return id -end - -return Ids \ No newline at end of file diff --git a/use/prints.lua b/use/prints.lua deleted file mode 100644 index 59e30de..0000000 --- a/use/prints.lua +++ /dev/null @@ -1,25 +0,0 @@ -Prints = {} -local function printMessage(level, color, message) - if type(message) == 'table' then - message = json.encode(message) - end - print(color .. '[' .. level .. ']:', message) -end - -Prints.Info = function(message) - printMessage('INFO', '^5', message) -end - -Prints.Warn = function(message) - printMessage('WARN', '^3', message) -end - -Prints.Error = function(message) - printMessage('ERROR', '^1', message) -end - -Prints.Debug = function(message) - printMessage('DEBUG', '^2', message) -end - -return Prints \ No newline at end of file diff --git a/use/require.lua b/use/require.lua deleted file mode 100644 index c151da3..0000000 --- a/use/require.lua +++ /dev/null @@ -1,36 +0,0 @@ -local loadedModules = {} - -function Require(modulePath, resourceName) - if resourceName and type(resourceName) ~= "string" then - resourceName = GetCurrentResourceName() - end - - if not resourceName then - resourceName = "community_bridge" - end - - local id = resourceName .. ":" .. modulePath - if loadedModules[id] then - print("Returning cached module [" .. id .. "]") - return loadedModules[id] - end - - local file = LoadResourceFile(resourceName, modulePath) - if not file then - error("Error loading file [" .. id .. "]") - end - - local chunk, loadErr = load(file, id) - if not chunk then - error("Error wrapping module [" .. id .. "] Message: " .. loadErr) - end - - local success, result = pcall(chunk) - if not success then - error("Error executing module [" .. id .. "] Message: " .. result) - end - loadedModules[id] = result - return result -end - -exports('Require', Require) \ No newline at end of file