[Resource] ACS-based limited sprint system

Sprites, textures, sounds, code, and other resources belong here. Share and share-alike!
Forum rules
Before posting your Resource, please make sure you can answer YES to any of the following questions:
  • Is the resource ENTIRELY my own work?
  • If no to the previous one, do I have permission from the original author?
  • If no to the previous one, did I put a reasonable amount of work into the resource myself, such that the changes are noticeably different from the source that I could take credit for them?
If you answered no to all three, maybe you should consider taking your stuff somewhere other than the Resources forum.

Consult the Resource/Request Posting Guidelines for more information.

Please don't put requests here! They have their own forum --> here. Thank you!
User avatar
TheRailgunner
Posts: 1556
Joined: Mon Jul 08, 2013 10:08 pm

[Resource] ACS-based limited sprint system

Post by TheRailgunner »

A manual ACS sprint system that doesn't use Doom's run. It lasts for 240 tics, or almost 7 seconds, then regenerates over the same amount of time. Sprinting animations do have to be set up for weapons unless they are usable while sprinting. If you are not moving forward in any way, out of sprint counters, reloading a weapon that you can't use while sprinting, or aiming down a weapon's sights, you cannot sprint.

The ACS:

Code: Select all

// Sprint system courtesy of revo794 and MagSigmaX
#include "zcommon.acs"
#library "sprint"

Script "S_Forward" ENTER {
	int keyPress = 0;
	int pforward = 0;
	int pstamina = 0;
	While(1) {
		pstamina = CheckActorInventory(1000 + PlayerNumber(),"SprintCounter");
		pforward = CheckActorInventory(1000 + PlayerNumber(),"Forward");
		keyPress = GetPlayerInput(-1, INPUT_BUTTONS);
		Delay(1);
			if(keyPress & BT_FORWARD && pstamina >> 0) {
				GiveActorInventory(1000 + PlayerNumber(),"Forward", 1);
			}
			else {
				TakeActorInventory(1000 + PlayerNumber(),"Forward", 1);
				}
		}
}

Script "S_Sprint" ENTER {
	int keyPress = 0;
	int sprint = 0;
	int aiming = 0;
	int pstamina = 0;
	int preload = 0;
	int pforward = 0;
	//int pslot5 = 0;
	int velocity = GetActorVelX(1000 + PlayerNumber());
	Thing_ChangeTID(0, 1000 + PlayerNumber());
	While(1) {
		GiveActorInventory(1000 + PlayerNumber(),"Sprint", 1);
		GiveActorInventory(1000 + PlayerNumber(),"SprintCancel", 1);
		sprint = CheckActorInventory(1000 + PlayerNumber(),"IsSprinting");
		aiming = CheckActorInventory(1000 + PlayerNumber(),"SprintAim");
		pstamina = CheckActorInventory(1000 + PlayerNumber(),"SprintCounter");
		preload = CheckActorInventory(1000 + PlayerNumber(),"IsReloading");
		pforward = CheckActorInventory(1000 + PlayerNumber(),"Forward");
		//pslot5 = CheckActorInventory(1000 + PlayerNumber(),"HoldingSlot5Weapon");
		keyPress = GetPlayerInput(-1, INPUT_BUTTONS);
		Delay(1);
			if(sprint==1 && pstamina >> 0) {
				if(keyPress != BT_BACK && pforward==1 && preload==0 && aiming==0) {
					TakeInventory("DontSprint", 1);
					SetActorProperty(1000 + PlayerNumber(), APROP_SPEED, 1.8);
					TakeActorInventory(1000 + PlayerNumber(),"SprintCounter", 1);
					Delay(5);
					//print(s:"\cF\n", d:pforward, s:"\cS\n", d:pstamina ,s:"\cR\n", d:preload, s:"\cI\n", d:sprint, s:"\cA\n", d:aiming);
				}
				else {
					TakeActorInventory(1000 + PlayerNumber(),"Forward", 1);
					TakeActorInventory(1000 + PlayerNumber(),"IsSprinting", 1);
					GiveActorInventory(1000 + PlayerNumber(),"DontSprint", 1);
					SetActorProperty(1000 + PlayerNumber(), APROP_SPEED, 1.0);
					TakeActorInventory(1000 + PlayerNumber(),"SprintCounter", 1);
					Delay(5);
					//print(s:"\cF\n", d:pforward, s:"\cS\n", d:pstamina ,s:"\cR\n", d:preload, s:"\cI\n", d:sprint, s:"\cA\n", d:aiming);
				}
			}
			else if(sprint==1 && pstamina==0){
				TakeActorInventory(1000 + PlayerNumber(),"Forward", 1);
				TakeActorInventory(1000 + PlayerNumber(),"IsSprinting", 1);
				GiveActorInventory(1000 + PlayerNumber(),"DontSprint", 1);
				SetActorProperty(1000 + PlayerNumber(), APROP_SPEED, 1.0);
				TakeActorInventory(1000 + PlayerNumber(),"SprintCounter", 1);
				Delay(5);
				//print(s:"\cF\n", d:pforward, s:"\cS\n", d:pstamina ,s:"\cR\n", d:preload, s:"\cI\n", d:sprint, s:"\cA\n", d:aiming);
			}
			else {
				TakeActorInventory(1000 + PlayerNumber(),"Forward", 1);
				TakeActorInventory(1000 + PlayerNumber(),"IsSprinting", 1);
				GiveActorInventory(1000 + PlayerNumber(),"DontSprint", 1);
				Delay(5);
				SetActorProperty(1000 + PlayerNumber(), APROP_SPEED, 1.0);
				GiveActorInventory(1000 + PlayerNumber(),"SprintCounter", 1);
				//print(s:"\cF\n", d:pforward, s:"\cS\n", d:pstamina ,s:"\cR\n", d:preload, s:"\cI\n", d:sprint, s:"\cA\n", d:aiming);
			}
		}
	}
