Projectile Trap

From ZDoom Wiki

Jump to: navigation, search

Description

Add this to your DECORATE lump, and this will add a new thing that fires projectiles in the direction of the thing. It has 3 modes. It works using Thing Arguments.

  • Arg0(Mode) - Determines the mode this thing is in. There are 3.
    • 1 - Fires a continuous stream of projectiles, non-stop.
    • 2 - Does the same, but will only fire when it can see a hostile target
    • 3 - Same as 2, but unlike the other modes, this one turns and fires directly at it's target.
    • Anything else defaults to 1. This includes 0.
  • Arg1(Type) - The SpawnID of the projectile. Note that it doesn't actually need to be a projectile. Could be useful as an ammo generator. Might spawn too much though.
  • Arg2(Pitch) - The pitch for the projectile to fire at. 90 = Parallel with the ground.
  • Arg3(FOV) - Used for determining whether to fire in modes 2 and 3. It's the trap's feild of view.
  • Arg4(Dist) - The maximum distance the trap can see. This is multiplied by 8, and 0 means unlimited. This is only useful for modes 2 and 3.

To use it in your map:

  • Add the defintion to the DECORATE lump
  • Add a thing of type 20005 to the map. You can change this if it gets in the way.
  • Give it the correct facing and ZHeight, and set the arguments.

Other tips:

  • You can change how fast it fires by editing the first State definition duration. On the line TNT1 A 5 A_LookEx... change the number. Higher numbers result in slower fire. DO NOT SET TO ZERO. This is the number of frames the delay lasts. 35 frames = 1 second. By default it fires at a rate of 5, or 7 rounds per second.
  • You can disable it by setting the dormant flag and unsetting with a script.
  • Set the friendly flag for modes 2 and 3 to make it only react to enemies.


Note: There is a major bug with this code. The SpawnID selection does not work. You will have to manually set the strings.

The Definition

 //Projectile Trap
 //Created by NerdBoy1392
 //You can use this and modify it as long as you leave these comments.
 
 ACTOR TrapProjectileLauncher 20005
 {
   +NOBLOCKMAP
   +NOGRAVITY
   -SHOOTABLE
   states
   {
     Spawn:
       TNT1 A 0 A_LookEx (LOF_NOSOUNDCHECK, 0, args[4]*8, 0, 0, "SpawnSkip")
     SpawnSkip:
       TNT1 A 5
       TNT1 A 0 A_JumpIf (args[0]==1,3)
       TNT1 A 0 A_JumpIf (args[0]==2,4)
       TNT1 A 0 A_JumpIf (args[0]==3,7)
       
       //First Function: Always Shoot
       TNT1 A 0 A_CustomMissile ( "PlasmaBall", 0, 0, 0, 2, args[2]-90)
       //The first arg on these is supposed to say: args[1], but it doesn't accept spawn numbers.
       TNT1 A 0
       goto Spawn
       
       //Second Function: Shoot when in sight
       TNT1 A 0 A_JumpIfTargetInLOS (2,args[3]*256)
       TNT1 A 0 A_Jump (256,2)
       TNT1 A 0 A_CustomMissile ("PlasmaBall", 0, 0, 0, 2, args[2]-90)
       TNT1 A 0
       goto Spawn
       
       //Third Function: Same as second, but can turn.
       TNT1 A 0 A_FaceTarget
       TNT1 A 0 A_JumpIfTargetInLOS (2,args[3]*256)
       TNT1 A 0 A_Jump (256,2)
       TNT1 A 0 A_CustomMissile ( "PlasmaBall", 0, 0, 0, 2, args[2]-90)
       TNT1 A 0
       goto Spawn
    }
 }
Personal tools