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
@@ -61,6 +61,7 @@ cLib.LootTables = LootTables or Require("lib/generators/server/lootTables.lua")
|
||||
cLib.Cache = Cache or Require("lib/cache/shared/cache.lua")
|
||||
cLib.ServerEntity = ServerEntity or Require("lib/entities/server/server_entity.lua")
|
||||
cLib.Marker = Marker or Require("lib/markers/server/server.lua")
|
||||
cLib.Particle = Particle or Require("lib/particles/server/particles.lua")
|
||||
if IsDuplicityVersion() then return cLib end
|
||||
::client::
|
||||
|
||||
@@ -80,4 +81,6 @@ cLib.Marker = Marker or Require("lib/markers/client/markers.lua")
|
||||
cLib.Anim = Anim or Require("lib/anim/client/client.lua")
|
||||
cLib.Cutscene = Cutscene or Require("lib/cutscenes/client/cutscene.lua")
|
||||
cLib.DUI = DUI or Require("lib/dui/client/dui.lua")
|
||||
cLib.Particle = Particle or Require("lib/particles/client/particles.lua")
|
||||
|
||||
return cLib
|
||||
@@ -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
|
||||
@@ -1,4 +1,8 @@
|
||||
Particles = {}
|
||||
Particle = {}
|
||||
---@diagnostic disable: duplicate-set-field
|
||||
local Ids = Ids or Require("lib/utility/shared/ids.lua")
|
||||
local point = Require("lib/points/client/points.lua")
|
||||
|
||||
---Loads a ptfx asset into memory.
|
||||
---@param dict string
|
||||
@@ -14,7 +18,6 @@ function LoadPtfxAsset(dict)
|
||||
return HasNamedPtfxAssetLoaded(dict)
|
||||
end
|
||||
|
||||
|
||||
--- Create a particle effect at the specified position and rotation.
|
||||
--- @param dict string
|
||||
--- @param ptfx string
|
||||
@@ -25,7 +28,7 @@ end
|
||||
--- @param looped boolean
|
||||
--- @param loopLength number|nil
|
||||
--- @return number|nil ptfxHandle -- The handle of the particle effect, or nil if it failed to create.
|
||||
function Particle.Create(dict, ptfx, pos, rot, scale, color, looped, loopLength)
|
||||
function Particle.Play(dict, ptfx, pos, rot, scale, color, looped, loopLength)
|
||||
LoadPtfxAsset(dict)
|
||||
UseParticleFxAssetNextCall(dict)
|
||||
SetParticleFxNonLoopedColour(color.x, color.y, color.z)
|
||||
@@ -45,14 +48,107 @@ function Particle.Create(dict, ptfx, pos, rot, scale, color, looped, loopLength)
|
||||
return particle
|
||||
end
|
||||
|
||||
function Particle.Remove(particle)
|
||||
function Particle.Stop(particle)
|
||||
if not particle then return end
|
||||
StopParticleFxLooped(particle, false)
|
||||
RemoveParticleFx(particle, false)
|
||||
RemoveNamedPtfxAsset(particle)
|
||||
|
||||
end
|
||||
|
||||
function Particle.Create(data)
|
||||
assert(data, "Particle data is nil")
|
||||
assert(data.dict, "Invalid particle data. Must contain string dict.")
|
||||
assert(data.ptfx, "Invalid particle data. Must contain string ptfx.")
|
||||
|
||||
local _id = data.id or Ids.CreateUniqueId(Particles)
|
||||
print("Creating particle", _id)
|
||||
-- data for particles above
|
||||
data = {
|
||||
id = _id,
|
||||
dict = data.dict,
|
||||
ptfx = data.ptfx,
|
||||
position = data.position or vector3(0.0, 0.0, 0.0),
|
||||
rotation = data.rotation or vector3(0, 0, 0),
|
||||
size = data.size or 1.0,
|
||||
color = data.color or vector3(255, 255, 255),
|
||||
looped = data.looped or false,
|
||||
loopLength = data.loopLength or nil,
|
||||
spawned = false,
|
||||
}
|
||||
Particles[_id] = data
|
||||
|
||||
point.Register( -- checking if players in range
|
||||
_id,
|
||||
data.position,
|
||||
data.drawDistance or 50.0,
|
||||
data,
|
||||
function(_)
|
||||
if not Particles[_id] then return point.Remove(_id) end
|
||||
local particleData = Particles[_id]
|
||||
if particleData.spawned then return end
|
||||
particleData.spawned = Particle.Play(
|
||||
particleData.dict,
|
||||
particleData.ptfx,
|
||||
particleData.position,
|
||||
particleData.rotation,
|
||||
particleData.size,
|
||||
particleData.color,
|
||||
particleData.looped,
|
||||
particleData.loopLength
|
||||
)
|
||||
end,
|
||||
function(markerData)
|
||||
if not Particles[_id] then return end
|
||||
local particleData = Particles[_id]
|
||||
if not particleData.spawned then return end
|
||||
Particle.Stop(particleData.spawned)
|
||||
particleData.spawned = nil
|
||||
end
|
||||
)
|
||||
return _id
|
||||
end
|
||||
|
||||
function Particle.Remove(id)
|
||||
if not id then return end
|
||||
print("Removing particle1", id)
|
||||
local particle = Particles[id]
|
||||
print("Removing particle2", id)
|
||||
if not particle then return end
|
||||
print("Removing particle3", id)
|
||||
Particle.Stop(particle.spawned)
|
||||
Particles[id] = nil
|
||||
point.Remove(id)
|
||||
end
|
||||
|
||||
|
||||
|
||||
RegisterNetEvent("community_bridge:Client:Particle", function(data)
|
||||
if not data then return end
|
||||
Particle.Create(data)
|
||||
end)
|
||||
|
||||
RegisterNetEvent("community_bridge:Client:ParticleBulk", function(datas)
|
||||
if not datas then return end
|
||||
for _, data in pairs(datas) do
|
||||
Particle.Create(data)
|
||||
end
|
||||
end)
|
||||
|
||||
RegisterNetEvent("community_bridge:Client:ParticleRemove", function(id)
|
||||
local particle = Particles[id]
|
||||
if not particle then return end
|
||||
Particle.Remove(Drawing[id])
|
||||
end)
|
||||
|
||||
RegisterNetEvent("community_bridge:Client:ParticleRemoveBulk", function(ids)
|
||||
print("community_bridge:Client:ParticleRemoveBulk", ids)
|
||||
for _, id in pairs(ids) do
|
||||
Particle.Remove(id)
|
||||
end
|
||||
end)
|
||||
|
||||
|
||||
|
||||
function Particle.CreateOnEntity(dict, ptfx, entity, offset, rot, scale, color, looped, loopLength)
|
||||
LoadPtfxAsset(dict)
|
||||
UseParticleFxAssetNextCall(dict)
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
---@diagnostic disable: duplicate-set-field
|
||||
|
||||
Particles = {}
|
||||
Particle = Particles or {}
|
||||
|
||||
function Particle.New(data)
|
||||
assert(data, "Particle data is nil")
|
||||
assert(data.dict, "Invalid particle data. Must contain string dict.")
|
||||
assert(data.ptfx, "Invalid particle data. Must contain string ptfx.")
|
||||
|
||||
local _id = data.id or id.CreateUniqueId(Particles)
|
||||
data = {
|
||||
id = _id,
|
||||
dict = data.dict,
|
||||
ptfx = data.ptfx,
|
||||
position = data.position or vector3(0.0, 0.0, 0.0),
|
||||
rotation = data.rotation or vector3(0, 0, 0),
|
||||
size = data.size or 1.0,
|
||||
color = data.color or vector3(255, 255, 255),
|
||||
looped = data.looped or false,
|
||||
loopLength = data.loopLength or nil,
|
||||
}
|
||||
Particles[_id] = data
|
||||
return data
|
||||
end
|
||||
|
||||
function Particle.Destroy(id)
|
||||
if not id or not Particles[id] then return end
|
||||
Particles[id] = nil
|
||||
return true
|
||||
end
|
||||
|
||||
function Particle.Create(data)
|
||||
local particleData = Particle.New(data)
|
||||
if not particleData then return end
|
||||
TriggerClientEvent("community_bridge:Client:Particle", -1, particleData)
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
function Particle.Remove(id)
|
||||
if not Particle.Destroy(id) then return end
|
||||
TriggerClientEvent("community_bridge:Client:ParticleRemove", -1, id)
|
||||
end
|
||||
|
||||
function Particle.CreateBulk(datas)
|
||||
if not datas then return end
|
||||
local toClient = {}
|
||||
for k, v in pairs(datas) do
|
||||
local data = Particle.New(v)
|
||||
table.insert(toClient, data)
|
||||
end
|
||||
TriggerClientEvent("community_bridge:Client:ParticleBulk", -1, toClient)
|
||||
return toClient
|
||||
end
|
||||
|
||||
function Particle.RemoveBulk(ids)
|
||||
if not ids then return end
|
||||
local toClient = {}
|
||||
for k, v in pairs(ids) do
|
||||
local id = v
|
||||
if type(v) == "table" then
|
||||
id = v.id
|
||||
end
|
||||
Particle.Destroy(id)
|
||||
table.insert(toClient, id)
|
||||
end
|
||||
TriggerClientEvent("community_bridge:Client:ParticleRemoveBulk", -1, toClient)
|
||||
return ids
|
||||
end
|
||||
|
||||
return Particle
|
||||
Reference in new issue
Block a user