Weapon that inherits from weapon with States not going to ready

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!)
Post Reply
peewee_RotA
Posts: 373
Joined: Fri Feb 07, 2014 6:45 am

Weapon that inherits from weapon with States not going to ready

Post by peewee_RotA »

I have a weapon that inherits from a parent weapon class. The parent class has an altfire state sequence and function that determines what extra animations to run (If you have a shield block, if you don't then punch)

The parent class has the altfire, althold, and a few extra states sequences defined.

The child class has all of the ready, select, deselect, fire, etc. state sequences defined.

What I'm running into is that the weapon equips fine. But the first time I alt fire, it never goes back to the child ready state. It just disappears and no other weapon actions can be taken. Primary fire works fine.

Is there a known issue where defining parent weapon frames causes bugs with child weapon classes?

Here's the state portions:
Parent: XRpgFighterShieldWeapon

Code: Select all

class XRpgFighterShieldWeapon : XRpgFighterWeapon
{
	States
	{
	AltFire:
        FSHL A 0 A_CheckShield;
	ShieldSpikedFire:
        FSHL A 1;
        FSHL BC 1;
        FSHL D 1 A_ShieldBashMelee;
    AltHold:
        FSHL E 0 A_CheckShieldHold;
	ShieldSpikedHold:
		FSHL E 8 A_UseShield;
		FSHL E 4 A_Refire;
        FSHL E 4 A_CheckShieldCharged;
        FSHL DCBA 2;
        Goto Ready;
	ShieldKiteFire:
		FSH2 A 1;
        FSH2 BC 1;
        FSH2 D 1 A_ShieldBashMelee;
	ShieldKiteHold:
		FSH2 E 8 A_UseShield;
		FSH2 E 4 A_Refire;
        FSH2 E 4 A_CheckShieldCharged;
        FSH2 DCBA 2;
        Goto Ready;
    ShieldCharged:
        FSHL FGH 2 BRIGHT A_UseShield(false);
		FSHL F 2 BRIGHT A_Refire;
        FSHL G 2 BRIGHT A_ShieldFire;
    ShieldFireFinish:
		FSHL DCBA 2;
        Goto Ready;
	FistFire:
		FPCH B 5 Offset (5, 40) A_Mirror;
		FPCH C 4 Offset (5, 40);
		FPCH D 4 Offset (5, 40) A_OffhandPunchAttack;
		FPCH C 4 Offset (5, 40);
		FPCH B 3 Offset (5, 40);
		FPCH B 3 Offset (5, 40) A_Refire;
		FPCH E 1 Offset (0, 150) A_RestoreMirror;
		Goto Ready;
	}
	
	//...
Child Class: XRpgFWeapRazor

Code: Select all

class XRpgFWeapRazor : XRpgFighterShieldWeapon replaces CentaurSword
{
	Default
	{
		+BLOODSPLATTER
		Weapon.SelectionOrder 900;
		+WEAPON.AXEBLOOD +WEAPON.AMMO_OPTIONAL +WEAPON.MELEEWEAPON
		Weapon.KickBack 150;
		Inventory.PickupMessage "$TXT_WEAPON_RAZOR";
		Obituary "$OB_MPFWEAPRAZOR";
		Tag "$TAG_FWEAPRAZOR";
		Inventory.MaxAmount 1;

        XRpgFighterWeapon.Pufftype "AxePuff";
        XRpgFighterWeapon.WeaponRange 2.0 * DEFMELEERANGE;
        XRpgFighterWeapon.MeleePush 0;
        XRpgFighterWeapon.MeleeAdjust true;
	}

	States
	{
	Spawn:
		CTDP KLMNOPQ 3;
		CTDP R 4;
		CTDP S 4;
		CTDP T -1;
		Stop;
	Select:
		FRZR A 1 A_Raise;
		Loop;
	Deselect:
		FRZR A 1 A_Lower;
		Loop;
	Ready:
		FRZR A 1 A_WeaponReady;
		Loop;
	Fire:
		FRZR B 2 Offset (5, 0);
		FRZR B 4 Offset (5, 0) A_CheckBerserk(false);
		FRZR C 1 Offset (5, 0) A_FWeaponMelee(10, 30, -25, 0.35);
		FRZR C 1 Offset (5, 0) A_FWeaponMelee(10, 30, 0, 0.35);
		FRZR C 1 Offset (5, 0) A_FWeaponMelee(10, 30, 25, 0.35);
		FRZR D 3 Offset (5, 0);
		FRZR E 2 Offset (5, 0);
		FRZR E 10 Offset (5, 150);
		FRZR A 1 Offset (0, 60);
		FRZR A 1 Offset (0, 55);
		FRZR A 1 Offset (0, 50);
		FRZR A 1 Offset (0, 45);
		FRZR A 1 Offset (0, 40);
		FRZR A 1 Offset (0, 35);
		FRZR A 1;
		Goto Ready;
	BerserkFire:
		FRZR C 1 Offset (5, 0) A_FWeaponMelee(10, 30, -25, 0.35);
		FRZR C 1 Offset (5, 0) A_FWeaponMelee(10, 30, 0, 0.35);
		FRZR C 1 Offset (5, 0) A_FWeaponMelee(10, 30, 25, 0.35);
		FRZR D 2 Offset (5, 0);
		FRZR E 2 Offset (5, 0);
		FRZR E 4 Offset (5, 150);
		FRZR A 1 Offset (0, 60);
		FRZR A 1 Offset (0, 55);
		FRZR A 1 Offset (0, 50);
		FRZR A 1 Offset (0, 45);
		FRZR A 1 Offset (0, 40);
		FRZR A 1 Offset (0, 35);
		FRZR A 1;
		Goto Ready;
	}
}
peewee_RotA
Posts: 373
Joined: Fri Feb 07, 2014 6:45 am

Re: Weapon that inherits from weapon with States not going to ready

Post by peewee_RotA »

Update:

I found a workaround. If I define the state sequence names I want on every child class, and use Goto to jump into custom (similarly named) state sequence names on the parent I can use the parent frames just fine.

Then I updated the parent to define all of the problem weapon state sequence names and then used custom action functions to directly set the state name to a similarlynamed state name for the children.

(These custom functions are needed because Goto errors at compile time if the name doesn't exist, and defining the name on the parent overrides the child.)

Here's the updated code:

Parent Class: XRpgFighterShieldWeapon

Code: Select all

class XRpgFighterShieldWeapon : XRpgFighterWeapon
{
	States
	{
	Select:
		TNT1 A 0 A_ForwardToSelect;
	Deselect:
		TNT1 A 0 A_ForwardToDeselect;
	Ready:
		TNT1 A 0 A_ForwardToReady;
	Fire:
		TNT1 A 0 A_ForwardToFire;
	ShieldFrameAltFire:
        FSHL A 0 A_CheckShield;
	ShieldFrameShieldSpikedFire:
        FSHL A 1;
        FSHL BC 1;
        FSHL D 1 A_ShieldBashMelee;
    ShieldFrameAltHold:
        FSHL E 0 A_CheckShieldHold;
	ShieldFrameShieldSpikedHold:
		FSHL E 8 A_UseShield;
		FSHL E 4 A_Refire;
        FSHL E 4 A_CheckShieldCharged;
        FSHL DCBA 2;
        Goto Ready;
	ShieldFrameShieldKiteFire:
		FSH2 A 1;
        FSH2 BC 1;
        FSH2 D 1 A_ShieldBashMelee;
	ShieldFrameShieldKiteHold:
		FSH2 E 8 A_UseShield;
		FSH2 E 4 A_Refire;
        FSH2 E 4 A_CheckShieldCharged;
        FSH2 DCBA 2;
        Goto Ready;
    ShieldFrameShieldCharged:
        FSHL FGH 2 BRIGHT A_UseShield(false);
		FSHL F 2 BRIGHT A_Refire;
        FSHL G 2 BRIGHT A_ShieldFire;
    ShieldFrameShieldFireFinish:
		FSHL DCBA 2;
        Goto Ready;
	ShieldFrameFistFire:
		FPCH B 5 Offset (5, 40) A_Mirror;
		FPCH C 4 Offset (5, 40);
		FPCH D 4 Offset (5, 40) A_OffhandPunchAttack;
		FPCH C 4 Offset (5, 40);
		FPCH B 3 Offset (5, 40);
		FPCH B 3 Offset (5, 40) A_Refire;
		FPCH E 1 Offset (0, 150) A_RestoreMirror;
		Goto Ready;
	}

	action void A_ForwardToReady()
	{
		A_SetWeapState("WeaponReady");
	}
	action void A_ForwardToSelect()
	{
		A_SetWeapState("WeaponSelect");
	}
	action void A_ForwardToDeselect()
	{
		A_SetWeapState("WeaponDeselect");
	}
		action void A_ForwardToFire()
	{
		A_SetWeapState("WeaponFire");
	}
	
	...
Child Class: XRpgFWeapRazor

Code: Select all

class XRpgFWeapRazor : XRpgFighterShieldWeapon replaces CentaurSword
{
	Default
	{
		+BLOODSPLATTER
		Weapon.SelectionOrder 900;
		+WEAPON.AXEBLOOD +WEAPON.AMMO_OPTIONAL +WEAPON.MELEEWEAPON
		Weapon.KickBack 150;
		Inventory.PickupMessage "$TXT_WEAPON_RAZOR";
		Obituary "$OB_MPFWEAPRAZOR";
		Tag "$TAG_FWEAPRAZOR";
		Inventory.MaxAmount 1;

        XRpgFighterWeapon.Pufftype "AxePuff";
        XRpgFighterWeapon.WeaponRange 2.0 * DEFMELEERANGE;
        XRpgFighterWeapon.MeleePush 0;
        XRpgFighterWeapon.MeleeAdjust true;
	}

	States
	{
	Spawn:
		CTDP KLMNOPQ 3;
		CTDP R 4;
		CTDP S 4;
		CTDP T -1;
		Stop;
	Select:
	WeaponSelect:
		FRZR A 1 A_Raise;
		Loop;
	Deselect:
	WeaponDeselect:
		FRZR A 1 A_Lower;
		Loop;
	Ready:
	WeaponReady:
		FRZR A 1 A_WeaponReady;
		Loop;
	Fire:
	WeaponFire:
		FRZR B 2 Offset (5, 0);
		FRZR B 4 Offset (5, 0) A_CheckBerserk(false);
		FRZR C 1 Offset (5, 0) A_FWeaponMelee(10, 30, -25, 0.35);
		FRZR C 1 Offset (5, 0) A_FWeaponMelee(10, 30, 0, 0.35);
		FRZR C 1 Offset (5, 0) A_FWeaponMelee(10, 30, 25, 0.35);
		FRZR D 3 Offset (5, 0);
		FRZR E 2 Offset (5, 0);
		FRZR E 10 Offset (5, 150);
		FRZR A 1 Offset (0, 60);
		FRZR A 1 Offset (0, 55);
		FRZR A 1 Offset (0, 50);
		FRZR A 1 Offset (0, 45);
		FRZR A 1 Offset (0, 40);
		FRZR A 1 Offset (0, 35);
		FRZR A 1;
		Goto Ready;
	BerserkFire:
		FRZR C 1 Offset (5, 0) A_FWeaponMelee(10, 30, -25, 0.35);
		FRZR C 1 Offset (5, 0) A_FWeaponMelee(10, 30, 0, 0.35);
		FRZR C 1 Offset (5, 0) A_FWeaponMelee(10, 30, 25, 0.35);
		FRZR D 2 Offset (5, 0);
		FRZR E 2 Offset (5, 0);
		FRZR E 4 Offset (5, 150);
		FRZR A 1 Offset (0, 60);
		FRZR A 1 Offset (0, 55);
		FRZR A 1 Offset (0, 50);
		FRZR A 1 Offset (0, 45);
		FRZR A 1 Offset (0, 40);
		FRZR A 1 Offset (0, 35);
		FRZR A 1;
		Goto Ready;
	AltFire:
		Goto ShieldFrameAltFire;
	ShieldSpikedFire:
		Goto ShieldFrameShieldSpikedFire;
    AltHold:
		Goto ShieldFrameAltHold;
	ShieldSpikedHold:
		Goto ShieldFrameShieldSpikedHold;
	ShieldKiteFire:
		Goto ShieldFrameShieldKiteFire;
	ShieldKiteHold:
		Goto ShieldFrameShieldKiteHold;
    ShieldCharged:
		Goto ShieldFrameShieldCharged;
    ShieldFireFinish:
		Goto ShieldFrameShieldFireFinish;
	FistFire:
		Goto ShieldFrameFistFire;
	}
}
User avatar
Jekyll Grim Payne
 
 
Posts: 1076
Joined: Mon Jul 21, 2008 4:08 am
Preferred Pronouns: He/Him
Graphics Processor: nVidia (Modern GZDoom)
Contact:

Re: Weapon that inherits from weapon with States not going to ready

Post by Jekyll Grim Payne »

Goto is a static jump, and it jumps within the actor, not aware of whether it's being used or not. Once the child class goes to the parent class' state, goto from the parent state will move within the parent.

Use dynamic jump functions instead, like TNT1 A 0 { return ResolveState("Ready"); } to make it return within the currently used weapon. See here: https://jekyllgrim.github.io/ZScript_Ba ... nheritance
Post Reply

Return to “Scripting”