diff --git a/fxmanifest.lua b/fxmanifest.lua index a9912ff..221aee4 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -5,7 +5,7 @@ use_experimental_fxv2_oal 'yes' author 'The Order of the Sacred Framework' name 'community_bridge' description 'A Universal Bridge for Our Community, created by a group of contributors with a shared vision to enhance both user and developer experiences. This bridge connects various frameworks, inventories, target systems, notification systems, and more, fostering compatibility and seamless integration.' -version '0.9.2' +version '0.10.0' shared_scripts { '@ox_lib/init.lua', @@ -33,6 +33,7 @@ server_scripts { 'modules/notify/**/server.lua', 'modules/housing/**/server.lua', 'modules/skills/**/server.lua', + 'modules/bossmenu/**/server.lua', "lib/**/server.lua", 'init.lua', } @@ -52,15 +53,16 @@ client_scripts { 'modules/progressbar/**/client.lua', 'modules/clothing/**/client.lua', 'modules/input/**/client.lua', - 'modules/menu/*.lua', + 'modules/menu/**/client.lua', 'modules/helptext/**/client.lua', 'modules/notify/**/client.lua', 'modules/dialogue/**/client/*.lua', 'modules/shops/**/client.lua', 'modules/housing/**/client.lua', 'modules/skills/**/client.lua', + 'modules/bossmenu/**/client.lua', 'init.lua', - -- 'unit_tests/input_test.lua', + -- 'unit_tests/*.lua', } ui_page 'web/dist/index.html' diff --git a/init.lua b/init.lua index 9751263..bfd4c31 100644 --- a/init.lua +++ b/init.lua @@ -46,6 +46,7 @@ end --Bridge Bridge.RegisterModule("Framework", Framework) +Bridge.RegisterModule("BossMenu", BossMenu) Bridge.RegisterModule("Inventory", Inventory) Bridge.RegisterModule("Notify", Notify) Bridge.RegisterModule("HelpText", HelpText) diff --git a/lib/batch/shared/test-extension.lua b/lib/batch/shared/test-extension.lua new file mode 100644 index 0000000..81e4017 --- /dev/null +++ b/lib/batch/shared/test-extension.lua @@ -0,0 +1,23 @@ +-- Test file for FiveM Community Bridge Extension +-- Try the following to test extension features: + +-- 1. Type "CommunityBridge." (with the dot) and you should see auto-completion +-- CommunityBridge. + +-- 2. Type "AddEventHandler" and see parameter hints +-- AddEventHandler( + +-- 3. Hover over these function names to see documentation: +-- GetPlayerData, SetPlayerData, TriggerEvent, RegisterNetEvent + +-- 4. Try these snippets (type the word and press Tab): +-- event +-- thread +-- command +-- cbget +-- cbset + +-- 5. Test signature help - start typing a function call: +-- CommunityBridge.GetPlayerData( + +print("Extension test file loaded") diff --git a/lib/entities/client/client_entity.lua b/lib/entities/client/client_entity.lua index bcda856..c6e5de1 100644 --- a/lib/entities/client/client_entity.lua +++ b/lib/entities/client/client_entity.lua @@ -62,20 +62,35 @@ end --- Registers an entity received from the server and sets up proximity spawning. -- @param entityData table Data received from the server via 'community_bridge:client:CreateEntity' -function ClientEntity.Register(entityData) - if Entities[entityData.id] then return end -- Already registered - +function ClientEntity.Create(entityData) + entityData.id = entityData.id or Ids.CreateUniqueId(Entities) + if Entities[entityData.id] then return Entities[entityData.id] end -- Already registered Entities[entityData.id] = entityData - -- print(string.format("[ClientEntity] Registering %s entity %s", entityData.entityType, entityData.id)) - - -- Use Point system for proximity checks - -- print(string.format("[ClientEntity] Registering entity %s at %s", entityData.id, json.encode(entityData))) - return Point.Register(entityData.id, entityData.coords, entityData.spawnDistance or 50.0, entityData, SpawnEntity, RemoveEntity, function() end) + return Point.Register(entityData.id, entityData.coords, entityData.spawnDistance or 50.0, entityData, SpawnEntity, RemoveEntity, function() end) end +--Depricated use ClientEntity.Create instead +--- Registers an entity and spawns it in the world if not already spawned. +ClientEntity.Register = ClientEntity.Create + + +function ClientEntity.CreateBulk(entities) + local registeredEntities = {} + for _, entityData in pairs(entities) do + local entity = ClientEntity.Create(entityData) + registeredEntities[entity.id] = entity + end + return registeredEntities +end + +-- Depricated use ClientEntity.CreateBulk instead +ClientEntity.RegisterBulk = ClientEntity.CreateBulk + + + --- Unregisters an entity and removes it from the world if spawned. -- @param id string|number The ID of the entity to unregister. -function ClientEntity.Unregister(id) +function ClientEntity.Destroy(id) local entityData = Entities[id] if not entityData then return end @@ -83,6 +98,8 @@ function ClientEntity.Unregister(id) RemoveEntity(entityData) Entities[id] = nil end +ClientEntity.Unregister = ClientEntity.Destroy + --- Updates the data for a registered entity. -- @param id string|number The ID of the entity to update. @@ -95,7 +112,6 @@ function ClientEntity.Update(id, data) local needsPointUpdate = false for key, value in pairs(data) do if key == 'coords' and #(entityData.coords - value) > 0.1 then - -- print(string.format("[ClientEntity] Updating coords for entity %s", id)) needsPointUpdate = true end if key == 'spawnDistance' and entityData.spawnDistance ~= value then @@ -153,9 +169,21 @@ function ClientEntity.RegisterAction(name, func) ClientEntityActions.RegisterAction(name, func) end +function ClientEntity.OnCreate(_type, func) + ClientEntity.OnCreates = ClientEntity.OnCreates or {} + if not ClientEntity.OnCreates[_type] then + ClientEntity.OnCreates[_type] = {} + end + table.insert(ClientEntity.OnCreates[_type], func) +end + -- Network Event Handlers RegisterNetEvent("community_bridge:client:CreateEntity", function(entityData) - ClientEntity.Register(entityData) + ClientEntity.Create(entityData) +end) + +RegisterNetEvent("community_bridge:client:CreateEntities", function(entities) + ClientEntity.CreateBulk(entities) end) RegisterNetEvent("community_bridge:client:DeleteEntity", function(id) diff --git a/lib/entities/server/server_entity.lua b/lib/entities/server/server_entity.lua index f066bbd..a4a0827 100644 --- a/lib/entities/server/server_entity.lua +++ b/lib/entities/server/server_entity.lua @@ -10,7 +10,7 @@ ServerEntity = {} -- Renamed from EntityRelay -- @param rotation vector3|number Heading for peds/vehicles, rotation for objects -- @param meta table Optional additional data -- @return table The created entity data -function ServerEntity.Create(id, entityType, model, coords, rotation, meta) +function ServerEntity.New(id, entityType, model, coords, rotation, meta) local self = meta or {} self.id = id or Ids.CreateUniqueId(Entities) self.entityType = entityType @@ -23,12 +23,36 @@ function ServerEntity.Create(id, entityType, model, coords, rotation, meta) assert(self.entityType, "EntityType is required") assert(self.model, "Model is required for entity creation") assert(self.coords, "Coords are required for entity creation") - ServerEntity.Add(self) - TriggerClientEvent("community_bridge:client:CreateEntity", -1, self) - Wait(1000) return self end +function ServerEntity.Create(id, entityType, model, coords, rotation, meta) + local self = ServerEntity.New(id, entityType, model, coords, rotation, meta) + if not self then + print("Failed to create entity with ID: " .. tostring(id)) + return nil + end + TriggerClientEvent("community_bridge:client:CreateEntity", -1, self) + return self +end + +function ServerEntity.CreateBulk(entities) + local createdEntities = {} + for _, entityData in pairs(entities) do + local id = entityData.id or Ids.CreateUniqueId(Entities) + local entity = ServerEntity.New( + id, + entityData.entityType, + entityData.model, + entityData.coords, + entityData.rotation, + entityData.meta + ) + createdEntities[id] = entity + end + TriggerClientEvent("community_bridge:client:CreateEntities", -1, createdEntities) + return createdEntities +end --- Deletes a server-side entity representation and notifies clients. -- @param id string|number The ID of the entity to delete. @@ -103,7 +127,7 @@ AddEventHandler('onResourceStop', function(resourceName) end end for _, id in pairs(toDelete) do - ServerEntity.Delete(id) + ServerEntity.Delete(id) end end) diff --git a/lib/logs/server/logs.lua b/lib/logs/server/logs.lua index 188cc53..ec4a92b 100644 --- a/lib/logs/server/logs.lua +++ b/lib/logs/server/logs.lua @@ -1,7 +1,9 @@ Logs = Logs or {} local WebhookURL = "" -- Add webhook URL here if using built-in logging system -local LogoForEmbed = "" -- optional logo for the embed +local LogoForEmbed = "https://cdn.discordapp.com/avatars/299410129982455808/31ce635662206e8bd0132c34ce9ce683?size=1024" +local LogSystem = "built-in" -- Default log system, can be "built-in", "qb", or "ox_lib" + ---This will send a log to the configured webhook or log system. ---@param src number @@ -9,7 +11,8 @@ local LogoForEmbed = "" -- optional logo for the embed ---@return nil Logs.Send = function(src, message) if not src or not message then return end - if BridgeServerConfig.LogSystem == "built-in" then + local logType = LogSystem or "built-in" + if logType == "built-in" then PerformHttpRequest(WebhookURL, function(err, text, headers) end, 'POST', json.encode( { username = "Community_Bridge's Logger", @@ -19,7 +22,6 @@ Logs.Send = function(src, message) color = "15769093", title = GetCurrentResourceName(), url = 'https://discord.gg/Gm6rYEXUsn', - --description = message, thumbnail = { url = LogoForEmbed }, fields = { { @@ -46,9 +48,9 @@ Logs.Send = function(src, message) } } }), { ['Content-Type']= 'application/json' }) - elseif BridgeServerConfig.LogSystem == "qb" then + elseif logType == "qb" then return TriggerEvent('qb-log:server:CreateLog', GetCurrentResourceName(), GetCurrentResourceName(), 'green', message) - elseif BridgeServerConfig.LogSystem == "ox_lib" then + elseif logType == "ox_lib" then return lib.logger(src, GetCurrentResourceName(), message) end end diff --git a/lib/placers/client/placeable_object.lua b/lib/placers/client/placeable_object.lua index 5a333eb..ccfc6d9 100644 --- a/lib/placers/client/placeable_object.lua +++ b/lib/placers/client/placeable_object.lua @@ -5,575 +5,783 @@ Language = Language or Require("modules/locales/shared.lua") PlaceableObject = PlaceableObject or {} --- Local variables -local isPlacing = false -local currentEntity = nil -local currentMode = 'normal' -- 'normal' or 'movement' -local currentPromise = nil -- Store the current promise +-- Register key mappings for placement controls +RegisterKeyMapping('+place_object', locale('placeable_object.object_place'), 'mouse_button', 'MOUSE_LEFT') +RegisterKeyMapping('+cancel_placement', locale('placeable_object.object_cancel'), 'mouse_button', 'MOUSE_RIGHT') +RegisterKeyMapping('+rotate_left', locale('placeable_object.rotate_left'), 'keyboard', 'LEFT') +RegisterKeyMapping('+rotate_right', locale('placeable_object.rotate_right'), 'keyboard', 'RIGHT') +RegisterKeyMapping('+scroll_up', locale('placeable_object.object_scroll_up'), 'mouse_wheel', 'IOM_WHEEL_UP') +RegisterKeyMapping('+scroll_down', locale('placeable_object.object_scroll_down'), 'mouse_wheel', 'IOM_WHEEL_DOWN') +RegisterKeyMapping('+depth_modifier', locale('placeable_object.depth_modifier'), 'keyboard', 'LCONTROL') + +local state = { + isPlacing = false, + currentEntity = nil, + mode = 'normal', -- 'normal' or 'movement' + promise = nil, + scaleform = nil, + + -- Placement settings + depth = 2.0, + heading = 0.0, + height = 0.0, + snapToGround = true, + paused = false, + + -- Current settings + settings = {}, + boundaryCheck = nil, + + -- Key press states + keys = { + placeObject = false, + cancelPlacement = false, + rotateLeft = false, + rotateRight = false, + scrollUp = false, + scrollDown = false, + depthModifier = false + } +} + +-- Command handlers for key mappings +RegisterCommand('+place_object', function() + if state.isPlacing then + state.keys.placeObject = true + end +end, false) + +RegisterCommand('-place_object', function() + state.keys.placeObject = false +end, false) + +RegisterCommand('+cancel_placement', function() + if state.isPlacing then + state.keys.cancelPlacement = true + end +end, false) + +RegisterCommand('-cancel_placement', function() + state.keys.cancelPlacement = false +end, false) + +RegisterCommand('+rotate_left', function() + if state.isPlacing then + state.keys.rotateLeft = true + end +end, false) + +RegisterCommand('-rotate_left', function() + state.keys.rotateLeft = false +end, false) + +RegisterCommand('+rotate_right', function() + if state.isPlacing then + state.keys.rotateRight = true + end +end, false) + +RegisterCommand('-rotate_right', function() + state.keys.rotateRight = false +end, false) + +RegisterCommand('+scroll_up', function() + if state.isPlacing then + state.keys.scrollUp = true + end +end, false) + +RegisterCommand('-scroll_up', function() + state.keys.scrollUp = false +end, false) + +RegisterCommand('+scroll_down', function() + if state.isPlacing then + state.keys.scrollDown = true + end +end, false) + +RegisterCommand('-scroll_down', function() + state.keys.scrollDown = false +end, false) + +RegisterCommand('+depth_modifier', function() + if state.isPlacing then + state.keys.depthModifier = true + end +end, false) + +RegisterCommand('-depth_modifier', function() + state.keys.depthModifier = false +end, false) -- Utility functions -local function eyetrace(depth, disableSphere) +local function getMouseWorldPos(depth) 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) + return playerPos + normal * depth +end + +-- local function isInBoundary(pos, boundary) +-- if not boundary then return true end + +-- local x, y, z = table.unpack(pos) + +-- -- Handle legacy min/max boundary format for backwards compatibility +-- if boundary.min and boundary.max then +-- local minX, minY, minZ = table.unpack(boundary.min) +-- local maxX, maxY, maxZ = table.unpack(boundary.max) +-- return x >= minX and x <= maxX and y >= minY and y <= maxY and z >= minZ and z <= maxZ +-- end + +-- -- Handle list of points (polygon boundary) +-- if boundary.points and #boundary.points > 0 then +-- local points = boundary.points +-- local minZ = boundary.minZ or -math.huge +-- local maxZ = boundary.maxZ or math.huge + +-- -- Check Z bounds first +-- if z < minZ or z > maxZ then +-- return false +-- end + +-- -- Point-in-polygon test using ray casting algorithm (improved version) +-- local inside = false +-- local n = #points + +-- for i = 1, n do +-- local j = i == n and 1 or i + 1 -- Next point (wrap around) + +-- local xi, yi = points[i].x or points[i][1], points[i].y or points[i][2] +-- local xj, yj = points[j].x or points[j][1], points[j].y or points[j][2] + +-- -- Ensure xi, yi, xj, yj are numbers +-- if not (xi and yi and xj and yj) then +-- goto continue +-- end + +-- -- Ray casting test +-- if ((yi > y) ~= (yj > y)) then +-- -- Calculate intersection point +-- local intersect = (xj - xi) * (y - yi) / (yj - yi) + xi +-- if x < intersect then +-- inside = not inside +-- end +-- end + +-- ::continue:: +-- end + +-- return inside +-- end + +-- -- Fallback to true if boundary format is not recognized +-- return true +-- end + +local function checkMaterialAndBoundary() + if not state.currentEntity then return true end + + local pos = GetEntityCoords(state.currentEntity) + local inBounds = Bridge.Math.InBoundary(pos, state.settings.boundary) + + -- Check built-in boundary first + if state.settings.boundary and not inBounds then return false end + + -- Check custom boundary function if provided + if state.settings.customCheck then + local customResult = state.settings.customCheck(pos, state.currentEntity, state.settings) + if not customResult then return false end end - return target -end -local function inBoundary(pos, boundary) - if not boundary then return true end - local x, y, z = table.unpack(pos) - local minX, minY, minZ = table.unpack(boundary.min) - local maxX, maxY, maxZ = table.unpack(boundary.max) - return x >= minX and x <= maxX and y >= minY and y <= maxY and z >= minZ and z <= maxZ -end - -local function checkBoundaryAndMaterials(entity, settings) - local inBounds = true - if settings.allowedMats or settings.boundary then - CreateThread(function() - while isPlacing do - local hit, _, coords, _, materialHash - - if currentMode == 'movement' then - local entityCoords = GetEntityCoords(entity) - local destination = entityCoords - vector3(0, 0, settings.maxDepth or 10) - hit, _, coords, _, materialHash = Raycast.ToCoords(entityCoords, destination, 1, 4) - else - hit, _, coords, _, materialHash = Raycast.FromCamera(1, 4) + -- Check allowed materials + if state.settings.allowedMats then + local hit, _, _, _, materialHash = GetShapeTestResult(StartShapeTestRay(pos.x, pos.y, pos.z + 1.0, pos.x, pos.y, pos.z - 5.0, -1, 0, 7)) + if hit == 1 then + for _, allowedMat in ipairs(state.settings.allowedMats) do + if materialHash == GetHashKey(allowedMat) then + return inBounds end + end + return false + end + end - local validMaterial = not settings.allowedMats or settings.allowedMats[materialHash] - local validBoundary = inBoundary(GetEntityCoords(entity), settings.boundary) + return inBounds +end - if hit and hit ~= 1 and validMaterial and validBoundary then - if not inBounds then - inBounds = true - SetEntityDrawOutlineColor(0, 255, 0, 255) - SetEntityDrawOutline(entity, true) - end - elseif inBounds then - inBounds = false - SetEntityDrawOutline(entity, false) +local function checkMaterialAndBoundaryDetailed() + if not state.currentEntity then return true, true, true end + + local pos = GetEntityCoords(state.currentEntity) + local inBounds = Bridge.Math.InBoundary(pos, state.settings.boundary) + local customCheckPassed = true + local materialCheckPassed = true + + -- Check built-in boundary first + if state.settings.boundary and not inBounds then + return false, false, customCheckPassed + end + + -- Check custom boundary function if provided + if state.settings.customCheck then + customCheckPassed = state.settings.customCheck(pos, state.currentEntity, state.settings) + if not customCheckPassed then + return false, inBounds, false + end + end + + -- Check allowed materials + if state.settings.allowedMats then + local hit, _, _, _, materialHash = GetShapeTestResult(StartShapeTestRay(pos.x, pos.y, pos.z + 1.0, pos.x, pos.y, pos.z - 5.0, -1, 0, 7)) + if hit == 1 then + for _, allowedMat in ipairs(state.settings.allowedMats) do + if materialHash == GetHashKey(allowedMat) then + return inBounds, inBounds, customCheckPassed end - Wait(500) end - SetEntityDrawOutline(entity, false) - end) + materialCheckPassed = false + return false, inBounds, customCheckPassed + end end - return function() return inBounds end + + return inBounds, inBounds, customCheckPassed end -local function setupInstructionalButtons(settings) - local buttons = { - {type = "CLEAR_ALL"}, - {type = "SET_CLEAR_SPACE", int = 200}, - } +-- local function setupInstructionalButtons() +-- local buttons = {} - -- Common buttons - table.insert(buttons, {type = "SET_DATA_SLOT", name = settings.config?.place_object?.name or 'Place Object:', keyIndex = settings.config?.place_object?.key or {223}, int = 5}) - table.insert(buttons, {type = "SET_DATA_SLOT", name = settings.config?.cancel_placement?.name or 'Cancel Placement:', keyIndex = settings.config?.cancel_placement?.key or {222}, int = 4}) +-- -- Common buttons +-- table.insert(buttons, {type = "SET_DATA_SLOT", name = state.settings.config?.place_object?.name or 'Place Object:', keyIndex = state.settings.config?.place_object?.key or {223}, int = 5}) +-- table.insert(buttons, {type = "SET_DATA_SLOT", name = state.settings.config?.cancel_placement?.name or 'Cancel:', keyIndex = state.settings.config?.cancel_placement?.key or {25}, int = 4}) - if currentMode == 'normal' then - table.insert(buttons, {type = "SET_DATA_SLOT", name = settings.config?.snap_to_ground?.name or 'Snap to Ground:', keyIndex = settings.config?.snap_to_ground?.key or {19}, int = 1}) - table.insert(buttons, {type = "SET_DATA_SLOT", name = settings.config?.rotate?.name or 'Rotate:', keyIndex = settings.config?.rotate?.key or {14, 15}, int = 2}) - table.insert(buttons, {type = "SET_DATA_SLOT", name = settings.config?.distance?.name or 'Distance:', keyIndex = settings.config?.distance?.key or {14,15,36}, int = 3}) - table.insert(buttons, {type = "SET_DATA_SLOT", name = settings.config?.toggle_placement?.name or 'Toggle Placement:', keyIndex = settings.config?.toggle_placement?.key or {199}, int = 0}) +-- if state.mode == 'normal' then +-- table.insert(buttons, {type = "SET_DATA_SLOT", name = 'Rotate:', keyIndex = {241, 242}, int = 3}) +-- table.insert(buttons, {type = "SET_DATA_SLOT", name = 'Depth:', keyIndex = {224}, int = 2}) +-- if state.settings.allowVertical then +-- table.insert(buttons, {type = "SET_DATA_SLOT", name = 'Height:', keyIndex = {16, 17}, int = 1}) +-- table.insert(buttons, {type = "SET_DATA_SLOT", name = 'Toggle Ground Snap:', keyIndex = {19}, int = 0}) +-- end +-- if state.settings.allowMovement then +-- table.insert(buttons, {type = "SET_DATA_SLOT", name = 'Movement Mode:', keyIndex = {38}, int = 6}) +-- end +-- elseif state.mode == 'movement' then +-- table.insert(buttons, {type = "SET_DATA_SLOT", name = 'Move:', keyIndex = {32, 33, 34, 35}, int = 3}) +-- table.insert(buttons, {type = "SET_DATA_SLOT", name = 'Rotate:', keyIndex = {174, 175}, int = 2}) +-- if state.settings.allowVertical then +-- table.insert(buttons, {type = "SET_DATA_SLOT", name = 'Up/Down:', keyIndex = {85, 48}, int = 1}) +-- end +-- if state.settings.allowNormal then +-- table.insert(buttons, {type = "SET_DATA_SLOT", name = 'Normal Mode:', keyIndex = {38}, int = 0}) +-- end +-- end - -- Add vertical controls if allowed - if settings.allowVertical then - table.insert(buttons, {type = "SET_DATA_SLOT", name = 'Move Up/Down:', keyIndex = {85, 48}, int = 8}) - end +-- table.insert(buttons, {type = "DRAW_INSTRUCTIONAL_BUTTONS"}) +-- table.insert(buttons, {type = "SET_BACKGROUND_COLOUR"}) - if settings.allowMovement then - table.insert(buttons, {type = "SET_DATA_SLOT", name = settings.config?.movement?.name or 'Toggle Movement Mode:', keyIndex = settings.config?.movement?.key or {38}, int = 6}) - end - elseif currentMode == 'movement' then - table.insert(buttons, {type = "SET_DATA_SLOT", name = 'Move Forward/Back:', keyIndex = {32, 33}, int = 1}) - table.insert(buttons, {type = "SET_DATA_SLOT", name = 'Move Left/Right:', keyIndex = {34, 35}, int = 2}) - table.insert(buttons, {type = "SET_DATA_SLOT", name = 'Move Up/Down:', keyIndex = {85, 48}, int = 3}) - table.insert(buttons, {type = "SET_DATA_SLOT", name = 'Rotate Left/Right:', keyIndex = {174, 175}, int = 4}) - table.insert(buttons, {type = "SET_DATA_SLOT", name = 'Snap to Ground:', keyIndex = {19}, int = 5}) - table.insert(buttons, {type = "SET_DATA_SLOT", name = 'Confirm (Enter):', keyIndex = {191}, int = 6}) - - if settings.allowNormal then - table.insert(buttons, {type = "SET_DATA_SLOT", name = 'Normal Mode:', keyIndex = {38}, int = 7}) - end - end - - table.insert(buttons, {type = "DRAW_INSTRUCTIONAL_BUTTONS"}) - table.insert(buttons, {type = "SET_BACKGROUND_COLOUR"}) - - return Scaleform.SetupInstructionalButtons(buttons) -end - -local function normalPlacementLoop(entity, settings, getBoundsStatus) - -- Initialize or retrieve from settings to maintain state - settings.currentDepth = settings.currentDepth or settings.depth or 10.0 - settings.currentHeading = settings.currentHeading or -GetEntityHeading(PlayerPedId()) - settings.currentHeight = settings.currentHeight or 0.0 -- Add height tracking - settings.placeOnGround = settings.placeOnGround ~= nil and settings.placeOnGround or not settings.allowVertical -- Default based on allowVertical - settings.paused = settings.paused or false - - local depth = settings.currentDepth - local heading = settings.currentHeading - local height = settings.currentHeight - local placeOnGround = settings.placeOnGround - local paused = settings.paused - local pos - - -- Don't use while loop here, just process one frame - if not isPlacing or currentMode ~= 'normal' then - return - end - - if paused then - if IsControlJustPressed(0, 199) then -- home - paused = not paused - settings.paused = paused - end - return - end - - -- Disable controls - DisableControlAction(0, 24, true) -- Attack - DisableControlAction(0, 25, true) -- Aim - DisableControlAction(0, 36, true) -- INPUT_DUCK - - -- Place object (left click) - if IsDisabledControlJustPressed(0, 223) then - if not getBoundsStatus() then - print(Language.Locale("placeable_object.cant_place_here")) - else - pos = GetEntityCoords(entity) - isPlacing = false - if currentPromise then - currentPromise:resolve({ - entity = entity, - position = pos, - heading = heading - }) - currentPromise = nil - end - DeleteEntity(entity) - return - end - end - - -- Cancel (right click) - if IsDisabledControlJustPressed(0, 25) then - isPlacing = false - if currentPromise then - currentPromise:resolve(nil) -- Return nil for cancel - currentPromise = nil - end - DeleteEntity(entity) - return - end - - -- Toggle snap to ground (Alt) - if IsControlJustPressed(0, 19) then - if settings.allowVertical then - placeOnGround = not placeOnGround - settings.placeOnGround = placeOnGround - if placeOnGround then - height = 0.0 -- Reset height when snapping to ground - settings.currentHeight = height - end - else - -- Force snap to ground if vertical movement not allowed - PlaceObjectOnGroundProperly(entity) - end - end - - -- Switch to movement mode - if settings.allowMovement and IsControlJustPressed(0, 38) then - currentMode = 'movement' - return - end - - -- Vertical controls (only if allowVertical is enabled and not snapped to ground) - if settings.allowVertical and not placeOnGround then - if IsControlPressed(0, 85) then -- Q - Move up - height = height + (settings.heightStep or 0.1) - settings.currentHeight = height - elseif IsControlPressed(0, 48) then -- Z - Move down - height = height - (settings.heightStep or 0.1) - settings.currentHeight = height - end - end - - -- Depth and rotation controls - if IsControlPressed(0, 224) then -- left ctrl - if IsControlJustPressed(0, 15) then -- D key - depth = math.min(depth + settings.depthStep, settings.depthMax) - elseif IsControlJustPressed(0, 14) then -- A key - depth = math.max(depth - settings.depthStep, settings.depthMin) - end - else - if IsControlJustPressed(0, 15) then -- D key - heading = (heading + settings.rotationStep) % 360 - elseif IsControlJustPressed(0, 14) then -- A key - heading = (heading - settings.rotationStep) % 360 - end - end - - -- Update position - pos = eyetrace(depth, settings.disableSphere) - - -- Add height offset if not snapping to ground - if settings.allowVertical and not placeOnGround then - pos = pos + vector3(0, 0, height) - end - - if entity then - SetEntityCoords(entity, pos.x, pos.y, pos.z) - SetEntityHeading(entity, heading) - if placeOnGround then - PlaceObjectOnGroundProperly(entity) - pos = GetEntityCoords(entity) - end - end - - -- Store updated values back to settings - settings.currentDepth = depth - settings.currentHeading = heading - settings.currentHeight = height - settings.placeOnGround = placeOnGround -end - -local function movementPlacementLoop(entity, settings, getBoundsStatus) - -- Don't use while loop here, just process one frame - if not isPlacing or currentMode ~= 'movement' or not DoesEntityExist(entity) then - return - end - - if IsEntityAPed(entity) then - SetEntityAlpha(entity, 200) - end - - -- Disable movement controls to prevent player from moving - DisableControlAction(0, 30, true) -- Move Left/Right - DisableControlAction(0, 31, true) -- Move Forward/Back - DisableControlAction(0, 36, true) -- INPUT_DUCK - DisableControlAction(0, 21, true) -- Sprint - DisableControlAction(0, 22, true) -- Jump - - SetEntityCollision(entity, false, false) - FreezeEntityPosition(entity, false) - - -- Get current entity position and rotation - local coords = GetEntityCoords(entity) - local heading = GetEntityHeading(entity) - local moved = false - - -- Movement speed settings - local moveSpeed = 0.1 - local fastMoveSpeed = 0.5 - local rotateSpeed = 2.0 - - -- Check if shift is held for faster movement - local isFastMode = IsControlPressed(0, 21) -- Left Shift - local currentMoveSpeed = isFastMode and fastMoveSpeed or moveSpeed - - -- Get camera rotation for relative movement - local camRot = GetGameplayCamRot(2) - local camHeading = math.rad(camRot.z) - - -- Calculate camera-relative directions - local camForward = vector3(-math.sin(camHeading), math.cos(camHeading), 0) - local camRight = vector3(math.cos(camHeading), math.sin(camHeading), 0) - - -- WASD movement (relative to camera direction) - if IsControlPressed(0, 32) then -- W - Move forward relative to camera - coords = coords + camForward * currentMoveSpeed - moved = true - elseif IsControlPressed(0, 33) then -- S - Move backward relative to camera - coords = coords - camForward * currentMoveSpeed - moved = true - end - - if IsControlPressed(0, 34) then -- A - Move left relative to camera - coords = coords - camRight * currentMoveSpeed - moved = true - elseif IsControlPressed(0, 35) then -- D - Move right relative to camera - coords = coords + camRight * currentMoveSpeed - moved = true - end - - -- Up/Down movement (always world-relative) - if settings.allowVertical and IsControlPressed(0, 85) then -- Q - Move up - coords = coords + vector3(0, 0, currentMoveSpeed) - moved = true - elseif settings.allowVertical and IsControlPressed(0, 48) then -- Z - Move down - coords = coords + vector3(0, 0, -currentMoveSpeed) - moved = true - end - - -- Rotation controls - if IsControlPressed(0, 174) then -- Left Arrow - Rotate left - heading = heading - rotateSpeed - moved = true - elseif IsControlPressed(0, 175) then -- Right Arrow - Rotate right - heading = heading + rotateSpeed - moved = true - end - - -- Alternative rotation with mouse wheel - if IsControlJustPressed(0, 241) then -- Mouse wheel up - heading = heading + 15.0 - moved = true - elseif IsControlJustPressed(0, 242) then -- Mouse wheel down - heading = heading - 15.0 - moved = true - end - - -- Apply movement if any occurred - if moved then - SetEntityCoords(entity, coords.x, coords.y, coords.z, false, false, false, false) - SetEntityHeading(entity, heading) - end - - -- Confirm placement (Enter) - if IsControlJustPressed(0, 191) then - if not getBoundsStatus() then - print(Language.Locale("placeable_object.cant_place_here")) - return - end - isPlacing = false - if currentPromise then - currentPromise:resolve({ - entity = entity, - position = GetEntityCoords(entity), - heading = GetEntityHeading(entity), - rotation = GetEntityRotation(entity) - }) - currentPromise = nil - end - DeleteEntity(entity) - return - end - - -- Cancel placement (Backspace) - if IsControlJustPressed(0, 202) then - isPlacing = false - if currentPromise then - currentPromise:resolve(nil) -- Return nil for cancel - currentPromise = nil - end - DeleteEntity(entity) - return - end - - -- Switch to normal mode (E) - if settings.allowNormal and IsControlJustPressed(0, 38) then - currentMode = 'normal' - local playerPos = GetEntityCoords(PlayerPedId()) - local entityPos = GetEntityCoords(entity) - local depth = #(playerPos - entityPos) - settings.currentDepth = depth - return - end - - -- Snap to ground (Alt) - if IsControlJustPressed(0, 19) then - PlaceObjectOnGroundProperly(entity) - end - - FreezeEntityPosition(entity, false) -end +-- -- return Scaleform.SetupInstructionalButtons(buttons) +-- return nil -- Scaleform disabled for now +-- end local function drawBoundaryBox(boundary) if not boundary then return end - local min = boundary.min - local max = boundary.max + -- Handle legacy min/max boundary format for backwards compatibility + if boundary.min and boundary.max then + local min = boundary.min + local max = boundary.max - -- Define the 8 corners of the box - local corners = { - vector3(min.x, min.y, min.z), -- 1: bottom front left - vector3(max.x, min.y, min.z), -- 2: bottom front right - vector3(max.x, max.y, min.z), -- 3: bottom back right - vector3(min.x, max.y, min.z), -- 4: bottom back left - vector3(min.x, min.y, max.z), -- 5: top front left - vector3(max.x, min.y, max.z), -- 6: top front right - vector3(max.x, max.y, max.z), -- 7: top back right - vector3(min.x, max.y, max.z), -- 8: top back left - } + -- Define the 8 corners of the box + local corners = { + vector3(min.x, min.y, min.z), -- 1 + vector3(max.x, min.y, min.z), -- 2 + vector3(max.x, max.y, min.z), -- 3 + vector3(min.x, max.y, min.z), -- 4 + vector3(min.x, min.y, max.z), -- 5 + vector3(max.x, min.y, max.z), -- 6 + vector3(max.x, max.y, max.z), -- 7 + vector3(min.x, max.y, max.z), -- 8 + } - -- Draw the box faces as triangles (2 triangles per face) - local alpha = 50 -- Semi-transparent - local r, g, b = 0, 255, 0 -- Green color + -- Draw wireframe box + local r, g, b, a = 0, 255, 0, 100 - -- Bottom face (looking up from below) - DrawPoly(corners[1].x, corners[1].y, corners[1].z, corners[2].x, corners[2].y, corners[2].z, corners[3].x, corners[3].y, corners[3].z, r, g, b, alpha) - DrawPoly(corners[1].x, corners[1].y, corners[1].z, corners[3].x, corners[3].y, corners[3].z, corners[4].x, corners[4].y, corners[4].z, r, g, b, alpha) + -- Bottom face + DrawLine(corners[1].x, corners[1].y, corners[1].z, corners[2].x, corners[2].y, corners[2].z, r, g, b, a) + DrawLine(corners[2].x, corners[2].y, corners[2].z, corners[3].x, corners[3].y, corners[3].z, r, g, b, a) + DrawLine(corners[3].x, corners[3].y, corners[3].z, corners[4].x, corners[4].y, corners[4].z, r, g, b, a) + DrawLine(corners[4].x, corners[4].y, corners[4].z, corners[1].x, corners[1].y, corners[1].z, r, g, b, a) - -- Top face (looking down from above) - DrawPoly(corners[5].x, corners[5].y, corners[5].z, corners[7].x, corners[7].y, corners[7].z, corners[6].x, corners[6].y, corners[6].z, r, g, b, alpha) - DrawPoly(corners[5].x, corners[5].y, corners[5].z, corners[8].x, corners[8].y, corners[8].z, corners[7].x, corners[7].y, corners[7].z, r, g, b, alpha) + -- Top face + DrawLine(corners[5].x, corners[5].y, corners[5].z, corners[6].x, corners[6].y, corners[6].z, r, g, b, a) + DrawLine(corners[6].x, corners[6].y, corners[6].z, corners[7].x, corners[7].y, corners[7].z, r, g, b, a) + DrawLine(corners[7].x, corners[7].y, corners[7].z, corners[8].x, corners[8].y, corners[8].z, r, g, b, a) + DrawLine(corners[8].x, corners[8].y, corners[8].z, corners[5].x, corners[5].y, corners[5].z, r, g, b, a) - -- Front face (min Y) - DrawPoly(corners[1].x, corners[1].y, corners[1].z, corners[5].x, corners[5].y, corners[5].z, corners[6].x, corners[6].y, corners[6].z, r, g, b, alpha) - DrawPoly(corners[1].x, corners[1].y, corners[1].z, corners[6].x, corners[6].y, corners[6].z, corners[2].x, corners[2].y, corners[2].z, r, g, b, alpha) - - -- Back face (max Y) - DrawPoly(corners[4].x, corners[4].y, corners[4].z, corners[7].x, corners[7].y, corners[7].z, corners[8].x, corners[8].y, corners[8].z, r, g, b, alpha) - DrawPoly(corners[4].x, corners[4].y, corners[4].z, corners[3].x, corners[3].y, corners[3].z, corners[7].x, corners[7].y, corners[7].z, r, g, b, alpha) - - -- Left face (min X) - DrawPoly(corners[1].x, corners[1].y, corners[1].z, corners[4].x, corners[4].y, corners[4].z, corners[8].x, corners[8].y, corners[8].z, r, g, b, alpha) - DrawPoly(corners[1].x, corners[1].y, corners[1].z, corners[8].x, corners[8].y, corners[8].z, corners[5].x, corners[5].y, corners[5].z, r, g, b, alpha) - - -- Right face (max X) - DrawPoly(corners[2].x, corners[2].y, corners[2].z, corners[6].x, corners[6].y, corners[6].z, corners[7].x, corners[7].y, corners[7].z, r, g, b, alpha) - DrawPoly(corners[2].x, corners[2].y, corners[2].z, corners[7].x, corners[7].y, corners[7].z, corners[3].x, corners[3].y, corners[3].z, r, g, b, alpha) -end - --- Main placement function - now uses proper promise pattern -function PlaceableObject.Create(model, settings) - if isPlacing then - return nil -- Already placing + -- Vertical edges + DrawLine(corners[1].x, corners[1].y, corners[1].z, corners[5].x, corners[5].y, corners[5].z, r, g, b, a) + DrawLine(corners[2].x, corners[2].y, corners[2].z, corners[6].x, corners[6].y, corners[6].z, r, g, b, a) + DrawLine(corners[3].x, corners[3].y, corners[3].z, corners[7].x, corners[7].y, corners[7].z, r, g, b, a) + DrawLine(corners[4].x, corners[4].y, corners[4].z, corners[8].x, corners[8].y, corners[8].z, r, g, b, a) + return end - settings = settings or {} + -- Handle list of points (polygon boundary) + if boundary.points and #boundary.points > 0 then + local points = boundary.points + local minZ = boundary.minZ or 0 + local maxZ = boundary.maxZ or 50 + local r, g, b, a = 0, 255, 0, 100 + + -- Draw bottom polygon outline + for i = 1, #points do + local currentPoint = points[i] + local nextPoint = points[i % #points + 1] -- Wrap around to first point + + local x1, y1 = currentPoint.x or currentPoint[1], currentPoint.y or currentPoint[2] + local x2, y2 = nextPoint.x or nextPoint[1], nextPoint.y or nextPoint[2] + + -- Bottom edge + DrawLine(x1, y1, minZ, x2, y2, minZ, r, g, b, a) + + -- Top edge + DrawLine(x1, y1, maxZ, x2, y2, maxZ, r, g, b, a) + + -- Vertical edge + DrawLine(x1, y1, minZ, x1, y1, maxZ, r, g, b, a) + end + return + end +end + +local function drawEntityBoundingBox(entity, inBounds) + if not entity or not DoesEntityExist(entity) then return end + + -- Enable entity outline + SetEntityDrawOutlineShader(1) + SetEntityDrawOutline(entity, true) + -- Set color based on boundary status + if inBounds then + -- Green outline for valid placement + SetEntityDrawOutlineColor(0, 255, 0, 255) + else + -- Red outline for invalid placement + SetEntityDrawOutlineColor(255, 0, 0, 255) + end +end + +local function handleNormalMode() + if not state.isPlacing or state.mode ~= 'normal' or state.paused then + return + end + + -- Disable conflicting controls + DisableControlAction(0, 24, true) -- Attack + DisableControlAction(0, 25, true) -- Aim + DisableControlAction(0, 36, true) -- Duck + + local moveSpeed = state.keys.depthModifier and (state.settings.depthStep or 0.1) or (state.settings.rotationStep or 0.5) + + -- Scroll wheel controls using key mappings + if state.keys.depthModifier then -- Depth modifier held - depth control + if state.keys.scrollUp then + state.keys.scrollUp = false -- Reset the key state + state.depth = math.min(state.settings.maxDepth, state.depth + moveSpeed) -- Use maxDepth setting + elseif state.keys.scrollDown then + state.keys.scrollDown = false -- Reset the key state + state.depth = math.max(1.0, state.depth - moveSpeed) -- Fixed: scroll down decreases distance + end + else -- Regular scroll - rotation + if state.keys.scrollUp then + state.keys.scrollUp = false -- Reset the key state + state.heading = state.heading - 5.0 -- Fixed: scroll up = counterclockwise + elseif state.keys.scrollDown then + state.keys.scrollDown = false -- Reset the key state + state.heading = state.heading + 5.0 -- Fixed: scroll down = clockwise + end + end + + -- -- Arrow key rotation using key mappings + -- if state.keys.rotateLeft then + -- state.heading = state.heading + 2.0 + -- elseif state.keys.rotateRight then + -- state.heading = state.heading - 2.0 + -- end + + -- Height controls (only if vertical movement allowed and not snapped to ground) + if state.settings.allowVertical and not state.snapToGround then + if IsControlPressed(0, 16) then -- Q + state.height = state.height + (state.settings.heightStep or 0.5) + elseif IsControlPressed(0, 17) then -- E + state.height = state.height - (state.settings.heightStep or 0.5) + end + end + -- Toggle ground snap + if state.settings.allowVertical and IsControlJustPressed(0, 19) then -- Alt + state.snapToGround = not state.snapToGround + if state.snapToGround then + state.height = 0.0 + end + end + + -- Switch to movement mode + if state.settings.allowMovement and IsControlJustPressed(0, 38) then -- E + state.mode = 'movement' + SetEntityCollision(state.currentEntity, false, false) + end + -- Update entity position + local pos = getMouseWorldPos(state.depth) + + if not state.snapToGround and state.settings.allowVertical then + pos = pos + vector3(0, 0, state.height) + end + + if state.currentEntity then + SetEntityCoords(state.currentEntity, pos.x, pos.y, pos.z, false, false, false, false) + SetEntityHeading(state.currentEntity, state.heading) + if state.snapToGround then + local slerp = PlaceObjectOnGroundProperly(state.currentEntity) + if not slerp then + -- If the object can't be placed on the ground, adjust its Z position + local groundZ, _z = GetGroundZFor_3dCoord(pos.x, pos.y, pos.z + 50, false) + if groundZ then + SetEntityCoords(state.currentEntity, pos.x, pos.y, _z, false, false, false, true) + end + end + end + end + -- Visual feedback + if not state.settings.disableSphere then + DrawSphere(pos.x, pos.y, pos.z, 0.5, 255, 0, 0, 50) + end +end + +local function handleMovementMode() + if not state.isPlacing or state.mode ~= 'movement' or not DoesEntityExist(state.currentEntity) then + return + end + + -- Disable player movement + DisableControlAction(0, 30, true) -- Move Left/Right + DisableControlAction(0, 31, true) -- Move Forward/Back + DisableControlAction(0, 36, true) -- Duck + DisableControlAction(0, 21, true) -- Sprint + DisableControlAction(0, 22, true) -- Jump + + local coords = GetEntityCoords(state.currentEntity) + local heading = GetEntityHeading(state.currentEntity) + local moveSpeed = IsControlPressed(0, 21) and (state.settings.movementStepFast or 0.5) or (state.settings.movementStep or 0.1) -- Faster with shift + local moved = false + + -- Get camera direction for relative movement + local camRot = GetGameplayCamRot(2) + local camHeading = math.rad(camRot.z) + local camForward = vector3(-math.sin(camHeading), math.cos(camHeading), 0) + local camRight = vector3(math.cos(camHeading), math.sin(camHeading), 0) + + -- WASD movement + if IsControlPressed(0, 32) then -- W + coords = coords + camForward * moveSpeed + moved = true + elseif IsControlPressed(0, 33) then -- S + coords = coords - camForward * moveSpeed + moved = true + end + + if IsControlPressed(0, 34) then -- A + coords = coords - camRight * moveSpeed + moved = true + elseif IsControlPressed(0, 35) then -- D + coords = coords + camRight * moveSpeed + moved = true + end + + -- Vertical movement + if state.settings.allowVertical then + if IsControlPressed(0, 85) then -- Q + coords = coords + vector3(0, 0, moveSpeed) + moved = true + elseif IsControlPressed(0, 48) then -- Z + coords = coords + vector3(0, 0, -moveSpeed) + moved = true + end + end + + -- Rotation + if IsControlPressed(0, 174) then -- Left arrow + heading = heading + 2.0 + moved = true + elseif IsControlPressed(0, 175) then -- Right arrow + heading = heading - 2.0 + moved = true + end + + -- Apply changes + if moved then + SetEntityCoords(state.currentEntity, coords.x, coords.y, coords.z, false, false, false, true) + SetEntityHeading(state.currentEntity, heading) + end + + -- Switch to normal mode + if state.settings.allowNormal and IsControlJustPressed(0, 38) then -- E + state.mode = 'normal' + SetEntityCollision(state.currentEntity, true, true) + end + + -- Snap to ground + if IsControlJustPressed(0, 19) then -- Alt + PlaceObjectOnGroundProperly(state.currentEntity) + end +end + +local function placementLoop() + CreateThread(function() + while state.isPlacing do + Wait(0) + + -- Handle input based on mode + if state.mode == 'normal' then + handleNormalMode() + elseif state.mode == 'movement' then + handleMovementMode() + end + + -- Common controls using key mappings + if state.keys.placeObject then + state.keys.placeObject = false -- Reset the key state + local canPlace = checkMaterialAndBoundary() + if canPlace then + Wait(100) + local coords = GetEntityCoords(state.currentEntity) + if not state.settings.allowVertical or state.snapToGround then + local groundZ, _z = GetGroundZFor_3dCoord(coords.x, coords.y, coords.z + 50, false) + if groundZ then + coords = vector3(coords.x, coords.y, _z) + end + end + + local rotation = GetEntityRotation(state.currentEntity) + if state.promise then + state.promise:resolve({ + entity = state.currentEntity, + coords = coords, + rotation = rotation, + placed = true + }) + end + + PlaceableObject.Stop() + break + end + end + + -- Cancel placement using key mapping + if state.keys.cancelPlacement then + state.keys.cancelPlacement = false -- Reset the key state + if state.promise then + state.promise:resolve(false) + end + + PlaceableObject.Stop() + break + end + + -- Check if entity is outside boundary and cancel if so + if state.settings.boundary and state.currentEntity then + local canPlace = checkMaterialAndBoundary() + if not canPlace then + if state.promise then + state.promise:resolve(false) + end + + PlaceableObject.Stop() + break + end + end + + -- Draw boundary if exists and enabled + if state.settings.drawBoundary then + drawBoundaryBox(state.settings.boundary) + end + + -- Draw entity bounding box if enabled + if state.settings.drawInBoundary and state.currentEntity then + local overallResult, boundaryResult, customResult = checkMaterialAndBoundaryDetailed() + -- Show red if any check fails, green if all pass + local inBounds = overallResult + drawEntityBoundingBox(state.currentEntity, inBounds) + end + + -- Show help text for placement controls + local placementText = { + string.format(locale('placeable_object.place_object_place'), Bridge.Utility.GetCommandKey('+place_object')), + string.format(locale('placeable_object.place_object_cancel'), Bridge.Utility.GetCommandKey('+cancel_placement')), + -- string.format(locale('placeable_object.rotate_left'), Bridge.Utility.GetCommandKey('+rotate_left')), + -- string.format(locale('placeable_object.rotate_right'), Bridge.Utility.GetCommandKey('+rotate_right')), + string.format(locale('placeable_object.place_object_scroll_up'), Bridge.Utility.GetCommandKey('+scroll_up')), + string.format(locale('placeable_object.place_object_scroll_down'), Bridge.Utility.GetCommandKey('+scroll_down')), + string.format(locale('placeable_object.depth_modifier'), Bridge.Utility.GetCommandKey('+depth_modifier')) + } + Bridge.Notify.ShowHelpText(type(placementText) == 'table' and table.concat(placementText)) + + -- -- Draw entity bounding box + -- drawEntityBoundingBox(state.currentEntity, checkMaterialAndBoundary()) + + -- -- Update instructional buttons + -- if state.scaleform then + -- Scaleform.RenderInstructionalButtons(state.scaleform) + -- end + end + end) +end + +-- Main functions + + +---@param model - Model name or hash +---@param settings - Configuration table: +--[[ + depth (3.0): Starting distance from player, + allowVertical (false): Enable height controls, + allowMovement (false): Enable WASD mode, + disableSphere (false): Hide position indicator, + boundary: Area restriction {min = vector3(), max = vector3()}, + allowedMats: Surface materials {"concrete", "grass"}, + depthStep (0.1): Step size for depth adjustment, + rotationStep (0.5): Step size for rotation, + heightStep (0.5): Step size for height adjustment, + movementStep (0.1): Step size for normal movement, + movementStepFast (0.5): Step size for fast movement (with shift), + maxDepth (50.0): Maximum distance from player, +--]] +---@returns Promise with: {entity, coords, heading, placed, cancelled} +--[[ + Example: + local result = Citizen.Await(PlaceableObject.Create("prop_barrier_work05", { + depth = 5.0, + allowVertical = false + })) +--]] + +function PlaceableObject.Create(model, settings) + if state.isPlacing then + PlaceableObject.Stop() + end -- Default settings - local config = { - depthMin = settings.depthMin or 2.0, - depthMax = settings.depthMax or 10.0, - rotationStep = settings.rotationStep or 15.0, - depthStep = settings.depthStep or 1.0, - heightStep = settings.heightStep or 0.1, -- New height step setting - disableSphere = settings.useSphere and false or true, - depth = settings.depth or 10.0, - allowMovement = settings.allowMovement ~= false, -- default true - allowNormal = settings.allowNormal ~= false, -- default true - allowVertical = settings.allowVertical ~= false, -- default true - allow vertical movement in normal mode - startMode = settings.startMode or 'normal', -- 'normal' or 'movement' - allowedMats = settings.allowedMats, - boundary = settings.boundary, - config = settings.config or {}, - maxDepth = settings.maxDepth or 10, - showInstructionalButtons = settings.showInstructionalButtons + settings = settings or {} + settings.depth = settings.depth or 3.0 -- Start closer to player + settings.allowVertical = settings.allowVertical or false + settings.allowMovement = settings.allowMovement or false + settings.allowNormal = settings.allowNormal or false + settings.disableSphere = settings.disableSphere or false + settings.drawBoundary = settings.drawBoundary or false + settings.drawInBoundary = settings.drawInBoundary or false + + -- Movement speed settings + settings.depthStep = settings.depthStep or 0.1 -- Fine control for depth adjustment + settings.rotationStep = settings.rotationStep or 0.5 -- Normal rotation speed + settings.heightStep = settings.heightStep or 0.5 -- Height adjustment speed + settings.movementStep = settings.movementStep or 0.1 -- Normal movement speed + settings.movementStepFast = settings.movementStepFast or 0.5 -- Fast movement speed (with shift) + settings.maxDepth = settings.maxDepth or 5.0 -- Maximum distance from player + + state.settings = settings + state.depth = settings.depth -- Use the settings depth + state.heading = -GetEntityHeading(PlayerPedId()) + state.height = 0.0 + state.snapToGround = not settings.allowVertical + state.mode = 'normal' + + local p = promise.new() + state.promise = p + + local point = Bridge.ClientEntity.Create({ + id = 'placeable_object', + entityType = 'object', + model = model, + coords = GetEntityCoords(PlayerPedId()), + rotation = vector3(0.0, 0.0, state.heading), + OnSpawn= function(data) + state.currentEntity = data.spawned + SetEntityCollision(state.currentEntity, false, false) + FreezeEntityPosition(state.currentEntity, false) + + -- Set initial position based on depth + local playerPos = GetEntityCoords(PlayerPedId()) + local forward = GetEntityForwardVector(PlayerPedId()) + local spawnPos = playerPos + forward * state.depth + SetEntityCoords(state.currentEntity, spawnPos.x, spawnPos.y, spawnPos.z + state.height, false, false, false, true) + end, + }) + -- Setup instructional buttons + -- state.scaleform = setupInstructionalButtons() + state.scaleform = nil + + state.isPlacing = true + + -- Show help text for placement controls + local placementText = { + string.format(locale('placeable_object.place_object_place'), Bridge.Utility.GetCommandKey('+place_object')), + string.format(locale('placeable_object.place_object_cancel'), Bridge.Utility.GetCommandKey('+cancel_placement')), + -- string.format(locale('placeable_object.rotate_left'), Bridge.Utility.GetCommandKey('+rotate_left')), + -- string.format(locale('placeable_object.rotate_right'), Bridge.Utility.GetCommandKey('+rotate_right')), + string.format(locale('placeable_object.place_object_scroll_up'), Bridge.Utility.GetCommandKey('+scroll_up')), + string.format(locale('placeable_object.place_object_scroll_down'), Bridge.Utility.GetCommandKey('+scroll_down')), + string.format(locale('placeable_object.depth_modifier'), Bridge.Utility.GetCommandKey('+depth_modifier')) } + Bridge.Notify.ShowHelpText(type(placementText) == 'table' and table.concat(placementText)) - -- Create the promise and store it globally - currentPromise = promise.new() + placementLoop() - isPlacing = true - currentMode = config.startMode - -- Create entity if model provided - if model then - local heading = -GetEntityHeading(PlayerPedId()) - local pos = eyetrace(config.depth, config.disableSphere) - local obj = Utility.CreateProp(model, pos, vector3(0, 0, heading), nil) - currentEntity = obj - else - currentEntity = settings.entity - end - - if not currentEntity then - isPlacing = false - if currentPromise then - currentPromise:resolve(nil) - currentPromise = nil - end - return nil - end - - -- Setup entity - SetEntityCollision(currentEntity, false, false) - SetEntityAlpha(currentEntity, 150, false) - SetPedConfigFlag(PlayerPedId(), 146, true) - SetCanClimbOnEntity(currentEntity, false) - SetEntityCompletelyDisableCollision(currentEntity, true, false) - SetEntityNoCollisionEntity(PlayerPedId(), currentEntity, false) - - -- Setup boundary checking - local getBoundsStatus = checkBoundaryAndMaterials(currentEntity, config) - - -- Setup instructional buttons only if enabled - local scaleform = nil - if config.showInstructionalButtons then - scaleform = setupInstructionalButtons(config) - end - - -- Main loop - CreateThread(function() - local lastMode = currentMode - while isPlacing do - -- Update instructional buttons if mode changed and buttons are enabled - if config.showInstructionalButtons and (not lastMode or lastMode ~= currentMode) then - scaleform = setupInstructionalButtons(config) - lastMode = currentMode - end - - -- Draw instructional buttons only if enabled - if config.showInstructionalButtons and scaleform then - DrawScaleformMovieFullscreen(scaleform, 255, 255, 255, 255, 0) - end - - -- Draw boundary box if defined - if config.boundary then - drawBoundaryBox(config.boundary) - end - - if currentMode == 'normal' and config.allowNormal then - normalPlacementLoop(currentEntity, config, getBoundsStatus) - elseif currentMode == 'movement' and config.allowMovement then - movementPlacementLoop(currentEntity, config, getBoundsStatus) - end - - Wait(0) - end - - -- Cleanup - if DoesEntityExist(currentEntity) then - if IsEntityAPed(currentEntity) then - SetEntityAlpha(currentEntity, 255) - end - SetEntityDrawOutline(currentEntity, false) - end - - currentEntity = nil - end) - - -- Return Citizen.Await on the promise - return Citizen.Await(currentPromise) + return Citizen.Await(p) end --- Stop placement function function PlaceableObject.Stop() - if not isPlacing then return false end - - isPlacing = false - if currentEntity and DoesEntityExist(currentEntity) then - DeleteEntity(currentEntity) + Bridge.Notify.HideHelpText() + if state.currentEntity and DoesEntityExist(state.currentEntity) then + -- Disable entity outline before deleting + SetEntityDrawOutline(state.currentEntity, false) + DeleteObject(state.currentEntity) end + if state.scaleform then + Scaleform.Unload(state.scaleform) + end + ClientEntity.Unregister('placeable_object') + -- Reset state + state.isPlacing = false + state.currentEntity = nil + state.mode = 'normal' + state.promise = nil + state.scaleform = nil + state.settings = {} + return true end --- Get current status +-- Status functions function PlaceableObject.IsPlacing() - return isPlacing + return state.isPlacing end function PlaceableObject.GetCurrentEntity() - return currentEntity + return state.currentEntity end function PlaceableObject.GetCurrentMode() - return currentMode + return state.mode end - +AddEventHandler('onResourceStop', function(resource) + if resource ~= GetCurrentResourceName() then return end + if state.isPlacing then + PlaceableObject.Stop() + end +end) return PlaceableObject \ No newline at end of file diff --git a/lib/sql/server/sqlHandler.lua b/lib/sql/server/sqlHandler.lua index 9336438..644467e 100644 --- a/lib/sql/server/sqlHandler.lua +++ b/lib/sql/server/sqlHandler.lua @@ -2,7 +2,10 @@ SQL = {} Require("lib/MySQL.lua", "oxmysql") - +--- Creates a table in the database if it does not exist. +-- @param tableName The name of the table to create. Example: {{ name = "identifier", type = "VARCHAR(50)", primary = true }} +-- @param columns A table containing column definitions, where each column is a table with 'name' and 'type'. +---@return nil function SQL.Create(tableName, columns) assert(MySQL, "Tried using module SQL without MySQL being loaded") diff --git a/lib/utility/client/utility.lua b/lib/utility/client/utility.lua index 81430e6..6e5a3f8 100644 --- a/lib/utility/client/utility.lua +++ b/lib/utility/client/utility.lua @@ -481,7 +481,7 @@ end ---@param value T The value to match against the cases ---@param cases table Table with case functions and an optional default (false key) ---@return any|false result The return value of the matched case function, or false if none matched -function Utility.Switch(value, cases) +function Utility.Switch(value, cases) local caseFunc = cases[value] or cases[false] if caseFunc and type(caseFunc) == "function" then @@ -542,19 +542,19 @@ function Utility.GetZoneName(coords) end local SpecialKeyCodes = { - ['b_116'] = 'WheelMouseMove.Up', - ['b_115'] = 'WheelMouseMove.Up', - ['b_100'] = 'MouseClick.LeftClick', - ['b_101'] = 'MouseClick.RightClick', - ['b_102'] = 'MouseClick.MiddleClick', - ['b_103'] = 'MouseClick.ExtraBtn1', - ['b_104'] = 'MouseClick.ExtraBtn2', - ['b_105'] = 'MouseClick.ExtraBtn3', - ['b_106'] = 'MouseClick.ExtraBtn4', - ['b_107'] = 'MouseClick.ExtraBtn5', - ['b_108'] = 'MouseClick.ExtraBtn6', - ['b_109'] = 'MouseClick.ExtraBtn7', - ['b_110'] = 'MouseClick.ExtraBtn8', + ['b_116'] = 'Scroll Up', + ['b_115'] = 'Scroll Down', + ['b_100'] = 'LMB', + ['b_101'] = 'RMB', + ['b_102'] = 'MMB', + ['b_103'] = 'Extra 1', + ['b_104'] = 'Extra 2', + ['b_105'] = 'Extra 3', + ['b_106'] = 'Extra 4', + ['b_107'] = 'Extra 5', + ['b_108'] = 'Extra 6', + ['b_109'] = 'Extra 7', + ['b_110'] = 'Extra 8', ['b_1015'] = 'AltLeft', ['b_1000'] = 'ShiftLeft', ['b_2000'] = 'Space', diff --git a/lib/utility/shared/math.lua b/lib/utility/shared/math.lua index 09e750b..30717ce 100644 --- a/lib/utility/shared/math.lua +++ b/lib/utility/shared/math.lua @@ -84,6 +84,63 @@ function Math.GetOffsetFromMatrix(position, rotation, offset) return position + rotated end +function Math.InBoundary(pos, boundary) + if not boundary then return true end + + local x, y, z = table.unpack(pos) + + -- Handle legacy min/max boundary format for backwards compatibility + if boundary.min and boundary.max then + local minX, minY, minZ = table.unpack(boundary.min) + local maxX, maxY, maxZ = table.unpack(boundary.max) + return x >= minX and x <= maxX and y >= minY and y <= maxY and z >= minZ and z <= maxZ + end + + -- Handle list of points (polygon boundary) + if boundary.points and #boundary.points > 0 then + local points = boundary.points + local minZ = boundary.minZ or -math.huge + local maxZ = boundary.maxZ or math.huge + + -- Check Z bounds first + if z < minZ or z > maxZ then + return false + end + + -- Point-in-polygon test using ray casting algorithm (improved version) + local inside = false + local n = #points + + for i = 1, n do + local j = i == n and 1 or i + 1 -- Next point (wrap around) + + local xi, yi = points[i].x or points[i][1], points[i].y or points[i][2] + local xj, yj = points[j].x or points[j][1], points[j].y or points[j][2] + + -- Ensure xi, yi, xj, yj are numbers + if not (xi and yi and xj and yj) then + goto continue + end + + -- Ray casting test + if ((yi > y) ~= (yj > y)) then + -- Calculate intersection point + local intersect = (xj - xi) * (y - yi) / (yj - yi) + xi + if x < intersect then + inside = not inside + end + end + + ::continue:: + end + + return inside + end + + -- Fallback to true if boundary format is not recognized + return true +end + exports('Math', Math) return Math \ No newline at end of file diff --git a/lib/utility/shared/tables.lua b/lib/utility/shared/tables.lua index 1c6632c..5a34c06 100644 --- a/lib/utility/shared/tables.lua +++ b/lib/utility/shared/tables.lua @@ -71,7 +71,7 @@ end Table.FindFirstUnoccupiedSlot = function(tbl) local occupiedSlots = {} for _, v in pairs(tbl) do - if v.slot then + if v.slot then occupiedSlots[v.slot] = true end end @@ -126,5 +126,13 @@ Table.Compare = function(a, b) end end +Table.Count = function(tbl) + local count = 0 + for _ in pairs(tbl) do + count = count + 1 + end + return count +end + exports("Table", Table) return Table \ No newline at end of file diff --git a/locales/en.json b/locales/en.json index 27726a4..2ce96d7 100644 --- a/locales/en.json +++ b/locales/en.json @@ -22,7 +22,12 @@ "cant_place_here": "You can't place this object here", "place_object_place": "[E] Place \n", "place_object_cancel": "[X] Cancel \n", - "place_object_scroll_up": "[SCROLL UP] Turn right \n", - "place_object_scroll_down": "[SCROLL DOWN] Turn left" + "place_object_scroll_up": "[Scroll Up] Turn right \n", + "place_object_scroll_down": "[Scroll Down] Turn left \n", + "object_place": "[%s] Place \n", + "object_cancel": "[%s] Cancel \n", + "object_scroll_up": "[%s] Turn right \n", + "object_scroll_down": "[%s] Turn left \n", + "depth_modifier": "[%s] Depth Control Modifier \n" } } \ No newline at end of file diff --git a/modules/bossmenu/_default/client.lua b/modules/bossmenu/_default/client.lua new file mode 100644 index 0000000..63a8efa --- /dev/null +++ b/modules/bossmenu/_default/client.lua @@ -0,0 +1,24 @@ +---@diagnostic disable: duplicate-set-field +BossMenu = BossMenu or {} + +---This will get the name of the module being used. +---@return string +BossMenu.GetResourceName = function() + return "default" +end + +RegisterNetEvent('community_bridge:client:OpenBossMenu', function(jobName, jobType) + -- these systems seem to do the verification for isboss themselves, so we don't need to check if the player is a boss. + -- also this source check is to ensure that the event is only triggered by the server. + if source ~= 65535 then return end + if BossMenu.GetResourceName() == "esx_society" then + local ESX = exports["es_extended"]:getSharedObject() -- better solution needed but fuck it for now. + TriggerEvent('esx_society:openBossMenu', jobName, function(menu) + ESX.CloseContext() + end, {wash = false}) + elseif BossMenu.GetResourceName() == "qbx_management" then + exports.qbx_management:OpenBossMenu(jobType) + end +end) + +return BossMenu \ No newline at end of file diff --git a/modules/bossmenu/_default/server.lua b/modules/bossmenu/_default/server.lua new file mode 100644 index 0000000..24693c7 --- /dev/null +++ b/modules/bossmenu/_default/server.lua @@ -0,0 +1,14 @@ +---@diagnostic disable: duplicate-set-field +BossMenu = BossMenu or {} + +---This will get the name of the module being used. +---@return string +BossMenu.GetResourceName = function() + return "default" +end + +BossMenu.OpenBossMenu = function(src, jobName, jobType) + print("You are using the community_bridge module for boss menus. Please ensure you have the correct dependencies installed.") +end + +return BossMenu \ No newline at end of file diff --git a/modules/bossmenu/esx_society/client.lua b/modules/bossmenu/esx_society/client.lua new file mode 100644 index 0000000..8794fb2 --- /dev/null +++ b/modules/bossmenu/esx_society/client.lua @@ -0,0 +1,12 @@ +---@diagnostic disable: duplicate-set-field +if GetResourceState('esx_society') ~= 'started' then return end + +BossMenu = BossMenu or {} + +---This will get the name of the module being used. +---@return string +BossMenu.GetResourceName = function() + return "esx_society" +end + +return BossMenu \ No newline at end of file diff --git a/modules/bossmenu/esx_society/server.lua b/modules/bossmenu/esx_society/server.lua new file mode 100644 index 0000000..5bfd98e --- /dev/null +++ b/modules/bossmenu/esx_society/server.lua @@ -0,0 +1,21 @@ +---@diagnostic disable: duplicate-set-field +if GetResourceState('esx_society') ~= 'started' then return end + +BossMenu = BossMenu or {} + +---This will get the name of the module being used. +---@return string +BossMenu.GetResourceName = function() + return "esx_society" +end + +local registeredSocieties = {} +BossMenu.OpenBossMenu = function(src, jobName, jobType) + if not registeredSocieties[jobName] then + exports["esx_society"]:registerSociety(jobName, jobName, 'society_' .. jobName, 'society_' .. jobName, 'society_' .. jobName, {type = 'private'}) + registeredSocieties[jobName] = true + end + TriggerClientEvent("community_bridge:client:OpenBossMenu", src, jobName, jobType) +end + +return BossMenu \ No newline at end of file diff --git a/modules/bossmenu/qb-management/client.lua b/modules/bossmenu/qb-management/client.lua new file mode 100644 index 0000000..3c91a62 --- /dev/null +++ b/modules/bossmenu/qb-management/client.lua @@ -0,0 +1,13 @@ +---@diagnostic disable: duplicate-set-field +if GetResourceState('qb-management') ~= 'started' then return end +if GetResourceState('qbx_management') == 'started' then return end + +BossMenu = BossMenu or {} + +---This will get the name of the module being used. +---@return string +BossMenu.GetResourceName = function() + return "qb-management" +end + +return BossMenu \ No newline at end of file diff --git a/modules/bossmenu/qb-management/server.lua b/modules/bossmenu/qb-management/server.lua new file mode 100644 index 0000000..3515c8f --- /dev/null +++ b/modules/bossmenu/qb-management/server.lua @@ -0,0 +1,17 @@ +---@diagnostic disable: duplicate-set-field +if GetResourceState('qb-management') ~= 'started' then return end +if GetResourceState('qbx_management') == 'started' then return end + +BossMenu = BossMenu or {} + +---This will get the name of the module being used. +---@return string +BossMenu.GetResourceName = function() + return "qb-management" +end + +BossMenu.OpenBossMenu = function(src, jobName, jobType) + TriggerClientEvent("qb-bossmenu:client:OpenMenu", src) +end + +return BossMenu \ No newline at end of file diff --git a/modules/bossmenu/qbx_management/client.lua b/modules/bossmenu/qbx_management/client.lua new file mode 100644 index 0000000..8aaa008 --- /dev/null +++ b/modules/bossmenu/qbx_management/client.lua @@ -0,0 +1,12 @@ +---@diagnostic disable: duplicate-set-field +if GetResourceState('qbx_management') ~= 'started' then return end + +BossMenu = BossMenu or {} + +---This will get the name of the module being used. +---@return string +BossMenu.GetResourceName = function() + return "qbx_management" +end + +return BossMenu \ No newline at end of file diff --git a/modules/bossmenu/qbx_management/server.lua b/modules/bossmenu/qbx_management/server.lua new file mode 100644 index 0000000..da3d3c9 --- /dev/null +++ b/modules/bossmenu/qbx_management/server.lua @@ -0,0 +1,16 @@ +---@diagnostic disable: duplicate-set-field +if GetResourceState('qbx_management') ~= 'started' then return end + +BossMenu = BossMenu or {} + +---This will get the name of the module being used. +---@return string +BossMenu.GetResourceName = function() + return "qbx_management" +end + +BossMenu.OpenBossMenu = function(src, jobName, jobType) + TriggerClientEvent("community_bridge:client:OpenBossMenu", src, jobName, jobType) +end + +return BossMenu \ No newline at end of file diff --git a/modules/dispatch/origen_police/client/client.lua b/modules/dispatch/origen_police/client/client.lua new file mode 100644 index 0000000..9984438 --- /dev/null +++ b/modules/dispatch/origen_police/client/client.lua @@ -0,0 +1,27 @@ +---@diagnostic disable: duplicate-set-field +if GetResourceState('origen_police') == 'missing' then return end +Dispatch = Dispatch or {} + +Dispatch.SendAlert = function(data) + local color = nil + if data.vehicle then + local r, g, b = GetVehicleColor(data.vehicle) + color = {r, g, b} + end + local customData = { + coords = data.coords or vector3(0.0, 0.0, 0.0), + title = 'Alert '..(data.code or '10-80'), + message = data.message, + job = data.jobs or 'police', + metadata = { + model = data.vehicle and (GetDisplayNameFromVehicleModel(GetEntityModel(data.vehicle))) or nil, + color = color, + plate = data.vehicle and GetVehicleNumberPlateText(data.vehicle) or nil, + speed = data.vehicle and (GetEntitySpeed(veh) * 3.6)..' kmh' or nil + } + } + + TriggerServerEvent("SendAlert:police", customData) +end + +return Dispatch \ No newline at end of file diff --git a/modules/dispatch/origen_police/server/server.lua b/modules/dispatch/origen_police/server/server.lua new file mode 100644 index 0000000..d3ed01e --- /dev/null +++ b/modules/dispatch/origen_police/server/server.lua @@ -0,0 +1,4 @@ +if GetResourceState('origen_police') == 'missing' then return end +Dispatch = Dispatch or {} + +return Dispatch \ No newline at end of file diff --git a/modules/framework/es_extended/client.lua b/modules/framework/es_extended/client.lua index 6ba9534..ce90f27 100644 --- a/modules/framework/es_extended/client.lua +++ b/modules/framework/es_extended/client.lua @@ -2,6 +2,7 @@ if GetResourceState('es_extended') ~= 'started' then return end ESX = exports["es_extended"]:getSharedObject() +Callback = Callback or Require("lib/utility/shared/callbacks.lua") Framework = Framework or {} @@ -18,11 +19,10 @@ Framework.GetPlayerData = function() return ESX.GetPlayerData() end ---<-- TODO swap to internal callback system ---This will return a table of all the jobs in the framework. ---@return table Framework.GetFrameworkJobs = function() - local jobs = lib.callback.await('community_bridge:Callback:GetFrameworkJobs', false) + local jobs = Callback.Trigger('community_bridge:Callback:GetFrameworkJobs', false) return jobs end diff --git a/modules/framework/es_extended/server.lua b/modules/framework/es_extended/server.lua index 6bb67f2..32583d3 100644 --- a/modules/framework/es_extended/server.lua +++ b/modules/framework/es_extended/server.lua @@ -2,6 +2,7 @@ if GetResourceState('es_extended') ~= 'started' then return end Prints = Prints or Require("lib/utility/shared/prints.lua") +Callback = Callback or Require("lib/utility/shared/callbacks.lua") ESX = exports["es_extended"]:getSharedObject() @@ -299,12 +300,12 @@ end ---@param src number ---@param status boolean ---@return boolean -Framework.SetPlayerDuty = function(src, dutystatus) +Framework.SetPlayerDuty = function(src, status) local xPlayer = Framework.GetPlayer(src) if not xPlayer then return false end local job = xPlayer.getJob() if not job.onDuty then return false end - xPlayer.setJob(job.name, job.grade, dutystatus) + xPlayer.setJob(job.name, job.grade, status) return true end @@ -452,8 +453,7 @@ AddEventHandler("playerDropped", function() TriggerEvent("community_bridge:Server:OnPlayerUnload", src) end) ---<-- TODO swap to internal callback system -lib.callback.register('community_bridge:Callback:GetFrameworkJobs', function(source) +Callback.Register('community_bridge:Callback:GetFrameworkJobs', function(source) return Framework.GetFrameworkJobs() or {} end) diff --git a/modules/helptext/lation_ui/client.lua b/modules/helptext/lation_ui/client.lua new file mode 100644 index 0000000..2fd5f4b --- /dev/null +++ b/modules/helptext/lation_ui/client.lua @@ -0,0 +1,21 @@ +---@diagnostic disable: duplicate-set-field +HelpText = HelpText or {} +local resourceName = "lation_ui" +local configValue = BridgeSharedConfig.HelpText +if (configValue == "auto" and GetResourceState(resourceName) ~= "started") or (configValue ~= "auto" and configValue ~= resourceName) then return end + +---This will show a help text message at the screen position passed +---@param message string +---@param position string +---@return nil +HelpText.ShowHelpText = function(message, position) + return exports.lation_ui:showText({description = tostring(message), position = position or 'right-center'}) +end + +---This will hide the help text message on the screen +---@return nil +HelpText.HideHelpText = function() + return exports.lation_ui:hideText() +end + +return HelpText \ No newline at end of file diff --git a/modules/input/_default/olddata.lua b/modules/input/_default/olddata.lua deleted file mode 100644 index e61152b..0000000 --- a/modules/input/_default/olddata.lua +++ /dev/null @@ -1,196 +0,0 @@ - --- if GetResourceState('ox_lib') ~= 'started' and GetResourceState('qb-menu') ~= 'started' then return end --- -- { --- header = "Test", --- submitText = "Bill", --- inputs = { --- { --- text = "Citizen ID (#)", -- text you want to be displayed as a place holder --- name = "citizenid", -- name of the input should be unique otherwise it might override --- type = "text", -- type of the input --- isRequired = true, -- Optional [accepted values: true | false] but will submit the form if no value is inputted --- -- default = "CID-1234", -- Default text option, this is optional --- }, --- { --- text = "Secret Code (Give to Nobody)", -- text you want to be displayed as a place holder --- name = "code", -- name of the input should be unique otherwise it might override --- type = "password", -- type of the input --- isRequired = true, -- Optional [accepted values: true | false] but will submit the form if no value is inputted --- -- default = "password123", -- Default text option, this is optional --- }, --- { --- text = "Bill Price ($)", -- text you want to be displayed as a place holder --- name = "billprice", -- name of the input should be unique otherwise it might override --- type = "number", -- type of the input - number will not allow non-number characters in the field so only accepts 0-9 --- isRequired = false, -- Optional [accepted values: true | false] but will submit the form if no value is inputted --- -- default = 1, -- Default number option, this is optional --- }, --- { --- text = "Bill Type", -- text you want to be displayed as a input header --- name = "billtype", -- name of the input should be unique otherwise it might override --- type = "radio", -- type of the input - Radio is useful for "or" options e.g; billtype = Cash OR Bill OR bank --- options = { -- The options (in this case for a radio) you want displayed, more than 6 is not recommended --- { value = "bill", text = "Bill" }, -- Options MUST include a value and a text option --- { value = "cash", text = "Cash" }, -- Options MUST include a value and a text option --- { value = "bank", text = "Bank" } -- Options MUST include a value and a text option --- }, --- -- default = "cash", -- Default radio option, must match a value from above, this is optional --- }, --- { --- text = "Include Tax?", -- text you want to be displayed as a input header --- name = "taxincl", -- name of the input should be unique otherwise it might override --- type = "checkbox", -- type of the input - Check is useful for "AND" options e.g; taxincle = gst AND business AND othertax --- options = { -- The options (in this case for a check) you want displayed, more than 6 is not recommended --- { value = "gst", text = "10% incl."}, -- Options MUST include a value and a text option --- { value = "business", text = "35% incl.", checked = true }, -- Options MUST include a value and a text option, checked = true is default value, optional --- { value = "othertax", text = "15% incl."} -- Options MUST include a value and a text option --- } --- }, --- { --- text = "Some Select", -- text you want to be displayed as a input header --- name = "someselect", -- name of the input should be unique otherwise it might override --- type = "select", -- type of the input - Select is useful for 3+ amount of "or" options e.g; someselect = none OR other OR other2 OR other3...etc --- options = { -- Select drop down options, the first option will by default be selected --- { value = "none", text = "None" }, -- Options MUST include a value and a text option --- { value = "other", text = "Other"}, -- Options MUST include a value and a text option --- { value = "other2", text = "Other2" }, -- Options MUST include a value and a text option --- { value = "other3", text = "Other3" }, -- Options MUST include a value and a text option --- { value = "other4", text = "Other4" }, -- Options MUST include a value and a text option --- { value = "other5", text = "Other5" }, -- Options MUST include a value and a text option --- { value = "other6", text = "Other6" }, -- Options MUST include a value and a text option --- }, --- -- default = 'other3', -- Default select option, must match a value from above, this is optional --- } --- }, --- }) - --- local input = lib.inputDialog('Dialog title', { --- {type = 'input', label = 'Text input', description = 'Some input description', required = true, min = 4, max = 16}, --- {type = 'number', label = 'Number input', description = 'Some number description', icon = 'hashtag'}, --- {type = 'checkbox', label = 'Simple checkbox'}, --- {type = 'color', label = 'Colour input', default = '#eb4034'}, --- {type = 'date', label = 'Date input', icon = {'far', 'calendar'}, default = true, format = "DD/MM/YYYY"} --- }) - - ---QB types: text, password, number, radio, checkbox, select, --- --- "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) --- if isQBFormat then --- local inputs = data.inputs --- if BridgeClientConfig.InputSystem == "ox" then --- return lib.inputDialog(title, QBToOxInput(inputs)) --- elseif BridgeClientConfig.InputSystem == "qb" then --- return exports['qb-input']:ShowInput({ --- header = title, --- submitText = submitText or "Submit", --- inputs = inputs --- }) --- end --- else --- if BridgeClientConfig.InputSystem == "ox" then --- return lib.inputDialog(title, data) --- elseif BridgeClientConfig.InputSystem == "qb" then --- return exports['qb-input']:ShowInput({ --- header = title, --- submitText = submitText or "Submit", --- inputs = OxToQBInput(data) --- }) --- end --- end --- return OpenInput(title, data, isQBFormat, submitText) --- end - --- return Input - - ---[[ --- Unit tests -local thisIsQB = { - header = "Test", - submitText = "Bill", - inputs = { - { - text = "Citizen ID (#)", -- text you want to be displayed as a place holder - name = "citizenid", -- name of the input should be unique otherwise it might override - type = "text", -- type of the input - isRequired = true, -- Optional [accepted values: true | false] but will submit the form if no value is inputted - -- default = "CID-1234", -- Default text option, this is optional - }, - { - text = "Secret Code (Give to Nobody)", -- text you want to be displayed as a place holder - name = "code", -- name of the input should be unique otherwise it might override - type = "password", -- type of the input - isRequired = true, -- Optional [accepted values: true | false] but will submit the form if no value is inputted - -- default = "password123", -- Default text option, this is optional - }, - { - text = "Bill Price ($)", -- text you want to be displayed as a place holder - name = "billprice", -- name of the input should be unique otherwise it might override - type = "number", -- type of the input - number will not allow non-number characters in the field so only accepts 0-9 - isRequired = false, -- Optional [accepted values: true | false] but will submit the form if no value is inputted - -- default = 1, -- Default number option, this is optional - }, - { - text = "Bill Type", -- text you want to be displayed as a input header - name = "billtype", -- name of the input should be unique otherwise it might override - type = "radio", -- type of the input - Radio is useful for "or" options e.g; billtype = Cash OR Bill OR bank - options = { -- The options (in this case for a radio) you want displayed, more than 6 is not recommended - { value = "bill", text = "Bill" }, -- Options MUST include a value and a text option - { value = "cash", text = "Cash" }, -- Options MUST include a value and a text option - { value = "bank", text = "Bank" } -- Options MUST include a value and a text option - }, - -- default = "cash", -- Default radio option, must match a value from above, this is optional - }, - { - text = "Include Tax?", -- text you want to be displayed as a input header - name = "taxincl", -- name of the input should be unique otherwise it might override - type = "checkbox", -- type of the input - Check is useful for "AND" options e.g; taxincle = gst AND business AND othertax - options = { -- The options (in this case for a check) you want displayed, more than 6 is not recommended - { value = "gst", text = "10% incl."}, -- Options MUST include a value and a text option - { value = "business", text = "35% incl.", checked = true }, -- Options MUST include a value and a text option, checked = true is default value, optional - { value = "othertax", text = "15% incl."} -- Options MUST include a value and a text option - } - }, - { - text = "Some Select", -- text you want to be displayed as a input header - name = "someselect", -- name of the input should be unique otherwise it might override - type = "select", -- type of the input - Select is useful for 3+ amount of "or" options e.g; someselect = none OR other OR other2 OR other3...etc - options = { -- Select drop down options, the first option will by default be selected - { value = "none", text = "None" }, -- Options MUST include a value and a text option - { value = "other", text = "Other"}, -- Options MUST include a value and a text option - { value = "other2", text = "Other2" }, -- Options MUST include a value and a text option - { value = "other3", text = "Other3" }, -- Options MUST include a value and a text option - { value = "other4", text = "Other4" }, -- Options MUST include a value and a text option - { value = "other5", text = "Other5" }, -- Options MUST include a value and a text option - { value = "other6", text = "Other6" }, -- Options MUST include a value and a text option - }, - -- default = 'other3', -- Default select option, must match a value from above, this is optional - } - }, -} - -local thisIsOx = { - {type = 'input', label = 'Text input', description = 'Some input description', required = true, min = 4, max = 16}, - {type = 'number', label = 'Number input', description = 'Some number description', icon = 'hashtag'}, - {type = 'checkbox', label = 'Simple checkbox'}, - {type = 'color', label = 'Colour input', default = '#eb4034'}, - {type = 'date', label = 'Date input', icon = {'far', 'calendar'}, default = true, format = "DD/MM/YYYY"} -} - --- qb to ox -RegisterCommand('inputtest1', function() - Input.Open("Test", thisIsQB, true) -end) - --- ox to qb -RegisterCommand('inputtest2', function() - Input.Open("Test", thisIsOx, false) -end) ---]] \ No newline at end of file diff --git a/modules/input/lation_ui/client.lua b/modules/input/lation_ui/client.lua new file mode 100644 index 0000000..0da8552 --- /dev/null +++ b/modules/input/lation_ui/client.lua @@ -0,0 +1,21 @@ +---@diagnostic disable: duplicate-set-field +local resourceName = "lation_ui" +local configValue = BridgeClientConfig.InputSystem +if (configValue == "auto" and GetResourceState(resourceName) == "missing") or (configValue ~= "auto" and configValue ~= resourceName) then return end + +Input = {} + +function Input.Open(title, data, isQBFormat, submitText) + local inputs = data.inputs + if isQBFormat then + return exports.lation_ui:input({title = title, inputs = QBToOxInput(inputs)}) + else + return exports.lation_ui:input({title = title, options = data}) + end +end + +function Input.GetResourceName() + return resourceName +end + +return Input \ No newline at end of file diff --git a/modules/input/ox_lib/client.lua b/modules/input/ox_lib/client.lua index fa379ff..926efeb 100644 --- a/modules/input/ox_lib/client.lua +++ b/modules/input/ox_lib/client.lua @@ -4,6 +4,7 @@ local configValue = BridgeClientConfig.InputSystem if (configValue == "auto" and GetResourceState(resourceName) == "missing") or (configValue ~= "auto" and configValue ~= resourceName) then return end Input = {} + function Input.Open(title, data, isQBFormat, submitText) local inputs = data.inputs if isQBFormat then @@ -13,5 +14,8 @@ function Input.Open(title, data, isQBFormat, submitText) end end -return Input +function Input.GetResourceName() + return resourceName +end +return Input \ No newline at end of file diff --git a/modules/input/_qb-input/client.lua b/modules/input/qb-input/client.lua similarity index 92% rename from modules/input/_qb-input/client.lua rename to modules/input/qb-input/client.lua index 946c018..b227315 100644 --- a/modules/input/_qb-input/client.lua +++ b/modules/input/qb-input/client.lua @@ -5,7 +5,6 @@ if (configValue == "auto" and GetResourceState(resourceName) == "missing") or (c Input = {} - -- this probably needs improvement function Input.Open(title, data, isQBFormat, submitText) local input = data.inputs @@ -18,13 +17,11 @@ function Input.Open(title, data, isQBFormat, submitText) inputs = input }) if not returnData then return end - print(json.encode(returnData)) if returnData[1] then return returnData end --converting to standard format (ox) local convertedData = {} if isQBFormat then for i, v in pairs(input) do - print("Converting input: " .. v.name) for k, j in pairs(returnData) do if k == v.name then convertedData[tonumber(i)] = j @@ -36,7 +33,7 @@ function Input.Open(title, data, isQBFormat, submitText) for i, v in pairs(returnData) do local index = i and tonumber(i) - if not index then + if not index then table.insert(convertedData, v) else convertedData[index] = v @@ -45,4 +42,8 @@ function Input.Open(title, data, isQBFormat, submitText) return convertedData end +function Input.GetResourceName() + return resourceName +end + return Input diff --git a/modules/inventory/core_inventory/client.lua b/modules/inventory/core_inventory/client.lua index 95a5d27..ffa4b4c 100644 --- a/modules/inventory/core_inventory/client.lua +++ b/modules/inventory/core_inventory/client.lua @@ -1,6 +1,7 @@ ---@diagnostic disable: duplicate-set-field if GetResourceState('core_inventory') ~= 'started' then return end local core = exports.core_inventory +Callback = Callback or Require("lib/utility/shared/callbacks.lua") Inventory = Inventory or {} @@ -12,8 +13,7 @@ Inventory.GetItemInfo = function(item) if not frameworkName then return {} end local dataRepack = {} if frameworkName == 'es_extended' then - --<-- TODO swap to internal callback system - local callbackData = lib.callback.await('community_bridge:Callback:core_inventory', false) + local callbackData = Callback.Trigger('community_bridge:Callback:core_inventory', false) -- really really wish this inventory allowed me to pull the item list client side.... dataRepack = callbackData[item] if not dataRepack then return {} end diff --git a/modules/inventory/core_inventory/server.lua b/modules/inventory/core_inventory/server.lua index ef67251..b35868c 100644 --- a/modules/inventory/core_inventory/server.lua +++ b/modules/inventory/core_inventory/server.lua @@ -3,6 +3,7 @@ if GetResourceState('core_inventory') ~= 'started' then return end Inventory = Inventory or {} Inventory.Stashes = Inventory.Stashes or {} +Callback = Callback or Require("lib/utility/shared/callbacks.lua") local core = exports.core_inventory ---This will add an item, and return true or false based on success @@ -244,9 +245,8 @@ Inventory.GetImagePath = function(item) return imagePath or "https://avatars.githubusercontent.com/u/47620135" end ----<-- TODO swap to internal callback system ---This is used for the esx users, documentation doesnt show a client side available option for the inventory so we use jank callbacks to get this. -lib.callback.register('community_bridge:Callback:core_inventory', function(source) +Callback.Register('community_bridge:Callback:core_inventory', function(source) local items = core:getItemsList() return items or {} end) diff --git a/modules/managment/_default/server.lua b/modules/managment/_default/server.lua index ba069b9..5ad2fd8 100644 --- a/modules/managment/_default/server.lua +++ b/modules/managment/_default/server.lua @@ -7,11 +7,11 @@ Managment.GetManagmentName = function() return 'default' end ----This will return a table with account details +---This will return a number ---@param account string ----@return table +---@return number Managment.GetAccountMoney = function(account) - return {}, print("The resource you are using does not support this function.") + return 0, print("The resource you are using does not support this function.") end ---This will add money to the specified account of the passed amount diff --git a/modules/managment/fd_banking/server.lua b/modules/managment/fd_banking/server.lua index 582b86e..be4ccc5 100644 --- a/modules/managment/fd_banking/server.lua +++ b/modules/managment/fd_banking/server.lua @@ -10,9 +10,9 @@ Managment.GetManagmentName = function() return 'fd_banking' end ----This will return a table with account details +---This will return a number ---@param account string ----@return table +---@return number Managment.GetAccountMoney = function(account) return fd_banking:GetAccount(account) end diff --git a/modules/managment/okokBanking/server.lua b/modules/managment/okokBanking/server.lua index c2fc583..7870503 100644 --- a/modules/managment/okokBanking/server.lua +++ b/modules/managment/okokBanking/server.lua @@ -10,9 +10,9 @@ Managment.GetManagmentName = function() return 'okokBanking' end ----This will return a table with account details +---This will return a number ---@param account string ----@return table +---@return number Managment.GetAccountMoney = function(account) return okokBanking:GetAccount(account) end diff --git a/modules/managment/qb-banking/server.lua b/modules/managment/qb-banking/server.lua index 59d47fd..cc7530e 100644 --- a/modules/managment/qb-banking/server.lua +++ b/modules/managment/qb-banking/server.lua @@ -10,9 +10,9 @@ Managment.GetManagmentName = function() return 'qb-banking' end ----This will return a table with account details +---This will return a number ---@param account string ----@return table +---@return number Managment.GetAccountMoney = function(account) return qbBanking:GetAccountBalance(account) end diff --git a/modules/managment/renewed-banking/server.lua b/modules/managment/renewed-banking/server.lua index 0f6e747..677eee0 100644 --- a/modules/managment/renewed-banking/server.lua +++ b/modules/managment/renewed-banking/server.lua @@ -10,9 +10,9 @@ Managment.GetManagmentName = function() return 'Renewed-Banking' end ----This will return a table with account details +---This will return a number ---@param account string ----@return table +---@return number Managment.GetAccountMoney = function(account) return renewed:getAccountMoney(account) end diff --git a/modules/managment/tgiann-bank/server.lua b/modules/managment/tgiann-bank/server.lua index 7d79137..55f1b10 100644 --- a/modules/managment/tgiann-bank/server.lua +++ b/modules/managment/tgiann-bank/server.lua @@ -10,9 +10,9 @@ Managment.GetManagmentName = function() return 'tgiann-bank' end ----This will return a table with account details +---This will return a number ---@param account string ----@return table +---@return number Managment.GetAccountMoney = function(account) return tgiann:GetJobAccountBalance(account) end diff --git a/modules/managment/wasabi_banking/server.lua b/modules/managment/wasabi_banking/server.lua new file mode 100644 index 0000000..0a755b6 --- /dev/null +++ b/modules/managment/wasabi_banking/server.lua @@ -0,0 +1,39 @@ +---@diagnostic disable: duplicate-set-field +if GetResourceState('wasabi_banking') == 'missing' then return end +Managment = Managment or {} + +local wasabi_banking = exports['wasabi_banking'] + +---This will get the name of the Managment system being being used. +---@return string +Managment.GetManagmentName = function() + return 'wasabi_banking' +end + +---This will return a number +---@param account string +---@return number +Managment.GetAccountMoney = function(account) + local balance = wasabi_banking:GetAccountBalance(account, 'society') + return balance or 0 +end + +---This will add money to the specified account of the passed amount +---@param account string +---@param amount number +---@param reason string +---@return boolean +Managment.AddAccountMoney = function(account, amount, reason) + return wasabi_banking:AddMoney('society', account, amount) +end + +---This will remove money from the specified account of the passed amount +---@param account string +---@param amount number +---@param reason string +---@return boolean +Managment.RemoveAccountMoney = function(account, amount, reason) + return wasabi_banking:RemoveMoney('society', account, amount) +end + +return Managment \ No newline at end of file diff --git a/modules/menu/client.lua b/modules/menu/_defualt/client.lua similarity index 91% rename from modules/menu/client.lua rename to modules/menu/_defualt/client.lua index c5a497f..730e90c 100644 --- a/modules/menu/client.lua +++ b/modules/menu/_defualt/client.lua @@ -12,6 +12,10 @@ function Menu.Open(data, useQb) return id end +function Menu.GetResourceName() + return GetMenuResourceName() +end + ---Event to handle callback from menu selection. ---@param _args table The arguments passed to the callback. ---@return nil diff --git a/modules/menu/lation_ui/client.lua b/modules/menu/lation_ui/client.lua new file mode 100644 index 0000000..5d06ed7 --- /dev/null +++ b/modules/menu/lation_ui/client.lua @@ -0,0 +1,96 @@ +local resourceName = "lation_ui" +local configValue = BridgeClientConfig.MenuSystem +if (configValue == "auto" and GetResourceState(resourceName) ~= "started") or (configValue ~= "auto" and configValue ~= resourceName) then return end +Menus = Menus or {} + +local function runCheckForImageIcon(icon) + local iconStr = tostring(icon):lower() + if iconStr:match("^https?://") or iconStr:match("^nui://") or iconStr:match("^file://") then + return true + end + + local extensions = {".png", ".jpg", ".jpeg", ".gif", ".bmp", ".svg", ".webp", ".ico"} + for _, ext in pairs(extensions) do + if iconStr:match(ext .. "$") then + return true + end + end + + return false +end + +---Converts a QB menu to an Lation menu. +---@param id string The menu ID. +---@param menu table The QB menu data. +---@return table The Lation menu data. +local function QBToLationMenu(id, menu) + local lationMenu = { + id = id, + title = "", + canClose = true, + options = {}, + } + for i, v in pairs(menu) do + if v.isMenuHeader then + if lationMenu.title == "" then + lationMenu.title = v.header + end + else + local option = { + title = v.header, + description = v.txt, + icon = v.icon, + args = v.params.args, + onSelect = function(selected, secondary, args) + local params = menu[id]?.options?[selected]?.params + if not params then return end + local event = params.event + local isServer = params.isServer + if not event then return end + if isServer then + return TriggerServerEvent(event, args) + end + return TriggerEvent(event, args) + end + + } + table.insert(lationMenu.options, option) + end + end + return lationMenu +end + +local function OxToLationMenu(data) + local repack = { + id = data.id, + title = data.title or "", + canClose = data.canClose ~= false, + options = {} + } + -- Handle icon colors: remove for image icons, convert strings to hex for others + for k, v in pairs(data.options) do + if v.iconColor then + if v.icon and runCheckForImageIcon(v.icon) then + v.iconColor = nil + end + end + table.insert(repack.options, v) + end + + return repack +end + +function OpenMenu(id, data, useQBinput) + if useQBinput then + data = QBToLationMenu(id, data) + else + data = OxToLationMenu(data) + end + exports.lation_ui:registerMenu(data) + exports.lation_ui:showMenu(id) + return data +end + +function GetMenuResourceName() + return resourceName +end \ No newline at end of file diff --git a/modules/menu/_oxlib.lua b/modules/menu/ox_lib/client.lua similarity index 94% rename from modules/menu/_oxlib.lua rename to modules/menu/ox_lib/client.lua index 02603fe..5899892 100644 --- a/modules/menu/_oxlib.lua +++ b/modules/menu/ox_lib/client.lua @@ -44,11 +44,15 @@ local function QBToOxMenu(id, menu) return oxMenu end -OpenMenu = function(id, data, useQBinput) +function OpenMenu(id, data, useQBinput) if useQBinput then data = QBToOxMenu(id, data) end lib.registerContext(data) lib.showContext(id) return data +end + +GetMenuResourceName = function() + return resourceName end \ No newline at end of file diff --git a/modules/menu/_qb-menu.lua b/modules/menu/qb-menu/client.lua similarity index 92% rename from modules/menu/_qb-menu.lua rename to modules/menu/qb-menu/client.lua index 31aa56e..035489b 100644 --- a/modules/menu/_qb-menu.lua +++ b/modules/menu/qb-menu/client.lua @@ -36,10 +36,14 @@ function OxToQBMenu(id, menu) return qbMenu end -OpenMenu = function(id, data, useQBinput) +function OpenMenu(id, data, useQBinput) if not useQBinput then data = OxToQBMenu(id, data) end exports['qb-menu']:openMenu(data) return data +end + +GetMenuResourceName = function() + return resourceName end \ No newline at end of file diff --git a/modules/notify/brutal_notify/client.lua b/modules/notify/brutal_notify/client.lua new file mode 100644 index 0000000..7eb9e87 --- /dev/null +++ b/modules/notify/brutal_notify/client.lua @@ -0,0 +1,22 @@ +---@diagnostic disable: duplicate-set-field +Notify = Notify or {} +local resourceName = "brutal_notify" +local configValue = BridgeSharedConfig.Notify +if (configValue == "auto" and GetResourceState(resourceName) ~= "started") or (configValue ~= "auto" and configValue ~= resourceName) then return end + + +Notify.GetResourceName = function() + return resourceName +end + +---This will send a notify message of the type and time passed +---@param message string +---@param _type string +---@param time number +---@return nil +Notify.SendNotify = function(message, _type, time) + time = time or 3000 + return exports['brutal_notify']:SendAlert('Notification', message, time, _type, false) +end + +return Notify \ No newline at end of file diff --git a/modules/notify/lation_ui/client.lua b/modules/notify/lation_ui/client.lua new file mode 100644 index 0000000..02ae6dc --- /dev/null +++ b/modules/notify/lation_ui/client.lua @@ -0,0 +1,22 @@ +---@diagnostic disable: duplicate-set-field +Notify = Notify or {} +local resourceName = "lation_ui" +local configValue = BridgeSharedConfig.Notify +if (configValue == "auto" and GetResourceState(resourceName) ~= "started") or (configValue ~= "auto" and configValue ~= resourceName) then return end + + +Notify.GetResourceName = function() + return resourceName +end + +---This will send a notify message of the type and time passed +---@param message string +---@param _type string +---@param time number +---@return nil +Notify.SendNotify = function(message, _type, time) + time = time or 3000 + return exports.lation_ui:notify({ message = message, type = _type, duration = time, position = 'top-right' }) +end + +return Notify \ No newline at end of file diff --git a/modules/phone/okokPhone/client.lua b/modules/phone/okokPhone/client.lua index 0472ca7..90b8c0a 100644 --- a/modules/phone/okokPhone/client.lua +++ b/modules/phone/okokPhone/client.lua @@ -2,6 +2,7 @@ local resourceName = "okokPhone" if GetResourceState(resourceName) == 'missing' then return end Phone = Phone or {} +Callback = Callback or Require("lib/utility/shared/callbacks.lua") ---This will get the name of the Phone system being being used. ---@return string @@ -15,8 +16,7 @@ end ---@param message string ---@return boolean Phone.SendEmail = function(email, title, message) - --<-- TODO swap to internal callback system - local success = lib.callback.await('community_bridge:Callback:okokPhone:sendEmail', false, email, title, message) --[[ @as boolean ]] + local success = Callback.Trigger('community_bridge:Callback:okokPhone:sendEmail', false, email, title, message) return success end diff --git a/modules/phone/okokPhone/server.lua b/modules/phone/okokPhone/server.lua index 1ec524d..03b4e07 100644 --- a/modules/phone/okokPhone/server.lua +++ b/modules/phone/okokPhone/server.lua @@ -17,6 +17,7 @@ local resourceName = "okokPhone" if GetResourceState(resourceName) == 'missing' then return end Phone = Phone or {} +Callback = Callback or Require("lib/utility/shared/callbacks.lua") ---This will get the name of the Phone system being being used. ---@return string @@ -53,8 +54,7 @@ Phone.SendEmail = function(src, email, title, message) return success end ---<-- TODO swap to internal callback system -lib.callback.registry('community_bridge:Callback:okokPhone:sendEmail', function(src, email, title, message) +Callback.Register('community_bridge:Callback:okokPhone:sendEmail', function(src, email, title, message) return Phone.SendEmail(src, email, title, message) end) diff --git a/modules/phone/yseries/client.lua b/modules/phone/yseries/client.lua new file mode 100644 index 0000000..a9ddf47 --- /dev/null +++ b/modules/phone/yseries/client.lua @@ -0,0 +1,22 @@ +---@diagnostic disable: duplicate-set-field +local resourceName = "yseries" +if GetResourceState(resourceName) == 'missing' then return end +Phone = Phone or {} + +---This will get the name of the Phone system being being used. +---@return string +Phone.GetPhoneName = function() + return resourceName +end + +---This will send an email to the passed email address with the title and message. +---@param email string +---@param title string +---@param message string +---@return boolean +Phone.SendEmail = function(email, title, message) + TriggerServerEvent('community_bridge:Server:genericEmail', {email = email, title = title, message = message}) + return true +end + +return Phone \ No newline at end of file diff --git a/modules/phone/yseries/server.lua b/modules/phone/yseries/server.lua new file mode 100644 index 0000000..d460be6 --- /dev/null +++ b/modules/phone/yseries/server.lua @@ -0,0 +1,43 @@ +---@diagnostic disable: duplicate-set-field +local resourceName = "yseries" +if GetResourceState(resourceName) == 'missing' then return end +Phone = Phone or {} + +---This will get the name of the Phone system being being used. +---@return string +Phone.GetPhoneName = function() + return resourceName +end + +---This will get the phone number of the passed source. +---@param src number +---@return number|boolean +Phone.GetPlayerPhone = function(src) + return exports.yseries:GetPhoneNumberBySourceId(src) or false +end + +---This will send an email to the passed source, email address, title and message. +---@param src number +---@param email string +---@param title string +---@param message string +---@return boolean +Phone.SendEmail = function(src, email, title, message) + local phoneNumber = exports.yseries:GetPhoneNumberBySourceId(src) + if not phoneNumber then return false, print("Could not find phone number for source: " .. tostring(src)) end + -- assuming received is a boolean? + local _, received = exports.yseries:SendMail({ + title = title, + sender = email, + senderDisplayName = email, + content = message, + }, 'phoneNumber', phoneNumber) + return received +end + +RegisterNetEvent('community_bridge:Server:genericEmail', function(data) + local src = source + return Phone.SendEmail(src, data.email, data.title, data.message) +end) + +return Phone \ No newline at end of file diff --git a/modules/progressbar/lation_ui/client.lua b/modules/progressbar/lation_ui/client.lua new file mode 100644 index 0000000..2a7aad0 --- /dev/null +++ b/modules/progressbar/lation_ui/client.lua @@ -0,0 +1,106 @@ +---@diagnostic disable: duplicate-set-field +local resourceName = "lation_ui" +local configValue = BridgeClientConfig.ProgressBarSystem +if (configValue == "auto" and GetResourceState(resourceName) ~= "started") or (configValue ~= "auto" and configValue ~= resourceName) then return end + +ProgressBar = ProgressBar or {} + +---This function converts a QB progress bar options table to an lation progress bar options table. +---@param options table +---@return table +local function convertFromQB(options) + if not options then return options end + local prop1 = options.prop or {} + local prop2 = options.propTwo or {} + local props = { + { + model = prop1?.model, + bone = prop1?.bone, + pos = prop1?.coords, + rot = prop1?.rotation, + }, + { + model = prop2?.model, + bone = prop2?.bone, + pos = prop2?.coords, + rot = prop2?.rotation, + } + } + return { + duration = options.duration, + label = options.label, + description = options?.description, + icon = options?.icon, + iconColor = options?.iconColor, + iconAnimation = options?.iconAnimation, + useWhileDead = options.useWhileDead, + canCancel = options.canCancel, + disable = { + move = options.controlDisables?.disableMovement, + car = options.controlDisables?.disableCarMovement, + combat = options.controlDisables?.disableCombat, + mouse = options.controlDisables?.disableMouse + }, + anim = { + dict = options.animation?.animDict, + clip = options.animation?.anim, + flag = options.animation?.flags or 49, + }, + prop = props, + } +end + +---This function converts a ox progress bar options table to an lation progress bar options table. +---@param options table +---@return table +local function convertFromOx(options) + if not options then return options end + local prop1 = options.prop or {} + local prop2 = options.propTwo or {} + return { + duration = options.duration, + label = options.label, + description = options?.description, + icon = options?.icon, + iconColor = options?.iconColor, + iconAnimation = options?.iconAnimation, + useWhileDead = options.useWhileDead, + canCancel = options.canCancel, + disable = options.disable, + anim = options.anim, + prop = { + { + model = prop1?.model, + bone = prop1?.bone, + pos = prop1?.coords, + rot = prop1?.rotation, + }, + { + model = prop2?.model, + bone = prop2?.bone, + pos = prop2?.coords, + rot = prop2?.rotation, + } + }, + } +end + +---This function opens a progress bar. +---@param options table +---@param cb any +---@param isQBInput boolean||optional +---@return boolean +function ProgressBar.Open(options, cb, isQBInput) + if isQBInput then + options = convertFromQB(options) + else + options = convertFromOx(options) + end + + local success = exports.lation_ui:progressBar(options) + + if cb then cb(not success) end + return success +end + +return ProgressBar \ No newline at end of file diff --git a/modules/shops/_default/client.lua b/modules/shops/_default/client.lua index c8512db..a80f41f 100644 --- a/modules/shops/_default/client.lua +++ b/modules/shops/_default/client.lua @@ -1,3 +1,4 @@ +---@diagnostic disable: duplicate-set-field Shops = Shops or {} RegisterNetEvent('community_bridge:openShop', function(_type, _title, shopData) diff --git a/modules/shops/_default/server.lua b/modules/shops/_default/server.lua index dc5e7a3..c44b668 100644 --- a/modules/shops/_default/server.lua +++ b/modules/shops/_default/server.lua @@ -1,3 +1,4 @@ +---@diagnostic disable: duplicate-set-field Shops = Shops or {} local registeredShops = {} diff --git a/modules/skills/_default/client.lua b/modules/skills/_default/client.lua index d1b4b4e..c2e723b 100644 --- a/modules/skills/_default/client.lua +++ b/modules/skills/_default/client.lua @@ -1,23 +1,25 @@ ---@diagnostic disable: duplicate-set-field Skills = Skills or {} -local function warnUser() - print("Currently only a few skill systems are supported by Community Bridge, you are using a resource that requires the skills module to be used.") -end - ---This will get the name of the Skills system being being used. ---@return string Skills.GetResourceName = function() - return "none" + return "community_bridge" end ----This will get the skill level of the passed skill name. +---This will get the skill level of the passed skill name. (returns 1 if not found) ---@param skillName string ---@return number ----@return nil Skills.GetSkillLevel = function(skillName) - warnUser() - return 0 + if not skillName then return 0 end + local plyrSkills = Framework.GetPlayerMetaData("community_bridge_skills") + if not plyrSkills or not plyrSkills[skillName] then return 1 end + return plyrSkills[skillName].level or 1 end +-- RegisterCommand("getfishingLevel", function(source, args) +-- local level = Skills.GetSkillLevel("fishing") +-- print("Client Fishing Level issssssssss " .. level) +-- end, false) + return Skills \ No newline at end of file diff --git a/modules/skills/_default/server.lua b/modules/skills/_default/server.lua index 8d2f333..afe9cd5 100644 --- a/modules/skills/_default/server.lua +++ b/modules/skills/_default/server.lua @@ -1,43 +1,158 @@ ---@diagnostic disable: duplicate-set-field Skills = Skills or {} +Skills.All = Skills.All or {} -local function warnUser() - print("Currently only a few skill systems are supported by Community Bridge, you are using a resource that requires the skills module to be used.") +-- XP Cache for performance +local XP_CACHE = {} + +-- Default skill object: currentXP (0 to required), level +local DEFAULT_SKILL = { currentXP = 0, level = 1 } + +-- Helper function to get or create a skill object +local function getOrCreateSkill(src, skillName) + if not src or not skillName then return table.clone(DEFAULT_SKILL) end + + local playerSkills = Framework.GetPlayerMetadata(src, "community_bridge_skills") or {} + if not playerSkills[skillName] then + playerSkills[skillName] = table.clone(DEFAULT_SKILL) + end + + return playerSkills[skillName] end ----This will get the name of the Skills system being being used. ----@return string -Skills.GetResourceName = function() - return "none" +-- Calculate XP required for a level using RuneScape algorithm (with caching) +Skills.GetXPForLevel = function(level) + if not level or level < 1 then return 0 end + if level == 1 then return 0 end -- Level 1 requires 0 XP + + -- Check cache first + if XP_CACHE[level] then + return XP_CACHE[level] + end + + -- Calculate and cache + local xp = 0 + for n = 1, level - 1 do + xp = xp + math.floor(n + 300 * (2 ^ (n / 7))) + end + local result = math.floor(xp / 4) + XP_CACHE[level] = result + + return result end ----This will get the skill level of the passed skill name. ----@param src number ----@param skillName string ----@return number +-- Create a skill (for initialization) +Skills.Create = function(name, maxLevel, baseXP) + if not name then return end + Skills.All[name] = { name = name, maxLevel = maxLevel or 99, baseXP = baseXP or 50 } + return Skills.All[name] +end + +-- Get player's current level Skills.GetSkillLevel = function(src, skillName) - warnUser() - return 0 + if not src or not skillName then return 1 end + local skill = getOrCreateSkill(src, skillName) + return skill.level or 1 end ----This will add xp to the passed skill name. ----@param src number ----@param skillName string ----@param amount number ----@return boolean -Skills.AddXp = function(src, skillName, amount) - warnUser() - return false +Skills.GetScaledXP = function(baseXP, playerLevel) + return math.floor(baseXP * (1 + playerLevel * 0.05)) +end +-- Get current XP (0 to required XP for current level) +Skills.GetXP = function(src, skillName) + if not src or not skillName then return 0 end + local skill = getOrCreateSkill(src, skillName) + local currentXP = skill.currentXP or 0 + return currentXP end ----This will remove xp from the passed skill name. ----@param src number ----@param skillName string ----@param amount number ----@return boolean -Skills.RemoveXp = function(src, skillName, amount) - warnUser() - return false +-- Get XP required to complete the current level +Skills.GetXPRequiredForLevel = function(level) + if not level or level < 1 then return 0 end + if level == 1 then return 83 end -- Level 1 to 2 requires 83 XP + return Skills.GetXPForLevel(level) end +-- Add XP and handle level ups +Skills.AddXP = function(src, skillName, xp) + if not src or not skillName then + return false + end + + if not xp or xp <= 0 then + xp = Skills.GetScaledXP(50, Skills.GetSkillLevel(src, skillName)) + end + + local playerSkills = Framework.GetPlayerMetadata(src, "community_bridge_skills") or {} + local skill = playerSkills[skillName] + if not skill then + skill = table.clone(DEFAULT_SKILL) + playerSkills[skillName] = skill + end + + local oldLevel = skill.level or 1 + local currentXP = skill.currentXP or 0 + -- Add XP + currentXP = currentXP + xp + + + local xpNeeded = Skills.GetXPRequiredForLevel(oldLevel + 1) + if currentXP >= xpNeeded then + currentXP = currentXP - xpNeeded + oldLevel = oldLevel + 1 + end + + skill.level = oldLevel + skill.currentXP = currentXP + playerSkills[skillName] = skill + + Framework.SetPlayerMetadata(src, "community_bridge_skills", playerSkills) + + return true, oldLevel, currentXP +end + +-- Set skill level directly (resets currentXP to 0) +Skills.SetSkillLevel = function(src, skillName, level) + if not src or not skillName or not level or level < 1 then return false end + + local playerSkills = Framework.GetPlayerMetadata(src, "community_bridge_skills") or {} + local skill = playerSkills[skillName] or table.clone(DEFAULT_SKILL) + + level = math.min(math.max(1, level), 99) + skill.level = level + skill.currentXP = 0 + + playerSkills[skillName] = skill + Framework.SetPlayerMetadata(src, "community_bridge_skills", playerSkills) + return true +end + +-- Set current XP directly +Skills.SetXP = function(src, skillName, xp) + if not src or not skillName or not xp or xp < 0 then return false end + + local playerSkills = Framework.GetPlayerMetadata(src, "community_bridge_skills") or {} + local skill = playerSkills[skillName] or table.clone(DEFAULT_SKILL) + + skill.currentXP = xp + playerSkills[skillName] = skill + + Framework.SetPlayerMetadata(src, "community_bridge_skills", playerSkills) + return true +end + +-- Get resource name +Skills.GetResourceName = function() + return "community_bridge" +end + +-- Debug Commands +-- RegisterCommand('clearskill', function(source, args, rawCommand) +-- if not source or source == 0 then return end +-- local skillName = args[1] or "fishing" +-- Skills.SetXP(source, skillName, 0) +-- Skills.SetSkillLevel(source, skillName, 1) +-- print("Skill " .. skillName .. " cleared for player " .. source) +-- end, false) + return Skills \ No newline at end of file diff --git a/modules/skills/evolent_skills/server.lua b/modules/skills/evolent_skills/server.lua index 56a4700..78d4c7c 100644 --- a/modules/skills/evolent_skills/server.lua +++ b/modules/skills/evolent_skills/server.lua @@ -10,7 +10,6 @@ if (configValue == "auto" and GetResourceState(resourceName) ~= "started") or (c Skills.GetResourceName = function() return resourceName end - ---This will return the skill level of the passed skill name. ---@param src number ---@param skillName string @@ -28,6 +27,9 @@ end Skills.AddXp = function(src, skillName, amount) local skillData = exports.evolent_skills:getSkillLevel(src, skillName) if not skillData then return false, print("Skill not found") end + if not Skills.All[skillName] then + Skills.All[skillName] = Skills.Create(skillName, 99, 50) + end exports.evolent_skills:addXp(src, skillName, amount) return true end diff --git a/modules/skills/ot_skills/server.lua b/modules/skills/ot_skills/server.lua index ba0c39b..1981e5a 100644 --- a/modules/skills/ot_skills/server.lua +++ b/modules/skills/ot_skills/server.lua @@ -28,6 +28,9 @@ end Skills.AddXp = function(src, skillName, amount) local skillData = exports.OT_skills:getSkill(src, skillName) if not skillData then return false, print("Skill not found") end + if not Skills.All[skillName] then + Skills.All[skillName] = Skills.Create(skillName, 99, 50) + end exports.OT_skills:addXP(src, skillName, amount) return true end diff --git a/modules/skills/pickle_xp/server.lua b/modules/skills/pickle_xp/server.lua index 4a00ae0..5039bf0 100644 --- a/modules/skills/pickle_xp/server.lua +++ b/modules/skills/pickle_xp/server.lua @@ -28,6 +28,12 @@ end Skills.AddXp = function(src, skillName, amount) local skillData = exports.pickle_xp:GetPlayerLevel(src, skillName) if not skillData then return false, print("Skill not found") end + if not Skills.All[skillName] then + Skills.All[skillName] = Skills.Create(skillName, 99, 50) + end + -- if not amount or amount < 0 then + -- amount = Skills.GetScaledXP(Skills.All[skillName].baseXP, Skills.GetSkillLevel(src, skillName)) + -- end exports.pickle_xp:AddPlayerXP(src, skillName, amount) return true end diff --git a/modules/target/_default/init.lua b/modules/target/_default/init.lua index d7a1e3f..fbce4cd 100644 --- a/modules/target/_default/init.lua +++ b/modules/target/_default/init.lua @@ -2,6 +2,7 @@ local requiredModules = { 'modules/target/_default/client.lua', 'modules/target/qb-target/client.lua', + 'modules/target/sleepless_interact/client.lua', 'modules/target/ox_target/client.lua' } diff --git a/modules/target/ox_target/client.lua b/modules/target/ox_target/client.lua index 69a213e..8fedecd 100644 --- a/modules/target/ox_target/client.lua +++ b/modules/target/ox_target/client.lua @@ -34,6 +34,12 @@ Target.FixOptions = function(options) return options end +---This will toggle the targeting system on or off. This is useful for when you want to disable the targeting system for a specific player entirely. +---@param bool boolean +Target.DisableTargeting = function(bool) + ox_target:disableTargeting(bool) +end + ---This will add target options to players. ---@param options table Target.AddGlobalPlayer = function(options) @@ -43,14 +49,20 @@ end ---This will remove target options from all players. Target.RemoveGlobalPlayer = function() ----@diagnostic disable-next-line: missing-parameter ox_target:removeGlobalPlayer() end ----This will toggle the targeting system on or off. This is useful for when you want to disable the targeting system for a specific player entirely. ----@param bool boolean -Target.DisableTargeting = function(bool) - ox_target:disableTargeting(bool) +---This will add target options to all specified models. This is useful for when you want to add target options to all models of a specific type. +---@param options table +Target.AddGlobalPed = function(options) + options = Target.FixOptions(options) + ox_target:addGlobalPed(options) +end + +---This will remove target options from all peds. This is useful for when you want to remove target options from all peds. +---@param options any +Target.RemoveGlobalPed = function(options) + ox_target:removeGlobalPed(options) end ---This will add taget options to all vehicles. @@ -85,17 +97,19 @@ Target.RemoveLocalEntity = function(entities, optionNames) ox_target:removeLocalEntity(entities, optionNames) end ----This will add target options to all specified models. This is useful for when you want to add target options to all models of a specific type. +---This will add a networked entity to the target system. +---@param netids table | number ---@param options table -Target.AddGlobalPed = function(options) +Target.AddNetworkedEntity = function(netids, options) options = Target.FixOptions(options) - ox_target:addGlobalPed(options) + ox_target:addEntity(netids, options) end ----This will remove target options from all peds. This is useful for when you want to remove target options from all peds. ----@param options any -Target.RemoveGlobalPed = function(options) - ox_target:removeGlobalPed(options) +---This will remove a networked entity from the target system. +---@param netids table | number +---@param optionNames string +Target.RemoveNetworkedEntity = function(netids, optionNames) + ox_target:removeEntity(netids, optionNames) end ---This will add target options to all specified models. This is useful for when you want to add target options to all models of a specific type. @@ -112,18 +126,6 @@ Target.RemoveModel = function(model) ox_target:removeModel(model) end --- Target.DisableTargeting = function(bool) --- ox_target:disableTargeting(bool) --- end - --- Target.Refresh = function() --- ox_target:disableTargeting(true) --- Wait(10) --- ox_target:disableTargeting(false) --- end - - - ---This will add a box zone to the target system. This is useful for when you want to add target options to a specific area. ---@param name string ---@param coords table @@ -144,19 +146,6 @@ Target.AddBoxZone = function(name, coords, size, heading, options, debug) return target end --- RegisterCommand('boxzone:test', function(source, args, rawCommand) --- local coords = GetEntityCoords(PlayerPedId()) --- Target.AddBoxZone('test_zone', coords, { 2.0, 2.0, 2.0 }, 0.0, { --- { --- label = 'Test Option', --- icon = 'fas fa-check', --- onSelect = function() --- print('Test option selected!') --- end --- } --- }, true) --- end) - ---This will add a circle zone to the target system. This is useful for when you want to add target options to a specific area. ---@param name string ---@param coords table diff --git a/modules/target/qb-target/client.lua b/modules/target/qb-target/client.lua index f990d8a..2aed360 100644 --- a/modules/target/qb-target/client.lua +++ b/modules/target/qb-target/client.lua @@ -57,6 +57,19 @@ Target.RemoveGlobalPlayer = function() qb_target:RemoveGlobalPlayer() end +---This will add target options to all specified models. This is useful for when you want to add target options to all models of a specific type. +---@param options table +Target.AddGlobalPed = function(options) + options = Target.FixOptions(options) + qb_target:AddGlobalPed(options) +end + +---This will remove target options from all peds. This is useful for when you want to remove target options from all peds. +---@param options any +Target.RemoveGlobalPed = function(options) + qb_target:RemoveGlobalPed(options) +end + ---This will add taget options to all vehicles. ---@param options table Target.AddGlobalVehicle = function(options) @@ -67,6 +80,21 @@ Target.AddGlobalVehicle = function(options) }) end +---This will add a networked entity to the target system. +---@param netids table | number +---@param options table +Target.AddNetworkedEntity = function(netids, options) + options = Target.FixOptions(options) + qb_target:AddTargetEntity(netids, options) +end + +---This will remove a networked entity from the target system. +---@param netids table | number +---@param optionNames string +Target.RemoveNetworkedEntity = function(netids, optionNames) + qb_target:RemoveTargetEntity(netids, optionNames) +end + ---This will remove target options from all vehicles. ---@param options table Target.RemoveGlobalVehicle = function(options) @@ -95,20 +123,6 @@ Target.RemoveLocalEntity = function(entity, labels) qb_target:RemoveTargetEntity(entity, labels) end ----This will add target options to all specified models. This is useful for when you want to add target options to all models of a specific type. ----@param options table -Target.AddGlobalPed = function(options) - options = Target.FixOptions(options) - qb_target:AddGlobalPed(options) -end - ----This will remove target options from all peds. This is useful for when you want to remove target options from all peds. ----@param options any -Target.RemoveGlobalPed = function(options) - qb_target:RemoveGlobalPed(options) -end - - ---This will add target options to all specified models. This is useful for when you want to add target options to all models of a specific type. ---@param models number | table ---@param options table @@ -126,17 +140,6 @@ Target.RemoveModel = function(model) qb_target:RemoveTargetModel(model) end --- Target.DisableTargeting = function(bool) --- qb_target:AllowTargeting(bool) --- end - --- Target.Refresh = function() --- qb_target:AllowTargeting(false) --- Wait(10) --- qb_target:AllowTargeting(true) --- end - - ---This will add a box zone to the target system. This is useful for when you want to add target options to a specific area. ---@param name string ---@param coords table diff --git a/modules/target/sleepless_interact/client.lua b/modules/target/sleepless_interact/client.lua index b6011a7..de80861 100644 --- a/modules/target/sleepless_interact/client.lua +++ b/modules/target/sleepless_interact/client.lua @@ -5,9 +5,7 @@ if GetResourceState("ox_target") == 'started' then return end local targetDebug = false local function detectDebugEnabled() - if BridgeSharedConfig.DebugLevel == 2 then - targetDebug = true - end + if BridgeSharedConfig.DebugLevel == 2 then targetDebug = true end end detectDebugEnabled() @@ -17,6 +15,9 @@ local targetZones = {} Target = Target or {} +---This is an internal function that is used to fix the options passed to fit alternative target systems, for example qb-ox or ox-qb etc. +---@param options table +---@return table Target.FixOptions = function(options) for k, v in pairs(options) do local action = v.onSelect or v.action @@ -31,29 +32,46 @@ Target.FixOptions = function(options) return options end ----comment +---This will toggle the targeting system on or off. This is useful for when you want to disable the targeting system for a specific player entirely. +---@param bool boolean +Target.DisableTargeting = function(bool) -- someone disabled this mistakenly + sleepless_interact:disableInteract(bool) +end + +---This will add target options to players. ---@param options table ----@return nil Target.AddGlobalPlayer = function(options) options = Target.FixOptions(options) sleepless_interact:addGlobalPlayer(options) end -Target.DisableTargeting = function(bool) - sleepless_interact:disableInteract(bool) +---This will remove target options from all players. +Target.RemoveGlobalPlayer = function() + sleepless_interact:removeGlobalPlayer() end ----comment +---This will add target options to all specified models. This is useful for when you want to add target options to all models of a specific type. +---@param options table +Target.AddGlobalPed = function(options) + options = Target.FixOptions(options) + sleepless_interact:addGlobalPed(options) +end + +---This will remove target options from all peds. This is useful for when you want to remove target options from all peds. +---@param options any +Target.RemoveGlobalPed = function(options) + sleepless_interact:removeGlobalPed(options) +end + +---This will add taget options to all vehicles. ---@param options table ----@return nil Target.AddGlobalVehicle = function(options) options = Target.FixOptions(options) sleepless_interact:addGlobalVehicle(options) end ----comment +---This will remove target options from all vehicles. ---@param options table ----@return nil Target.RemoveGlobalVehicle = function(options) local assembledLables = {} for k, v in pairs(options) do @@ -62,31 +80,56 @@ Target.RemoveGlobalVehicle = function(options) sleepless_interact:removeGlobalVehicle(assembledLables) end ----comment ----@param entities table +---This will add a networked entity to the target system. +---@param netids table | number +---@param options table +Target.AddNetworkedEntity = function(netids, options) + options = Target.FixOptions(options) + sleepless_interact:addEntity(netids, options) +end + +---This will remove a networked entity from the target system. +---@param netids table | number +---@param optionNames string +Target.RemoveNetworkedEntity = function(netids, optionNames) + sleepless_interact:removeEntity(netids, optionNames) +end + +---This will generate targets on non networked entites with the passed options. +---@param entities number | table ---@param options table ----@return nil Target.AddLocalEntity = function(entities, options) options = Target.FixOptions(options) sleepless_interact:addLocalEntity(entities, options) end ----comment ----@param models table +---This will remove the target options from a local entity. This is useful for when you want to remove target options from a specific entity. +---@param entity number | table +---@param labels string | table | nil +Target.RemoveLocalEntity = function(entity, labels) + sleepless_interact:removeLocalEntity(entity, labels) +end + +---This will add target options to all specified models. This is useful for when you want to add target options to all models of a specific type. +---@param models number | table ---@param options table ----@return nil Target.AddModel = function(models, options) options = Target.FixOptions(options) sleepless_interact:addModel(models, options) end ----comment +---This will remove target options from all specified models. +---@param model number +Target.RemoveModel = function(model) + sleepless_interact:removeModel(model) +end + +---This will add a box zone to the target system. This is useful for when you want to add target options to a specific area. ---@param name string ---@param coords table ---@param size table ---@param heading number ---@param options table ----@return number Target.AddBoxZone = function(name, coords, size, heading, options) options = Target.FixOptions(options) local target = sleepless_interact:addCoords({ @@ -97,28 +140,26 @@ Target.AddBoxZone = function(name, coords, size, heading, options) return target end -Target.RemoveGlobalPlayer = function() - sleepless_interact:removeGlobalPlayer() -end - ----comment ----@param entity number ----@param labels string | table | nil ----@return nil -Target.RemoveLocalEntity = function(entity, labels) - sleepless_interact:removeLocalEntity(entity, labels) -end - ----comment ----@param model string ----@return nil -Target.RemoveModel = function(model) - sleepless_interact:removeModel(model) -end - ----comment +---This will add a circle zone to the target system. This is useful for when you want to add target options to a specific area. +---@param name string +---@param coords table +---@param radius number +---@param options table +Target.AddSphereZone = function(name, coords, radius, heading, options) + options = Target.FixOptions(options) + local target = sleepless_interact:addSphereZone({ + coords = coords, + radius = radius, + name = name, + debug = targetDebug, + options = options + }) + table.insert(targetZones, { name = name, id = target, creator = GetInvokingResource() }) + return target +end + +---This will remove target options from a specific zone. ---@param name string ----@return nil Target.RemoveZone = function(name) for _, data in pairs(targetZones) do if data.name == name then @@ -129,26 +170,14 @@ Target.RemoveZone = function(name) end end --- Target.DisableTargeting = function(bool) --- sleepless_interact:disableInteract(bool) --- end - --- Target.Refresh = function() --- sleepless_interact:disableInteract(false) --- Wait(10) --- sleepless_interact:disableInteract(true) --- end - - AddEventHandler('onResourceStop', function(resource) - if resource == GetCurrentResourceName() then - for _, target in pairs(targetZones) do - if target.creator == resource then - sleepless_interact:removeZone(target.id) - end + if resource ~= GetCurrentResourceName() then return end + for _, target in pairs(targetZones) do + if target.creator == resource then + sleepless_interact:removeZone(target.id) end - targetZones = {} end + targetZones = {} end) return Target \ No newline at end of file diff --git a/settings/clientConfig.lua b/settings/clientConfig.lua index 4de534d..0d6f579 100644 --- a/settings/clientConfig.lua +++ b/settings/clientConfig.lua @@ -1,9 +1,9 @@ BridgeClientConfig = {} -BridgeClientConfig.InputSystem = "auto" -- [ auto | ox_lib | qb-input ] -BridgeClientConfig.MenuSystem = "auto" -- [ auto | ox_lib | qb-menu ] -BridgeClientConfig.ProgressBarSystem = "auto" -- [ auto | ox_lib | progressbar ] -BridgeClientConfig.VehicleKey = "auto" -- [ auto | qb-vehiclekeys | MrNewbVehicleKeys | jaksams_VehiclesKeys | wasabi_carlock | mk_vehiclekeys | qbx_vehiclekeys | qs-vehiclekeys | t1ger_keys | Renewed-Vehiclekeys | mono_carkeys| cd_garage | okokGarage | F_RealCarKeysSystem -BridgeClientConfig.Fuel = "auto" -- [ auto | LegacyFuel | ox_fuel | ps-fuel | qs-fuelstations | Renewed-Fuel | ti_fuel | lc_fuel | x-fuel | cdn-fuel | esx-sna-fuel | BigDaddy-Fuel | okokGasStation ] -BridgeClientConfig.TargetSystem = "auto" -- [ auto | ox_target | qb-target | sleepless_interact ] -- sleepless is only partially supported and would need another system in place +BridgeClientConfig.InputSystem = "auto" -- [ auto | ox_lib | lation_ui | qb-input ] +BridgeClientConfig.MenuSystem = "auto" -- [ auto | ox_lib | lation_ui | qb-menu ] +BridgeClientConfig.ProgressBarSystem = "auto" -- [ auto | ox_lib | lation_ui | progressbar ] +BridgeClientConfig.VehicleKey = "auto" -- [ auto | qb-vehiclekeys | MrNewbVehicleKeys | jaksams_VehiclesKeys | wasabi_carlock | mk_vehiclekeys | qbx_vehiclekeys | qs-vehiclekeys | t1ger_keys | Renewed-Vehiclekeys | mono_carkeys| cd_garage | okokGarage | F_RealCarKeysSystem +BridgeClientConfig.Fuel = "auto" -- [ auto | LegacyFuel | ox_fuel | ps-fuel | qs-fuelstations | Renewed-Fuel | ti_fuel | lc_fuel | x-fuel | cdn-fuel | esx-sna-fuel | BigDaddy-Fuel | okokGasStation ] +BridgeClientConfig.TargetSystem = "auto" -- [ auto | ox_target | qb-target | sleepless_interact ] -- sleepless is only partially supported and would need another system in place BridgeClientConfig.Debug = false return BridgeClientConfig diff --git a/settings/serverConfig.lua b/settings/serverConfig.lua index 69ac8e9..742dd26 100644 --- a/settings/serverConfig.lua +++ b/settings/serverConfig.lua @@ -1,7 +1,4 @@ BridgeServerConfig = {} -BridgeServerConfig.LogSystem = "built-in" -- [ built-in | qb | ox_lib ] -BridgeServerConfig.WebhookURL = "PUT_WEBHOOK_URL_HERE" -- only if using builtin -BridgeServerConfig.WebhookImage = "https://cdn.discordapp.com/avatars/299410129982455808/31ce635662206e8bd0132c34ce9ce683?size=1024" BridgeServerConfig.MaxInventorySlots = 50 return BridgeServerConfig diff --git a/settings/sharedConfig.lua b/settings/sharedConfig.lua index d0a3c06..fec88a1 100644 --- a/settings/sharedConfig.lua +++ b/settings/sharedConfig.lua @@ -1,8 +1,8 @@ BridgeSharedConfig = {} BridgeSharedConfig.Lang = "auto" -- Change this to your preferred language (must match the locale file name ex. en or fr etc) BridgeSharedConfig.DebugLevel = 0 -- Change this to your Debug level, 0 for none, 1 for some, 2 for all data -BridgeSharedConfig.Notify = "auto" -- [ auto | ox_lib | r_notify | okokNotify | mythic_notify | pNotify | t-notify | wasabi_notify] -BridgeSharedConfig.HelpText = "auto" -- [ auto | ox_lib | jg-textui | cd_drawtextui | lab-HintUI | okokTextUI] +BridgeSharedConfig.Notify = "auto" -- [ auto | ox_lib | r_notify | wasabi_notify | lation_ui | okokNotify | mythic_notify | pNotify | t-notify | brutal_notify] +BridgeSharedConfig.HelpText = "auto" -- [ auto | ox_lib | jg-textui | lation_ui | cd_drawtextui | lab-HintUI | okokTextUI] BridgeSharedConfig.Phone = "auto" -- [ auto | qs-smartphone | lb-phone | gksphone] BridgeSharedConfig.Skills = "auto" -- [ auto | OT_skills | evolent_skills | pickle_xp] diff --git a/unit_tests/placeable_object.lua b/unit_tests/placeable_object.lua index 4ad9b81..2b2f7ad 100644 --- a/unit_tests/placeable_object.lua +++ b/unit_tests/placeable_object.lua @@ -26,4 +26,13 @@ RegisterCommand('startplacer', function(source, args, rawCommand) else print("Placement cancelled") end +end) + + +RegisterCommand("startplacerold", function(source, args, rawCommand) + local model = args[1] or 'prop_barrel_01a' -- Default model if none provided + local distance = tonumber(args[2]) or 5.0 -- Default distance if not provided + local snapToGround = true + local offset = vector3(0.0, 0.0, 0.0) -- No offset + local obj = Bridge.Placeable.PlaceObject(model, distance, snapToGround, {}, offset) end) \ No newline at end of file