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 the most generalized hitscan function in ZScript; most other functions (such as A_FireBullets, A_CustomBulletAttack, A_Saw and others) usually function as wrappers for it.

In contrast to more specific functions, like A_FireBullets, this doesn't imply ammo consumptions or randomized offsets, and comes with its own set of behaviors.

Parameters

  • double angle
The absolute angle of the attack.
  • double distance
The maximum distance at which the attack successfully hits.
For reference, normally player hitscan attacks would use PLAYERMISSILERANGE which is equal to 8192, while monster attacks would use MISSILERANGE, which is 2048. However, any value is valid. Very short distances can be used to make a melee attack.
  • pitch
The absolute pitch of the attack.
  • int damage
The damage to be dealt by the attack. If randomization is desired, it has to be added manually.
  • 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 to 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_ABSOFFSET — the forward/side offset parameters will not be rotated by the angle value, instead aligning to the global X/Y axes (they will still be offsets from the actor's position, however).
  • LAF_ABSPOSITION — the offset parameters will be treated like global map position, not relative to the actor's current position. (Clarificaton needed: Does this imply LAF_ABSOFFSET?)
  • 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, additional data can be read from it.

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

See Also