I'm afraid we don't have a property for getting the "ammo" of an NPC.
Simply because the NPC can have many weapons, many ammo, so there is not just one count.
If you know the ammo itemDefinition, you can get how many ammo the NPC has in his inventory. But it won't tell you how much is already loaded in the weapon clip.
You'll need a reference to the npc inventory and the ammo item definition
Code:
int ammoCount = inventory.GetItemAmount(ammoDefinition);
if you want to know the ammoCount in the weapon clip, it's a bit more complicated because you need to get a reference to the weapon of the NPC
Here is a snippet of code from the WeaponAmmoItemViewModule.cs script to give you an idea of how to grab the "clip reamining", "clip size" and "unloaded ammo" counts
Code:
var characterItem = inventoryBridge.GetCharacterItem(info.Item);
if (characterItem == null) {
UseAmmoAttribute(info);
return;
}
// Multiple item actions can be attached to the same item.
var foundShootableWeapon = false;
for (int i = 0; i < characterItem.ItemActions.Length; ++i) {
var shootableWeapon = characterItem.ItemActions[i] as ShootableAction;
if (shootableWeapon == null) { continue; }
var consumableItemIdentifierAmount = shootableWeapon.ClipRemainingCount;
// If the count is -1 then only the loaded should be shown.
if (consumableItemIdentifierAmount == -1) {
Clear();
return;
}
foundShootableWeapon = true;
if (m_AmmoItemImage != null) {
var itemAmmoModule = shootableWeapon.MainAmmoModule;
var ammoItem = itemAmmoModule?.AmmoItemDefinition as ItemDefinition;
if (ammoItem != null && ammoItem.TryGetAttributeValue("Icon", out Sprite icon)) {
m_AmmoItemImage.sprite = icon;
} else {
m_AmmoItemImage.sprite = null;
}
}
m_LoadedCount.text = shootableWeapon.ClipRemainingCount.ToString();
m_ClipSize.text = shootableWeapon.ClipSize.ToString();
m_UnloadedCount.text = shootableWeapon.MainAmmoModule?.GetAmmoRemainingCount().ToString();
break;
}