* Makes calls for GetAmmo() and GetVec3() safer with pcall()

* Small docu fix Ben-Gurion
This commit is contained in:
Applevangelist
2023-06-13 08:39:56 +02:00
parent 12f260e857
commit 241b2beee1
3 changed files with 24 additions and 16 deletions

View File

@@ -698,20 +698,27 @@ end
--- Returns the Unit's ammunition.
-- @param #UNIT self
-- @return DCS#Unit.Ammo Table with ammuntion of the unit (or nil). This can be a complex table!
-- @return DCS#Unit.Ammo Table with ammuntion of the unit (or nil). This can be a complex table!
function UNIT:GetAmmo()
self:F2( self.UnitName )
local DCSUnit = self:GetDCSObject()
if DCSUnit then
local UnitAmmo = DCSUnit:getAmmo()
return UnitAmmo
local status, unitammo = pcall(
function()
local UnitAmmo = DCSUnit:getAmmo()
return UnitAmmo
end
)
if status then
return unitammo
end
--local UnitAmmo = DCSUnit:getAmmo()
--return UnitAmmo
end
return nil
end
--- Sets the Unit's Internal Cargo Mass, in kg
-- @param #UNIT self
-- @param #number mass to set cargo to