The DECORATE:

Code: Select all

ACTOR IsSprinting : Inventory
{
	-InvBar
	+Inventory.IgnoreSkill
	Inventory.MaxAmount 1
}

ACTOR SprintAim : Inventory
{
	-InvBar
	+Inventory.IgnoreSkill
	Inventory.MaxAmount 1
}

ACTOR DontSprint : Inventory
{
	-InvBar
	+Inventory.IgnoreSkill
	Inventory.MaxAmount 1
}

ACTOR Forward : Inventory
{
	-InvBar
	+Inventory.IgnoreSkill
	Inventory.MaxAmount 1
}

ACTOR SprintCounter : Inventory
{
	-InvBar
	+Inventory.IgnoreSkill
	Inventory.MaxAmount 40
}

ACTOR Sprint : CustomInventory
{
    -InvBar
    +Inventory.IgnoreSkill
	Inventory.MaxAmount 1
	Inventory.Amount 1
    States
    {
    Use:
        TNT1 A 0 A_GiveInventory("IsSprinting",1)
		TNT1 A 0 A_GiveInventory("SprintCancel",1)
        Fail
    }
}

ACTOR SprintCancel : CustomInventory
{
	-InvBar
    +Inventory.IgnoreSkill
	Inventory.MaxAmount 1
	Inventory.Amount 1
    States
    {
    Use:
        TNT1 A 0 A_TakeInventory("IsSprinting",1)
		TNT1 A 0 A_GiveInventory("Sprint",1)
        Fail
    }
}
And the KEYCONF:

Code: Select all

AddKeySection "Mod Settings" SprintStuff
AddMenuKey "Sprint" +sprinting

Alias +sprinting "use Sprint"
Alias -sprinting "use SprintCancel"

Bind LeftShift sprinting
And finally, an example of a weapon using this system, an M1 Garand:

Code: Select all

Actor M1Aiming : Inventory
{
inventory.maxamount 1
}

Actor M1Reloading : Inventory
{
inventory.maxamount 1
}

Actor M1ReloadingA : Inventory
{
inventory.maxamount 1
}

ACTOR M1Loaded : Ammo
{
 Inventory.MaxAmount 8
 Inventory.Icon "M1ICO0"
 +IGNORESKILL
}

