Server-sided markers and particles
This commit is contained in:
1 parent
5bff52034c
commit
2f7c40e809
5 files changed
+230
-16
No files matched your search
@@ -1,8 +1,8 @@
|
||||
---@diagnostic disable: duplicate-set-field
|
||||
Marker = {}
|
||||
local Created = setmetatable({}, { __mode = "k" }) --what is mode?
|
||||
local id = Ids or Require("lib/utility/shared/ids.lua")
|
||||
local point = Require("lib/points/client/points.lua")
|
||||
local Ids = Ids or Require("lib/utility/shared/ids.lua")
|
||||
local point = Point or Require("lib/points/client/points.lua")
|
||||
local loopRunning = false
|
||||
local Drawing = {}
|
||||
|
||||
@@ -29,7 +29,7 @@ end
|
||||
--- @param data table{position: vector3, offset: vector3, rotation: vector3, size: vector3, color: vector3, alpha: number, bobUpAndDown: boolean, marker: number, interaction: function}
|
||||
--- @return string|nil
|
||||
function Marker.Create(data)
|
||||
local _id = data.id or id.Random()
|
||||
local _id = data.id or Ids.CreateUniqueId(Created)
|
||||
if not validateMarkerData(data) then return end
|
||||
local basePosition = data.position or vector3(0.0, 0.0, 0.0)
|
||||
local baseOffset = data.offset or vector3(0.0, 0.0, 0.0)
|
||||
@@ -61,7 +61,7 @@ function Marker.Create(data)
|
||||
end,
|
||||
function(markerData)
|
||||
Drawing[_id] = nil
|
||||
end
|
||||
end, nil
|
||||
)
|
||||
return _id
|
||||
end
|
||||
@@ -117,14 +117,27 @@ function Marker.Run(data)
|
||||
end
|
||||
|
||||
RegisterNetEvent("community_bridge:Client:Marker", function(data)
|
||||
print("community_bridge:Client:Marker")
|
||||
Marker.Create(data)
|
||||
end)
|
||||
|
||||
RegisterNetEvent("community_bridge:Client:MarkerBulk", function(datas)
|
||||
if not datas then return end
|
||||
for _, data in pairs(datas) do
|
||||
Marker.Create(data)
|
||||
end
|
||||
end)
|
||||
|
||||
RegisterNetEvent("community_bridge:Client:MarkerRemove", function(id)
|
||||
Marker.Remove(id)
|
||||
end)
|
||||
|
||||
RegisterNetEvent("community_bridge:Client:MarkerRemoveBulk", function(ids)
|
||||
if not ids then return end
|
||||
for _, id in pairs(ids) do
|
||||
Marker.Remove(id)
|
||||
end
|
||||
end)
|
||||
|
||||
-- local loopRunning = false
|
||||
-- function Marker.Draw()
|
||||
-- if loopRunning then return end
|
||||
|
||||
@@ -3,7 +3,7 @@ local id = Ids or Require("lib/utility/shared/ids.lua")
|
||||
Marker = {}
|
||||
local Created = {}
|
||||
|
||||
function Marker.Create(data)
|
||||
function Marker.New(data)
|
||||
if not data.position or not data.position.x or not data.position.y or not data.position.z then
|
||||
print("Invalid marker position. Must be a vector3 with x, y, and z coordinates.")
|
||||
return
|
||||
@@ -40,19 +40,49 @@ function Marker.Create(data)
|
||||
drawOnEnts = data.drawOnEnts,
|
||||
}
|
||||
Created[_id] = data
|
||||
TriggerClientEvent("community_bridge:Client:Marker", -1, data)
|
||||
return _id
|
||||
end
|
||||
function Marker.Destroy(id)
|
||||
if not id or not Created[id] then return end
|
||||
Created[id] = nil
|
||||
return true
|
||||
end
|
||||
|
||||
function Marker.Create(data)
|
||||
local _id = Marker.New(data)
|
||||
if not _id then return end
|
||||
TriggerClientEvent("community_bridge:Client:Marker", -1, Created[_id])
|
||||
return _id
|
||||
end
|
||||
|
||||
function Marker.Remove(id)
|
||||
if not Created[id] then return end
|
||||
if not Marker.Destroy(id) then return end
|
||||
TriggerClientEvent("community_bridge:Client:MarkerRemove", -1, id)
|
||||
Created[id] = nil
|
||||
end
|
||||
|
||||
RegisterNetEvent("community_bridge:Server:MarkerRemove", function(id)
|
||||
Marker.Remove(id)
|
||||
end)
|
||||
function Marker.CreateBulk(datas)
|
||||
if not datas then return end
|
||||
local toClient = {}
|
||||
for k, v in pairs(datas) do
|
||||
table.insert(toClient, Marker.Create(v))
|
||||
end
|
||||
TriggerClientEvent("community_bridge:Client:MarkerBulk", -1, toClient)
|
||||
return toClient
|
||||
end
|
||||
|
||||
function Marker.RemoveBulk(ids)
|
||||
if not ids then return end
|
||||
local toClient = {}
|
||||
for k, v in pairs(ids) do
|
||||
local id = v
|
||||
if type(v) == "table" then
|
||||
id = v.id
|
||||
end
|
||||
Marker.Destroy(id)
|
||||
table.insert(toClient, id)
|
||||
end
|
||||
TriggerClientEvent("community_bridge:Client:MarkerRemoveBulk", -1, toClient)
|
||||
end
|
||||
|
||||
exports("Marker", Marker)
|
||||
return Marker
|
||||
Reference in new issue
Block a user