Page 1 of 1

Weapon scripting help (zscript)

Posted: Tue May 24, 2022 11:50 am
by JamesTheMaker

Code: Select all

// --------------------------------------------------------------------------
//
// Grenade launcher
//
// --------------------------------------------------------------------------

class GrenadeLauncher : FranticWeapon 14167
{
	Default
	{
		Weapon.SelectionOrder 2500;
		Weapon.AmmoUse 1;
		Weapon.AmmoGive 2;
		Weapon.AmmoType "RocketAmmo";
		Weapon.SlotNumber 2;
		+WEAPON.NOAUTOFIRE
		Inventory.PickupMessage "$GOTLAUNCHER";
		Tag "$TAG_ROCKETLAUNCHER";
	}
	States
	{
	Ready:
		MISG A 1 A_WeaponReady;
		Loop;
	Deselect:
		MISG A 1 A_Lower;
		Loop;
	Select:
		MISG A 1 A_Raise;
		Loop;
	Fire:
		MISG B 8 A_GunFlash;
		MISG B 12 A_FireGrenade;
		MISG B 0 A_ReFire;
		Goto Ready;
	Flash:
		MISF A 3 Bright A_Light1;
		MISF B 4 Bright;
		MISF CD 4 Bright A_Light2;
		Goto LightDone;
	Spawn:
		LAUN A -1;
		Stop;
	}
}

class Grenade : Actor
{
	Default
	{
		Radius 11;
		Height 8;
		Speed 50;
		Damage 20;
		Projectile;
		-NOGRAVITY
		+RANDOMIZE
		+DEHEXPLOSION
		+ROCKETTRAIL
		+ZDOOMTRANS
		SeeSound "weapons/rocklf";
		DeathSound "weapons/rocklx";
		Obituary "$OB_MPROCKET";
	}
	States
	{
	Spawn:
		MISL A 1 Bright;
		Loop;
	Death:
		MISL B 8 Bright A_Explode;
		MISL C 6 Bright;
		MISL D 4 Bright;
		Stop;
	BrainExplode:
		MISL BC 10 Bright;
		MISL D 10 A_BrainExplode;
		Stop;
	}
}

//===========================================================================
//
// Code (must be attached to StateProvider)
//
//===========================================================================

extend class StateProvider
{

	//===========================================================================
	//
	// A_FireMissile
	//
	//===========================================================================

	action void A_FireGrenade()
	{
		if (player == null)
		{
			return;
		}
		Weapon weap = player.ReadyWeapon;
		if (weap != null && invoker == weap && stateinfo != null && stateinfo.mStateType == STATE_Psprite)
		{
			if (!weap.DepleteAmmo (weap.bAltFire, true, 1))
				return;
		}
		
		SpawnPlayerMissile ("Grenade");
	}
}
I've followed all the information I can find, yet it still won't work. It doesn't appear in map editors nor can I use the give command to spawn it in. I don't understand what I'm doing wrong.

Re: Weapon scripting help (zscript)

Posted: Tue May 24, 2022 1:22 pm
by Ac!d
JamesTheMaker wrote:It doesn't appear in map editors nor can I use the give command to spawn it in.
Adding a editor number after the name of an actor is possible in Decorate. In ZScript however, the best way is to use the Editor number definition in MAPINFO like so :

Code: Select all

DoomEdNums
{
  14167 = GrenadeLauncher 
}
Also,
- The actor "Grenade" is already in GZDoom.pk3, no need to copy it. Else, rename it, indicate that the parent is "Grenade" and remove the state "BrainExplode", which is used for the rocket.
- A_FireGrenade() is already used for the "StrifeGrenadeLauncher" from Strife : Quest for the Sigil. Rename that function.

Re: Weapon scripting help (zscript)

Posted: Fri Jun 03, 2022 6:06 am
by Player701
Ac!d wrote:- A_FireGrenade() is already used for the "StrifeGrenadeLauncher" from Strife : Quest for the Sigil. Rename that function.
The function as defined shouldn't even compile, since extend class StateProvider is not valid in user-supplied ZScript code. It would only work in a modified gzdoom.pk3, but changing its contents is something I'd advise against. Aside from that, A_FireGrenade can be defined directly inside GrenadeLauncher and wouldn't conflict with A_FireGrenade from the Strife grenade launcher because neither of these two classes inherit from each other (directly or indirectly).