small tweaks

entities now has register bulk
added docs to a function for sql module
added table.count
This commit is contained in:
gononono64 committed 2025-06-22 17:40:41 -05:00
1 parent 82f9ff6c42
commit 9b44fcbc16
5 files changed
+78 -7

No files matched your search

+23
View File
@@ -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")
+13
View File
@@ -73,6 +73,15 @@ function ClientEntity.Register(entityData)
return Point.Register(entityData.id, entityData.coords, entityData.spawnDistance or 50.0, entityData, SpawnEntity, RemoveEntity, function() end)
end
function ClientEntity.RegisterBulk(entities)
local registeredEntities = {}
for _, entityData in pairs(entities) do
ClientEntity.Register(entityData)
registeredEntities[entityData.id] = entityData
end
return registeredEntities
end
--- 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)
@@ -158,6 +167,10 @@ RegisterNetEvent("community_bridge:client:CreateEntity", function(entityData)
ClientEntity.Register(entityData)
end)
RegisterNetEvent("community_bridge:client:CreateEntities", function(entities)
ClientEntity.RegisterBulk(entities)
end)
RegisterNetEvent("community_bridge:client:DeleteEntity", function(id)
ClientEntity.Unregister(id)
end)
+29 -5
View File
@@ -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)
+4 -1
View File
@@ -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")
+9 -1
View File
@@ -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