ACTOR M1 : Weapon replaces BFG9000
{
	Weapon.SelectionOrder 1902
	Weapon.SlotNumber 7
	Weapon.AmmoUse 1
	Weapon.AmmoGive2 1
	Weapon.AmmoType "M1Loaded"
	Weapon.AmmoType2 "M1Clip"
	Weapon.AmmoUse2 0
	Weapon.BobRangeX 0.3
	Weapon.BobRangeY 0.5
	Weapon.BobStyle InverseSmooth
	Weapon.BobSpeed 0.6
	AttackSound "sounds/M1/fire"
	Inventory.PickupSound "sounds/M1/pickup"
	+WEAPON.NOAUTOFIRE
	+WEAPON.NOAUTOAIM
	+WEAPON.NOALERT
	+WEAPON.AMMO_OPTIONAL
	+IGNORESKILL
	Scale 0.2
	Inventory.Pickupmessage "You picked up an M1 Garand rifle."
	States
	{
	Ready:
      	TNT1 A 0 A_JumpIfInventory("M1Aiming",1, "Ready2")
		TNT1 A 0 A_JumpIfInventory("IsSprinting", 1, "Sprinting")
		TNT1 A 0 A_JumpIfInventory("M1Loaded",1, "ReadyNoReload")
		M1GG A 1 A_WeaponReady (WRF_ALLOWRELOAD)
		Loop
	ReadyNoSprint:
      	TNT1 A 0 A_JumpIfInventory("M1Aiming",1, "Ready2")
		TNT1 A 0 A_JumpIfInventory("SprintCounter", 1, "Ready")
		TNT1 A 0 A_JumpIfInventory("M1Loaded",1, "ReadyNoReload")
		M1GG A 1 A_WeaponReady (WRF_ALLOWRELOAD)
		Loop
	SprintAbort:
		M1GG A 1 A_WeaponReady (WRF_ALLOWRELOAD)
		Goto Ready
	Sprinting:
		TNT1 A 0 A_JumpIfInventory("DontSprint",1, "SprintAbort")
		TNT1 A 0 A_JumpIfInventory("M1Aiming",1, "Ready2")
		M1SP ABCDEF 1
	SprintLoop:
		//TNT1 A 0 A_TakeInventory("SprintCounter", 1)
		M1SR ABCDEFGHIJKLMNO 1
		M1SR ONMLKJIHGFEDCB 1
		TNT1 A 0 A_JumpIfInventory("IsSprinting", 1, "SprintLoop")
	SprintEnd:
		TNT1 A 0 A_TakeInventory("IsSprinting", 1)
		M1SP FEDCBA 1
		Goto Ready
	ReadyNoReload:
      	TNT1 A 0 A_JumpIfInventory("M1Aiming",1, "Ready2")
		TNT1 A 0 A_JumpIfInventory("IsSprinting", 1, "Sprinting")
		M1GG A 1 A_WeaponReady
		Loop
	Ready2:
		TNT1 A 0 A_JumpIfInventory("IsSprinting",1, "Unaim")
		TNT1 A 0 A_JumpIfInventory("M1Loaded",1, "Ready2NoReload")
		M1AG A 1 A_WeaponReady (WRF_ALLOWRELOAD)
		Loop
	Ready2NoReload:
		TNT1 A 0 A_JumpIfInventory("IsSprinting",1, "Unaim")
		M1AG A 1 A_WeaponReady
		Loop
	DeselectUnaim:
		M1AZ GFEDC 1
		TNT1 A 0 A_ZoomFactor(1.0)
		M1AZ BA 1
		TNT1 A 0 A_Takeinventory("M1Aiming",1)
		TNT1 A 0 A_Takeinventory("SprintAim",1)
		TNT1 A 0 A_Takeinventory("M1Reloading",1)
	Deselect:
		TNT1 A 0 A_JumpIfInventory("M1Aiming",1, "DeselectUnaim")
		M1GG A 1 A_Lower
		Loop
	Select:
		M1GG A 1 A_Raise
		Loop
	Fire:
		TNT1 A 0 A_JumpIfInventory("IsSprinting",1, "Sprinting")
		TNT1 A 0 A_JumpIfInventory("M1PingCounter",7,"FirePing")
		TNT1 A 0 A_JumpIfInventory("M1Aiming",1,"FireAiming")
		TNT1 A 0 A_JumpIfNoAmmo("Dryfire")
		TNT1 A 0 A_GiveInventory("M1PingCounter", 1)
		TNT1 A 0 A_GunFlash
		M1GF A 1 A_FireBullets (1, 1, -1, random(50,75), "BulletPuff")
		M1GF B 1 A_AlertMonsters
		M1GF B 0 A_SetPitch(pitch - 6.5)
		M1GF C 1 A_SetPitch(pitch - 4.0)
		M1GF D 1 A_SetPitch(pitch - 2.0)
		M1GF E 1 A_SetPitch(pitch - 1.0)
		M1GF F 1 A_SetPitch(pitch - 0.75)
		M1GF G 1 A_WeaponReady
		M1GF G 0 A_SetPitch(pitch - 0.5)
		M1GF H 1 A_WeaponReady
		M1GF H 0 A_SetPitch(pitch - 0.25)
		M1GF I 1 A_WeaponReady
		M1GF I 0 A_SetPitch(pitch + 0.25)
		M1GF J 1 A_WeaponReady
		M1GF J 0 A_SetPitch(pitch + 0.5)
		M1GF K 1 A_WeaponReady
		M1GF K 0 A_SetPitch(pitch + 1.0)
		M1GF L 1 A_WeaponReady
		M1GF L 0 A_SetPitch(pitch + 2.0)
		Goto Ready
	FireAiming:
		TNT1 A 0 A_JumpIfInventory("IsSprinting",1, "Unaim")
		TNT1 A 0 A_JumpIfInventory("M1PingCounter",7,"FireAimingPing")
		TNT1 A 0 A_JumpIfNoAmmo("DryfireAiming")
		TNT1 A 0 A_GiveInventory("M1PingCounter", 1)
		TNT1 A 0 A_GunFlash
		M1AF A 1 A_FireBullets (0.25, 0.25, -1, random(50,75), "BulletPuff")
		M1AF B 1 A_AlertMonsters
		M1AF B 0 A_SetPitch(pitch - 4.5)
		M1AF C 1 A_SetPitch(pitch - 2.5)
		M1AF D 1 A_SetPitch(pitch - 1.0)
		M1AF E 1 A_SetPitch(pitch - 0.5)
		M1AF F 1 A_SetPitch(pitch - 1.0)
		M1AF G 1 A_WeaponReady
		M1AF G 0 A_SetPitch(pitch - 0.5)
		M1AF H 1 A_WeaponReady
		M1AF H 0 A_SetPitch(pitch - 0.25)
		M1AF I 1 A_WeaponReady
		M1AF I 0 A_SetPitch(pitch + 0.25)
		M1AF J 1 A_WeaponReady
		M1AF J 0 A_SetPitch(pitch + 0.5)
		M1AF K 1 A_WeaponReady
		M1AF K 0 A_SetPitch(pitch + 1.0)
		M1AF L 1 A_WeaponReady
		M1AF L 0 A_SetPitch(pitch + 2.0)
		Goto Ready
	FirePing:
		TNT1 A 0 A_JumpIfInventory("M1Aiming",1,"FireAimingPing")
		TNT1 A 0 A_JumpIfNoAmmo("Dryfire")
		TNT1 A 0 A_TakeInventory("M1PingCounter", 999)
		TNT1 A 0 A_GunFlash
		TNT1 A 0 A_PlaySound("sounds/M1/ping", 6)
		M1GF A 1 A_FireBullets (1, 1, -1, random(50,75), "BulletPuff")
		M1GF B 1 A_AlertMonsters
		M1GF B 0 A_SetPitch(pitch - 8.0)
		M1GF C 1 A_SetPitch(pitch - 4.0)
		M1GF D 1 A_SetPitch(pitch - 2.0)
		M1GF E 1 A_SetPitch(pitch - 1.0)
		M1GF F 1 A_SetPitch(pitch - 0.75)
		M1GF G 1 A_WeaponReady
		M1GF G 0 A_SetPitch(pitch - 0.5)
		M1GF H 1 A_WeaponReady
		M1GF H 0 A_SetPitch(pitch - 0.25)
		M1GF I 1 A_WeaponReady
		M1GF I 0 A_SetPitch(pitch + 0.25)
		M1GF J 1 A_WeaponReady
		M1GF J 0 A_SetPitch(pitch + 0.5)
		M1GF K 1 A_WeaponReady
		M1GF K 0 A_SetPitch(pitch + 1.0)
		M1GF L 1 A_WeaponReady
		M1GF L 0 A_SetPitch(pitch + 2.0)
		Goto Ready
	FireAimingPing:
		TNT1 A 0 A_JumpIfNoAmmo("DryfireAiming")
		TNT1 A 0 A_GunFlash
		TNT1 A 0 A_TakeInventory("M1PingCounter", 999)
		TNT1 A 0 A_PlaySound("sounds/M1/ping", 6)
		M1AF A 1 A_FireBullets (0.25, 0.25, -1, random(50,75), "BulletPuff")
		M1AF B 1 A_AlertMonsters
		M1AF B 0 A_SetPitch(pitch - 5.5)
		M1AF C 1 A_SetPitch(pitch - 2.5)
		M1AF D 1 A_SetPitch(pitch - 1.0)
		M1AF E 1 A_SetPitch(pitch - 0.5)
		M1AF F 1 A_SetPitch(pitch - 1.0)
		M1AF G 1 A_WeaponReady
		M1AF G 0 A_SetPitch(pitch - 0.5)
		M1AF H 1 A_WeaponReady
		M1AF H 0 A_SetPitch(pitch - 0.25)
		M1AF I 1 A_WeaponReady
		M1AF I 0 A_SetPitch(pitch + 0.25)
		M1AF J 1 A_WeaponReady
		M1AF J 0 A_SetPitch(pitch + 0.5)
		M1AF K 1 A_WeaponReady
		M1AF K 0 A_SetPitch(pitch + 1.0)
		M1AF L 1 A_WeaponReady
		M1AF L 0 A_SetPitch(pitch + 2.0)
		Goto Ready
	AltFire:	
		TNT1 A 0 A_JumpIfInventory("M1Aiming",1,"Unaim")
		TNT1 A 0 A_Giveinventory("SprintAim",1)
		TNT1 A 0 A_Giveinventory("M1Aiming",1)
		M1AZ AB 1
		TNT1 A 0 A_ZoomFactor(3.0)
		M1AZ CDEFG 1
		Goto Ready2
	DryfireAiming:
		TNT1 A 0 A_PlaySound("sounds/M1/dryfire")
		M1AF JIK 1
	ReloadAiming:
		TNT1 A 0 A_JumpIfInventory("M1Loaded", 8, 2)
		TNT1 A 0 A_JumpIfInventory("M1Clip", 1, "ReloadContinue")
		M1AG A 1 A_WeaponReady(WRF_NOFIRE)
		Goto Ready2
	Dryfire:
		TNT1 A 0 A_PlaySound("sounds/M1/dryfire")
		M1GF HIJ 1
	Reload:
		TNT1 A 0 A_JumpIfInventory("M1Aiming",1,"ReloadAiming")
		TNT1 A 0 A_JumpIfInventory("M1Loaded", 8, 2)
		TNT1 A 0 A_JumpIfInventory("M1Clip", 1, "ReloadContinue")
		M1GG A 1 A_WeaponReady(WRF_NOFIRE)
		Goto Ready
	ReloadContinue:
		TNT1 A 0 A_Giveinventory("IsReloading",1)
		TNT1 A 0 A_Giveinventory("M1Reloading",1)		
		TNT1 A 0 A_JumpIfInventory("M1Aiming",1,"Unaim")
		TNT1 A 0 A_TakeInventory("M1PingCounter", 999)
		M1GR ABCDEFGHIJKLMNOPQRSTUVWXY 1 
		M1GR Z 1 A_PlaySound("sounds/M1/reload")
		M1GS ABCDEFGHIJKLMNOPQRS 1 
	ReloadLoop:
		TNT1 A 0 A_TakeInventory("M1Clip", 1)
		TNT1 A 0 A_GiveInventory("M1Loaded", 8)
		Goto ReloadFinish
	ReloadFinish:
		M1GS TUVWXYZ 2
		M1GT ABCDEFGHIJKLMNOPQRSTUVWXYZ 1
		M1GU ABCDE 1
		TNT1 A 0 A_Takeinventory("M1Reloading",1)
		TNT1 A 0 A_Takeinventory("IsReloading",1)
		Goto Ready
	Unaim:
		M1AZ GFEDC 1
		TNT1 A 0 A_ZoomFactor(1.0)
		M1AZ BA 1
		TNT1 A 0 A_Takeinventory("M1Aiming",1)
		TNT1 A 0 A_Takeinventory("SprintAim",1)
		TNT1 A 0 A_JumpIfInventory("M1Reloading",1,"Reload")
		TNT1 A 0 A_JumpIfInventory("IsSprinting",1,"Sprinting")
		Goto Ready
	Flash:
		TNT1 A 1 Bright A_Light2
		TNT1 A 1 Bright A_Light1
		Goto LightDone
		TNT1 A 1 Bright A_Light2
		TNT1 A 1 Bright A_Light1
		Goto LightDone
 	Spawn:
		M1GP A -1
		Stop
	}
}
Last edited by TheRailgunner on Wed Nov 27, 2013 3:28 am, edited 1 time in total.
User avatar
The Zombie Killer
Posts: 1528
Joined: Thu Jul 14, 2011 12:06 am
Location: Gold Coast, Queensland, Australia

