Zscript pitch help

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
Xtyfe
Posts: 1490
Joined: Fri Dec 14, 2007 6:29 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 11
Graphics Processor: nVidia with Vulkan support

Zscript pitch help

Post by Xtyfe »

So I have taken on learning Zscript, I wanted to change Heretics Wand to have vertical spread.

Doing this for the non-powered attack was simple based on other examples I had seen but the powered version uses explicit values that I can't seem to replicate. I know I can easily use A_FireBullets to do what I want but from a learning perspective, I wanted to check to see what I had done wrong.

For reference, this is what I wanted to replicate in the original function

Code: Select all

				A_FireBullets (0, 0, 1, FRandom(1, 3)*5, "XtGoldWandPuff2", FBF_USEAMMO | FBF_NORANDOM | FBF_EXPLICITANGLE, 128*64, null, 32, 0);
				A_FireBullets (5, 0, 1, FRandom(1, 3)*5, "XtGoldWandPuff2", FBF_NORANDOM | FBF_EXPLICITANGLE, 128*64, null, 32, 0);
				A_FireBullets (-5, 0, 1, FRandom(1, 3)*5, "XtGoldWandPuff2", FBF_NORANDOM | FBF_EXPLICITANGLE, 128*64, null, 32, 0);
				A_FireBullets (0, 5, 1, FRandom(1, 3)*5, "XtGoldWandPuff2", FBF_NORANDOM | FBF_EXPLICITANGLE, 128*64, null, 32, 0);
				A_FireBullets (0, -5, 1, FRandom(1, 3)*5, "XtGoldWandPuff2", FBF_NORANDOM | FBF_EXPLICITANGLE, 128*64, null, 32, 0);
				A_FireProjectile ("XtGoldWandFX2", 5, 0, 0, 0, 0, 0);
				A_FireProjectile ("XtGoldWandFX2",-5, 0, 0, 0, 0, 0);
and this has been my attempt so far based on examples I found.

Code: Select all

	action void A_XtFireElvenWandP()
	{
		if (player == null)
		{
			return;
		}

		Weapon weapon = player.ReadyWeapon;
		if (weapon != null)
		{
			if (!weapon.DepleteAmmo (weapon.bAltFire))
				return;
		}
		double bangle = angle;
		double bslope = BulletSlope ();

		double vz = -GetDefaultByType("XtGoldWandFX2").Speed * clamp(tan(pitch), -5, 5);
		SpawnMissileAngle("XtGoldWandFX2", angle - (40. / 8), vz);
		SpawnMissileAngle("XtGoldWandFX2", angle + (40. / 8), vz);
		for(int i = 0; i < 5; i++)
		{
			double pangle = bangle;
			double slope = bslope;

			pangle += 5;
			slope += 5;
			int damage = random[FireGoldWand](1, 8);
			LineAttack (pangle, PLAYERMISSILERANGE, slope, damage, 'Hitscan', "GoldWandPuff2");
		}
		A_StartSound("weapons/wandhit", CHAN_WEAPON);
	}
Post Reply

Return to “Scripting”