Getting rid of the annoying "autoswap on empty" on weapons

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!)
User avatar
Z.Franz
Posts: 35
Joined: Fri Jun 12, 2015 3:46 am
Location: Italy

Getting rid of the annoying "autoswap on empty" on weapons

Post by Z.Franz »

Hi all. I've looked through the forums for a while now and I haven't found an answer to this, so I have to ask for help.
I'm basically working on a "realistic" survival horror mod, where you basically have the guns and the magazine they come with. What you do get are instead single bullets, that you put inside said magazine by extracting it from the weapon with the "altfire" and then reload it with a simple "inventory item". The system works.
The problem with this system, though, is that if the player runs out of ammo in the clip and presses the trigger again, the game removes the weapon and takes out another, even if the player has ammo to put inside the clip/magazine.
Is there a way to make it go to a state where the gun doesn't fire but "clicks" using A_JumpIfNoAmmo, without the game taking my weapon away?
Basically, the switching out would happen only due to player input.
Because all my tries have been fruitless...I'm kind of desperate...everything else works like a charm, damn.
I thank you all in advance for your help, and I apologize if my writing isn't at its best, but it's 2:35 AM here so I'm kind of sleepy :) .
Thank you all, guys! :wink:
User avatar
gwHero
Posts: 360
Joined: Mon May 08, 2017 3:23 am
Graphics Processor: Intel with Vulkan/Metal Support
Location: The Netherlands

Re: Getting rid of the annoying "autoswap on empty" on weapo

Post by gwHero »

Hi, I remember struggling with this too. I found a solution; maybe there are more but this one worked for me: I added the AMMO_OPTIONAL flag and added A_JumpIfNoAmmo to the fire state of my weapon, like this:

Code: Select all

	Fire:		
		HZPI B 1 A_JumpIfNoAmmo("NoAmmoMsg");

	NoAmmoMsg:
		HZPI B 1 ... do something like making a click sound
		Goto Ready;
User avatar
Z.Franz
Posts: 35
Joined: Fri Jun 12, 2015 3:46 am
Location: Italy

Re: Getting rid of the annoying "autoswap on empty" on weapo

Post by Z.Franz »

Thank you! With your method I was able to make it work.
Now onto the other errors to fix...well, it was bound to happen. Stupid PlayerPawn not refreshing after loading/dying and restarting...
I still can't thank you enough though :)
EDIT:(fixed even the last issue, so thread should be closed)

Return to “Scripting”