How to give hitscan weapons custom dynamic lights

Handy guides on how to do things, written by users for users.

Moderators: GZDoom Developers, Raze Developers

Forum rules
Please don't start threads here asking for help. This forum is not for requesting guides, only for posting them. If you need help, the Editing forum is for you.

How to give hitscan weapons custom dynamic lights

Postby Nevander » Wed Apr 27, 2016 10:09 pm

So, you want to add dynamic lights to a hitscan weapon? There is a fairly simple method to accomplish this and it's the only one I believe would work across all possible situations.

The way dynamic lights are added to the Pistol, Shotgun, Super Shotgun, and Chaingun in unmodified GZDoom without running any additional mods is by attaching a dynamic light to the player during the PLAYF frame set, which will work because it's just a sprite frame in the world that works like a projectile, attach a light to it, it will work. This method will still work, however only if all your weapons have the same color weapon flash.

It would be strange seeing a yellow flash come from a weapon that fires a blue flash, like a plasma shotgun or something. You can actually observe this behavior in unmodified GZDoom by firing the BFG and you will notice a yellow flash right before the green light comes in from the BFGBall projectile.

This doesn't happen on the Plasma Rifle, Fist, or Chainsaw because the PLAYF frames aren't called during the player animation (from third person or chasecam). I believe this is something defined in the game's source code, because it's not defined in any DECORATE definitions for those three weapons to NOT call that frame.

You can observe all of the light behavior by going into chasecam in GZDoom and firing all the weapons. You will notice the weapons that have a light attached to the player sprite itself are the ones that call the PLAYF frames.

So, enough explaining, let's get onto the tutorial.

The method I would advise using to attach a dynamic light to a weapon that uses a hitscan attack would be to modify the actor's DECORATE definition to fire a dummy projectile, and attach the dynamic light to that. Attaching a light to the first person sprite frame will NOT work. The light will not appear in-game when fired. Why this doesn't work, I'm not sure, but I'm assuming it has something to do with the fact that first person sprites are rendered on screen from the first person perspective and the game wouldn't know how to attach a light to the first person view, since dynamic lights work through being spawned in the world.

So let's start off by writing the dummy projectile definition in DECORATE:

Code: Select allExpand view
ACTOR DummyProjectile1
{
   Radius 0
   Height 0
   Speed 0
   Damage 0
   Projectile
   SeeSound "Null"
   DeathSound "Null"
   +THRUACTORS
   +NONSHOOTABLE
   +NOGRAVITY
   
   States
   {
      Spawn:
         TNT1 A 4
      Death:
         TNT1 A 0
         Stop
   }
}


As you can see, this projectile is set up to be invisible, automatically dies, causes no damage, no speed, no gravity, goes through actors, no sound, etc. You get the idea. You can adjust the tics on the spawn and death frames if you'd like, I've found having 4 or 5 tics on the spawn state and none on death seems to work best (closest to standard PLAYF lights).

