diff --git a/fxmanifest.lua b/fxmanifest.lua index f968048..48cfc4f 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -31,6 +31,7 @@ server_scripts { 'modules/notify/**/server.lua', 'modules/housing/**/server.lua', 'modules/skills/**/server.lua', + "lib/**/server.lua", 'init.lua', } diff --git a/lib/markers/client/markers.lua b/lib/markers/client/markers.lua index f587da3..c83dc60 100644 --- a/lib/markers/client/markers.lua +++ b/lib/markers/client/markers.lua @@ -1,6 +1,39 @@ -Marker = {} +Marker = { +} +local Created = setmetatable({}, { __mode = "k" }) +local id = Require("lib/utility/shared/ids") + +--- This will validate the marker data. +--- @param data table{position: vector3, offset: vector3, rotation: vector3, size: vector3, color: vector3, alpha: number, bobUpAndDown: boolean, marker: number, interaction: function} +--- @return boolean +local function validateMarkerData(data) + if not data.position or not data.position.x or not data.position.y or not data.position.z then + print("Invalid marker position. Must be a vector3 with x, y, and z coordinates.") + return false + end + if data.offset and (not data.offset.x or not data.offset.y or not data.offset.z) then + print("Invalid marker offset. Must be a vector3 with x, y, and z coordinates.") + return false + end + if data.rotation and (not data.rotation.x or not data.rotation.y or not data.rotation.z) then + print("Invalid marker rotation. Must be a vector3 with x, y, and z coordinates.") + return false + end + return true +end + +AddEventHandler("community_bridge:client:marker", function(data) + if not validateMarkerData(data) then return end + if source == "" then return end + Marker.DrawMarker(data) +end) + +--- This will create a marker. +--- @param data table{position: vector3, offset: vector3, rotation: vector3, size: vector3, color: vector3, alpha: number, bobUpAndDown: boolean, marker: number, interaction: function} +---@return number function Marker.DrawMarker(data) + local _id = data.id or id.Random() local position = data.position or vector3(0.0, 0.0, 0.0) local offset = data.offset or vector3(0.0, 0.0, 0.0) local marker = data.marker or 1 @@ -10,17 +43,72 @@ function Marker.DrawMarker(data) local color = data.color or vector3(0, 255, 0) local alpha = data.alpha or 255 local bobUpAndDown = data.bobUpAndDown - DrawMarker( - marker, - pos.x, pos.y, pos.z, - 0.0, 0.0, 0.0, - rotation.x, rotation.y, rotation.z, - size.x, size.y, size.z, - color.r, color.g, color.b, alpha, - bobUpAndDown, false, false - ) + local interaction = data.interaction or false + Created[_id] = { + position = pos, + rotation = rotation, + size = size, + color = color, + alpha = alpha, + bobUpAndDown = + bobUpAndDown, + marker = marker, + offset = offset, + interaction = interaction, + id = _id, + } + return _id end +function Marker.RemoveMarker(id) + if Created[id] then + Created[id] = nil + return true + end + return false +end + +function Marker.Draw() + while true do + Wait(0) + if not next(Created) then + Wait(1000) -- Reduce CPU usage when no markers are present + goto continue + end + + for id, _ in pairs(Created) do + if Created[id] then + local data = Created[id] + if #(data.position - GetEntityCoords(PlayerPedId())) > 100.0 then + goto continue + else + DrawMarker( + data.marker, + data.position.x, data.position.y, data.position.z, + 0.0, 0.0, 0.0, + data.rotation.x, data.rotation.y, data.rotation.z, + data.size.x, data.size.y, data.size.z, + data.color.x, data.color.y, data.color.z, data.alpha, + data.bobUpAndDown, false, false + ) + if data.interaction then + local playerCoords = GetEntityCoords(PlayerPedId()) + local distance = #(data.position - playerCoords) + if distance < 2.0 then + if IsControlJustReleased(0, 38) then -- E key + data.interaction(data.id) + end + end + end + end + end + end + ::continue:: + end +end + +Marker.Draw() -- Start the marker drawing loop exports("Marker", Marker) + return Marker diff --git a/lib/markers/server/server.lua b/lib/markers/server/server.lua new file mode 100644 index 0000000..c009c7d --- /dev/null +++ b/lib/markers/server/server.lua @@ -0,0 +1,24 @@ +local function RegisterNewMarker(data) + if not data.position or not data.position.x or not data.position.y or not data.position.z then + print("Invalid marker position. Must be a vector3 with x, y, and z coordinates.") + return + end + if data.offset and (not data.offset.x or not data.offset.y or not data.offset.z) then + print("Invalid marker offset. Must be a vector3 with x, y, and z coordinates.") + return + end + if data.rotation and (not data.rotation.x or not data.rotation.y or not data.rotation.z) then + print("Invalid marker rotation. Must be a vector3 with x, y, and z coordinates.") + return + end + + if not data.size or not data.size.x or not data.size.y or not data.size.z then + print("Invalid marker size. Must be a vector3 with x, y, and z dimensions.") + return + end + + TriggerClientEvent("community_bridge:client:marker", source, data) +end + +RegisterNetEvent("community_bridge:server:createMarker", RegisterNewMarker) +exports("RegisterNewMarker", RegisterNewMarker) diff --git a/lib/sql/server/sqlHandler.lua b/lib/sql/server/sqlHandler.lua index 942bcf2..9336438 100644 --- a/lib/sql/server/sqlHandler.lua +++ b/lib/sql/server/sqlHandler.lua @@ -2,6 +2,8 @@ SQL = {} Require("lib/MySQL.lua", "oxmysql") + + function SQL.Create(tableName, columns) assert(MySQL, "Tried using module SQL without MySQL being loaded") local columnsList = {} @@ -26,7 +28,7 @@ function SQL.InsertOrUpdate(tableName, data) for column, value in pairs(data) do table.insert(columns, column) - table.insert(values, "'" .. value .. "'") -- Ensure values are properly quoted + table.insert(values, "'" .. value .. "'") -- Ensure values are properly quoted table.insert(updates, column .. " = VALUES(" .. column .. ")") -- Use VALUES() for update end @@ -65,4 +67,4 @@ exports('SQL', function() return SQL end) -return SQL \ No newline at end of file +return SQL