2025-09-03 00:28:17 -05:00
|
|
|
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
|
2025-09-03 04:06:31 -05:00
|
|
|
Bridge.Entity.Set(entityData.id, "oldWeapon", entityData.oldWeapon)
|
2025-09-03 00:28:17 -05:00
|
|
|
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
|
2025-09-03 04:06:31 -05:00
|
|
|
Bridge.Entity.Set(entityData.id, "weapon", entityData.weapon)
|
2025-09-03 00:28:17 -05:00
|
|
|
end
|
|
|
|
|
end)
|
2025-09-03 04:06:31 -05:00
|
|
|
Bridge.Entity.Set(entityData.id, "weapon", entityData.weapon)
|
2025-09-03 00:28:17 -05:00
|
|
|
end
|
|
|
|
|
|
2025-09-03 04:06:31 -05:00
|
|
|
Bridge.Entity.RegisterBehavior("weapon", Weapon)
|
2025-09-03 00:28:17 -05:00
|
|
|
return Weapon
|