[Zscript] adding something to a custom action function

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!)
Ultimate Freedoomer
Posts: 215
Joined: Fri Jan 30, 2015 10:32 pm
Location: Pittman Center

[Zscript] adding something to a custom action function

Post by Ultimate Freedoomer »

Hi. As some of you may know, I did a little set of DECORATE that replicates Strife: Quest For The Sigil's vanilla weapon functionality using non-restricted action functions. I'm currently working on the 1st post-release update, & I had to use ZScript to create a non-restricted custom action function that identically replicates the existing functionality of A_FireGrenade. The thing is, I'm trying to add a "consume ammo" boolean (functionality in this custom function is otherwise unchanged from A_FireGrenade) so a weapon that relies on a firemode toggle alt for accessing different primary fire modes (rather than using separate ammo for primary & secondary) only consumes the appropriate ammo for the active primary fire mode. Here's the code for the custom function as applies to my mod:

Code: Select all

version "3.2.5"

class SimpleStrifeGrenadeLauncherBase : StrifeWeapon
{
action void A_CustomGrenade (class<Actor> grenadetype, double angleofs, statelabel flash, bool useammo = true)
	{
		if (player == null)
		{
			return;
		}
		Weapon weapon = player.ReadyWeapon;
		if (weapon != null)
		{
			if (!weapon.DepleteAmmo (weapon.bAltFire))
				return;
			player.SetPsprite (PSP_FLASH, weapon.FindState(flash), true);
		}
		if (grenadetype != null)
		{
			AddZ(32);
			Actor grenade = SpawnSubMissile (grenadetype, self);
			AddZ(-32);
			if (grenade == null)
				return;
			if (grenade.SeeSound != 0)
			{
				grenade.A_PlaySound (grenade.SeeSound, CHAN_VOICE);
			}
			grenade.Vel.Z = (-clamp(tan(Pitch), -5, 5)) * grenade.Speed + 8;
			Vector2 offset = AngleToVector(angle, radius + grenade.radius);
			double an = Angle + angleofs;
			offset += AngleToVector(an, 15);
			grenade.SetOrigin(grenade.Vec3Offset(offset.X, offset.Y, 0.), false);
		}
	}
}
I guess what I'm trying to ask is: what do I add/change to make the "ammo consumption" boolean functional?

Return to “Scripting”