Player State for Running

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
JossTheFox
Posts: 30
Joined: Sat Jun 19, 2021 6:35 am
Preferred Pronouns: She/Her

Player State for Running

Post by JossTheFox »

In the mod I'm making, I would like for the player to switch to a different animation if they're running. The only way I'd know how to do this is by making an additional state for each player class (lets call it See.Run), but I have no idea how to actually trigger that state if the player runs. I looked at some articles from the wiki and tried to cobble it together myself (keep in mind that I have pretty much no experience coding, so I'm kinda way out of my depth here.) but it just gave me an "invalid acs module" error when I loaded it in-game.
This is the failed script that I cobbled together

Code: Select all

#library "RunScript"

script 1 ENTER
{
	if (!GetCVar ("cl_run"))
		{int buttons;
 
		while (TRUE)
		{
			buttons = GetPlayerInput( -1, INPUT_BUTTONS );
 
			if ( buttons & +speed )
			{
				SetActorState (0, "See.Run", TRUE);
			}
			delay(1);
		}
	else
	{
		SetActorState (0, "See.Run", TRUE);
		(int buttons;
	
		while (TRUE)
		{
			buttons = GetPlayerInput (-1, INPUT_BUTTONS );
			
			if (buttons & +speed )
			{
				SetActorState (0, "See", TRUE};
			}
			delay (1);
		}
	}
}
I loaded the code into LOADACS and the file is in the acs directory in the pk3 I'm using.
The bottom part is supposed to be for if the player is using autorun. Can someone explain what's going on here? I honestly have no clue.
Knowing me, it's probably going to be some detail I overlooked...
Jarewill
 
 
Posts: 1853
Joined: Sun Jul 21, 2019 8:54 am

Re: Player State for Running

Post by Jarewill »

I assume you didn't compile the script, because it wouldn't compile as it is right now:
1) It's missing #include "zcommon.acs" after #library, which is essential for ACS scripts.
2) +speed is not a valid way to check for key input, you have to use the variables specified in GetPlayerInput's wiki page. (BT_SPEED)
3) The first If check never ends and the script errors out at the Else.
4) There is a loose ( before the second definition of int buttons, which isn't needed as you can define int buttons at the very beginning of the script.

There is also issues of it not checking the player's health, (and turning them into a ghost on death) not checking for velocity and never stopping the While loops.
Also if it's for a gameplay mod, you should make it a named script, so it doesn't mess with the map's scripts.

There isn't really an elegant DECORATE/ACS solution to this, as using jumps in DECORATE will leave the See.Run state stuck and ACS cannot check for the current state.
The best method here would be using ZScript:
Spoiler:
User avatar
Player701
 
 
Posts: 1710
Joined: Wed May 13, 2009 3:15 am
Graphics Processor: nVidia with Vulkan support
Contact:

Re: Player State for Running

Post by Player701 »

Here is another ZScript-based approach that does not rely on 1-to-1 sprite replacement. The See.Run state sequence can be completely arbitrary.

Code: Select all

class TestPlayer : DoomPlayer
{
	States
	{
		See.Run:
			// TODO: Put your state sequence here
			Loop;
	}
	
	override void PlayIdle ()
	{
		if (InStateSequence(CurState, GetRunState()))
		{
			// Switch to standing from running
			SetState(SpawnState);
		}
		else
		{
			Super.PlayIdle();
		}
	}

	override void PlayRunning ()
	{
		if (IsRunning() && (InStateSequence(CurState, SpawnState) || InStateSequence(CurState, SeeState)))
		{
			// Switch to running from standing or walking
			SetState(GetRunState());
		}
		else if (!IsRunning() && InStateSequence(CurState, GetRunState()))
		{
			// Switch to walking from running
			SetState(SeeState);
		}
		else
		{
			// Base class behavior (switches to walking from standing)
			Super.PlayRunning();
		}
	}

	private bool IsRunning()
	{
		return player != null && (player.cmd.buttons & BT_RUN);
	}
	
	private state GetRunState()
	{
		return ResolveState('See.Run');
	}
}
JossTheFox
Posts: 30
Joined: Sat Jun 19, 2021 6:35 am
Preferred Pronouns: She/Her

Re: Player State for Running

Post by JossTheFox »

Okay, thanks to both of you for replying.
I don't really know how to do much in ZScript so I probably won't end up using these in my mod yet. I'll probably end up using them when I know more...
Thanks again, though! I wouldn't be surprised if others have the exact same question I had, so hopefully someone will end up using what you told me.
Post Reply

Return to “Scripting”