Animated weapon Raise

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!)
Ninlhil
Posts: 52
Joined: Mon Mar 02, 2015 11:47 pm

Animated weapon Raise

Post by Ninlhil »

I'm working on a Flamerthrower weapon for a Mod I'm working on, but I'm having trouble with some aspects. When selected, I want the flamer to raise into position and then for a pilot light to flash on. So far, all I've managed to get is a bit of the raise, the pilot light animation and then the raise finishes. Any help and insight with the scripting would be greatly appreciated.
Jarewill
 
 
Posts: 1766
Joined: Sun Jul 21, 2019 8:54 am

Re: Animated weapon Raise

Post by Jarewill »

What can be done, and what most mods do, is put the actual pickup animation in the Ready state and the actual Ready state in a separate state.
For example:

Code: Select all

  Select:
    SHTG A 1 A_Raise
    Loop
  Ready: //Pickup animation
    SHTG ABCDCB 4
    Goto Ready2
  Ready2: //The actual Ready state, make all your other states (such as Fire) go here instead
    SHTG A 1 A_WeaponReady
    Loop
User avatar
Enjay
 
 
Posts: 26534
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland
Contact:

Re: Animated weapon Raise

Post by Enjay »

Which is, of course, a good method. But remember that any other state sequences that normally end with "goto ready" should have "goto ready2" instead, unless you want the animation to be repeated after firing etc.
User avatar
Logan MTM
Posts: 678
Joined: Mon Jan 16, 2006 8:53 pm
Location: Rio de Janeiro - Brazil

Re: Animated weapon Raise

Post by Logan MTM »

Crazzy tip from dumb modder:
I usually do all frames as Custom States. Every single one.

Code: Select all

Ready:
FRAM ABCD A_WeaponReady
Loop
Becomes:

Code: Select all

Ready:
ReadyLoop:
ReadyLoopA:
FRAM A A_WeaponReady
ReadyLoopB:
FRAM B A_WeaponReady
ReadyLoopC:
FRAM C A_WeaponReady
ReadyLoopD:
FRAM D A_WeaponReady
Goto ReadyLoop
User avatar
MartinHowe
Posts: 2022
Joined: Mon Aug 11, 2003 1:50 pm
Location: Waveney, United Kingdom
Contact:

Re: Animated weapon Raise

Post by MartinHowe »

It's been a long time since I looked at it due to an ongoing attack of RL, but the MaiowSpeak fake smartphone app in the Black Cats mod does this sort of thing. You are welcome to rip and mess about with the code from that 'weapon' if you like. (I will return to finish the mod, but until some distressing family matters are fully settled, my life isn't truly my own).
Ninlhil
Posts: 52
Joined: Mon Mar 02, 2015 11:47 pm

Re: Animated weapon Raise

Post by Ninlhil »

These solved my problem, thanks much. Now just have a new one.

https://youtu.be/_LZOzJLFSJ8

So I've run into a strange hiccup here where the Flamer gets stuck on one frame, but ONLY when the ammo count is 10 or less. I think this is the offending bit of code...

Code: Select all

	AltFire:
		FFTR A 0 A_JumpIf(waterlevel>= 2,"NoWay");
		FFTR A 0 A_JumpIfInventory("PyrolightLoaded",10,1);
		Goto Dryfire;
So now I can't figure out how to get it to return to the ready animation cycle when it has less than 10 ammo units. Any ideas?
Jarewill
 
 
Posts: 1766
Joined: Sun Jul 21, 2019 8:54 am

Re: Animated weapon Raise

Post by Jarewill »

I have no idea from that snippet, seeing the entire code would help to find the issue.
Ninlhil
Posts: 52
Joined: Mon Mar 02, 2015 11:47 pm

Re: Animated weapon Raise

Post by Ninlhil »

Ah, ok. Its the basic code from Blade of Agony.
Spoiler:
Jarewill
 
 
Posts: 1766
Joined: Sun Jul 21, 2019 8:54 am

Re: Animated weapon Raise

Post by Jarewill »

Here's the problem I think:

