SetPointer

From ZDoom Wiki
Jump to navigation Jump to search

bool SetPointer(int assign_slot, int tid[, int pointer_selector[, int flags]])

Usage

Set the value of one of the activator's stored actor pointers.

Note: The function tests for circular reference on master and target fields, setting them to NULL if one is found. That test does not occur when assigning to the tracer field. Any attempt to make the actor point directly to itself will also result in a NULL assignment.

Parameters

  • int assign_slot: an actor pointer selector. Must refer to an assignable pointer type (target, master, tracer).
  • int tid: TID of the actor to be stored in the selected slot. 0 selects the activator, but the caller can only be an intermediate selection.
  • int pointer_selector: if this is specified, the actor specified by TID is used as an intermediate actor. The final value is determined by selecting any available actor pointer from the intermediate actor.
  • int flags:
    • PTROP_UNSAFETARGET: don't nullify assignments that result in an infinite chain of missiles referencing each other.
    • PTROP_UNSAFEMASTER: don't nullify assignments that result in an infinite chain of actors referencing each other.

Return value

  • TRUE (1) if a non-NULL assignment was made (a suitable actor was found and stored).
  • FALSE (0) if there is no activator, or if a NULL assignment was made. This function assigns data to the activator, and cannot operate without one.

Examples

This script will cause any monster with provided TID to attack the calling player's current target. It could be used for summoned minions and the script could be activated via a hot-key.

Script "AttackTarget" (int TID) NET
{
 int oldTID, target;
 if(SetActivator(0,AAPTR_PLAYER_GETTARGET)) // Get the target of the activator. If it fails because there is none nothing will happen.
{ 
  oldTID = ActivatorTID(); // Save the TID of the target.
  target = UniqueTID(); // Get a new unique TID for the target actor.
  Thing_ChangeTID(0, target); // Set that TID to the actor.
  SetActivator(TID); // Set the activator to the actor with the given TID.
  SetPointer(AAPTR_TARGET, target); // Give a new target to it.
  Thing_ChangeTID(target,oldTID); // Restore the previous TID, because it might be used already by other scripts.
}

See also