Creating a "parent weapon" for several weapons

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!)
User avatar
wildweasel
Posts: 21706
Joined: Tue Jul 15, 2003 7:33 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): A lot of them
Graphics Processor: Not Listed
Contact:

Re: Creating a "parent weapon" for several weapons

Post by wildweasel »

A_Overlay works like the Flash state, just that you can tell it to use any state you want, and layer them however you wish. So move the code for your kick attack into its own state, and then specify that state's label with A_Overlay.

Here is some pseudocode:

Code: Select all

BootToTheHead:
   KICK A 5
   KICK B 5 A_CustomPunch(a lot of damage)
   KiCK A 5
   Stop

ToMakeThatHappen:
   "####" "#" 1 A_Overlay(2, "BootToTheHead")
Kzer-Za
Posts: 521
Joined: Sat Aug 19, 2017 11:52 pm
Graphics Processor: nVidia (Modern GZDoom)

Re: Creating a "parent weapon" for several weapons

Post by Kzer-Za »

Aha, lowering the weapon before the kick, and the kick itself now work. But following the kick I still lose the weapon sprites, which I need to raise it. The code is this now:

Code: Select all

	Kicking:
		"----" A 1 A_WeaponOffset(0,42);
		"----" A 1 A_WeaponOffset(0,52);
		"----" A 1 A_WeaponOffset(0,62);
		"----" A 1 A_WeaponOffset(0,72);
		"----" A 1 A_WeaponOffset(0,82);

		"----" A 0 A_Overlay(1, "KickingLoop");

		"----" A 1 A_WeaponOffset(0,82);
		"----" A 1 A_WeaponOffset(0,72);
		"----" A 1 A_WeaponOffset(0,62);
		"----" A 1 A_WeaponOffset(0,52);
		"----" A 1 A_WeaponOffset(0,42);
		"----" A 0 A_WeaponOffset(0,32);
		Goto Ready;
	KickingLoop:
		TNT1 A 0 A_PlaySound("WHOP");
		CKCK ABCD 2;
		TNT1 A 0 A_CustomPunch(25,true,0,"BrutalKickPuff", 104);
		CKCK E 4;
		CKCK DCB 2;
		CKCK AA 1 A_WeaponReady(WRF_NOSECONDARY);
		TNT1 AAA 1 A_WeaponReady(WRF_NOSECONDARY);
		TNT1 A 0 A_JumpIfInventory("Action1",1,"KickingLoop");
Obviously, following the kick, the last sprite used is TNT1. Even if I used CKCK with 0 duration as the last sprite in the KickingLoop, that would just make the last sprite CKCK.
Also, the first kick acts as if it has an offset raising it above its usual level vertically, but if I keep the kick button pressed, the rest of the kicks are on the normal level.

Upd: well, the issue with the first kick offset I fixed by changing the first line of the KickingLoop into

Code: Select all

TNT1 A 0 Offset(0,32) A_PlaySound("WHOP");
Kzer-Za
Posts: 521
Joined: Sat Aug 19, 2017 11:52 pm
Graphics Processor: nVidia (Modern GZDoom)

Re: Creating a "parent weapon" for several weapons

Post by Kzer-Za »

So it seems I will need string variables after all. So could someone please explain how am I supposed to declare variables in zscript? This isn't working:

Code: Select all