Code: Select all

   Ready2:
      FFTR A 0 A_JumpIfInventory("PyrolightLoaded",10,4);
      FFTR A 0 A_JumpIfInventory("FlameAmmo",1,2);
      FFTR A 1 A_WeaponReady(WRF_NOSECONDARY); //<--- This....
      Loop;
      FFTR A 1 A_WeaponReady(WRF_ALLOWRELOAD|WRF_NOSECONDARY); //<--- ....And this states happen if the weapon has less than 10 ammo, and only show a single frame of animation
      Loop;
Ninlhil
Posts: 52
Joined: Mon Mar 02, 2015 11:47 pm

Re: Animated weapon Raise

Post by Ninlhil »

Jarewill wrote:Here's the problem I think:

Code: Select all

   Ready2:
      FFTR A 0 A_JumpIfInventory("PyrolightLoaded",10,4);
      FFTR A 0 A_JumpIfInventory("FlameAmmo",1,2);
      FFTR A 1 A_WeaponReady(WRF_NOSECONDARY); //<--- This....
      Loop;
      FFTR A 1 A_WeaponReady(WRF_ALLOWRELOAD|WRF_NOSECONDARY); //<--- ....And this states happen if the weapon has less than 10 ammo, and only show a single frame of animation
      Loop;

S̶o̶ ̶I̶ ̶d̶o̶n̶'̶t̶ ̶i̶m̶a̶g̶i̶n̶e̶ ̶t̶h̶a̶t̶ ̶s̶i̶m̶p̶l̶y̶ ̶r̶e̶m̶o̶v̶i̶n̶g̶ ̶t̶h̶e̶m̶ ̶w̶o̶u̶l̶d̶ ̶d̶o̶ ̶g̶o̶o̶d̶ ̶t̶h̶i̶n̶g̶s̶,̶ ̶s̶o̶ ̶c̶o̶u̶l̶d̶ ̶I̶ ̶p̶u̶t̶ ̶t̶h̶e̶ ̶4̶ ̶f̶r̶a̶m̶e̶s̶ ̶i̶n̶ ̶t̶h̶o̶s̶e̶ ̶s̶l̶o̶t̶s̶ ̶w̶i̶t̶h̶ ̶t̶h̶e̶ ̶l̶o̶o̶p̶?̶

Well, that got the animation into the place it needs, but disabled the secondary fire...
Jarewill
 
 
Posts: 1766
Joined: Sun Jul 21, 2019 8:54 am

Re: Animated weapon Raise

Post by Jarewill »

You might also need to edit the jump offsets.
So if you added 3 more frames of animation to each of the A_WeaponReady states, the first two jumps would look like this:

Code: Select all

      FFTR A 0 A_JumpIfInventory("PyrolightLoaded",10,10); //4 previous jump + 6 (3 + 3) added frames
      FFTR A 0 A_JumpIfInventory("FlameAmmo",1,5); //2 previous jump + 3 added frames  
User avatar
ramon.dexter
Posts: 1529
Joined: Tue Oct 20, 2015 12:50 pm
Graphics Processor: nVidia with Vulkan support
Location: Kozolupy, Bohemia

Re: Animated weapon Raise

Post by ramon.dexter »

...Or avoid using numbered jumps and make properly names states, which is reasonable better than numbered state jumps.
Ninlhil
Posts: 52
Joined: Mon Mar 02, 2015 11:47 pm

Re: Animated weapon Raise

Post by Ninlhil »

Jarewill wrote:You might also need to edit the jump offsets.
So if you added 3 more frames of animation to each of the A_WeaponReady states, the first two jumps would look like this:

Code: Select all

      FFTR A 0 A_JumpIfInventory("PyrolightLoaded",10,10); //4 previous jump + 6 (3 + 3) added frames
      FFTR A 0 A_JumpIfInventory("FlameAmmo",1,5); //2 previous jump + 3 added frames   
That actually worked pretty well. Thanks.
User avatar
Jekyll Grim Payne
 
 
Posts: 1071
Joined: Mon Jul 21, 2008 4:08 am
Preferred Pronouns: He/Him
Graphics Processor: nVidia (Modern GZDoom)
Contact:

