Currently I need to add some functionality to the checks weapon switching does. I have a couple weapons that have AmmoUse set to 0 so I can do some conditional checking on them and, similar to standard weapons when they run out of ammo, I want to make sure that if they're truly out of ammo they'll be ignored in the weapon cycle/when the user presses the slot number and when picking a weapon of higher priority. A lot of the functions used aren't virtual so there's no way to override easily, but I'm wondering if there's an easier solution I might be missing.
Also, is there a way to delay (not disable) auto weapon swapping until a certain state is finished? E.g. I have a custom reload state for the SSG that uses A_WeaponReady to let users switch weapons manually during it to cancel it, but that comes with the caveat of new weapon pick ups cancelling it if the user has the setting enabled to auto switch. Ideally I'd like to let the animation finish first and then swap to the new weapon.
[ZScript] Reworking the way weapon switching works
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!)
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!)
- RicardoLuis0
-
- Posts: 57
- Joined: Tue Aug 21, 2018 9:31 pm
- Preferred Pronouns: He/Him
- Graphics Processor: nVidia (Modern GZDoom)
- Location: Brazil
- Contact:
Re: [ZScript] Reworking the way weapon switching works
you could use an event handler and intercept the weapon switch keys, or alternatively have the player unbind those keys themselves and rebind weapon switching keys specific to your mod, but i'm not sure about weapon pickup auto switching other than on the player setup menu's "Switch on Pickup" option.
Re: [ZScript] Reworking the way weapon switching works
Thankfully I found an easier solution. Weapon's CheckAmmo and AttachToOwner can both be overridden and will handle the first and second issues respectively. For the second one if the player has auto switching enabled I set a string on the weapon and then tell it not to swap by setting Owner.player.PendingWeapon to WP_NOCHANGE. Then I do a check in the weapon animation itself to see if the string has a length greater than 0. If so, it swaps to that weapon (taking priority into account if it gets deleted for whatever reason). Then whenever the weapon lowers or is tossed (by overriding CreateTossable) I set the string to "".