Re: [Resource] ACS-based limited sprint system

Post by The Zombie Killer »

The code wrote:// Sprint system courtesy of revo794 and MagSigmaX
If you're using the sprint system from DoomField, then I'd just like to point out that I did the main code for that.
I don't actually care if I'm credited or not, just thought I'd letcha know. (of course, this is only if you used that sprint system)

Oh and by the way, this code:

Code: Select all

#define S_Sprint 2
Isn't needed :wink:
User avatar
TheRailgunner
Posts: 1556
Joined: Mon Jul 08, 2013 10:08 pm

Re: [Resource] ACS-based limited sprint system

Post by TheRailgunner »

The Zombie Killer wrote:
The code wrote:// Sprint system courtesy of revo794 and MagSigmaX
If you're using the sprint system from DoomField, then I'd just like to point out that I did the main code for that.
I don't actually care if I'm credited or not, just thought I'd letcha know. (of course, this is only if you used that sprint system)

Oh and by the way, this code:

Code: Select all

#define S_Sprint 2
Isn't needed :wink:
Yes I am, and I will update the post accordingly soon. On that note, if you release forward but continue to hold Shift/Sprint afterwards, the player will not stop sprinting. Is there a way to fix this?
User avatar
The Zombie Killer
Posts: 1528
Joined: Thu Jul 14, 2011 12:06 am
Location: Gold Coast, Queensland, Australia