Re: Animated weapon Raise

Post by Jekyll Grim Payne »

Ninlhil wrote:I'm working on a Flamerthrower weapon for a Mod I'm working on, but I'm having trouble with some aspects. When selected, I want the flamer to raise into position and then for a pilot light to flash on. So far, all I've managed to get is a bit of the raise, the pilot light animation and then the raise finishes. Any help and insight with the scripting would be greatly appreciated.
If you want to do a completely custom raise animation, you can simply do this:

Code: Select all

Select:
	FRAM ABCDEF 1; //this is meant to be your custom animation
	TNT1 A 0 A_Raise;
	wait; //this will loop the previous frame, resulting in instantl jump to Ready
This is the simplest approach. Yes, it's totally fine to loop a 0-tic state with an A_Raise call, because that call contains an unconditional jump to Ready. There's no reason to add more state sequences and I recommend avoiding that.

Moreover, if your weapon is already at its default offsets (0,32), then you can simply call goto ready and do nothing else. Calling A_Raise is not a requirement.

Note, when the weapon is deselected, it's offset below the screen. You can use [wiki]A_WeaponOffset[/wiki] to move it any way you want around the screen. You can also use A_WeaponReady(WRF_NOFIRE) to let the player switch the weapon during the selection animation, like in vanilla.

Here's an example of a simple custom animation where the gun is moved from the side instead of raising vertically:

Code: Select all

		Select:
			TNT1 A 0 A_Weaponoffset(30.0,67.0); //move the gun to a fixed position at the bottom right
			RIFN AAAAAAA 1 
			{
				A_WeaponOffset(-4.0,-5.0,WOF_ADD); //move the gun up and left
				A_WeaponReady(WRF_NOFIRE|WRF_NOBOB); //allow the player to interrupt the animation and select a different weapon
			}
			// At this point the sprite is already at 0, 32, so I don't need to call A_Raise, I simply move to Ready:
			goto ready;
As for the pilot light, I recommend using [wiki]A_Overlay[/wiki] and drawing it on a separate layer. You can then handle the delay on that layer.
User avatar
Sir Robin
Posts: 537
Joined: Wed Dec 22, 2021 7:02 pm
Graphics Processor: Intel (Modern GZDoom)
Location: Medellin, Colombia

Re: Animated weapon Raise

Post by Sir Robin »

Jekyll Grim Payne wrote:

Code: Select all

Select:
	FRAM ABCDEF 1; //this is meant to be your custom animation
	TNT1 A 0 A_Raise;
	wait; //this will loop the previous frame, resulting in instantl jump to Ready
Hi, I'm also trying to make weapons with custom raise and lower animations.

First issue with my weapons is that the sprites look perfect when I view them in Slade with HUD offsets, but in game they are much lower. I've found that if I put Weapon.YAdjust -32 in the defaults block then they look right in fullscreen but still way too low with a status bar. How to fix that?

So I tried following your example and animating them this way:

Code: Select all

	Ready:
		UWAA A 1 A_WeaponReady;
		Loop;
	Deselect:
		UWAA ANO 4;
		TNT1 ] 0 A_Lower;
		wait;
	Select:
		UWAA ONA 4;
		TNT1 ] 0 A_Raise;
		wait;
The deselect works but the select does not. There is a pause though so maybe it's playing off screen.

So then I tried it the other way you suggested

Code: Select all

	Ready:
		UWAA A 1 A_WeaponReady;
		Loop;
	Deselect:
		TNT1 ] 0 A_WeaponOffset(0,0);
		UWAA ANO 8 A_WeaponReady(WRF_NOFIRE|WRF_NOBOB);
		goto Ready;
	Select:
		TNT1 ] 0 A_WeaponOffset(0,0);
		UWAA ONA 8 A_WeaponReady(WRF_NOFIRE|WRF_NOBOB);
		goto Ready;
Now the select works but then the weapon freezes, can't fire and can't switch it for another weapon
Post Reply

Return to “Scripting”