Page 1 of 1

Infinite ammo weapons and cooldowns

Posted: Sun Jul 11, 2021 11:36 pm
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]

Re: Infinite ammo weapons and cooldowns

Posted: Mon Jul 12, 2021 3:40 am
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:

Re: Infinite ammo weapons and cooldowns

Posted: Mon Jul 12, 2021 8:01 am
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

Re: Infinite ammo weapons and cooldowns

Posted: Mon Jul 12, 2021 8:21 am
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