Weapon sprint animation state/script?

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
User avatar
body_cleaner666
Posts: 7
Joined: Thu Aug 03, 2023 7:02 am
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10
Graphics Processor: Intel (Modern GZDoom)
Location: Russian Federation

Weapon sprint animation state/script?

Post by body_cleaner666 »

Good day, everyone. I'm a newbie in this modding, and at one day I got an idea to add to all my guns sprint animation when player holds shift button (and when moving), but I have no clue how to realize this feature. How I can do this? And if possible, will it work only for Decorate type?
User avatar
body_cleaner666
Posts: 7
Joined: Thu Aug 03, 2023 7:02 am
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10
Graphics Processor: Intel (Modern GZDoom)
Location: Russian Federation

Re: Weapon sprint animation state/script?

Post by body_cleaner666 »

Uh, excuse me, somebody here? I just really need some help here, please!
User avatar
Caligari87
Admin
Posts: 6233
Joined: Thu Feb 26, 2004 3:02 pm
Preferred Pronouns: He/Him
Contact:

Re: Weapon sprint animation state/script?

Post by Caligari87 »

Do not bump or double-post. If someone is able and willing to help you, they will.

It may help to post an example of your existing weapon code.

8-)
User avatar
Alfred Don
Posts: 45
Joined: Mon Aug 01, 2022 11:52 am
Contact:

Re: Weapon sprint animation state/script?

Post by Alfred Don »

body_cleaner666 wrote: Thu Aug 03, 2023 7:21 am Good day, everyone. I'm a newbie in this modding, and at one day I got an idea to add to all my guns sprint animation when player holds shift button (and when moving), but I have no clue how to realize this feature. How I can do this? And if possible, will it work only for Decorate type?
You could check the player's momentum with the decorate variables and jump to another state.
Jarewill
 
 
Posts: 1853
Joined: Sun Jul 21, 2019 8:54 am

Re: Weapon sprint animation state/script?

Post by Jarewill »

You can also use GetPlayerInput for this:
A_JumpIf(GetPlayerInput(MODINPUT_BUTTONS,-1)&BT_SPEED,"SprintState")
User avatar
body_cleaner666
Posts: 7
Joined: Thu Aug 03, 2023 7:02 am
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10
Graphics Processor: Intel (Modern GZDoom)
Location: Russian Federation

Re: Weapon sprint animation state/script?

Post by body_cleaner666 »

Jarewill wrote: Mon Aug 07, 2023 11:36 am You can also use GetPlayerInput for this:
A_JumpIf(GetPlayerInput(MODINPUT_BUTTONS,-1)&BT_SPEED,"SprintState")
Thank you, but how I can make when player not moves (but still can hold shift button), animation/different gun position won't animate?

And for everyone, thank you for remarks and sorry for double-post.. and if something wrong will go, I'll post my weapon code here.
User avatar
openroadracer
Posts: 496
Joined: Mon Sep 23, 2019 1:03 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): SteamOS
Graphics Processor: ATI/AMD with Vulkan/Metal Support
Location: SES Flame of Liberty
Contact:

Re: Weapon sprint animation state/script?

Post by openroadracer »

body_cleaner666 wrote: Mon Aug 07, 2023 10:45 pmThank you, but how I can make when player not moves (but still can hold shift button), animation/different gun position won't animate?

And for everyone, thank you for remarks and sorry for double-post.. and if something wrong will go, I'll post my weapon code here.
I have no coding knowledge whatsoever, but I'd say that you'd need to run two checks, one after the other. Put the input check first; then, if it comes back "true", go to the velocity check; if it comes back with a high enough speed, it changes the animation state of the weapon.
User avatar
body_cleaner666
Posts: 7
Joined: Thu Aug 03, 2023 7:02 am
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10
Graphics Processor: Intel (Modern GZDoom)
Location: Russian Federation

Re: Weapon sprint animation state/script?

Post by body_cleaner666 »

openroadracer wrote: Tue Aug 08, 2023 7:01 am
body_cleaner666 wrote: Mon Aug 07, 2023 10:45 pmThank you, but how I can make when player not moves (but still can hold shift button), animation/different gun position won't animate?

And for everyone, thank you for remarks and sorry for double-post.. and if something wrong will go, I'll post my weapon code here.
I have no coding knowledge whatsoever, but I'd say that you'd need to run two checks, one after the other. Put the input check first; then, if it comes back "true", go to the velocity check; if it comes back with a high enough speed, it changes the animation state of the weapon.
Got the idea with states, but don't know how to make the second speed state check for playing animation...
Jarewill
 
 
Posts: 1853
Joined: Sun Jul 21, 2019 8:54 am