Re: [Resource] ACS-based limited sprint system

Post by The Zombie Killer »

Yes, just add another check to the ACS for if the player is still pressing the forward key.
You'll have to add another inventory check, or you could use ACS to enable and disable the sprinting, which would probably make things easier.
I'll see if I can rewrite some of the code to show you an example soon
User avatar
TheRailgunner
Posts: 1556
Joined: Mon Jul 08, 2013 10:08 pm

Re: [Resource] ACS-based limited sprint system

Post by TheRailgunner »

The Zombie Killer wrote:Yes, just add another check to the ACS for if the player is still pressing the forward key.
You'll have to add another inventory check, or you could use ACS to enable and disable the sprinting, which would probably make things easier.
I'll see if I can rewrite some of the code to show you an example soon
I fixed it by having the Forward script require the player to have stamina before giving him/her "Forward" (hence disabling sprint correctly if the player isn't moving, moves and then stops, or if he/she runs out of stamina/sprint counters).
User avatar
The Zombie Killer
Posts: 1528
Joined: Thu Jul 14, 2011 12:06 am
Location: Gold Coast, Queensland, Australia

Re: [Resource] ACS-based limited sprint system

Post by The Zombie Killer »

Good to know that you ended up fixing it. If you still want to have a look, here's what I ended up with:
ACS:

Code: Select all

// ACS
#library "sprint"
#include "zcommon.acs"

// Defines
#define PLRCOUNT 8

// Variables
int pStamina[PLRCOUNT];
int pSpeed[PLRCOUNT];

// Scripts
Script "Sprint" ENTER
{
	int keyPress, playerNum, maxStamina;
	playerNum = PlayerNumber();
	maxStamina = 40;
	pStamina[playerNum] = 40;
	While (true)
	{
		keyPress = GetPlayerInput(-1, INPUT_BUTTONS);
		if ((keyPress & BT_SPEED) && (pStamina[playerNum] > 0) && (keyPress & BT_FORWARD))
		{
			pSpeed[playerNum] = 2.8;
			pStamina[playerNum]--;
		}
		if ((keyPress & BT_SPEED) && (pStamina[playerNum] == 0))
			pSpeed[playerNum] = 1.0;
		else if (!(keyPress & BT_SPEED))
		{
			pSpeed[playerNum] = 1.0;
			if (pStamina[playerNum] < maxStamina)
				pStamina[playerNum]++;
		}
		Print(i:pStamina[playerNum]);
		SetActorProperty(0, APROP_Speed, pSpeed[playerNum]);
		Delay(5);
	}
}

// Functions
Decorate (player class):

Code: Select all

// Decorate
ACTOR NewDoomPlayer : DoomPlayer replaces DoomPlayer
{
	Player.ForwardMove 1, 0.5
	Player.SideMove 1, 0.5
}
User avatar
Devianteist
Posts: 945
Joined: Wed Sep 24, 2014 4:07 pm
Location: Creating a SPACE HULK conversion!

Re: [Resource] ACS-based limited sprint system

Post by Devianteist »

Hey everybody, been a while.

I'm trying to figure out how to slow down the speed of the sprint, and I'm assuming it's APROP_SPEED in the ACS, but I wanted to get some confirmation on that beforehand.

I also was wondering if anyone had any idea how to temporarily "stun" the player each time they took a "step" while sprinting, to give them an additional amount of weight.
User avatar
TheRailgunner
Posts: 1556
Joined: Mon Jul 08, 2013 10:08 pm

Re: [Resource] ACS-based limited sprint system

Post by TheRailgunner »

Devianteist wrote:Hey everybody, been a while.

I'm trying to figure out how to slow down the speed of the sprint, and I'm assuming it's APROP_SPEED in the ACS, but I wanted to get some confirmation on that beforehand.

I also was wondering if anyone had any idea how to temporarily "stun" the player each time they took a "step" while sprinting, to give them an additional amount of weight.
It is APROP_SPEED. It mainly works by having the player's Forward/SideMove speed set to 0.5 (last I checked - I'm using a limitless sprint variant of it with an automatic sprint option for Malice, which has it set to 0.4).

