Infinite ammo weapons and cooldowns

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!
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
Ac!d
Posts: 351
Joined: Tue Apr 02, 2019 5:13 am

Infinite ammo weapons and cooldowns

Post by Ac!d »

Dr_Cosmobyte wrote:Weapons mod idea:

All your weapons have infinite ammo (which gives room for more situational weapons and more items on ammo pickups),

BUT

The more you you use them, the worse they get, until they deal the minimal damage possible, and you must wait them for recharge in the background if you want to use them full power again (although you can still use them if you ever need to, no restrictions involved). Ammo pickups could help them recharge faster, OR some weapons could recharge faster than others.

Don't know what crossed my mind so i could have this idea. Hope someone makes a good use of it.
- How can I make a "background reload" like in Beautiful Doom but whitout any ammo ? (for exemple in my code with "Int NailgunCharge")
- How could I reload faster a weapon with "fake ammo pickups" (with the utilisation of Inventory and/or Int)
Spoiler: Exemple with a Nailgun
[spoiler="background reload" code of Beautiful Doom. All Credits to Agent_Ash aka Jekyll Grim Payne]

Code: Select all

// I removed some parts of the original code for keeping the important parts of my request. - Ac!d

Class BDoomWeapon : Weapon abstract
{
	protected int NonselTimer; //counts how long the weapon was deselected, used for automatic background reload
	protected int AutoReloadTime; //the value that NonselTimer is compared to
	property AutoReloadTime : AutoReloadTime;
	
	Default
	{
		BDoomWeapon.AutoReloadTime 60;
		BDoomWeapon.maxOffsetTics 1; //required default values for A_CameraSway. Otherwise it'll crash due to division by zero
		BDoomWeapon.offsetTics -1;
	}
	
	override void DoEffect()
	{
		if (!owner || !owner.player)
			return;
		let plr = owner.player;
		
		Super.DoEffect();
	
		if (!ammo1 || !ammo2 || (ammo1 == ammo2))
			return;
		if (plr.readyweapon == self || ammo1.amount == ammo1.maxamount || ammo2.amount < 1) {
			NonselTimer = 0;
			return;
		}
		if (NonselTimer < AutoReloadTime)
			NonselTimer++;
		else
		{
			while (ammo2.amount > 0 && ammo1.amount < ammo1.maxamount)
			{
				owner.TakeInventory(ammo2.GetClass(),1);
				owner.GiveInventory(ammo1.GetClass(),1);
			}
			if (plr == players[consoleplayer])
				Console.Printf("%s reloaded",GetTag());
			owner.A_StartSound(reloadsound,slot:CHAN_AUTO,flags:CHAN_NOPAUSE,volume:0.5,attenuation:20);
		}			
	}
}
[/spoiler]
Jarewill
 
 
Posts: 1855
Joined: Sun Jul 21, 2019 8:54 am

Re: Infinite ammo weapons and cooldowns

Post by Jarewill »

- For a background reload you would have to override DoEffect and check if the weapon isn't the player's readyweapon:
Spoiler:
- You can override TryPickup to make inventory items increase the weapon's variables directly:
Spoiler:
Ac!d
Posts: 351
Joined: Tue Apr 02, 2019 5:13 am

Re: Infinite ammo weapons and cooldowns

Post by Ac!d »

The background reload doesn't seems to work and I would like to decrease the weapon's variable to 0.
I made an exemple with a weapon (replaces chainsaw) and an item (replaces zombieman)
test.wad
(11.92 KiB) Downloaded 35 times
User avatar
Virathas
Posts: 254
Joined: Thu Aug 10, 2017 9:38 am

Re: Infinite ammo weapons and cooldowns

Post by Virathas »

Background Reload doesn't work simply because you have put wrong comparison operator:
You had

Code: Select all

 If(owner&&owner.player&&!(owner.player.readyweapon is self.GetClassName())&&weaponCharge>=100)
instead of

Code: Select all

 If(owner&&owner.player&&!(owner.player.readyweapon is self.GetClassName())&&weaponCharge<=100)
So it only worked if the charge was 100 or more instead of 100 or less
Post Reply

Return to “Scripting”