Re: Weapon sprint animation state/script?

Post by Jarewill »

You can access the player's velocity with velx and vely expressions.
Untested example:
A_JumpIf(velx>=10||vely>=10,"SprintState")
Since velx and vely are absolute and not relative, you have to check both of them with an OR operator. ( || )

You could also add another key check to see if the player is also holding forward, for example:
A_JumpIf(GetPlayerInput(MODINPUT_BUTTONS,-1)&BT_SPEED && GetPlayerInput(MODINPUT_BUTTONS,-1)&BT_FORWARD, "SprintState")

It all depends on how you want it to work.
User avatar
body_cleaner666
Posts: 7
Joined: Thu Aug 03, 2023 7:02 am
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10
Graphics Processor: Intel (Modern GZDoom)
Location: Russian Federation

Re: Weapon sprint animation state/script?

Post by body_cleaner666 »

Jarewill wrote: Tue Aug 08, 2023 2:54 pm You can access the player's velocity with velx and vely expressions.
Untested example:
A_JumpIf(velx>=10||vely>=10,"SprintState")
Since velx and vely are absolute and not relative, you have to check both of them with an OR operator. ( || )

You could also add another key check to see if the player is also holding forward, for example:
A_JumpIf(GetPlayerInput(MODINPUT_BUTTONS,-1)&BT_SPEED && GetPlayerInput(MODINPUT_BUTTONS,-1)&BT_FORWARD, "SprintState")

It all depends on how you want it to work.
Thank you very much, the first variant is fine for me, just what I needed.

(after some minutes of testing) A yes, the first variant is somewhere bugged because sometimes player still has ready state.. Tried second, works fine, but how to add also BT_BACK correctly? I tried to add it, but didn't worked.
User avatar
ramon.dexter
Posts: 1562
Joined: Tue Oct 20, 2015 12:50 pm
Graphics Processor: nVidia with Vulkan support
Location: Kozolupy, Bohemia

Re: Weapon sprint animation state/script?

Post by ramon.dexter »

body_cleaner666 wrote: Wed Aug 09, 2023 12:08 am I tried to add it, but didn't worked.
Show what you tried doing.
User avatar
openroadracer
Posts: 496
Joined: Mon Sep 23, 2019 1:03 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): SteamOS
Graphics Processor: ATI/AMD with Vulkan/Metal Support
Location: SES Flame of Liberty
Contact:

Re: Weapon sprint animation state/script?

Post by openroadracer »

body_cleaner666 wrote: Wed Aug 09, 2023 12:08 amThank you very much, the first variant is fine for me, just what I needed.

(after some minutes of testing) A yes, the first variant is somewhere bugged because sometimes player still has ready state.. Tried second, works fine, but how to add also BT_BACK correctly? I tried to add it, but didn't worked.
Just upload your mod file to some other file hosting website and link to it here, please. It'd help all of us.
Jarewill
 
 
Posts: 1853
Joined: Sun Jul 21, 2019 8:54 am

Re: Weapon sprint animation state/script?

Post by Jarewill »

body_cleaner666 wrote: Wed Aug 09, 2023 12:08 am Tried second, works fine, but how to add also BT_BACK correctly? I tried to add it, but didn't worked.
How exactly did you try to do it?

The simplest way would be to put another A_JumpIf that just differs with BT_BACK instead of BT_FORWARD.
However you can also do this to check if either of the keys was pressed:
GetPlayerInput(MODINPUT_BUTTONS,-1)&(BT_FORWARD|BT_BACK)
And you can add any other key there as long as you separate them with a binary OR operator. ( | )
User avatar
body_cleaner666
Posts: 7
Joined: Thu Aug 03, 2023 7:02 am
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10
Graphics Processor: Intel (Modern GZDoom)
Location: Russian Federation

Re: Weapon sprint animation state/script?

Post by body_cleaner666 »

Jarewill wrote: Wed Aug 09, 2023 5:02 am
body_cleaner666 wrote: Wed Aug 09, 2023 12:08 am Tried second, works fine, but how to add also BT_BACK correctly? I tried to add it, but didn't worked.
How exactly did you try to do it?

The simplest way would be to put another A_JumpIf that just differs with BT_BACK instead of BT_FORWARD.
However you can also do this to check if either of the keys was pressed:
GetPlayerInput(MODINPUT_BUTTONS,-1)&(BT_FORWARD|BT_BACK)
And you can add any other key there as long as you separate them with a binary OR operator. ( | )
Ah, there is it. Thank you, now works finally as I wished. And here's codes (full of my gun and sprint only state) yet somewhere it's a bit gross.

Sprint:
Spoiler:
Gun:
Spoiler:
Post Reply

Return to “Scripting”