Targets, entities and events, oh my!
Targets updated to have boxzone Entities dont require a model and are effectively points with on spawn on despawn onplayerloaded and onplayeriunloaded now pass source
This commit is contained in:
1 parent
3a141cb8f2
commit
34d24cb6a9
11 files changed
+61
-352
No files matched your search
+14
-20
@@ -25,7 +25,6 @@ function Anim.RequestDict(animDict)
|
||||
end
|
||||
|
||||
--- This will start the animation update loop.
|
||||
--- @return void
|
||||
function Anim.Start()
|
||||
if Anim.isUpdateLoopRunning then return end
|
||||
Anim.isUpdateLoopRunning = true
|
||||
@@ -37,15 +36,13 @@ function Anim.Start()
|
||||
end
|
||||
|
||||
if #idsToProcess == 0 then
|
||||
Wait(750)
|
||||
Wait(750)
|
||||
else
|
||||
for _, id in ipairs(idsToProcess) do
|
||||
local animData = Anim.Active[id]
|
||||
|
||||
if animData then
|
||||
local animData = Anim.Active[id]
|
||||
if animData then
|
||||
local entity = animData.entity
|
||||
local onComplete = animData.onComplete
|
||||
|
||||
local onComplete = animData.onComplete
|
||||
if not DoesEntityExist(entity) then
|
||||
if onComplete then onComplete(false, "despawned") end
|
||||
Anim.Active[id] = nil
|
||||
@@ -54,10 +51,8 @@ function Anim.Start()
|
||||
animData.startTime = GetGameTimer()
|
||||
animData.animEndTime = animData.duration > 0 and (animData.startTime + animData.duration) or -1
|
||||
animData.status = "playing"
|
||||
|
||||
elseif animData.status == "playing" then
|
||||
local animationCompletedNaturally = false
|
||||
|
||||
if animData.duration == -1 then
|
||||
if not IsEntityPlayingAnim(entity, animData.animDict, animData.animName, 3) and GetEntityAnimCurrentTime(entity, animData.animDict, animData.animName) > 0.8 then
|
||||
animationCompletedNaturally = true
|
||||
@@ -65,17 +60,16 @@ function Anim.Start()
|
||||
elseif animData.animEndTime ~= -1 and GetGameTimer() >= animData.animEndTime then
|
||||
animationCompletedNaturally = true
|
||||
end
|
||||
|
||||
if animationCompletedNaturally then
|
||||
if onComplete then onComplete(true, "completed") end
|
||||
Anim.Active[id] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Wait(100)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Wait(100)
|
||||
end
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
@@ -92,7 +86,7 @@ end
|
||||
--- @param onComplete function | nil
|
||||
--- @return string | nil
|
||||
function Anim.Play(id, entity, animDict, animName, blendIn, blendOut, duration, flag, playbackRate, onComplete)
|
||||
local newId = id or Ids.CreateUniqueId(Anim.Active)
|
||||
local newId = id or Ids.CreateUniqueId(Anim.Active)
|
||||
if Anim.Active[newId] then
|
||||
if onComplete then
|
||||
onComplete(false, "id_in_use")
|
||||
@@ -111,7 +105,7 @@ function Anim.Play(id, entity, animDict, animName, blendIn, blendOut, duration,
|
||||
if onComplete then
|
||||
onComplete(false, "dict_load_failed")
|
||||
end
|
||||
return nil
|
||||
return nil
|
||||
end
|
||||
|
||||
Anim.Active[newId] = {
|
||||
@@ -124,7 +118,7 @@ function Anim.Play(id, entity, animDict, animName, blendIn, blendOut, duration,
|
||||
flag = flag or 1,
|
||||
playbackRate = playbackRate or 0.0,
|
||||
onComplete = onComplete,
|
||||
status = "pending_task",
|
||||
status = "pending_task",
|
||||
startTime = 0,
|
||||
animEndTime = 0
|
||||
}
|
||||
@@ -139,7 +133,7 @@ function Anim.Stop(id)
|
||||
end
|
||||
|
||||
local animData = Anim.Active[id]
|
||||
|
||||
|
||||
if animData.entity and DoesEntityExist(animData.entity) and IsEntityAPed(animData.entity) then
|
||||
if animData.status == "playing" or animData.status == "pending_task" then
|
||||
StopAnimTask(animData.entity, animData.animDict, animData.animName, 1.0)
|
||||
@@ -150,7 +144,7 @@ function Anim.Stop(id)
|
||||
animData.onComplete(false, "stopped_by_id")
|
||||
end
|
||||
|
||||
Anim.Active[id] = nil
|
||||
Anim.Active[id] = nil
|
||||
local anyLeft = Anim.Active and next(Anim.Active) ~= nil
|
||||
if not anyLeft then
|
||||
Anim.isUpdateLoopRunning = false
|
||||
|
||||
@@ -13,7 +13,7 @@ local function SpawnEntity(entityData)
|
||||
-- print(string.format("SpawnEntity %s: %s", k, v))
|
||||
-- end
|
||||
local model = entityData.model and type(entityData.model) == 'string' and GetHashKey(entityData.model) or entityData.model
|
||||
if not Utility.LoadModel(model) then
|
||||
if model and not Utility.LoadModel(model) then
|
||||
print(string.format("[ClientEntity] Failed to load model %s for entity %s", entityData.model, entityData.id))
|
||||
return
|
||||
end
|
||||
@@ -30,23 +30,20 @@ local function SpawnEntity(entityData)
|
||||
-- Apply ped specific settings from entityData.meta if needed
|
||||
elseif entityData.entityType == 'vehicle' then
|
||||
entity = CreateVehicle(model, coords.x, coords.y, coords.z, type(rotation) == 'number' and rotation or rotation.z, false, false)
|
||||
-- Apply vehicle specific settings from entityData.meta if needed
|
||||
else
|
||||
print(string.format("[ClientEntity] Unknown entity type '%s' for entity %s", entityData.entityType, entityData.id))
|
||||
end
|
||||
if entity then
|
||||
-- print(string.format("[ClientEntity] Spawned %s entity %s (GameID: %s)", entityData.entityType, entityData.id, entity))
|
||||
if entity and model then
|
||||
entityData.spawned = entity
|
||||
SetModelAsNoLongerNeeded(model)
|
||||
SetEntityAsMissionEntity(entity, true, true) -- Keep entity from being deleted by game engine
|
||||
FreezeEntityPosition(entity, true) -- Optional freeze based on meta
|
||||
if entityData.OnSpawn then
|
||||
entityData.OnSpawn(entityData)
|
||||
end
|
||||
-- print(string.format("[ClientEntity] Spawned %s entity %s (GameID: %s)", entityData.entityType, entityData.id, entity))
|
||||
SetEntityAsMissionEntity(entity, true, true)
|
||||
FreezeEntityPosition(entity, true)
|
||||
else
|
||||
SetModelAsNoLongerNeeded(model)
|
||||
end
|
||||
if entityData.OnSpawn then
|
||||
entityData.OnSpawn(entityData)
|
||||
end
|
||||
end
|
||||
|
||||
local function RemoveEntity(entityData)
|
||||
@@ -83,8 +80,8 @@ function ClientEntity.Unregister(id)
|
||||
local entityData = Entities[id]
|
||||
if not entityData then return end
|
||||
|
||||
Point.Remove(id)
|
||||
RemoveEntity(entityData)
|
||||
Point.Remove(id)
|
||||
RemoveEntity(entityData)
|
||||
Entities[id] = nil
|
||||
end
|
||||
|
||||
@@ -193,7 +190,7 @@ end)
|
||||
RegisterNetEvent("community_bridge:client:TriggerEntityActions", function(entityId, actions, endPosition)
|
||||
local entityData = Entities[entityId]
|
||||
if entityData then
|
||||
for _, actionData in pairs(actions) do
|
||||
for _, actionData in pairs(actions) do
|
||||
local actionName = actionData.name
|
||||
local actionParams = actionData.params
|
||||
if actionName == "Stop" then
|
||||
|
||||
Reference in new issue
Block a user