Hi Modders and Developers,
I tried to use the global variable WeaponTypes to determine the type of a Turret Weapon. The only clue is weapon.prefix. But unfortunately the 'id' in the WeaponTypes and the prefix on a weapon do not match.
Here is a sample code:
the basics:
local ctTurret, ctWeapon
function GetInventorySelect()
ctTurret = customInventory.inventory.input.selected.item --works perfect
end
function GetWeaponType()
local weapons = {ctTurret:getWeapons()}
if not ctWeapon then
for _, weapon in pairs(weapons) do
ctWeapon = weapon
end
end
for prefix, id in pairs(WeaponTypes) do
if prefix == ctWeapon.prefix then
return id
end
end
return nil
end
in WeaponTypes we have (weapontypes.lua):
WeaponTypes["ChainGun"] = 0
But at the Turret Weapon we have (weapongenerator.lua):
weapon.prefix = "Chaingun /* Weapon Prefix*/"%_t
So when I try to get the correct weapon type of the selected inventory turret I get the translated prefix which I can't match with the WeaponTypes.
Are the ID's in weapontypes.lua something else or is there another way to determine the type of a weapon in the inventory?