Add modular entity behaviors and update entity logic
Introduces modular behaviors for entities, including anim, attach, clothing, follow, particles, scenarios, shop, stash, targets, and weapon, each in their own files. Updates client_entity.lua and behaviors.lua to support dynamic behavior registration, initialization, and triggering. Refactors entity update logic to improve movement handling and behavior invocation.
This commit is contained in:
1 parent
facffe26c5
commit
8346130b00
12 files changed
+693
-11
No files matched your search
@@ -0,0 +1,54 @@
|
||||
if IsDuplicityVersion() then return end
|
||||
local Weapon = {
|
||||
property = "weapon",
|
||||
default = {
|
||||
name = "WEAPON_UNARMED",
|
||||
ammo = 0
|
||||
}
|
||||
}
|
||||
|
||||
function Weapon.GiveWeapon(entityData)
|
||||
if entityData.entityType ~= "ped" then return end
|
||||
local entity = entityData.spawned
|
||||
|
||||
if not entity or not DoesEntityExist(entity) then return end
|
||||
if entityData.weapon?.name then
|
||||
local ammo = entityData.weapon.ammo or 0
|
||||
local hash = GetHashKey(entityData.weapon.name)
|
||||
GiveWeaponToPed(entity, hash, ammo, false, true)
|
||||
TaskSwapWeapon(entity, true)
|
||||
end
|
||||
entityData.oldWeapon = entityData.weapon
|
||||
Bridge.ClientEntity.Set(entityData.id, "oldWeapon", entityData.oldWeapon)
|
||||
end
|
||||
|
||||
function Weapon.OnSpawn(entityData)
|
||||
if not entityData.spawned or not entityData.weapon then return end
|
||||
Weapon.GiveWeapon(entityData)
|
||||
entityData.weapon.updating = false
|
||||
end
|
||||
|
||||
function Weapon.OnRemove(entityData)
|
||||
if not entityData.spawned or not entityData.weapon then return end
|
||||
entityData.oldWeapon = nil
|
||||
entityData.weapon.updating = true
|
||||
end
|
||||
|
||||
function Weapon.OnUpdate(entityData)
|
||||
if not entityData.spawned or not entityData.weapon then return end
|
||||
if entityData.weapon.updating then return end
|
||||
entityData.weapon.updating = true
|
||||
if not entityData.oldWeapon or entityData.oldWeapon.name ~= entityData.weapon.name then
|
||||
Weapon.GiveWeapon(entityData)
|
||||
end
|
||||
SetTimeout(1000, function()
|
||||
if entityData.weapon then
|
||||
entityData.weapon.updating = false
|
||||
Bridge.ClientEntity.Set(entityData.id, "weapon", entityData.weapon)
|
||||
end
|
||||
end)
|
||||
Bridge.ClientEntity.Set(entityData.id, "weapon", entityData.weapon)
|
||||
end
|
||||
|
||||
Bridge.ClientEntity.RegisterBehavior("weapon", Weapon)
|
||||
return Weapon
|
||||
Reference in new issue
Block a user