Code for a Stun Attack?

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

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!)
Post Reply
User avatar
ReX
Posts: 1584
Joined: Tue Aug 05, 2003 10:01 am
Location: Quatto's Palace
Contact:

Code for a Stun Attack?

Post by ReX »

Would someone please point me to a mod that includes a stun attack? Specifically, I'm trying to develop an attack, wielded by an enemy, that momentarily freezes (or, preferably, slows down) the player, while also reducing the player's health by a small amount. If the player gets hit by multiple attacks the s/he freezes/slows down for longer, loses more health, and allows enemies to keep attacking without the player being able to retaliate or escape. Therefore, even though the enemies are individually weak, the player needs to avoid being surrounded or swarmed by them.

There is a reference to a "stun blast" here (you'll need to show the spoiler text), and I'll study the mod to see where it is defined. But I'd appreciate any additional help. Thanks.
User avatar
Enjay
 
 
Posts: 27063
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland
Contact:

Re: Code for a Stun Attack?

Post by Enjay »

While I don't have any code for you, I would certainly urge caution with any effect that can incapacitate the player. Such mechanisms can very easily go from kewl to insanely frustrating. So, consider short durations for the stun (shorter than you, as the author and therefore intimately familiar with the behaviour, might feel is OK) and also consider adding some method or chance for the player to break out of being stunned if swamped by stunning enemies.
Jarewill
 
 
Posts: 1853
Joined: Sun Jul 21, 2019 8:54 am

Re: Code for a Stun Attack?

Post by Jarewill »

Enjay raised good points about this mechanic and how to properly balance it.
But to make something like this, you could make a PowerSpeed powerup with the +INVENTORY.ADDITIVETIME flag set so the time keeps increasing on every hit.
Then you can use the +HITTRACER flag on the projectile / bullet puff to set the hit actor as the tracer, which then you can reference in A_GiveInventory.
For example:
Spoiler:
User avatar
ReX
Posts: 1584
Joined: Tue Aug 05, 2003 10:01 am
Location: Quatto's Palace
Contact:

Re: Code for a Stun Attack?

Post by ReX »

@Enjay: You've made a completely valid point about the potential for a stun attack to become very frustrating. One way to make it less so, is (as you suggested) to limit the duration of the player's incapacitation. Another way, is to set up the map so that the player is not required to engage with multiple stun-attack enemies, but there is always a chance that it can occur. (After all, if there's no risk then why bother?) Also, as a player myself, I will sometimes intentionally enter a risky situation to test my skills/get the adrenaline pumping/etc. Punch a cyberdemon to death, anyone?

@Jarewill: Let me study your code and see how it will work and how much I'll need to tweak it. If I use your code I will, of course, credit you.

Thank you both.
User avatar
Tormentor667
Posts: 13555
Joined: Wed Jul 16, 2003 3:52 am
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 11
Graphics Processor: nVidia (Modern GZDoom)
Location: Germany
Contact:

Re: Code for a Stun Attack?

Post by Tormentor667 »

Stronghold has that :)
User avatar
ReX
Posts: 1584
Joined: Tue Aug 05, 2003 10:01 am
Location: Quatto's Palace
Contact:

Re: Code for a Stun Attack?

Post by ReX »

Tormentor667 wrote: Sun May 07, 2023 3:22 pm Stronghold has that :)
Daniel! It's good to hear from you.

Considering what a beast (and I mean that in the best possible way) of a mod Stronghold is, would you please narrow down the enemy with the stun attack? Better yet, copy & paste the code here, if it's not too much trouble.
User avatar
Xim
Posts: 2094
Joined: Fri Feb 20, 2009 2:46 pm
Location: somewhere with trees

Re: Code for a Stun Attack?

Post by Xim »

Yeah I think Jarewill has a good code for stunning right there. Xim's Star Wars is a bit similar but it uses a custom damage type and actually gives the stun effect in the player classes' pain states. This is also used to trigger custom stun pain for the enemies.
Spoiler:
But now I might want to touch up the code in it for the next version, heh.
User avatar
Tormentor667
Posts: 13555
Joined: Wed Jul 16, 2003 3:52 am
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 11
Graphics Processor: nVidia (Modern GZDoom)
Location: Germany
Contact:

Re: Code for a Stun Attack?

Post by Tormentor667 »

ReX wrote: Tue May 09, 2023 7:54 pmDaniel! It's good to hear from you.Considering what a beast (and I mean that in the best possible way) of a mod Stronghold is, would you please narrow down the enemy with the stun attack? Better yet, copy & paste the code here, if it's not too much trouble.
My fault, after reading the thread again, I noticed you mean an enemy stunning the player and not vice versa (which is what we did for Stronghold). Sorry for the misunderstanding :(
Post Reply

Return to “Scripting”