AimTarget

From ZDoom Wiki
Jump to navigation Jump to search

Actor

Actor AimTarget ()

Usage

Finds another actor in the direction the calling actor is facing. This function is also used by A_Mushroom and A_JumpIfCloser.

Return value

  • Actor — a pointer to the actor that was found by the function; if nothing was found, returns null.

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;
	}
}

ZScript definition

Note: The ZScript definition below is for reference and may be different in the current version of GZDoom.The most up-to-date version of this code can be found on GZDoom GitHub.
	Actor AimTarget()
	{
		FTranslatedLineTarget t;
		BulletSlope(t, ALF_PORTALRESTRICT);
		return t.linetarget;
	}

See also