I'm trying to read the inventory of a turret when it kills a unit, but am gettign an error when the turret does not have any inventory to check.
Not sure what to add to my code to precent this.
The error line is:
Code: Select all
local inventoryContent = inventory.get_contents()
Code: Select all
local function On_Death(event)
local entity = event.entity
if event.force ~= nil and entity.force.name == "enemy" and entity.type == "unit" and event.cause then
local name = entity.name
local inventory = event.cause.get_inventory(1)
local inventoryContent = inventory.get_contents() -- <-- Line causign issue
local AmmoType
local Ammo = 0
if inventoryContent ~= nil then
for n,a in pairs(inventoryContent) do
AmmoType=n
Ammo=a
end
end
writeDebug("Ammo Type: " .. AmmoType) -- disply Ammo Type
writeDebug("Ammo Count: " .. Ammo) -- disply Ammo Count
if AmmoType == "basic-dart-magazine_c" or AmmoType == "enhanced-dart-magazine_c" then
-- do something
end
end
end

Thanks.