[HELP] Create a stackable pickup which raises AirSupply by 10 every time

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
User avatar
Ozymandias81
Posts: 2069
Joined: Thu Jul 04, 2013 8:01 am
Graphics Processor: nVidia with Vulkan support
Location: Mount Olympus, Mars
Contact:

[HELP] Create a stackable pickup which raises AirSupply by 10 every time

Post by Ozymandias81 »

As per the thread title, I am trying to figure out if it is possible to create this kind of pickup (needed for DoomExhumed, a mod that soon will be released as demo).
The effect should allow players to "stack" an addition of 10 seconds PERMANENTLY every time we collect this object, that it's been called LungsCapacity... I tried checking for some good VirtualFunctions to override and let the effect work (DoEffect, InitEffect and toying with playerpawn.aircapacity somehow), but still the effect doesn't happen as intended.

I am gonna into details of what I have atm and what did I try, without any luck:

The MAPINFO of the project has AirCapacity set to 30 on its DefaultMap, also the AirControl is set to 0.00390625

By checking this forum, I noticed something that might have help for my purpose, but with no avail unfortunately, cause it doesn't stack.
This is the actual code, which mind you it doesn't work yet:

Player

Code: Select all

Class DExh_Player : DoomPlayer
{
	//Define here all the weapons you plan to put
	//Player.WeaponSlot 1, "DExh_Machete", "DExh_Fist";
	Default
	{
		Speed 1.1;
		Radius 16;
		Height 46;
		Player.StartItem "DExh_Underwater";
		Player.StartItem "Machete";
		Player.StartItem "PistolFix";
		Player.StartItem "MagnumRounds", 20;
		Player.MaxHealth 100;
		+OLDRADIUSDMG
	}
	
	override void CheckAirSupply()
	{
		{
			let player = self.player;
			if (waterlevel < 3 || (bInvulnerable) || (player.cheats & (CF_GODMODE | CF_NOCLIP2)) ||	(player.cheats & CF_GODMODE2))
			{
				ResetAirSupply();
			}
			else if (player.air_finished <= Level.maptime && !(Level.maptime & 31))
			{
				DamageMobj(NULL, NULL, 2 + ((Level.maptime - player.air_finished) / TICRATE), 'Drowning');
			}
		}
	}
}
Modified PowerAir to exclude Fire damage

Code: Select all

Class PowerAir : PowerIronFeet
{
	Default
	{
		Powerup.Duration -1;
		
		Inventory.MaxAmount 1;
		+INVENTORY.HUBPOWER
		+INVENTORY.ALWAYSPICKUP
		+INVENTORY.AUTOACTIVATE
		//Inventory.Icon "I_MASK";
	}
	
	override void AbsorbDamage (int damage, Name damageType, out int newdamage, Actor inflictor, Actor source, int flags)
	{
		if (damageType == 'Drowning') //checks only Drowning, original also check Fire - ozy81
		{
			newdamage = 0;
		}
	}

	override void DoEffect ()
	{
		Super.DoEffect ();
		if (!(Level.maptime & 0x3f))
		{
			//need to figure out this better, atm does nothing
		}
	}
	
}
Pickup that should modify AirCapacity and the CustomInventory item

Code: Select all

Class Gills : Inventory
{
	override void doeffect()
	{
	
		if (owner is "playerpawn")
		{
			//playerpawn(owner).aircapacity = playerpawn(owner).aircapacity + 0.5;
			playerpawn(owner).aircapacity + 1.3;
		}
	}
}

Class LungCapacity : CustomInventory 
{
	Default
	{
		//$Category Powerups
		//$Title Lung Capacity (+10)
		Radius 16;
		Height 16;
		Scale 1.3;
		Inventory.Pickupsound "";
		Inventory.PickupMessage "";
		FloatBobStrength 0.2;
		+COUNTITEM
		+FLOATBOB
		+INVENTORY.ALWAYSPICKUP
		+NOGRAVITY
		//Armor.SaveAmount 1
		//Armor.MaxSaveAmount 0 //200
	}
	
	States
	{
	Spawn:
		LUNG ABCDCBA 8 BRIGHT;
		Loop;
	Pickup:
		TNT1 A 0 { A_GiveInventory("Gills", 1); A_GiveInventory("PowerAir", 1); }
		Stop;
	}
}
I am asking this for a project that's not mine but done by CasketCrusher, which soon you will notice how cool are his mapping skills. Any help and suggestions, in zscript possibly, are welcome. Project is using 4.2.9 version of ZScript but shouldn't be mandatory. Thanks a lot. :wub:
Jarewill
 
 
Posts: 1855
Joined: Sun Jul 21, 2019 8:54 am

Re: [HELP] Create a stackable pickup which raises AirSupply by 10 every time

Post by Jarewill »

You want to override TryPickup for this:

Code: Select all

Class Gills : Inventory
{
	Override bool TryPickup(in out Actor toucher){
		PlayerPawn(toucher).AirCapacity+=0.33;
		GoAwayAndDie();
		Return 1;
	}
}
User avatar
Ozymandias81
Posts: 2069
Joined: Thu Jul 04, 2013 8:01 am
Graphics Processor: nVidia with Vulkan support
Location: Mount Olympus, Mars
Contact:

Re: [HELP] Create a stackable pickup which raises AirSupply by 10 every time

Post by Ozymandias81 »

Thank you a lot, works like a charm!
Post Reply

Return to “Scripting”