Damage Slow Movement for Players and Monsters

Archive of the old editing forum
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. This forum is archived - please use this set of forums to ask new questions.
Locked
Skwirl
Posts: 214
Joined: Sun Feb 01, 2015 11:38 pm
Location: 'merica
Contact:

Damage Slow Movement for Players and Monsters

Post by Skwirl »

Okay, so now I'm really getting my hands dirty with ACS. At the time of this writing my head is feeling all-over-the-place so I'm probably missing important information to get the help I need, but um...

I'm trying to do an effect for all monsters and players in any given level, where their movement speed is proportional to the amount of damage they took beneath their standard amount. I need this to be a constant system so it is done evenly and without interruption or other cockamamie flaws.

So I need to make ACS that:

1. Keeps track of the original health and speed values, so even if a player/monster has more than 100% of their normal health, the code won't run, or if it's less, the code will. Remember, players may have 100 or 200 health, but some monsters can have 400 to 4000 health, so percentages and proportion math will be necessary.

2. Runs a constant loop for each character actor (both player and monster) to make sure the values are what they're supposed to be instead of doing it in specific states.

3. Takes into account that I have weapons that set speed values, that these should not reset the movement speed (it happened to me during testing).

4. When health gets unbearably low, the speed limiting effect should cut off so you aren't completely immobile when you're down to like 15% of health points or less.

I originally wanted to write this as an OPEN script to run across the level for every player and monster that does spawn while the level is active (thus use a loop). Then I found out that it's impossible to keep an array of every specific player and monster on the map.

That's when I decided to instead make it a required ACS call for each player or monster that spawns in the Spawn: state, and move its original Spawn: to Idle:. Doing this makes a little more sense, because now it is specific to whatever actors have it rather than relying on the level to decide that.

I made sure my library, file, and even script names are all the same exact name, and 8 characters or less. I used LOADACS to ensure that the .o gets loaded in. But the game kept throwing an "unrecognized" script, even with [ Spawn: TNT1 A 1 ACS_NamedExecuteAlways("dmgslwmv") ].

If it helps any, here's my ACS...

Code: Select all

/*
Damage Slow Move

When a character actor (player or enemy) suffers enough damage,
they will start to move slower than normal.

This must be called on every relevant actor's Spawn state.
*/



// Initial
#library "dmgslwmv"

#include "zcommon.acs"



// Main Script
script "dmgslwmv" ENTER {

	int health = GetActorProperty(0, APROP_Health);
	int speed = GetActorProperty(0, APROP_Speed);

	while (GetActorProperty(0, APROP_Health > 0)) {
		int newspeed = (GetActorProperty(0, APROP_Health)*speed)/health;
		SetActorProperty(0, APROP_Speed, newspeed);
               // Still need to do the "very low health" limiter so you aren't completely trapped.
		delay(1);
	}

}
Blue Shadow
Posts: 5046
Joined: Sun Nov 14, 2010 12:59 am

Re: Damage Slow Movement for Players and Monsters

Post by Blue Shadow »

Could you post the WAD/PK3 so we can take a look and see what's wrong?
User avatar
arookas
Posts: 265
Joined: Mon Jan 24, 2011 6:04 pm
Contact:

Re: Damage Slow Movement for Players and Monsters

Post by arookas »

Skwirl wrote:That's when I decided to instead make it a required ACS call for each player or monster that spawns in the Spawn: state, and move its original Spawn: to Idle:. Doing this makes a little more sense, because now it is specific to whatever actors have it rather than relying on the level to decide that.
You might want to make sure you guard it with a user variable or something to ensure it really only runs once. If the actor returns to the Spawn state through another state (e.g. Pain), it'll execute the script again.
I made sure my library, file, and even script names are all the same exact name, and 8 characters or less. I used LOADACS to ensure that the .o gets loaded in. But the game kept throwing an "unrecognized" script, even with [ Spawn: TNT1 A 1 ACS_NamedExecuteAlways("dmgslwmv") ].
Also make sure the compiled library is in the ACS namespace (in a pk3 this is the "acs" folder, in wads this is the A_* markers). Other than that, I wouldn't know the problem without seeing an example file.

Code: Select all

int newspeed = (GetActorProperty(0, APROP_Health)*speed)/health;
Health is integer, so you need to cast them to fixed points in order to get a fractional scalar (otherwise, you'd be doing integer division). You are also multiplying the health by the speed. You should get the scalar first, then multiply by speed like so:

Code: Select all

int newspeed = FixedMul(FixedDiv(GetActorProperty(0, APROP_Health) << 16, health << 16), speed);
As for the speed cap, you could either use a max clamp to make sure it doesn't, for example, go below 20% of the original speed. Or you could make the proportion go from 100% health - 100% speed to 0% health - 20% speed. This could be done like so:

Code: Select all

#define MINSPEED 0.2
#define MAXSPEED 1.0

...

int healthpercent = FixedDiv(GetActorProperty(0, APROP_Health) << 16, health << 16);
if (healthpercent > 1.0) {
  healthpercent = 1.0; // clamp when over spawn health
}
int newspeed = FixedMul(1.0 - healthpercent, MINSPEED) + FixedMul(healthpercent, MAXSPEED); // basic lerp function
SetActorProperty(0, APROP_Speed, newspeed);
Also, I would recommend using the ENTER script type for starting scripts on players rather than using their actor states to call it.
Skwirl
Posts: 214
Joined: Sun Feb 01, 2015 11:38 pm
Location: 'merica
Contact:

Re: Damage Slow Movement for Players and Monsters

Post by Skwirl »

Both of you made a point about looking through the code. I made my latest Github update with my mod work now, if you want to look through it and see...

https://github.com/Tricorne-Games/Count ... t/tree/mod
Skwirl
Posts: 214
Joined: Sun Feb 01, 2015 11:38 pm
Location: 'merica
Contact:

Re: Damage Slow Movement for Players and Monsters

Post by Skwirl »

Also, how would I make this work so that depending on whatever weapon I use, that additionally impacts the speed?

If I'm using a pistol, I should move fast enough. If I'm lugging around a bazooka, that should slow me considerably.

Is there an appropriate process? All I can think of is that assuming this works the way I think it does, the ACS loop doing this health check would be done first always, then move the A_SetSpeed (or whatever) to the weapon's Ready: state so as long as the gun is up, the speed is whatever the ACS does, FOLLOWED by the weapon's own effect, so when I swap out to another weapon, the ACS is still called, followed by the new weapon.

Or wouldn't the weapon's own update do that? Wouldn't I need to make another ACS that takes in a specific parameter so it's not a definite value but based on what speed is currently?
Locked

Return to “Editing (Archive)”