GetCurrentAmmo
Jump to navigation
Jump to search
Ammo, Ammo, int, int GetCurrentAmmo()
Usage
Can be used in a ZScript HUD to obtain information about ammo used by the weapon currently selected by the player.
Return values
The function returns two Ammo
pointers and two integer values. Note, the ammo pointers are pointers to instances of those ammo classes in the user's inventory, not class names. Normally it can only be null if the weapon doesn't use ammo at all, since weapons will give the player an instance of the ammo they use (even if Weapon.AmmoGive
is set to 0);
- Ammo
- A pointer to an instance of primary ammo (as defined by the Weapon.AmmoType1 property) in the user's inventory.
- Ammo
- A pointer to an instance of primary ammo (as defined by the Weapon.AmmoType2 property) in the user's inventory.
- int
- The amount of primary ammo currently in the user's inventory.
- int
- The amount of primary ammo currently in the user's inventory.
Examples
This will draw primary and secondary ammo icons at the bottom right corner of the screen, and the amount of ammo will be printed next to them. There will be 1 pixel of padding between the icons and the text.
Ammo am1, am2;
int am1amt, am2amt;
[am1, am2, am1amt, am2amt] = GetCurrentAmmo();
vector2 iconSize = (10, 10); //the icon's size is limited to this
vector2 iconPos = (-24, -8); //starting position of the first icon
if (am1)
{
DrawInventoryIcon(am1, iconPos, DI_SCREEN_RIGHT_BOTTOM|DI_ITEM_CENTER, boxSize: iconSize);
DrawString(numHUDFont, ""..am1amt, (iconPos.x + iconSize.x * 0.5 + 1, iconPos.y), DI_SCREEN_RIGHT_BOTTOM|DI_TEXT_ALIGN_LEFT);
}
if (am2)
{
iconPos -= (0, iconSize.y + 1);
DrawInventoryIcon(am2, iconPos, DI_SCREEN_RIGHT_BOTTOM|DI_ITEM_CENTER, boxSize: iconSize);
DrawString(numHUDFont, ""..am2amt, (iconPos.x + iconSize.x * 0.5 + 1, iconPos.y), DI_SCREEN_RIGHT_BOTTOM|DI_TEXT_ALIGN_LEFT);
}