If you want more dummy projectiles (to attach different colored lights, since you can't attach two different lights to the same projectile and have it be used for multiple weapons), simply inherit from the first dummy projectile like so:

Code: Select allExpand view
ACTOR DummyProjectile2 : DummyProjectile1 {}
ACTOR DummyProjectile3 : DummyProjectile1 {}
ACTOR DummyProjectile4 : DummyProjectile1 {}


Now we want to create our light definitions in GLDEFS:

Code: Select allExpand view
flickerlight2 HITSCAN_X1
{
   color 0.9 0.8 0.4
   size 64
   secondarySize 80
   interval 1
   offset 0 40 0
}
flickerlight2 HITSCAN_X2
{
   color 0.3 0.1 0.8
   size 64
   secondarySize 80
   interval 1
   offset 0 40 0
}
flickerlight2 HITSCAN_X3
{
   color 0.0 1.0 0.0
   size 80
   secondarySize 96
   interval 1
   offset 0 40 0
}


As you can see, we have three hitscan lights set up. One is a yellow-ish flash much like you'd expect out of the normal GLDEFS, the second one is a purple-blue flash, and the last is a green flash.

Now we will attach the lights to the objects in question like so:

Code: Select allExpand view
object DummyProjectile1
{
   frame TNT1A { light HITSCAN_X1 }
}
object DummyProjectile2
{
   frame TNT1A { light HITSCAN_X2 }
}
object DummyProjectile3
{
   frame TNT1A { light HITSCAN_X3 }
}


So now the dummy projectiles are set up and so are the lights for them. The last step is to attach them to our weapon actors at the right places:

Code: Select allExpand view
States
   {
      Fire:
         CHGG A 0 A_GunFlash
         CHGG A 0 A_FireCustomMissile("DummyProjectile2", 0, 0, 0, 0, 0, 0)
         CHGG A 0 A_FireBullets(5.6, 0, 1, 5, "BulletPuff")
         CHGG A 1 A_PlaySound("weapons/chngun", CHAN_WEAPON, 1, 0, ATTN_NORM)
         CHGG B 1
         CHGG C 1
         CHGG D 1
         CHGG A 0 A_GunFlash
         CHGG A 0 A_FireCustomMissile("DummyProjectile2", 0, 0, 0, 0, 0, 0)
         CHGG A 0 A_FireBullets(5.6, 0, 1, 5, "BulletPuff")
         CHGG A 1 A_PlaySound("weapons/chngun", CHAN_WEAPON, 1, 0, ATTN_NORM)
         CHGG B 1
         CHGG C 1
         CHGG D 1
         CHGG C 0 A_ReFire
         Goto Ready
      Flash:
         CHGF A 1 BRIGHT A_Light2
         CHGF C 1 BRIGHT A_Light2
         Goto LightDone
   }


In the above example, this weapon is set up to fire the purple-blue flash at the same time as the weapon itself fires. The PLAYF frame will still play but the light attached will now match the muzzleflash of the weapon being fired.

You can also redefine the lights for the enemies too if you'd want them to match like so:

Code: Select allExpand view
object ZombieMan
{
   frame POSSF { light HITSCAN_X1 }
}
object ShotgunGuy
{
   frame SPOSF { light HITSCAN_X1 }
}
object 64ChaingunGuy
{
   frame CPOSE { light HITSCAN_X2 }
   frame CPOSF { light HITSCAN_X2 }
}


I've used this method so far without issue, if someone can suggest areas for improvement it would be much appreciated, and please tell me if I made any mistakes.
Last edited by Nevander on Sun Feb 05, 2017 12:21 am, edited 1 time in total.
Nevander
Self-Banned User
 
Joined: 07 Jan 2014

Re: How to give hitscan weapons custom dynamic lights

Postby YukiHerz » Thu Apr 28, 2016 11:45 am

This will come in handy!
User avatar
YukiHerz
Expensive pasta dude
 
Joined: 03 Dec 2013
Location: Where corruption is redefined daily.
Operating System: Windows 10/8.1/8/201x 64-bit
Graphics Processor: Intel (Legacy GZDoom)

Re: How to give hitscan weapons custom dynamic lights

Postby Lagi » Sat Jan 18, 2020 8:30 am

thank You for that,
this help me with weapon lights. I set the TNT tic to 30 to receive the constant light on weapons, instead epilepsy flickering.
User avatar
Lagi
 
Joined: 23 Jun 2018
Location: Thou shalt alter thy beliefs with new evidence

Re: How to give hitscan weapons custom dynamic lights

Postby Graf Zahl » Mon Jan 20, 2020 3:18 am

I wanted to suggest A_AttachLight but apparently new features don't make it to the Wiki anymore without taking care of it myself... :?
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
 
Joined: 19 Jul 2003
Location: Germany

Re: How to give hitscan weapons custom dynamic lights

Postby Lagi » Mon Jan 20, 2020 12:39 pm

A_AttachLight - is not recognize by slade
where can I found about this function?
User avatar
Lagi
 
Joined: 23 Jun 2018
Location: Thou shalt alter thy beliefs with new evidence

Re: How to give hitscan weapons custom dynamic lights

Postby Dylan Simpson » Thu Jan 23, 2020 6:14 am

Awesome, that's what I was looking for
User avatar
Dylan Simpson
 
Joined: 30 Dec 2019

Re: How to give hitscan weapons custom dynamic lights

Postby SanyaWaffles » Thu Jan 23, 2020 7:44 pm

Graf Zahl wrote:I wanted to suggest A_AttachLight but apparently new features don't make it to the Wiki anymore without taking care of it myself... :?


Say no more chief. I haven't figured out an example for A_AttachLight as it seems more involved but I was able to figure out A_AttachLightDef rather easily.

https://zdoom.org/wiki/A_AttachLightDef

I worked up a code snipplet for A_AttachLightDef. I figure A_AttachLight works the same except you can define more specific lights without using GLDEFS... but it requires a bit more work. I'll have to look into what each parameter does.
User avatar
SanyaWaffles
Wouldn't be an epic gamer if I didn't commit a few war crimes.
 
Joined: 25 Apr 2013
Location: Eastern Ohio
Discord: SanyaWaffles#5095
Twitch ID: sanyawaffles
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support

Re: How to give hitscan weapons custom dynamic lights

Postby Redneckerz » Fri Jan 24, 2020 2:10 am

Graf Zahl wrote:I wanted to suggest A_AttachLight but apparently new features don't make it to the Wiki anymore without taking care of it myself... :?

Certain parts are embarrasingly out of date. Yesterday i removed the reference as to who the idgames maintainers are, as it still mentioned Ty Halderman.

Ty has passed away for 4.5 years now.
User avatar
Redneckerz
To it's ports i may have seen
Spotlight Team
 
Joined: 25 Nov 2019
Discord: Redneckerz#8399
Operating System: Windows Vista/7/2008 64-bit
Graphics Processor: nVidia (Legacy GZDoom)


Return to Tutorials

Who is online

Users browsing this forum: No registered users and 1 guest