ACS: Decrease Player Speed Depending On Item Weight

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!)
CaptainNurbles
Posts: 225
Joined: Sat Jan 27, 2018 9:12 pm
Graphics Processor: nVidia (Modern GZDoom)
Location: The Deepest Reaches of Space

ACS: Decrease Player Speed Depending On Item Weight

Post by CaptainNurbles »

I'm working out a sort of encumbrance system which limits the player's ability to carry tons of gear. It's mostly functional, but I know bugger all about ACS and have been having a hard time figuring out how to make the encumbrance part work.

Whenever the player picks up a weapon, inventory item, or piece of armor, it adds a set amount of an inventory item - WeaponBulk. A 10mm pistol adds 12 units. The hard limit is 1200 WeaponBulk units, and after that the player can carry no more. This aspect functions perfectly adequately.

What I'm needing is a separate ACS script which decreases the player's speed based on how much of that WeaponBulk item they have. I've taken some previous scripts used in my mod and attempted to reverse engineer something together, but haven't been super lucky just yet.

Code: Select all

Script "InventorySpeedSystem" ENTER
{
   While(true)
   {
   Delay(1);
   If(CheckActorInventory(0,"WeaponBulk">149)){SetActorProperty(0, APROP_SPEED, 0.75);}
   If(CheckActorInventory(0,"WeaponBulk">299)){SetActorProperty(0, APROP_SPEED, 0.7);}
   If(CheckActorInventory(0,"WeaponBulk">399)){SetActorProperty(0, APROP_SPEED, 0.55);}
   If(CheckActorInventory(0,"WeaponBulk">599)){SetActorProperty(0, APROP_SPEED, 0.4);}
   If(CheckActorInventory(0,"WeaponBulk">799)){SetActorProperty(0, APROP_SPEED, 0.25);}
   If(CheckActorInventory(0,"WeaponBulk">999)){SetActorProperty(0, APROP_SPEED, 0.1);}
   Restart;
   }
}
Jarewill
Posts: 1400
Joined: Sun Jul 21, 2019 8:54 am

Re: ACS: Decrease Player Speed Depending On Item Weight

Post by Jarewill »

The main reason why it isn't working is because you put the condition check in the wrong place.
Instead of If(CheckActorInventory(0,"WeaponBulk">149))
You should use If(CheckActorInventory(0,"WeaponBulk")>149)

A few more notes.
Since it's an ENTER script, CheckInventory can be used instead of CheckActorInventory as the player is the activator.
Restart is not needed as the While will loop without it.
Remember to reset the speed back to 1.0 if none of the conditions pass.
CaptainNurbles
Posts: 225
Joined: Sat Jan 27, 2018 9:12 pm
Graphics Processor: nVidia (Modern GZDoom)
Location: The Deepest Reaches of Space

Re: ACS: Decrease Player Speed Depending On Item Weight

Post by CaptainNurbles »

Well, it partially works! Did as you had recommended and when I'm at the 1,000 bulk threshold it does slow me down significantly. Anything before that however, no difference in speed.

Code: Select all

Script "InventorySpeedSystem" ENTER
{
   While(true)
   {
   Delay(1);
   If(CheckInventory("WeaponBulk")>149){SetActorProperty(0, APROP_SPEED, 0.9);}
   If(CheckInventory("WeaponBulk")>299){SetActorProperty(0, APROP_SPEED, 0.8);}
   If(CheckInventory("WeaponBulk")>399){SetActorProperty(0, APROP_SPEED, 0.65);}
   If(CheckInventory("WeaponBulk")>599){SetActorProperty(0, APROP_SPEED, 0.4);}
   If(CheckInventory("WeaponBulk")>799){SetActorProperty(0, APROP_SPEED, 0.25);}
   If(CheckInventory("WeaponBulk")>999){SetActorProperty(0, APROP_SPEED, 0.1);}
   Else
   SetActorProperty(0,APROP_SPEED,1.0);
   }
}
Jarewill
Posts: 1400
Joined: Sun Jul 21, 2019 8:54 am

Re: ACS: Decrease Player Speed Depending On Item Weight

Post by Jarewill »

Your Else block is put in such a place that it will always trigger below the 1000 threshold.
To fix this, you can either put it at the very beginning outside any blocks, like this:

Code: Select all

   ....
   Delay(1);
   SetActorProperty(0,APROP_SPEED,1.0);
   If(CheckInventory("WeaponBulk")>149){SetActorProperty(0, APROP_SPEED, 0.9);}
   ....
Or by altering the script's logic, like this:
Spoiler:
CaptainNurbles
Posts: 225
Joined: Sat Jan 27, 2018 9:12 pm
Graphics Processor: nVidia (Modern GZDoom)
Location: The Deepest Reaches of Space

Re: ACS: Decrease Player Speed Depending On Item Weight

Post by CaptainNurbles »

That's the ticket! Much appreciated.
User avatar
Graaicko
Posts: 524
Joined: Tue Jun 17, 2014 11:22 pm
Graphics Processor: nVidia (Legacy GZDoom)

Re: ACS: Decrease Player Speed Depending On Item Weight

Post by Graaicko »

This has some Escape from Tarkov vibes.

Return to “Scripting”