Class HLParent : HereticWeapon
{
Default
{
}
String CurSprtName = "something";
GZDoom gives this:

Code: Select all

Script error, ":zscript.weap_hlparent"line 6:
Unexpected '='
Expecting ';' or ','
User avatar
Matt
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia
Contact:

Re: Creating a "parent weapon" for several weapons

Post by Matt »

Unfortunately you can't define variables on startup like that, it has to be added in an actor's PostBeginPlay/BeginPlay function or using a custom property.
Kzer-Za
Posts: 521
Joined: Sat Aug 19, 2017 11:52 pm
Graphics Processor: nVidia (Modern GZDoom)

Re: Creating a "parent weapon" for several weapons

Post by Kzer-Za »

Okay, so now I have

Code: Select all

Class HLParent : HereticWeapon
{
String CurSprtName;
property CurSprtName: CurSprtName;
Default
{
HLParent.CurSprtName "something";
}
But when I put it in place of the sprite:

Code: Select all

	Kicking:
		CurSprtName A 1 A_WeaponOffset(0,42);
I get

Code: Select all

:zscript.weap_hlparent, line 25: Sprite name must be exactly 4 characters. Found 'CurSprtName'
It doesn't say Found 'something', as I expected, it says Found 'CurSprtName', which means that it's taken not as a variable.
User avatar
Matt
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia
Contact:

Re: Creating a "parent weapon" for several weapons

Post by Matt »

Can't use variable pointers that way in the frame definitions either - sorry, there's a lot of stuff that's inherited from the way Decorate works (which was inherited from the way DeHacked works) that might not be obvious.

Try (untested)

Code: Select all

	Kicking:
		TNT1 A 0 {player.GetPSprite(PSP_WEAPON).CurState.sprite=GetSpriteIndex(invoker.CurSprtName);}
		---- A 1 A_WeaponOffset(0,42);
Kzer-Za
Posts: 521
Joined: Sat Aug 19, 2017 11:52 pm
Graphics Processor: nVidia (Modern GZDoom)

Re: Creating a "parent weapon" for several weapons

Post by Kzer-Za »

I have tried it, copied your code as is, and the engine gives

Code: Select all

Script error, ":zscript.weap_hlparent" line 25:
Expression must be a modifiable value
Line 25 is the line with

Code: Select all

{player.GetPSprite(PSP_WEAPON).CurState.sprite=GetSpriteIndex(invoker.CurSprtName);}
User avatar
Matt
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia
Contact:

Re: Creating a "parent weapon" for several weapons

Post by Matt »

Whoops, meant:

Code: Select all

{player.GetPSprite(PSP_WEAPON).sprite=GetSpriteIndex(invoker.CurSprtName);}
without the ".CurState".
Kzer-Za
Posts: 521
Joined: Sat Aug 19, 2017 11:52 pm
Graphics Processor: nVidia (Modern GZDoom)

Re: Creating a "parent weapon" for several weapons

Post by Kzer-Za »

Yes, with that GZDoom launched, but the problem with the absent sprite persisted :(

Well, after trying that I've been twiddling with the code almost at random, and found something that almost works:

Code: Select all

	Ready:
		"----" A 0 A_JumpIfInventory("Action1",1,"Kicking");
		"----" A 1 A_WeaponReady;
		Loop;
	Fire:
	Select:
		"----" A 0 A_Raise;
		"----" A 1 A_Raise;
		Loop;
	Deselect:
		"----" A 0 A_Lower;
		"----" A 1 A_Lower;
		Loop;
	Kicking:
		"----" A 1 Offset(0,42);
		"----" A 1 Offset(0,52);
		"----" A 1 Offset(0,62);
		"----" A 1 Offset(0,72);
		"----" A 1 Offset(0,82);
	KickingLoop:
		TNT1 A 0 Offset(0,32) A_PlaySound("WHOP");
		CKCK ABCD 2;
		TNT1 A 0 A_CustomPunch(25,true,0,"BrutalKickPuff", 104);
		CKCK E 4;
		CKCK DCB 2;
		CKCK AA 1 A_WeaponReady(WRF_NOSECONDARY);
		TNT1 AAA 1 A_WeaponReady(WRF_NOSECONDARY);
		TNT1 A 0 A_JumpIfInventory("Action1",1,"KickingLoop");
		"----" A 0 A_Overlay(1, "Ready");
Although why the heck it works when "----" in the last line should stand fot TNT1, I have no idea. (And replacing the last line with Goto Ready or Goto Select leads to the sprite being absent).

Unfortunately, the weapon is drawn instantly, not raising from the lower edge of the screen, as it should. The same is with specifying Select as the state in the last line. I tried defining a state Raise with gradually raising weapon and going to it in the last line instead:

Code: Select all

		...
		"----" A 0 A_Overlay(1, "Raise");
	Raise:
		"----" A 1 Offset(0,82);
		"----" A 1 Offset(0,72);
		"----" A 1 Offset(0,62);
		"----" A 1 Offset(0,52);
		"----" A 1 Offset(0,42);
		"----" A 0 Offset(0,32);
But this doesn't work, weapon sprite is not displayed. It is drawn only if in A_Overlay I specify Ready or Select.
Kzer-Za
Posts: 521
Joined: Sat Aug 19, 2017 11:52 pm
Graphics Processor: nVidia (Modern GZDoom)

Re: Creating a "parent weapon" for several weapons

Post by Kzer-Za »

I realized something. When I use "Goto state" inside HLParent file, it goes to the state defined in HLParent file. But when I invoke A_Overlay(1, "State"), it goes staright to the state of the weapon which the Kicking was called from. So with A_Overlay(1, "Ready") it goes to the Ready state of the Goldwand, if I was using the Goldwand at the moment of kicking. That is why the weapon in the case of Goto is not drawn, and with A_Overlay is drawn correctly.

So I decided to put this in all weapons, it's still less code in separate weapons and more code in the parent:

Code: Select all

	Sprite:
		GWND A 0
		Goto Postkick
(With Sprite being called from A_Overlay in the end of the Kickingloop instead of Ready).

And this in the HLParent:

Code: Select all

	Postkick:
		"----" A 1 Offset(0,82);
		"----" A 1 Offset(0,72);
		"----" A 1 Offset(0,62);
		"----" A 1 Offset(0,52);
		"----" A 1 Offset(0,42);
		"----" A 1 Offset(0,32);
		Goto Ready;
And it almost works... Except I now noticed that "----" in HLParent draws not exatly the sprite used by the weapon itself. The thing is, I use Hi-Res pack with new weapon models. But "----" in HLParent draws not the new GWND, for example, but the original one (the same story with other weapons). I did not notice it before because it was drawn only while the weapon was lowered, but now it is properly raised and stays on screen, and it's the old, original Heretic HUD sprites. As soon as I start firing, they are replaced with the new weapon models, but while lowering, raising and just being ready after the kick, i.e. in all states defined in HLParent, it's old sprites. How and why?
User avatar
Matt
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia
Contact:

Re: Creating a "parent weapon" for several weapons

Post by Matt »

At this point I don't think we can do this piecemeal back-and-forth fruitfully - it's best to do a standalone simple weapon that demonstrates the principle (and which I've also tested to get rid of silly formatting, etc. mistakes).

Code: Select all

class testwep:weapon{
    spriteid cursprite; //get rid of all the "CurSprtName" stuff
    states{
    select:
        TNT1 A 0 A_Raise();
        wait;
    deselect:
        TNT1 A 0 A_Lower();
        wait;
    ready:
        PISG A 1 A_WeaponReady();
        wait;
    fire:
        ---- A 0{
            invoker.cursprite=player.getpsprite(PSP_WEAPON).sprite;
        }
        ---- A 5 offset(0,32); //obviously should be smoother in the final
        ---- A 5 offset(0,42);
        ---- A 5 offset(0,62);
        TNT1 A 30; //kick goes here
        TNT1 A 0{
            player.getpsprite(PSP_WEAPON).sprite=invoker.cursprite;
        }
        ---- A 5 offset(0,62);
        ---- A 5 offset(0,42);
        ---- A 5 offset(0,32);
        ---- A 0 A_Jump(256,"ready"); //do *NOT* use goto here or it will go to parent weapon's state!
    }
}
class testwep2:testwep{
    states{
    ready:
        SHTG A 1 A_WeaponReady();
        wait;
    }
} 
Kzer-Za
Posts: 521
Joined: Sat Aug 19, 2017 11:52 pm
Graphics Processor: nVidia (Modern GZDoom)

Re: Creating a "parent weapon" for several weapons

Post by Kzer-Za »

Thanks! That works, but could you explain what testwep2 is doing?

Could you also, please, advise me on the issue with 3D models of HUD weapons? That is, "----" is being replaced with old sprites. I have Modeldef.Heretic.HUD.txt and all new HUD 3D models of weapons are described there. By the example of the Goldwand:

Code: Select all

Model BrutalGoldWand 
{
	Path "Models\HUD\GoldWand"
	
	Model 0 Goldwand.md2
	Skin 0 Goldwand.png
	
	PitchOffset 0
	Offset 0 4 0
	Scale 1 1 1

	Frameindex GWND A 0 0
	Frameindex GWND B 0 3
}
Yesterday I wrote that the problem with "----" was pertaining to the parent weapon, but I tested it, and it turns out that it goes for states described within a single weapon actor as well. Frames, for which GWND is specified directly by its name, are drawn using the model; the frames, for which "----" (or "####") were used, are drawn using sprites.

The example with the Goldwand I'm going to attach. The first picture is the new model, the second is taken during one of the frames specified with "----".
Attachments
2019-02-02_13-25-34.png
2019-02-02_13-25-37.png
User avatar
wildweasel
Posts: 21706
Joined: Tue Jul 15, 2003 7:33 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): A lot of them
Graphics Processor: Not Listed
Contact:

Re: Creating a "parent weapon" for several weapons

Post by wildweasel »

This almost seems more like a bug or oversight in MODELDEF's implementation, and not something that'd be your fault, either. It might be worth putting together a simple example file to submit in a bug report.
Kzer-Za
Posts: 521
Joined: Sat Aug 19, 2017 11:52 pm
Graphics Processor: nVidia (Modern GZDoom)

Re: Creating a "parent weapon" for several weapons

Post by Kzer-Za »

I created a topic in the Bugs section of the forum. Is it the proper way to report bugs in this project? I don't see the Issues tab on https://github.com/coelckers/gzdoom
User avatar
wildweasel
Posts: 21706
Joined: Tue Jul 15, 2003 7:33 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): A lot of them
Graphics Processor: Not Listed
Contact:

Re: Creating a "parent weapon" for several weapons

Post by wildweasel »

Kzer-Za wrote:I created a topic in the Bugs section of the forum. Is it the proper way to report bugs in this project? I don't see the Issues tab on https://github.com/coelckers/gzdoom
Yes, the forum is the preferred method of bug tracking. We'd tried a proper bug tracker before, but people weren't keeping tabs on their reports, and many bug reports that needed additional feedback were being abandoned. It was determined that the forum was a better way to keep track of them.
Post Reply

Return to “Scripting”