1
0
Fork 0
forked from Simnation/Main
This commit is contained in:
Nordi98 2025-08-12 16:56:50 +02:00
parent 9178871ecd
commit 640cdd069b
9 changed files with 583 additions and 269 deletions

View file

@ -1447,6 +1447,28 @@ end
return values
end
-- Uses table.clone for fast shallow copying (memcpy) before checking and doing actual deepcopy for nested tables
-- Handles circular references via seen table
-- Significantly faster (~50%) than doing actual deepcopy for flat or lightly-nested structures
---@param orig table
---@return table
table.deepcopy = function(orig, seen)
if type(orig) ~= "table" then return orig end
seen = seen or {}
if seen[orig] then return seen[orig] end
local copy = table.clone(orig)
seen[orig] = copy
for k, v in next, orig do
if type(v) == "table" then
copy[k] = table.deepcopy(v, seen)
end
end
return copy
end
math.round = function(number, decimals)
local _ = 10 ^ decimals
@ -2512,7 +2534,8 @@ end
NetworkRequestControlOfEntity(trolly)
end
local bagObj = CreateObject("hei_p_m_bag_var22_arm_s", vector3(0.0, 0.0, 0.0), true)
local playerCoords = GetEntityCoords(ped)
local bagObj = CreateObject("hei_p_m_bag_var22_arm_s", playerCoords + vector3(0.0, 0.0, -6.0), true)
SetEntityCollision(bagObj, false, true)
-- Intro
@ -2984,13 +3007,26 @@ end
--// UtilityNet //
local CreatedEntities = {}
local old_GetEntityArchetypeName = GetEntityArchetypeName
GetEntityArchetypeName = function(entity)
if not entity or not DoesEntityExist(entity) then
return ""
end
local res = old_GetEntityArchetypeName(entity)
if res == "" then
return Entity(entity)?.state?.abstract_model or res
else
return res
end
end
--#region API
UtilityNet.ForEachEntity = function(fn, slices)
if slices then
local entities = GlobalState.Entities
for i = 1, #slices do
local _entities = entities[slices[i]]
local _entities = UtilityNet.GetEntities(slices[i])
local n = 0
if _entities then
@ -3009,7 +3045,7 @@ UtilityNet.ForEachEntity = function(fn, slices)
end
end
else
local entities = GlobalState.Entities
local entities = UtilityNet.GetEntities()
if not entities then
return
@ -3035,14 +3071,6 @@ UtilityNet.ForEachEntity = function(fn, slices)
end
end
UtilityNet.InternalFindFromNetId = function(uNetId)
for sliceI, slice in pairs(GlobalState.Entities) do
if slice[uNetId] then
return slice[uNetId], sliceI
end
end
end
UtilityNet.SetDebug = function(state)
UtilityNetDebug = state
@ -3071,7 +3099,9 @@ UtilityNet.SetDebug = function(state)
for k,v in pairs(localEntities) do
local state = UtilityNet.State(v.netId)
DrawText3Ds(GetEntityCoords(v.obj), "NetId: "..v.netId, 0.25)
if DoesEntityExist(v.obj) then
DrawText3Ds(GetEntityCoords(v.obj), "NetId: "..v.netId, 0.25)
end
end
Citizen.Wait(1)
end
@ -3089,16 +3119,16 @@ UtilityNet.CreateEntity = function(model, coords, options)
-- Set resource name in options
options = options or {}
options.resource = GetCurrentResourceName()
options.createdBy = GetCurrentResourceName()
local callId = math.random(0, 10000000)
local event = nil
local entity = promise:new()
-- Callback
event = RegisterNetEvent("Utility:Net:EntityCreated", function(_callId, uNetId)
event = RegisterNetEvent("Utility:Net:EntityCreated", function(_callId, object)
if _callId == callId then
entity:resolve(uNetId)
entity:resolve(object.id)
RemoveEventHandler(event)
end
end)
@ -3207,18 +3237,18 @@ UtilityNet.DetachEntity = function(uNetId)
end
-- Using a latent event to prevent blocking the network channel
UtilityNet.SetEntityCoords = function(uNetId, coords)
UtilityNet.SetEntityCoords = function(uNetId, coords, skipPositionUpdate)
TriggerLatentServerEvent("Utility:Net:SetEntityCoords", 5120, uNetId, coords)
-- Instantly sync for local obj
TriggerEvent("Utility:Net:RefreshCoords", uNetId, coords)
TriggerEvent("Utility:Net:RefreshCoords", uNetId, coords, skipPositionUpdate)
end
UtilityNet.SetEntityRotation = function(uNetId, rot)
TriggerLatentServerEvent("Utility:Net:SetEntityRotation", 5120, uNetId, rot)
UtilityNet.SetEntityRotation = function(uNetId, rot, skipRotationUpdate)
TriggerLatentServerEvent("Utility:Net:SetEntityRotation", 5120, uNetId, rot, skipRotationUpdate)
-- Instantly sync for local obj
TriggerEvent("Utility:Net:RefreshRotation", uNetId, rot)
TriggerEvent("Utility:Net:RefreshRotation", uNetId, rot, skipRotationUpdate)
end
UtilityNet.SetEntityModel = function(uNetId, model)
@ -3322,6 +3352,22 @@ end
UtilityNet.GetUNetIdFromEntity = function(entity)
return exports["utility_lib"]:GetUNetIdFromEntity(entity)
end
UtilityNet.GetuNetIdCreator = function(uNetId)
return exports["utility_lib"]:GetuNetIdCreator(uNetId)
end
UtilityNet.GetEntityCreator = function(entity)
return exports["utility_lib"]:GetEntityCreator(entity)
end
UtilityNet.InternalFindFromNetId = function(uNetId)
return exports["utility_lib"]:InternalFindFromNetId(uNetId)
end
UtilityNet.GetEntities = function(slice)
return exports["utility_lib"]:GetEntities(slice)
end
--#endregion
--#endregion