[ACS] Help with an ACS script that shows jumping sprites

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!)
WorldEater
Posts: 4
Joined: Fri Jan 05, 2024 1:15 am

[ACS] Help with an ACS script that shows jumping sprites

Post by WorldEater »

I'll admit that I used ChatGPT to help me generate this script because I didn't understand how to use ACS. I did learn some stuff about ACS from this but I still don't really know what I'm doing yet. What am I doing wrong here?

I'm trying to write a script that shows jumping sprites when the player presses the jump button. I'm pretty sure it was working fine originally but then I changed some other stuff in the player decorate file and later on noticed it wasn't working properly. The sprites are supposed to show as soon as the jump button is pressed, while the player is going up into the air. I then use a_jumpif(momz < 0, "falling") to show the jump sprite when falling back down or dropping from a ledge.

It seems that my script just doesn't work at all so Doomguy jumps into the air looking stiff but falls back down showing the correct falling sprites.

Here is the jump script:

Code: Select all

#include "zcommon.acs"

#define JUMP_ITEM "isJumping"
#define PLAYER_TID 1000

script 1 ENTER
{
    Thing_ChangeTID(0, PLAYER_TID); // Assign TID if needed

    while (true)
    {
        // Check if player is pressing jump
        if (GetPlayerInput(-1, INPUT_BUTTONS) & BT_JUMP)
        {
            if (!CheckInventory(JUMP_ITEM))
            {
                GiveInventory(JUMP_ITEM, 1);
            }
        }
        else
        {
            if (CheckInventory(JUMP_ITEM))
            {
                TakeInventory(JUMP_ITEM, 1);
            }
        }

        Delay(1); // Run every tic
    }
}


And here is the player decorate code:

Code: Select all

actor Doomguy : PlayerPawn replaces Doomplayer
{
	Health 100
	Radius 16
	Height 56
	Player.AttackZOffset 8
	Player.JumpZ 8
	Player.ViewHeight 41
	Player.ForwardMove 1.1
	Player.SideMove 1.1
	Player.ColorRange 112, 127
	Player.SoundClass "player"
	Player.DisplayName "Marine"
	Player.CrouchSprite "PLYC"
	Player.StartItem "SmoothPistol"
	Player.StartItem "Fist"
	Player.StartItem "Clip", 50
	States
	{
	Spawn:
		TNT1 A 0 A_JumpIf(momz < 0, "Falling")
		TNT1 A 0 A_JumpIfInventory("isJumping", 1, "Jumping")
		PLAY A 1
		Goto StandStill

	StandStill:
		TNT1 A 0 A_JumpIf(momz < 0, "Falling")
		TNT1 A 0 A_JumpIfInventory("isJumping", 1, "Jumping")
		PLAY A 1
		Loop

	See:
		TNT1 A 0 A_JumpIf(momz < 0, "Falling")
		TNT1 A 0 A_JumpIfInventory("isJumping", 1, "Jumping")
		PLAY A 4
		TNT1 A 0 A_JumpIf(momz < 0, "Falling")
		TNT1 A 0 A_JumpIfInventory("isJumping", 1, "Jumping")

		PLAY B 4
		TNT1 A 0 A_JumpIf(momz < 0, "Falling")
		TNT1 A 0 A_JumpIfInventory("isJumping", 1, "Jumping")

		PLAY C 4
		TNT1 A 0 A_JumpIf(momz < 0, "Falling")
		TNT1 A 0 A_JumpIfInventory("isJumping", 1, "Jumping")

		PLAY D 4
		TNT1 A 0 A_JumpIf(momz < 0, "Falling")
		TNT1 A 0 A_JumpIfInventory("isJumping", 1, "Jumping")
		Loop

	Jumping:
		PJMP A 4
		TNT1 A 0 A_JumpIf(momz > 0, "Falling")
		Goto StandStill

	Falling:
		PJMP A 4
		Goto StandStill

	Missile:
		TNT1 A 0 A_JumpIf(momz < 0, "Falling")
		TNT1 A 0 A_JumpIfInventory("isJumping", 1, "Jumping")
		PLAY E 12 
		Goto Spawn
		
	MoveShoot:
		POSS ABCD 4
		Goto See

	Melee:
		TNT1 A 0 A_JumpIf(momz < 0, "Falling")
		TNT1 A 0 A_JumpIfInventory("isJumping", 1, "Jumping")
		PLAY F 6 BRIGHT
		Goto Missile

	Pain:
		TNT1 A 0 A_JumpIf(momz < 0, "Falling")
		TNT1 A 0 A_JumpIfInventory("isJumping", 1, "Jumping")
		PLAY G 4
		PLAY G 4 A_Pain
		Goto Spawn
	Death:
		PLAY H 10 A_PlayerSkinCheck("AltSkinDeath")
		PLAY I 10 A_PlayerScream
		PLAY J 10 A_NoBlocking
		PLAY KLM 10
		PLAY N -1
		Stop
	XDeath:
		PLAY O 5 A_PlayerSkinCheck("AltSkinXDeath")
		PLAY P 5 A_XScream
		PLAY Q 5 A_NoBlocking
		PLAY RSTUV 5
		PLAY W -1
		Stop
	AltSkinDeath:
		PLAY H 6
		PLAY I 6 A_PlayerScream
		PLAY JK 6
		PLAY L 6 A_NoBlocking
		PLAY MNO 6
		PLAY P -1
		Stop
		AltSkinXDeath:
		PLAY Q 5 A_PlayerScream
		PLAY R 0 A_NoBlocking
		PLAY R 5 A_SkullPop
		PLAY STUVWX 5
		PLAY Y -1
		Stop
	}
}

actor isJumping : Inventory
{
    Inventory.MaxAmount 1
    +INVENTORY.HUBPOWER
}
It seems to make sense to me. From what I understand it works like this: when the jump button is pressed the script gives an item to the player which triggers the jumping state and then takes the item away when the jump button is no longer being pressed. So I don't understand why it wouldn't work.

Return to “Scripting”