If you want to have the speed fluctuate to give the appearance of actual stepping, maybe try something like this (actual timing, speed values, and all other sort of nonsense is open to adjustment):

Code: Select all

Script "S_Sprint" ENTER {
	int keyPress = 0;
	int sprint = 0;
	int aiming = 0;
	int pstamina = 0;
	int preload = 0;
	int pforward = 0;
	//int pslot5 = 0;
	int velocity = GetActorVelX(1000 + PlayerNumber());
	Thing_ChangeTID(0, 1000 + PlayerNumber());
	While(1) {
		GiveActorInventory(1000 + PlayerNumber(),"Sprint", 1);
		GiveActorInventory(1000 + PlayerNumber(),"SprintCancel", 1);
		sprint = CheckActorInventory(1000 + PlayerNumber(),"IsSprinting");
		aiming = CheckActorInventory(1000 + PlayerNumber(),"SprintAim");
		pstamina = CheckActorInventory(1000 + PlayerNumber(),"SprintCounter");
		preload = CheckActorInventory(1000 + PlayerNumber(),"IsReloading");
		pforward = CheckActorInventory(1000 + PlayerNumber(),"Forward");
		//pslot5 = CheckActorInventory(1000 + PlayerNumber(),"HoldingSlot5Weapon");
		keyPress = GetPlayerInput(-1, INPUT_BUTTONS);
		Delay(1);
			if(sprint==1 && pstamina >> 0) {
				if(keyPress != BT_BACK && pforward==1 && preload==0 && aiming==0) {
					TakeInventory("DontSprint", 1);
					SetActorProperty(1000 + PlayerNumber(), APROP_SPEED, 1.8);
					TakeActorInventory(1000 + PlayerNumber(),"SprintCounter", 1);
					Delay(5);
					SetActorProperty(1000 + PlayerNumber(), APROP_SPEED, 1.3);
					TakeActorInventory(1000 + PlayerNumber(),"SprintCounter", 1);
					Delay(4);
					SetActorProperty(1000 + PlayerNumber(), APROP_SPEED, 0.9);
					TakeActorInventory(1000 + PlayerNumber(),"SprintCounter", 1);
					Delay(4);
					SetActorProperty(1000 + PlayerNumber(), APROP_SPEED, 0.6);
					TakeActorInventory(1000 + PlayerNumber(),"SprintCounter", 1);
					Delay(4);
					SetActorProperty(1000 + PlayerNumber(), APROP_SPEED, 0.3);
					TakeActorInventory(1000 + PlayerNumber(),"SprintCounter", 1);
					Delay(10);
					SetActorProperty(1000 + PlayerNumber(), APROP_SPEED, 0.6);
					TakeActorInventory(1000 + PlayerNumber(),"SprintCounter", 1);
					Delay(4);
					SetActorProperty(1000 + PlayerNumber(), APROP_SPEED, 1.3);
					TakeActorInventory(1000 + PlayerNumber(),"SprintCounter", 1);
					Delay(4);
					//print(s:"\cF\n", d:pforward, s:"\cS\n", d:pstamina ,s:"\cR\n", d:preload, s:"\cI\n", d:sprint, s:"\cA\n", d:aiming);
				}
				else {
					SetActorProperty(1000 + PlayerNumber(), APROP_SPEED, 0.9);
					TakeActorInventory(1000 + PlayerNumber(),"SprintCounter", 1);
					Delay(5);
					SetActorProperty(1000 + PlayerNumber(), APROP_SPEED, 0.65);
					TakeActorInventory(1000 + PlayerNumber(),"SprintCounter", 1);
					Delay(4);
					SetActorProperty(1000 + PlayerNumber(), APROP_SPEED, 0.45);
					TakeActorInventory(1000 + PlayerNumber(),"SprintCounter", 1);
					Delay(4);
					SetActorProperty(1000 + PlayerNumber(), APROP_SPEED, 0.3);
					TakeActorInventory(1000 + PlayerNumber(),"SprintCounter", 1);
					Delay(4);
					SetActorProperty(1000 + PlayerNumber(), APROP_SPEED, 0.15);
					TakeActorInventory(1000 + PlayerNumber(),"SprintCounter", 1);
					Delay(10);
					SetActorProperty(1000 + PlayerNumber(), APROP_SPEED, 0.3);
					TakeActorInventory(1000 + PlayerNumber(),"SprintCounter", 1);
					Delay(4);
					SetActorProperty(1000 + PlayerNumber(), APROP_SPEED, 0.65);
					TakeActorInventory(1000 + PlayerNumber(),"SprintCounter", 1);
					Delay(4);
					//print(s:"\cF\n", d:pforward, s:"\cS\n", d:pstamina ,s:"\cR\n", d:preload, s:"\cI\n", d:sprint, s:"\cA\n", d:aiming);
				}
			}
			else if(sprint==1 && pstamina==0){
				TakeActorInventory(1000 + PlayerNumber(),"Forward", 1);
				TakeActorInventory(1000 + PlayerNumber(),"IsSprinting", 1);
				GiveActorInventory(1000 + PlayerNumber(),"DontSprint", 1);
				SetActorProperty(1000 + PlayerNumber(), APROP_SPEED, 0.9);
				TakeActorInventory(1000 + PlayerNumber(),"SprintCounter", 1);
				Delay(5);
				SetActorProperty(1000 + PlayerNumber(), APROP_SPEED, 0.65);
				TakeActorInventory(1000 + PlayerNumber(),"SprintCounter", 1);
				Delay(4);
				SetActorProperty(1000 + PlayerNumber(), APROP_SPEED, 0.45);
				TakeActorInventory(1000 + PlayerNumber(),"SprintCounter", 1);
				Delay(4);
				SetActorProperty(1000 + PlayerNumber(), APROP_SPEED, 0.3);
				TakeActorInventory(1000 + PlayerNumber(),"SprintCounter", 1);
				Delay(4);
				SetActorProperty(1000 + PlayerNumber(), APROP_SPEED, 0.15);
				TakeActorInventory(1000 + PlayerNumber(),"SprintCounter", 1);
				Delay(10);
				SetActorProperty(1000 + PlayerNumber(), APROP_SPEED, 0.3);
				TakeActorInventory(1000 + PlayerNumber(),"SprintCounter", 1);
				Delay(4);
				SetActorProperty(1000 + PlayerNumber(), APROP_SPEED, 0.65);
				TakeActorInventory(1000 + PlayerNumber(),"SprintCounter", 1);
				Delay(4);
				//print(s:"\cF\n", d:pforward, s:"\cS\n", d:pstamina ,s:"\cR\n", d:preload, s:"\cI\n", d:sprint, s:"\cA\n", d:aiming);
			}
			else {
				TakeActorInventory(1000 + PlayerNumber(),"Forward", 1);
				TakeActorInventory(1000 + PlayerNumber(),"IsSprinting", 1);
				GiveActorInventory(1000 + PlayerNumber(),"DontSprint", 1);
				SetActorProperty(1000 + PlayerNumber(), APROP_SPEED, 0.9);
				GiveActorInventory(1000 + PlayerNumber(),"SprintCounter", 1);
				Delay(5);
				SetActorProperty(1000 + PlayerNumber(), APROP_SPEED, 0.65);
				GiveActorInventory(1000 + PlayerNumber(),"SprintCounter", 1);
				Delay(4);
				SetActorProperty(1000 + PlayerNumber(), APROP_SPEED, 0.45);
				GiveActorInventory(1000 + PlayerNumber(),"SprintCounter", 1);
				Delay(4);
				SetActorProperty(1000 + PlayerNumber(), APROP_SPEED, 0.3);
				GiveActorInventory(1000 + PlayerNumber(),"SprintCounter", 1);
				Delay(4);
				SetActorProperty(1000 + PlayerNumber(), APROP_SPEED, 0.15);
				GiveActorInventory(1000 + PlayerNumber(),"SprintCounter", 1);
				Delay(10);
				SetActorProperty(1000 + PlayerNumber(), APROP_SPEED, 0.3);
				GiveActorInventory(1000 + PlayerNumber(),"SprintCounter", 1);
				Delay(4);
				SetActorProperty(1000 + PlayerNumber(), APROP_SPEED, 0.65);
				GiveActorInventory(1000 + PlayerNumber(),"SprintCounter", 1);
				Delay(4);
				//print(s:"\cF\n", d:pforward, s:"\cS\n", d:pstamina ,s:"\cR\n", d:preload, s:"\cI\n", d:sprint, s:"\cA\n", d:aiming);
			}
		}
	}
