AimTarget

From ZDoom Wiki
Jump to navigation Jump to search

Actor AimTarget ()

Usage

Fires a hitscan at the direction the caller is facing to find another actor. This function is also used by A_Mushroom and A_JumpIfCloser.

Return value

Returns a pointer to the actor that was found by the hitscan, if no actor was found, then no pointer will be returned.

Examples

This Pistol-derived class has a special alt fire, that prints out the class name of the of the actor in front of the player to the console, if any.

class ScannerPistol : Pistol
{
	Actor FoundActor; // Pointer to the actor that was found.
	States
	{
	AltFire:
		PISG A 16
		{
			invoker.FoundActor = AimTarget(); // Set the actor found by AimTarget() as the FoundActor.
			
			if (invoker.FoundActor)
			{
				A_StartSound ("Misc/Chat",CHAN_WEAPON,CHANF_OVERLAP);
				Console.Printf ("There is a %s in front of you.", invoker.FoundActor.GetClassName());
				invoker.FoundActor = null; // Remove pointer for the next AltFire.
			}
			else
			{
				A_StartSound ("Misc/Chat",CHAN_WEAPON,CHANF_OVERLAP);
				Console.Printf ("No actor was found!");
			}
		}
		Goto Ready;
	}
}