[ZScript] Smooth scaling of weapon/psprite animation speed

Post your example zscripts/ACS scripts/etc here.
Forum rules
The Projects forums are only for projects. If you are asking questions about a project, either find that project's thread, or start a thread in the General section instead.

Got a cool project idea but nothing else? Put it in the project ideas thread instead!

Projects for any Doom-based engine (especially 3DGE) are perfectly acceptable here too.

Please read the full rules for more details.
Post Reply
argv
Posts: 184
Joined: Tue Aug 30, 2016 4:47 pm

[ZScript] Smooth scaling of weapon/psprite animation speed

Post by argv »

The attached pk3 adds three new weapons to the game (which you'll have to “give” yourself from the console): “SpeedScalingPistol”, “SpeedScalingShotgun”, and “SpeedScalingChaingun”. The rate of fire of these weapons is controlled by the CVar “weapon_speed_scale”. If set to a negative number, then for each tic of animation, that many tics will be skipped. If set to a positive number, then for each tic of animation, that many tics will be added. This can be a fraction; “weapon_speed_scale -0.5” makes the weapons fire at 1.5× their normal rate.

If you think you could use this in your mod, take a look inside the pk3. You'll need to copy the class “PSpriteSpeedScaler” and the struct “PSpriteSpeedScalerSet” into your mod. Then, on your weapon classes, add a PSpriteSpeedScalerSet field, and call it from the Tick method as shown.

The main use case I had in mind for this is RPG-like mods, where attack speed is affected by the player character's skills and attributes.

Hope it helps!
Attachments
speedscale.pk3
(1.81 KiB) Downloaded 311 times
User avatar
Nash
 
 
Posts: 17433
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia
Contact:

Re: [ZScript] Smooth scaling of weapon/psprite animation spe

Post by Nash »

Very useful! Thanks for sharing.
argv
Posts: 184
Joined: Tue Aug 30, 2016 4:47 pm

Re: [ZScript] Smooth scaling of weapon/psprite animation spe

Post by argv »

I've done some additional work on this code, which you can track in my Bitbucket repository.

Specifically, I've made the following changes:
  • Slight optimization.
  • Split into two ZScript files: one with the actual mod, and one with the demonstration weapons.
  • Improve the way it interacts with PowerDoubleFiringSpeed.
User avatar
Nash
 
 
Posts: 17433
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia
Contact:

Re: [ZScript] Smooth scaling of weapon/psprite animation spe

Post by Nash »

Hey, sorry for the bump. I've finally integrated this into my project and it works beautifully.

I have a suggestion though; would it be possible to change the scale numbering so that 1.0 = normal speed? Then 0.5 would be half speed, 2.0 would be double speed, etc etc... If you can't then it's okay. I just feel that a scale multiplier would make more logical sense.

Thanks again for this amazing underrated gem!
DRouve
Posts: 1
Joined: Fri Aug 26, 2022 5:29 pm

Re: [ZScript] Smooth scaling of weapon/psprite animation speed

Post by DRouve »

I contacted mod author, he told me that Bitbucket repo was moved to Github:
https://github.com/argv-minus-one/gzdoo ... ed-scaling
Post Reply

Return to “Script Library”