Right, so, I'm coming into this one fully expecting it to not be possible, but I figured I'd ask the powers that be if it's doable somehow.
So, in my mod, I have a few weapons that utilize what amount to zero-spread shotgun blasts (eg. TNT1 A 0 A_FireBullets(0, 0, 5, (random(5,6)), "RiflePuff")) to allow a hitscan attack to roughly replicate the behavior of a powerful rifle bullet than can overpenetrate a weak target, but consequently loses velocity and therefore damage. As you can tell, this shot is always perfectly accurate, all the time.
I want to see if there's any way to actually roll and pass along a predetermined pair of random float values to A_FireBullets specifically (or to have a customized version of the function, say "A_FireRifleBullets" or such, done up in ZScript which I can in turn run via DEC) to allow such a weapon to have some slight, believable inaccuracy but retain the damage/penetration characteristics-- I.E. multiple hitscans all inline, but not always exactly on the crosshair. I can't replicate this behavior exactly with the obvious answer, A_FireRailgun, even with their ripping capability limited by flags, as the damage call for each rail's identical, and even if I randomize the amount of targets a rail can rip, it still does identical damage to anything it hits rather than diminish as it passes through targets. Projectiles-- A_FireCustomMissile/A_FireProjectile aren't an option either, as, well, they're not hitscan.
Is this doable? The weapon's coded in DECORATE (as is the mod-- don't ask me to port the DEC code to ZScript, it ain't broke so I ain't fixin' it), but I figure this would need some named ACS call that I could pass the ranges to (to run and store the RNG values) or some other ZScript vodou like a customized form of A_FireBullets that I could run through the DEC code.
-Xterra
[SOLVED!] (DEC/ZSC/maybe ACS?) External trajectory randomization?
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.
Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.
Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
- Xterra
- Posts: 70
- Joined: Thu Feb 24, 2011 3:20 pm
- Preferred Pronouns: He/Him
- Operating System Version (Optional): Win7 SP1 / Tiny10 dualboot
- Graphics Processor: nVidia with Vulkan support
- Location: The ragged edge of disaster ('Bama)
[SOLVED!] (DEC/ZSC/maybe ACS?) External trajectory randomization?
Last edited by Xterra on Sun May 19, 2024 9:49 am, edited 1 time in total.
-
peewee_RotA
- Posts: 407
- Joined: Fri Feb 07, 2014 6:45 am
Re: (DEC/ZSC/maybe ACS?) External trajectory randomization?
So what is the end desired result? Do you want a bunch of shots all on the same straight line, but that single line is inaccurate, or do you want the path to change as the bullet flies, like dropping? Or do you want the path to change every time it hits something?
For the first one it's probably really easy for you. You get the random value first, assign it to 2 integers, and then call the hitscan attack on a loop with those 2 variables as their pitch and yaw.
The second option of changing paths as it flies is very hard to do with hitscans (but not completely impossible). The easiest is to use a fast projectile that is a ripper and reduce its damage in one of the virtual functions every time it hits something. There are weapons that look like hitscans that are actually fastprojectiles... like the Mage's wand in Hexen.
Changing the path is even more complicated
Now keep in mind these things are significantly easier in the other Id Techs. I've done that in both Quake and Quake 2. It's also pretty easy to reduce damage based on distance in those games as well. You just create short hitscans like legs in a lightning strike.
If you ever go down the path of using hitscans with branching paths, you have to keep in mind that "Joints" on legs hit targets twice. So they have to be smart enough to ignore a target already hit by the earlier leg. That's super easy in q2 because the railgun already does something similar. They also seem to handle arrays slightly better. In Zscript holding an array of already hit targets can be weird, and you have to resize the array and deal with limitations, especially issues passing arrays into functions.
I use a fastprojectile in my mod to create a lightning effect with branchs and sharp changes as it flies. It really looks like a hitscan.
https://github.com/cabbruzzese/xrpg/blo ... nd.zs#L375
For the first one it's probably really easy for you. You get the random value first, assign it to 2 integers, and then call the hitscan attack on a loop with those 2 variables as their pitch and yaw.
The second option of changing paths as it flies is very hard to do with hitscans (but not completely impossible). The easiest is to use a fast projectile that is a ripper and reduce its damage in one of the virtual functions every time it hits something. There are weapons that look like hitscans that are actually fastprojectiles... like the Mage's wand in Hexen.
Changing the path is even more complicated
Now keep in mind these things are significantly easier in the other Id Techs. I've done that in both Quake and Quake 2. It's also pretty easy to reduce damage based on distance in those games as well. You just create short hitscans like legs in a lightning strike.
If you ever go down the path of using hitscans with branching paths, you have to keep in mind that "Joints" on legs hit targets twice. So they have to be smart enough to ignore a target already hit by the earlier leg. That's super easy in q2 because the railgun already does something similar. They also seem to handle arrays slightly better. In Zscript holding an array of already hit targets can be weird, and you have to resize the array and deal with limitations, especially issues passing arrays into functions.
I use a fastprojectile in my mod to create a lightning effect with branchs and sharp changes as it flies. It really looks like a hitscan.
https://github.com/cabbruzzese/xrpg/blo ... nd.zs#L375
Re: (DEC/ZSC/maybe ACS?) External trajectory randomization?
If you want to further customize hitscans, you have to define a new LineTracer, in which you can customize how it penetrates and deals damage to enemies, for example by using DamageMobj.
I don't have any example on hand right now, but this thread might be of help to you.
However I don't think you can change the trajectory mid-trace, but you could potentially cast another linetrace from the hit actor with slightly modified angle and pitch.
I recommend using SpecialMissileHit instead, as it will allow you to customize how they penetrate and change their behavior when they do.
I don't have any example on hand right now, but this thread might be of help to you.
However I don't think you can change the trajectory mid-trace, but you could potentially cast another linetrace from the hit actor with slightly modified angle and pitch.
Now regarding this, rippers are pretty inflexible when it comes to how they penetrate and you can't alter their variables when they do penetrate.peewee_RotA wrote: ↑Fri May 17, 2024 8:09 am The second option of changing paths as it flies is very hard to do with hitscans (but not completely impossible). The easiest is to use a fast projectile that is a ripper and reduce its damage in one of the virtual functions every time it hits something. There are weapons that look like hitscans that are actually fastprojectiles... like the Mage's wand in Hexen.
I recommend using SpecialMissileHit instead, as it will allow you to customize how they penetrate and change their behavior when they do.
- Xterra
- Posts: 70
- Joined: Thu Feb 24, 2011 3:20 pm
- Preferred Pronouns: He/Him
- Operating System Version (Optional): Win7 SP1 / Tiny10 dualboot
- Graphics Processor: nVidia with Vulkan support
- Location: The ragged edge of disaster ('Bama)
Re: (DEC/ZSC/maybe ACS?) External trajectory randomization?
The first one. I don't want to have the bullets actually drop off, trajectory-wise. If I wanted to do that I'd just use a FastProjectile subject to a tiny amount of gravity.peewee_RotA wrote: ↑Fri May 17, 2024 8:09 am So what is the end desired result? Do you want a bunch of shots all on the same straight line, but that single line is inaccurate, or do you want the path to change as the bullet flies, like dropping? Or do you want the path to change every time it hits something?
Just a bunch of hitscans all in a line, but the line's inaccurate. I do have a few FastProjectile pseudo-hitscans going, like an invisible one that adds a dynamic light to railgun trails with comparatively minimal performance overhead (compared to, say, actor replacements each with their own lights...I used to develop the mod on a 2013-era performance laptop, I'm quite sensitive to performance concerns).
Basically...I've got multiple rifle-type weapons which I've always wanted to give some very mild inaccuracy to, but offhand I had no idea if A_FireBullets was gonna jive with some external RNG caller like a simple ACS script.
Re: (DEC/ZSC/maybe ACS?) External trajectory randomization?
https://zdoom.org/wiki/User_variable
I have no way of checking if this will work since I don't even have GZDoom installed now (no time, RL), but I think this should work in pure Decorate, maybe with some adjustments.
I have no way of checking if this will work since I don't even have GZDoom installed now (no time, RL), but I think this should work in pure Decorate, maybe with some adjustments.
Code: Select all
...
Spawn:
TNT1 A 0 NoDelay
{
user_vert_spread = 0;
user_horz_spread = 0;
}
...
Missile:
...
TNT1 A 0
{
user_vert_spread = Random(0, 5.0);
user_horz_spread = Random(0, 5.0);
}
SHTG A 7 A_FireBullets(user_horz_spread, user_vert_spread, 5, random(5,6), "RiflePuff", FBF_EXPLICITANGLE);
...
- Xterra
- Posts: 70
- Joined: Thu Feb 24, 2011 3:20 pm
- Preferred Pronouns: He/Him
- Operating System Version (Optional): Win7 SP1 / Tiny10 dualboot
- Graphics Processor: nVidia with Vulkan support
- Location: The ragged edge of disaster ('Bama)
Re: (DEC/ZSC/maybe ACS?) External trajectory randomization?
Obviously, I wouldn't be able to use it with that state structure (it's for a weapon, not a monster), but if it's doable purely in DEC, all the better.Kzer-Za wrote: ↑Sat May 18, 2024 8:06 am https://zdoom.org/wiki/User_variable
I have no way of checking if this will work since I don't even have GZDoom installed now (no time, RL), but I think this should work in pure Decorate, maybe with some adjustments.
Code: Select all
... Spawn: TNT1 A 0 NoDelay { user_vert_spread = 0; user_horz_spread = 0; } ... Missile: ... TNT1 A 0 { user_vert_spread = Random(0, 5.0); user_horz_spread = Random(0, 5.0); } SHTG A 7 A_FireBullets(user_horz_spread, user_vert_spread, 5, random(5,6), "RiflePuff", FBF_EXPLICITANGLE); ...
Legit, I didn't think you could roll a user variable RNG purely within DEC. It'd deffo be FRandom calls-- I.E.:
Code: Select all
Fire:
TNT1 A 0
{
vspread = 0;
hspread = 0;
}
TNT1 A 0
{
vspread = FRandom(-0.25, 0.25);
hspread = FRandom(-0.25,0.25);
}
TNT1 A 0 A_FireBullets(user_horz_spread, user_vert_spread, 5, random(5,6), "RiflePuff", FBF_EXPLICITANGLE)
. . .
Re: (DEC/ZSC/maybe ACS?) External trajectory randomization?
Oh I entirely misunderstood what you had wanted, apologies.
Weapons can't use user variables in Decorate due to the default pointer.
However what Kzer-Za posted will still work if you move the FRandom calls directly to the spread parameters of A_FireBullets:
A_FireBullets(FRandom(-0.25, 0.25), FRandom(-0.25, 0.25), 5, random(5,6), "RiflePuff", FBF_EXPLICITANGLE)
Just remember to use the FBF_EXPLICITANGLE flag.
Weapons can't use user variables in Decorate due to the default pointer.
However what Kzer-Za posted will still work if you move the FRandom calls directly to the spread parameters of A_FireBullets:
A_FireBullets(FRandom(-0.25, 0.25), FRandom(-0.25, 0.25), 5, random(5,6), "RiflePuff", FBF_EXPLICITANGLE)
Just remember to use the FBF_EXPLICITANGLE flag.
- Xterra
- Posts: 70
- Joined: Thu Feb 24, 2011 3:20 pm
- Preferred Pronouns: He/Him
- Operating System Version (Optional): Win7 SP1 / Tiny10 dualboot
- Graphics Processor: nVidia with Vulkan support
- Location: The ragged edge of disaster ('Bama)
Re: (DEC/ZSC/maybe ACS?) External trajectory randomization?
So the answer to my question here's the FBF_EXPLICITANGLE flag, eh?Jarewill wrote: ↑Sun May 19, 2024 2:29 am Oh I entirely misunderstood what you had wanted, apologies.
Weapons can't use user variables in Decorate due to the default pointer.
However what Kzer-Za posted will still work if you move the FRandom calls directly to the spread parameters of A_FireBullets:
A_FireBullets(FRandom(-0.25, 0.25), FRandom(-0.25, 0.25), 5, random(5,6), "RiflePuff", FBF_EXPLICITANGLE)
Just remember to use the FBF_EXPLICITANGLE flag.
Will try it.
-Xt.
EDIT: IT'Z VURKINK! I had no idea it was that simple. 'Scuse me while I rewrite SO VERY MANY weapons.
Thank y'all very, very much. This topic is solved. -Xt.
EDIT EDIT: Now, if only I could have it to where two seperate function calls (I.E. an A_FireBullets for the damage, and an A_RailAttack for a smoke trail) use a shared RNG call for their trajectories...ah well, that's for another post.)
