SetAmmoCapacity (ACS)

From ZDoom Wiki
Jump to navigation Jump to search

void SetAmmoCapacity(str typename, int maxamount);

Usage

Sets the maximum amount of a type of ammo the player can carry. Any item from the list Ammo is accepted, as well as derived types from Ammo, while any other valid Inventory item will simply be silently ignored.

Examples

An example of backpacks that can be stacked, as in, each backpack increases the max ammo a little:

bool playerbackpack[8] = { FALSE };

script 1 (void)
{
	if (playerbackpack[PlayerNumber()])
	{
		if (GetAmmoCapacity("Clip") < 800)
		{
			SetAmmoCapacity("Clip", GetAmmoCapacity("Clip") + 100);
			SetAmmoCapacity("Shell", GetAmmoCapacity("Shell") + 25);
			SetAmmoCapacity("RocketAmmo", GetAmmoCapacity("RocketAmmo") + 25);
			SetAmmoCapacity("Cell", GetAmmoCapacity("Cell") + 75);
		}
	}
	else
		playerbackpack[PlayerNumber()] = TRUE;
}

script 998 ENTER
{
	if (GetAmmoCapacity("Clip") > 200)
		playerbackpack[PlayerNumber()] = TRUE;
}

script 999 RESPAWN
{
	playerbackpack[PlayerNumber()] = FALSE;
}

As the backpack will force a change in the amount of ammo the player has the first time it is picked up, this script records the whether each player has picked up a backpack already. There are eight potential players and by default each has their variable set to FALSE. There are two exceptions, which are handled by scripts 998 and 999. 998 checks if the player has a backpack when entering the level by testing their capacity for bullets. 999 resets the player's variable should they die and therefore lose the backpack.

The actual stacking script is number 1, and should be set as the thing special of every backpack. That is, the backpack should have special number 80 (ACS_Execute) with parameters (1, 0, 0, 0, 0). The script checks if the player has already picked up a backpack previously to this, and if so, starts incrementing each type of ammo a little. It does this by first checking if the ammo has reached the absolute maximum amount. If not, it adds a little bit on to each. Note that it only checks if “Clip” has reached the maximum amount, but as each value is incremented at the same time, they will all hit their limits at the same time as the “Clip” type. If the player hasn't picked up a backpack before, they have now, so their variable is set to TRUE.