"SetActorProperty" damage troubles

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!)
Post Reply
AnotherLurker
Posts: 36
Joined: Wed May 24, 2017 10:58 am

"SetActorProperty" damage troubles

Post by AnotherLurker »

I'm making a mod where the player's weapon damage is set to a changeable variable in ACS.

But in doing so I've come across a problem.

The weapon's projectile, when fired, activates a script apon spawning which changes its damage according to the variable.

This is all fine and good, no problems here.. The problem comes when it does the actual damage.. The damage follows the doom formula, when I want it to be an exact value, but there doesn't seem to be any
way to make this happen.

Here's the ACS Half of the code.

Code: Select all

int weapondamage = 3;

script 7 (void) // Weapon damage Script
{
SetActorProperty (0, APROP_Damage, weapondamage);
}
This works just fine, but regardless if I put either value in parenthesis, that does not change the value from being effected by the doom formula.
(I have also tried just putting in a basic formula to see if it somehow overrides it, like "SetActorProperty (0, APROP_Damage, (0 + weapondamage))")

Here is the DECORATE portion of the code.

Code: Select all

ACTOR Projectile
{
  Radius 6
  Height 8
  Scale 0.5
  Speed 10
  FastSpeed 20
  Damage (0)
  Projectile
  +RANDOMIZE
  RenderStyle Normal
  States
  {
  Spawn:
    BAL1 A 0
    BAL1 A 1 Bright ACS_Execute (7, 0) //Weapon Damage Script
  Fly:
    BAL1 AB 4
    loop
  Death:
    BAL1 CDE 3 Bright
    Stop
  }
}
The projectile deals 3 damage, but randomly multiplied by 1-8 as per the formula, when I want it to just deal 3.

How would I go about fixing this?
Blue Shadow
Posts: 4949
Joined: Sun Nov 14, 2010 12:59 am

Re: "SetActorProperty" damage troubles

Post by Blue Shadow »

Call the script from the Damage property using [wiki]ACS_ExecuteWithResult[/wiki]:

Code: Select all

actor Projectile
{
    // ...
    Damage (ACS_ExecuteWithResult(7))
    // ...
}
Use [wiki]SetResultValue[/wiki] to return the damage:

Code: Select all

int weapondamage = 3;

script 7 (void) // Weapon damage Script
{
    SetResultValue(weapondamage);
}
AnotherLurker
Posts: 36
Joined: Wed May 24, 2017 10:58 am

Re: "SetActorProperty" damage troubles

Post by AnotherLurker »

This works perfectly!

There's always a lot of learning gaps when trying to learn parts of ACS when your main work is in decorate. I only just recently learned how to use those variables!

I had no idea you could use an ACS_Execute call inside of an actor stat like that! This simplifies a lot of my future code! Thank you so much!

A lot of these commands that do these exact functions all seem so obvious and simple, "after" you've learned about them, but unless you have someone experienced to help teach you the ropes, or
a really decent and slow-paced tutorial to follow, it always feels like this kind of stuff is just too foreboding and complicated to get into, which is why I avoided it for years.

Regardless, this issue is now resolved, thanks for the help!

EDIT: I tried applying this to other actor stats like speed and gravity, but it doesn't seem to like that.. Is this something that can only be applied to damage? Or am I simply doing something wrong?
User avatar
Arctangent
Posts: 1235
Joined: Thu Nov 06, 2014 1:53 pm
Contact:

Re: "SetActorProperty" damage troubles

Post by Arctangent »

AnotherLurker wrote:EDIT: I tried applying this to other actor stats like speed and gravity, but it doesn't seem to like that.. Is this something that can only be applied to damage? Or am I simply doing something wrong?
Damage is a very special property, in that when you put its value in parenthesis, it doesn't take a number, but what is essentially an eval expression that ZDoom runs when applying the damage. This is specifically done via special handling in the Decorate interpreter, something that's not even handled by ZScript due to the clutter it causes - instead, the functionality is done by another property called DamageFunction.

So, no, you can't actually use function calls inside most properties, because they really do just take a simple value with no runtime evaluation.
Post Reply

Return to “Scripting”