[ZSCRIPT] My reloadable weapon isn't switching how it should.

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
yum13241
Posts: 780
Joined: Mon May 10, 2021 8:08 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): EndeavorOS (basically Arch)
Graphics Processor: Intel with Vulkan/Metal Support
Contact:

[ZSCRIPT] My reloadable weapon isn't switching how it should.

Post by yum13241 »

ZSBattleRifle:
Spoiler:
ZMonstrousWeapon:
Spoiler:
Here's how I want weapon switching to work:
1. If I have Clips, but NO BRAmmo, and if the player presses fire, reload the gun. Do NOT make the gun unselectable.
2. If I have BRAmmo, but NO Clips, then do not allow reloading and DO NOT make the gun unselectable (seems to be handled by ZMonstrousWeapon alr)
3. If I have NO BRAmmo AND Clips, then switch away and make the gun UNSELECTABLE.
4. If I have both, then just continue as normal. (I can reload as long as BRAmmo isn't at max and I have Clips)

Now obviously if the user has "Check Weapon Switch" OFF then I want to respect that and make the gun unconditionally selectable (just switch away when they try to fire)

How do I do this?
+WEAPON.AMMO_CHECKBOTH won't work here.
Last edited by yum13241 on Tue Dec 20, 2022 11:26 am, edited 2 times in total.
Jarewill
 
 
Posts: 1759
Joined: Sun Jul 21, 2019 8:54 am

Re: [ZSCRIPT] My reloadable weapon isn't switching how it should.

Post by Jarewill »

The best you can do is to add the +WEAPON.AMMO_OPTIONAL flag and make custom logic before firing/reloading.
But I don't know of any way to make a weapon not selectable with that flag.
yum13241
Posts: 780
Joined: Mon May 10, 2021 8:08 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): EndeavorOS (basically Arch)
Graphics Processor: Intel with Vulkan/Metal Support
Contact:

Re: [ZSCRIPT] My reloadable weapon isn't switching how it should.

Post by yum13241 »

Maybe I can use
TNT1 A 0 A_SelectWeapon("BFG9000",SWF_SELECTPRIORITY);

if the weapon is not meant to be selectable, but then how do I respect "Check Ammo Before Switch" being off?
Blue Shadow
Posts: 4949
Joined: Sun Nov 14, 2010 12:59 am

Re: [ZSCRIPT] My reloadable weapon isn't switching how it should.

Post by Blue Shadow »

Have you thought about trying a weapon reloading library, like this one?
yum13241
Posts: 780
Joined: Mon May 10, 2021 8:08 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): EndeavorOS (basically Arch)
Graphics Processor: Intel with Vulkan/Metal Support
Contact:

Re: [ZSCRIPT] My reloadable weapon isn't switching how it should.

Post by yum13241 »

Yeah I was looking for one but my DDGfoo wasn't enough.
User avatar
Player701
 
 
Posts: 1636
Joined: Wed May 13, 2009 3:15 am
Graphics Processor: nVidia with Vulkan support
Contact:

Re: [ZSCRIPT] My reloadable weapon isn't switching how it should.

Post by Player701 »

Blue Shadow wrote: Tue Dec 20, 2022 11:29 pm Have you thought about trying a weapon reloading library, like this one?
Being the author of that library in question, I can confirm it works just like the OP wants it to - especially considering that I was aiming for the exact same behavior. The need for the AMMO_OPTIONAL flag is a known issue with many reloading systems out there - or at least it was, when I first started working on mine, so I specifically wanted to avoid using that flag. Please read the instructions carefully and study the provided examples, and if you're still having issues, don't hesitate to ask (but preferably in the library thread and not here).
Post Reply

Return to “Scripting”