A_JumpIf Crouched?

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
TheGameratorT
Posts: 63
Joined: Sun Mar 04, 2018 4:42 am
Graphics Processor: nVidia with Vulkan support
Location: Portugal

A_JumpIf Crouched?

Post by TheGameratorT »

I wonder if it's possible to make a JumpIf if the player is crouching.
User avatar
gwHero
Posts: 360
Joined: Mon May 08, 2017 3:23 am
Graphics Processor: Intel with Vulkan/Metal Support
Location: The Netherlands

Re: A_JumpIf Crouched?

Post by gwHero »

Yes it is:

Code: Select all

TNT1 A 0 A_JumpIf(GetPlayerInput(INPUT_BUTTONS) & BT_CROUCH, "Crouching");
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

Re: A_JumpIf Crouched?

Post by Matt »

Or A_JumpIf(height<40,"Crouching")
(There's a more complicated alternative that directly accesses the player's status but I don't remember it off the top of my head)

Checking for player input won't catch those few people who use toggle-crouch.
User avatar
gwHero
Posts: 360
Joined: Mon May 08, 2017 3:23 am
Graphics Processor: Intel with Vulkan/Metal Support
Location: The Netherlands

Re: A_JumpIf Crouched?

Post by gwHero »

Matt wrote:Or A_JumpIf(height<40,"Crouching")
(There's a more complicated alternative that directly accesses the player's status but I don't remember it off the top of my head)

Checking for player input won't catch those few people who use toggle-crouch.
I indeed never used toggle crouch. Yes, your solution should also work, but I guess you mean the ViewHeight?
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

Re: A_JumpIf Crouched?

Post by Matt »

I mean height. After all, making your hitbox smaller to avoid incoming fire or to get under map geometry is the main point of crouching.

EDIT: And of course that 40 could be higher or lower depending on whether you want this to kick in sooner or later.
User avatar
comet1337
Posts: 876
Joined: Fri Sep 25, 2015 3:48 am
Location: elsewhere

Re: A_JumpIf Crouched?

Post by comet1337 »

getcrouchfactor() < 1.0 ?
User avatar
TheGameratorT
Posts: 63
Joined: Sun Mar 04, 2018 4:42 am
Graphics Processor: nVidia with Vulkan support
Location: Portugal

Re: A_JumpIf Crouched?

Post by TheGameratorT »

The crouching works very well, the A_JumpIf(height<40, "Crouching") :D Thx

Also on ZScript is there any way to check actor velocity all the time and if the value is 1 to jump to another state?
Because vel.x>1 and vel.y>1 sometimes fail because it needs to go in certain directions.
User avatar
Arctangent
Posts: 1235
Joined: Thu Nov 06, 2014 1:53 pm

Re: A_JumpIf Crouched?

Post by Arctangent »

In ZScript, vel is a vector. This means you can call its Length() function to get the non-directional speed an actor is moving at, rather than calculating that yourself through the distance formula.
User avatar
TheGameratorT
Posts: 63
Joined: Sun Mar 04, 2018 4:42 am
Graphics Processor: nVidia with Vulkan support
Location: Portugal

Re: A_JumpIf Crouched?

Post by TheGameratorT »

Could you explain me how to do that please?

Also could you explain why this doesn't work:

Code: Select all

BNNY A 1 { bNoTarget = true; }
?
User avatar
Caligari87
Admin
Posts: 6209
Joined: Thu Feb 26, 2004 3:02 pm
Preferred Pronouns: He/Him

Re: A_JumpIf Crouched?

Post by Caligari87 »

Code: Select all

if(vel.length() > 1)
8-)
User avatar
TheGameratorT
Posts: 63
Joined: Sun Mar 04, 2018 4:42 am
Graphics Processor: nVidia with Vulkan support
Location: Portugal

Re: A_JumpIf Crouched?

Post by TheGameratorT »

Code: Select all

		BonnieStand:
			BNNY A 1
			{
				if(vel.length() > 1)
				{
					Goto BonnieWalk;
				}
			}
			Loop;
		BonnieWalk:
			BONY ABCDE 1;
			TNT1 A 0 A_PlaySound("pstepm",0,1.0);
			BONY FGHIJKLMNOPQ 1;
			TNT1 A 0 A_PlaySound("pstepm",0,1.0);
			BONY RSTUVWXY 1;
			Loop;
How can I do something like this for example?

(Sorry for being annoying but I'm really new with this :|)
User avatar
gwHero
Posts: 360
Joined: Mon May 08, 2017 3:23 am
Graphics Processor: Intel with Vulkan/Metal Support
Location: The Netherlands

Re: A_JumpIf Crouched?

Post by gwHero »

To be honest, it can be a bit confusing in the beginning, because of the old "Decorate" syntax and the new ZScript possibilities, which can be combined.
You can achieve this in several ways.

Example 1 (more classic way):

Code: Select all

    BonnieStand:
         BNNY A 1 A_JumpIf(vel.length() > 1, "BonnieWalk");
         Loop;
    BonnieWalk:
   etc...
Example 2(inline Zscript code):

Code: Select all

      BonnieStand:
         BNNY A 1
         {
          if(vel.length() > 1)
				return ResolveState("BonnieWalk"); 
			else
				return ResolveState(null); // nojump
         }
         Loop;
    BonnieWalk:
   etc...
User avatar
TheGameratorT
Posts: 63
Joined: Sun Mar 04, 2018 4:42 am
Graphics Processor: nVidia with Vulkan support
Location: Portugal

Re: A_JumpIf Crouched?

Post by TheGameratorT »

Thanks :)

Return to “Scripting”