I kind of whipped this up in the confines of this post, so I don't know how well it'll run. I'll get back to you on this one sometime soon.
User avatar
Devianteist
Posts: 945
Joined: Wed Sep 24, 2014 4:07 pm
Location: Creating a SPACE HULK conversion!

Re: [Resource] ACS-based limited sprint system

Post by Devianteist »

When I get an hour or so to test this out I'll give it a whirl. Gearing up for my buddy's wedding is a lot more stressful than I thought it'd be.
User avatar
iSpook
Posts: 743
Joined: Sun Feb 05, 2006 9:23 am
Location: In the middle of Stephen King Territory

Re: [Resource] ACS-based limited sprint system

Post by iSpook »

Question: I'm using TZK's script. How would I make it so I can display the stamina counter as a hud element?
User avatar
AndroSynth
Posts: 8
Joined: Wed Nov 15, 2023 10:48 am

Re: [Resource] ACS-based limited sprint system

Post by AndroSynth »

Hope this isn't bad form to revive this 4 year old post, but it was what I found on google for sprinting in GZDoom.

I've taken The Zombie Killer's version (Thanks!) and modified it a bit to be more to my liking. I tried running that version alongside the wonderful Doom RPG SE compilation and found it didn't work as I wanted. I think this is due to DoomRPG or one of the components also editing the speed property of the player actor. Because of this, a slightly different setup (aka a dirty hack) is needed to get a satisfactory result. Note also that you will need to either comment out the vanilla version(like I do), or the modded compat version, depending on your own usecase. I've also made sure that the configuration variables are all placed at the top if anyone would like to have custom values. To be honest, I haven't tested the vanilla setup much at all, and just fixed it up as an afterthought tonight because I realized it probably wasn't working correctly given the changes I made. I think it is working similarly from my brief tests. I'm also not sure if the decorate class is needed for this version, but I'm a newbie at this.

