SpawnPlayerMissile

From ZDoom Wiki
Jump to navigation Jump to search

Actor

native Actor, Actor SpawnPlayerMissile(class<Actor> type, double angle = 1e37, double x = 0, double y = 0, double z = 0, out FTranslatedLineTarget pLineTarget = null, bool nofreeaim = false, bool noautoaim = false, int aimflags = 0)

Usage

A generalized function for spawning projectiles that are meant to be fired by the player. For ease of access, it's defined in the Actor class and does not require casting the calling actor as PlayerPawn.

A_FireProjectile serves as a Weapon-specific wrapper for this function with added functionality, and thus it's recommended to use it in weapons instead. Using SpawnPlayerMissile is warranted for cases when the PlayerPawn must fire a projectile indirectly (for example, by using an inventory item).

Other than not being a Weapon function, SpawnPlayerMissile also doesn't imply any ammo consumption

Parameters

  • class<Actor> type
The projectile class to fire. Technically, can be any actor, but is meant to be used on projectiles.
  • double angle
The absolute (Verification needed) angle to fire the projectile at. The default value of 1e37 equals "use the calling actor's angle".
  • double x
Horizontal offset from the actor's vertical center to spawn the projectile at.
  • double y
Vertical offset from the projectile's vertical spawn to the projectile at.
  • double z
Vertical position to spawn the projectile at (the y argument is added on top). The default value of 0 spawns at the actor's attack height (for the PlayerPawn it's calculated from Height and Player.AttackZOffset.
  • out FTranslatedLineTarget pLineTarget
Can take a pointer to the previously defined FTranslatedLineTarget struct. The function will fill it with information, such as linetarget.
  • bool nofreeaim
(Need more info)
  • bool noautoaim
(Need more info)
  • int aimflags
A list of flags. Multiple flags can be combined with |.
  • ALF_FORCENOSMART — ignore sv_smartaim console variable (Verification needed)
  • ALF_CHECK3D(Need more info)
  • ALF_CHECKNONSHOOTABLE — don't ignore actors with the NONSHOOTABLE flag (Verification needed)
  • ALF_CHECKCONVERSATION(Need more info)
  • ALF_NOFRIENDS — ignore actors that are friendly to the caller (Verification needed)
  • ALF_PORTALRESTRICT — only work through portals with a global offset (to be used for stuff that cannot remember the calculated FTranslatedLineTarget info)
  • ALF_NOWEAPONCHECK — ignore Weapon.NOAUTOAIM flag on a player's weapon.
  • ALF_IGNORENOAUTOAIM — for informative stuff like 'linetarget' CCMD

Note that SpawnPlayerMissile doesn't define an argument for pitch. Instead the calling actor's pitch is used directly to determine at which pitch the projectile must be fired. Adding pitch to it requires modifying the actor's pitch field directly (this is how A_FireProjectile does it, for example — it modifies the PlayerPawn's pitch, fires the projectile, then restores the PlayerPawn's pitch).

Return values

Just like A_FireProjectile, this returns two Actor pointers, both pointing to the projectile that was fired. While they point to the same actor, they're created with different conditions:

  • The first pointer is only created if the projectile managed to enter its Spawn state sequence. If the projectile is fired an an enemy, object or a wall at a point-blank range, it'll instead immediately enter its Death (Crash, XDeath, etc.) state sequence, completely skipping Spawn, and this pointer will be null.
  • The second pointer is always created, regardless of the state sequence the projectile entered.

As such, if there's a need to modify some properties of the projectile, the second pointer should be used, because the first one is simply not guaranteed to exist. (The second pointer should still be null-checked for safety, but normally it will never be null).

Examples

This example is from Hexen's generic flechette: it fires a projectile defined in the actor's MissileType property:

	override bool Use (bool pickup)
	{
		Class<Actor> missiletype = MissileName;
		if (missiletype != null)
		{
			Actor mo = Owner.SpawnPlayerMissile(missiletype);
			if (mo != null)
			{
				// automatic handling of seeker missiles
				if (mo.bSeekerMissile)
				{
					mo.tracer = Owner.target;
				}
				return true;
			}
		}
		return false;
	}

See also