A_GiveToTarget

From ZDoom Wiki
Jump to navigation Jump to search

bool A_GiveToTarget (string type [, int amount [, pointer forward_ptr]])

Usage

Tries to add count items of type type to the calling actor's current target's inventory. This function will not add more items than can be carried. Note that when an actor dies its target is automatically set to the killer. Projectiles also target the actor which shot them when they are fired.

If type is an item derived from Health, then the amount received is the result of multiplying count by the item's amount, e.g. if type is Medikit and count is 2, then the amount of health received would be 50 points, not 2.

Parameters

  • type: the item to give. This should be a valid inventory item.
  • amount: the number of samples of this item to give. Default is 0, which is interpreted as 1.
  • forward_ptr: the actor to give the item to, with the calling actor's target being the context, here, as opposed to the caller itself. This is an actor pointer selector. Default is AAPTR_DEFAULT, which corresponds to the calling actor's target.

Return value

The function returns true if the item is successfully received, otherwise it returns false.

Examples

This function can be used to reward players with items for killing certain monsters.

Death:
  CYBR H 10 A_GiveToTarget("Credits", 1000)
  CYBR I 10 A_Scream
  CYBR JKL 10
  CYBR M 10 A_NoBlocking
  CYBR NO 10
  CYBR P 30
  CYBR P -1 A_BossDeath
  stop


If this imp dies, it gives a partial invisibility sphere to its target's (killer's) master.

ACTOR BlurSphereDoomImp : DoomImp
{
    States
    {
    Death:
        TROO A 0 A_GiveToTarget("BlurSphere", 1, AAPTR_MASTER)
        Goto Super::Death

    XDeath:
        TROO A 0 A_GiveToTarget("BlurSphere", 1, AAPTR_MASTER)
        Goto Super::XDeath
    }
}