LineAttack (ZScript)

From ZDoom Wiki
Jump to navigation Jump to search

Actor

native Actor, int LineAttack(double angle, double distance, double pitch, int damage, Name damageType, class<Actor> pufftype, int flags = 0, out FTranslatedLineTarget victim = null, double offsetz = 0., double offsetforward = 0., double offsetside = 0.)

Usage

Fires a hitscan attack, originating from the calling actor. This a more generalized function than A_FireBullets or similar; it doesn't imply ammo consumptions, randomized offsets, and comes with its own set of behaviors.

Parameters

  • double angle
The angle offset at which the attack should be fired relative to the calling actor's current angle.
  • double distance
The maximum distance at which the attack successfully hits.
For reference, normally player hitscan attacks would use PLAYERMISSILERANGE which is equal to 4096, while monster attacks would use 2048. However, any value is valid. Very short distances can be used to make a melee attack.
  • pitch
The pitch by which the attack should be fired relative to the calling actor's current pitch.
  • int damage
The damage to be dealt by the attack.
  • Name damageType
The damage type of the attack.
For reference hitscans usually use 'Hitscan', other attacks normally use 'Normal'. Any value can be passed here, however.
  • class<Actor> pufftype
The puff actor class to spawn. If this is null it defaults BulletPuff.
  • int flags
Multiple flags can be combined with |. The following flags are available:
  • LAF_ISMELEEATTACK — enables, but does not force, the puff to enter its Melee state if it has it.
  • LAF_NORANDOMPUFFZ — disables the random z offset given to the puff when spawned.
  • LAF_NOIMPACTDECAL — disables the generation of decals as a result of the attack.
  • LAF_NOINTERACT — guarantees puff spawning and returns it directly to the calling function. Damage is not inflicted, sounds are not played, and blood splatters are not spawned.
  • LAF_TARGETISSOURCE — the calling actor's target is considered the source of the damage, otherwise it is the calling actor itself.
  • LAF_OVERRIDEZ — disregards the default calculations for the height at which the attack is fired, and instead fires it from the base of the actor, only taking offsetz into account.
  • LAF_ABSOFFSETangle is used as an absolute angle instead of a relative one to the calling actor's angle.
  • LAF_ABSPOSITION — the offset parameters below are treated as absolute coordinates.
  • FTranslatedLineTarget victim
Allows outputting the data from the function to a previously declared FTranslatedLineTarget struct.
  • double offsetz
Shifts the spawn point of the attack upwards and downwards. Positive values shift it upwards, while negative values shift it downwards.
  • double offsetforward
Shifts the spawn point of the attack forwards and backwards. Positive values shift it forwards, while negative values shift it backwards.
  • double offsetside
Shifts the spawn point of the attack to either sides. Positive values shift it to the right side, while negative values shift it to the left side.

Return value

The function has 2 return values:

  • Actor - a pointer to the spawned puff
  • int - the amount of inflicted damage the hit actor may had sustained

If a FTranslatedLineTarget struct was passed to the victim argument, the following values can be read from it:

  • Actor linetarget - The actor that was hit by the attack if any. Otherwise null.
  • double angleFromSource - The angle of the target from the caller.
  • double attackAngleFromSource - The angle of the target from the position where it was hit.
  • bool unlinked - Found by a trace that went through an unlinked portal.
  • native void TraceBleed (int damage, Actor missile)

Examples

This fist uses a stripped-down version of A_Punch to highlight the function's use.

class NewFist : Fist
{
    Default
    {
        Weapon.SlotNumber 1;
    }

    States
    {
    Fire:
        PUNG B 4;
        PUNG C 4
        {
            FTranslatedLineTarget t;
            double ang = angle + Random2() * (5.625 / 256);
            double pitch = AimLineAttack(ang, 64, null, 0., ALF_CHECK3D);
            LineAttack(ang, 64, pitch, 100, 'Melee', "BulletPuff", LAF_ISMELEEATTACK, t);

            // Turn to face the hit actor.
            if (t.linetarget)
            {
                angle = t.angleFromSource;
            }
        }
        PUNG D 5;
        PUNG C 4;
        PUNG B 5 A_ReFire;
        Goto Ready;
    }
}