CountInv

From ZDoom Wiki
Jump to: navigation, search

int CountInv (string itemtype [, int ptr_select])

Usage

Returns the specified pointer's inventory item count for a specific item, like CheckInventory but for DECORATE.

Note that this function is to be used where an expression is expected. It is mostly useful when combined with A_JumpIf and can be used to replace A_JumpIfInventory.

Parameters

  • itemtype: the inventory item to count and return.
  • ptr_select: the pointer to examine. Default is AAPTR_DEFAULT, which points to the caller of the function. See actor pointers.

Return value

Returns the exact count of itemtype an actor has.

Examples

This monster strafes randomly left or right.

 <...>
 Strafe:
   TNT1 A 0 A_Jump( 128, "See" )                    // Chance to fail.
   TNT1 A 0 A_TakeInventory( "NmAngle", 0 )
   TNT1 A 0 A_TakeInventory( "NmForce", 0 )
   TNT1 A 0 A_GiveInventory( "NmAngle", RandomPick( 
                   80, 90, 100, 110, 120, 135,      // Left (in degrees).
                   225, 240, 250, 260, 270, 280     // Right (in degrees).
                   ) )
   NGHT A 8 A_GiveInventory( "NmForce", Random( 5, 10 ) )
   NGHT A 0 ThrustThing( ( Angle + CountInv( "NmAngle" ) ) * 256/360, CountInv( "NmForce" ) )
   NGHT A 0 ThrustThingZ( 0, Random( 40, 80 ), 0, 0 )
   Goto See