Using ZScript to create custom player states

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!
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!)
vAethor
Posts: 93
Joined: Wed May 10, 2017 4:10 pm

Using ZScript to create custom player states

Post by vAethor »

My friend and I are working on a partial conversion gameplay mod. It'll be a third-person action-platformer/shooter hybrid. We've got the 3rd-person camera set up and working just fine, the game is definitely playable, but next up is actually modifying the player's states.

I have all the graphics ready (using DBJ87's allied marine sprites for the player,) now I started ZScripting the custom player and his states. But I don't know where to go next.

Here is my code so far (it is a script called 3DPlayerStates that will get included in the main ZScript lump):

Code: Select all

// Animation states for the player
// Heavily based on Nash's side-scroller player script
// Still trying to figure it out for myself

enum EAnimationStates
{
	ANIMSTATE_SPAWN,
	ANIMSTATE_STAND,
	ANIMSTATE_RUN,
	ANIMSTATE_JUMP,
	ANIMSTATE_SHOOT,
	ANIMSTATE_PAIN,
	ANIMSTATE_DEATH,
	ANIMSTATE_GIBBED,
	TOTAL_PLAYER_STATES
}

// Player sprite to be moved and animated
extend class 3DPlayer
{
	const moveThreshold = 0.05;
	
	// Function
	void Animate3DPlayer(void)
	{
		// Get player information
		bool isOnFloor = bIsOnFloor();
		double pSpeed  = GetMoveSpeed();
		
		/////////////////////////////////
		// STATES                      //
		/////////////////////////////////
		int StateToPlay;
		StateLabel stateName[TOTAL_PLAYER_STATES];
		stateName[0] = "Spawn";
		stateName[1] = "Stand";
		stateName[2] = "Run";
		stateName[3] = "Jump";
		stateName[4] = "Shoot";
		stateName[5] = "Pain";
		stateName[6] = "Death";
		stateName[7] = "Gibbed";

		// standing still
		if (isOnFloor && pSpeed <= moveThreshold)
		{
			StateToPlay = ANIMSTATE_STAND;
		}

		// running
		if (isOnFloor && pSpeed > moveThreshold)
		{
			StateToPlay = ANIMSTATE_RUN;
		}

		// jump
		if (!isOnFloor)
		{
			StateToPlay = ANIMSTATE_JUMP;
		}

		// set the new animation
		if (oldState != StateToPlay)
		{
			SetStateLabel(stateName[StateToPlay]);
			oldState = StateToPlay;
		}
	}
	
	// Don't know where to go next
}
Forgive me, I know almost no ZScript myself so I sorta borrowed Nash's side-scroller script for this. I really wish ZScript tutorials were easier to find.

Any help on where to go next would be highly appreciated.
User avatar
Apeirogon
Posts: 1606
Joined: Mon Jun 12, 2017 12:57 am

Re: Using ZScript to create custom player states

Post by Apeirogon »

What you want to achieve, again?
vAethor
Posts: 93
Joined: Wed May 10, 2017 4:10 pm

Re: Using ZScript to create custom player states

Post by vAethor »

It's an...interesting project, to say the least. We are making a partial conversion which turns Doom into basically a 3D platformer, but retaining the shooter elements. I read up on 3rd-person cameras on the wiki and got one working myself, while my friend made the map and added other custom stuff.


It's a little bit of Sonic, and a little bit of Doom. The working title is DoomGuy 3D Blast.

Anyways, what I am eventually wanting to include, are separate states for running around, jumping, slashing with a chainsaw, shooting, getting killed, and getting gibbed. I have all of the graphics I am going to use, I just do not know how to put them all together yet, and get each state working and stuff. Hope that cleared things up.
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: Using ZScript to create custom player states

Post by Matt »

User avatar
Apeirogon
Posts: 1606
Joined: Mon Jun 12, 2017 12:57 am

Re: Using ZScript to create custom player states

Post by Apeirogon »

Why you just dont create custom playerpawn, attach to it all related sprites and then look how it works. Because I dont see any reasons why it should not work with default playerpawn class.
Except jump state, for this you need to override player jump virtual and tick.
vAethor
Posts: 93
Joined: Wed May 10, 2017 4:10 pm

Re: Using ZScript to create custom player states

Post by vAethor »

Wow, that looks like a lot to take in. I bookmarked it to look at it later. I am starting to think I'm not ready for Zscript, since I still haven't fully mastered Decorate and ACS, and most people recommend knowing those two first before going on to Zscript.
Apeirogon wrote:Why you just dont create custom playerpawn, attach to it all related sprites and then look how it works. Because I dont see any reasons why it should not work with default playerpawn class.
Except jump state, for this you need to override player jump virtual and tick.
Huh, okay. I am luckily pretty familiar with states at least in Decorate. I presume creating a custom PlayerPawn is a lot like creating custom enemies or weapons?
User avatar
Apeirogon
Posts: 1606
Joined: Mon Jun 12, 2017 12:57 am

Re: Using ZScript to create custom player states

Post by Apeirogon »

Yes, same.
Look into in zscript folder into gzdoom pack to see how doom player pawn was implemented.
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: Using ZScript to create custom player states

Post by Matt »

Apeirogon's recommendations are on the right track, but I do recommend ignoring these other people's recommendation to start with Decorate because it really is just ZScript with some options removed at this point - format everything as ZScript, even if you're doing everything as though you were limited to Decorate, and if/when you need to add one bit of ZS-only stuff here or there you don't need to convert the entire thing later.
User avatar
TDRR
Posts: 832
Joined: Sun Mar 11, 2018 4:15 pm
Location: Venezuela

Re: Using ZScript to create custom player states

Post by TDRR »

Use some velocity checks (with A_JumpIf) to make the character have more animations. (You need a custom playerpawn, and this is only tested in DECORATE, not sure if it works in ZScript)

See:
TNT1 A 0 A_JumpIf(velz > 0, "JumpingAnimation")
(rest of this state's code)

JumpingAnimation:
(code for the animation, make it short, like 5 tics or less)
TNT1 A 0 A_JumpIf(velz > 0, "JumpingAnimation") //check again
Goto Spawn //Check failed, go back to regular animation
User avatar
Apeirogon
Posts: 1606
Joined: Mon Jun 12, 2017 12:57 am

Re: Using ZScript to create custom player states

Post by Apeirogon »

There are dedicated virtual function in zscript, which calls every time player press "jump" key. So no need in hack...at least for this.
vAethor
Posts: 93
Joined: Wed May 10, 2017 4:10 pm

Re: Using ZScript to create custom player states

Post by vAethor »

Apeirogon wrote:Yes, same.
Look into in zscript folder into gzdoom pack to see how doom player pawn was implemented.
I just did, I looked in the script for DoomPlayer, and it looks way simpler than what I was trying to do. Now I think I am off to a better track.

One question though, is when creating a new PlayerPawn, do I need to retype all the Default code for Doom Player, or will my custom player inherit those from the default player?

Aside from that, I feel about ready to start coding this.
Matt wrote:Apeirogon's recommendations are on the right track, but I do recommend ignoring these other people's recommendation to start with Decorate because it really is just ZScript with some options removed at this point - format everything as ZScript, even if you're doing everything as though you were limited to Decorate, and if/when you need to add one bit of ZS-only stuff here or there you don't need to convert the entire thing later.
Huh, okay. Considering my later, more advanced WAD ideas wnat to do things I think are only possible with Zscript, I guess that could be good practice.
TDRR wrote:Use some velocity checks (with A_JumpIf) to make the character have more animations. (You need a custom playerpawn, and this is only tested in DECORATE, not sure if it works in ZScript)

See:
TNT1 A 0 A_JumpIf(velz > 0, "JumpingAnimation")
(rest of this state's code)

JumpingAnimation:
(code for the animation, make it short, like 5 tics or less)
TNT1 A 0 A_JumpIf(velz > 0, "JumpingAnimation") //check again
Goto Spawn //Check failed, go back to regular animation
I don't currently have a jumping animation, I just have a single frame from the player's walk cycle I am using as a placeholder jumping sprite. I will add my own animation of the player jumping after I lay down the basic code.

I sure hope this also works in Zscript, because I understood the vast majority of that code.
User avatar
Apeirogon
Posts: 1606
Joined: Mon Jun 12, 2017 12:57 am

Re: Using ZScript to create custom player states

Post by Apeirogon »

It will inherit all default data from doom player, yes. ANd if you define some new, or change some defined field, you dont need to copy paste entire definition, because you just change one, already filled, field from many other, filled to.
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: Using ZScript to create custom player states

Post by Matt »

It'll work fine in ZS as long as you format it for ZS (in particular the "vel.z" thing).

And TDRR's suggestion plus Apeirogon's reply is exactly the sort of thing I had in mind with my last post - TDRR's suggestion is fine if you don't need to get exactly only the moment of a voluntary player jump (as opposed to, e.g., a rocket jump or archvile attack), and I'd recommend doing that if you don't want to mess with the jump check function yet.

EDIT: An example might be in order. Here's the entire "see" state sequence from HD's playerpawn. "A_CheckSeeState()" is a function that checks a bunch of things that must happen when the player first takes a step, and then sets the playerpawn's state depending on various factors. "runwalksprint" is a custom variable that is modified elsewhere.

Code: Select all

    see:
        ---- A 0 A_CheckSeeState();
        #### ABCD 4;
        goto spawn;
    seestun:
        #### ABCD random(2,10) A_GiveInventory("IsMoving",2);
        goto spawn;
    seewalk:
        #### ABCD 6{
            if(height>40 && runwalksprint<0)A_TakeInventory("IsMoving",5);
        }
        goto spawn;
    seesprint:
        ---- A 4 A_TakeInventory("PowerFrightener");
        #### B 2;
        #### C 4;
        #### D 2;
        goto spawn; 
vAethor
Posts: 93
Joined: Wed May 10, 2017 4:10 pm

Re: Using ZScript to create custom player states

Post by vAethor »

Well I started my custom player script, and it runs just fine, the only problem is it doesn't work. I don't see the custom sprites I added for the See state.

Here's my code:

Code: Select all

// The custom PlayerPawn "3DPlayer"
class 3DPlayer : PlayerPawn
{
	States
	{
		Spawn:
			DRUN A -1;
			loop;
			
		/* I figured out the "see" state defines the walking state of
		   the player or monster. */
		See:
			DRUN ABCD 4;
			loop;
		
		// Slashing with the chainsaw
		Melee:
			DCUT AB 4;
			Goto spawn;
			
		// Shooting with a gun
		Missile:
			DGUN AB 12;
			Goto Spawn;
			
		// Taking damage
		Pain:
			DHIT A 4;
			DHIT A 4 A_Pain;
			Goto spawn;
	} // End 'States'
} // End class
the walking animation is supposed to look like this (I just made a quick example test that doesn't include all angles):


But instead I get the default one. Any idea what I did wrong?

Also eventually I am going to have to figure out how to bind the chainsaw melee attack to a separate button than shoot, since there will eventually be a gun button and a chainsaw button. But I's say worry about the jumping and getting the animations working first.

But that's good about the inheritance.
User avatar
Arctangent
Posts: 1235
Joined: Thu Nov 06, 2014 1:53 pm
Contact:

Re: Using ZScript to create custom player states

Post by Arctangent »

Most likely is that you didn't tell the game to actually use the new player actor, as ZDoom doesn't make assumptions about what player classes you want active ( otherwise, since all native actor data is valid for all games, you'd get the player classes for Heretic and Hexen in Doom, not to mention if you created a base class for a bunch of new player classes then that'd automatically get sucked in too ). You can define what player classes are in use in the GameInfo block of MAPINFO, specifically with the playerclasses property.
Post Reply

Return to “Scripting”