sprintModifier controls the increase in speed from sprinting
maxStamina controls the max stamina a player may have
staminaDrain is the amount of stamina that is removed from the player per active tick that the player is sprinting (may not happen every tick)
staminaGain is the amount of stamina returned to the player when not sprinting per active tick
tickDelay controls the delay between each modification. This can be used to simulate a sort of bursty sprinting if that is wanted.

Code: Select all

// ACS
#library "sprint"
#include "zcommon.acs"

// Defines
#define PLRCOUNT 8

// Variables
int pStamina[PLRCOUNT];

// Scripts
Script "Sprint" ENTER
{
	int keyPress, playerNum, maxStamina,initialSpeed,staminaDrain,sprintModifier,staminaGain,tickDelay,currentSpeed;
	playerNum = PlayerNumber();
	//Vanilla sprint modifier
	sprintModifier = 1.25;
	//Modded sprint modifier
	sprintModifier = 4.1;
	maxStamina = 100;
	staminaDrain = 4;
	staminaGain = 2;
	tickDelay = 8;
	initialSpeed = GetActorProperty(0,APROP_Speed);
	pStamina[playerNum] = maxStamina;
	While (true)
	{
		keyPress = GetPlayerInput(-1, INPUT_BUTTONS);
		if ((keyPress & BT_SPEED) && (pStamina[playerNum] > 0) && (keyPress & BT_FORWARD))
		{
			if(pStamina[playerNum] >= staminaDrain)
			{
				currentSpeed = GetActorProperty(0,APROP_Speed);
				//Vanilla Version
				/* SetActorProperty(0, APROP_Speed, FixedMul(initialSpeed , sprintModifier)); */
				//Modded version if other mods are tweaking speed
				SetActorProperty(0, APROP_Speed, FixedMul(currentSpeed , sprintModifier));
			}
			if(pStamina[playerNum] > staminaDrain)
				pStamina[playerNum] = pStamina[playerNum] - staminaDrain;
			else
				pStamina[playerNum] = 0;

		}
		else if ((keyPress & BT_SPEED) && (pStamina[playerNum] == 0))
		{
			SetActorProperty(0, APROP_Speed, initialSpeed);
		}
		else if (!(keyPress & BT_SPEED))
		{
			if (pStamina[playerNum] < maxStamina)
			{
				if(pStamina[playerNum] + staminaGain < maxStamina)
					pStamina[playerNum] += staminaGain;
				else
					pStamina[playerNum] = maxStamina;
			}
			SetActorProperty(0, APROP_Speed, initialSpeed);
		}
		int velX = GetActorVelX(PlayerNumber());
		int velY = GetActorVelY(PlayerNumber());
		HudMessage(s:"Stamina: ", i:pStamina[playerNum], s:"| Velocity X: ", i:velX/10000, s:",Y: " ,i:velY/10000; HUDMSG_PLAIN, 1, CR_YELLOW, 0.5, 1.0051, 0.0);
		Delay(tickDelay);
	}
}
Enjoy!
Lossvoise
Posts: 1
Joined: Tue May 28, 2024 8:15 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 11
Graphics Processor: ATI/AMD with Vulkan/Metal Support

Re: [Resource] ACS-based limited sprint system

Post by Lossvoise »

The Zombie Killer wrote: Wed Nov 27, 2013 3:36 am Good to know that you ended up fixing it. If you still want to have a look, here's what I ended up with:
ACS:

Code: Select all

// ACS
#library "sprint"
#include "zcommon.acs"

// Defines
#define PLRCOUNT 8

// Variables
int pStamina[PLRCOUNT];
int pSpeed[PLRCOUNT];

// Scripts
Script "Sprint" ENTER
{
	int keyPress, playerNum, maxStamina;
	playerNum = PlayerNumber();
	maxStamina = 40;
	pStamina[playerNum] = 40;
	While (true)
	{
		keyPress = GetPlayerInput(-1, INPUT_BUTTONS);
		if ((keyPress & BT_SPEED) && (pStamina[playerNum] > 0) && (keyPress & BT_FORWARD))
		{
			pSpeed[playerNum] = 2.8;
			pStamina[playerNum]--;
		}
		if ((keyPress & BT_SPEED) && (pStamina[playerNum] == 0))
			pSpeed[playerNum] = 1.0;
		else if (!(keyPress & BT_SPEED))
		{
			pSpeed[playerNum] = 1.0;
			if (pStamina[playerNum] < maxStamina)
				pStamina[playerNum]++;
		}
		Print(i:pStamina[playerNum]);
		SetActorProperty(0, APROP_Speed, pSpeed[playerNum]);
		Delay(5);
	}
}

// Functions
Decorate (player class):

Code: Select all

// Decorate
ACTOR NewDoomPlayer : DoomPlayer replaces DoomPlayer
{
	Player.ForwardMove 1, 0.5
	Player.SideMove 1, 0.5
}
Thank you! very useful, took this for my modpack, I will credit you, when it will be here :)

Return to “Resources”