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..f714dca 100644 --- a/lib/entities/client/client_entity.lua +++ b/lib/entities/client/client_entity.lua @@ -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) 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/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/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