GetActorProperty APROP_SpawnHealth broke?

Forum rules
Please don't bump threads here if you have a problem - it will often be forgotten about if you do. Instead, make a new thread here.

Post a reply

Smilies
:D :) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :geek: :ugeek: :!: :?: :idea: :arrow: :| :mrgreen: :3: :wub: >:( :blergh:
View more smilies

BBCode is OFF
Smilies are ON

Topic review
   

Expand view Topic review: GetActorProperty APROP_SpawnHealth broke?

Re: GetActorProperty APROP_SpawnHealth broke?

by Graf Zahl » Mon Sep 21, 2009 11:55 pm

Please don't ask me what the actual motivation was here. I didn't write that code. It was a code submission. But that assumption is not true. deh.MaxHealth is not a player class property but global. And Dehacked patches can be loaded in all games.

Re: GetActorProperty APROP_SpawnHealth broke?

by randi » Mon Sep 21, 2009 9:00 pm

Graf Zahl wrote:0 is a default setting that translates to 'use the default', meaning, the value being set in Dehacked or 100
I suppose the non-Doom classes could have proper values, though, since they can't use Dehacked patches.

Re: GetActorProperty APROP_SpawnHealth broke?

by Zhs2 » Mon Sep 21, 2009 8:52 pm

Thanks for the reply. I did some tinkering and testing with this for a bit, and found that there isn't TOO much problem between map changes and the APROP_SpawnHealth property.

Speaking of tinkering, I also found out that setting a player.maxhealth property for a playerclass seems to initialize the APROP_SpawnHealth property just as setting it with SAP would; however, the default Doomplayer doesn't have a player.maxhealth property -- nor do the other playerclasses for the other games as I browse through zdoom.pk3, it seems. Might be intended, though, if we had to uncover what we did in this topic... =P

Re: GetActorProperty APROP_SpawnHealth broke?

by Graf Zahl » Mon Sep 21, 2009 8:35 am

The safest bet is to do it every map but only if GetActorProperty returns 0. If the value is already set you shouldn't change it.

Re: GetActorProperty APROP_SpawnHealth broke?

by Zhs2 » Mon Sep 21, 2009 6:35 am

And now I know. [wiki=ACS_actor_properties]Fix'd the wiki entry.[/wiki]

Do I have to initialize APROP_SpawnHealth just once for a game, or do I have to do it every map? This is a library script, and I ask because I have another method of stating its initial value, but the way it is set up means only setting it from the first map...

Re: GetActorProperty APROP_SpawnHealth broke?

by Nash » Mon Sep 21, 2009 2:39 am

I never knew 0 was the default. I have been using this for a very long time, but it always worked because for some reason I did remember to initialize it (without even knowing what I was doing) in my startup scripts...

This is some useful information!

Re: GetActorProperty APROP_SpawnHealth broke?

by HotWax » Mon Sep 21, 2009 1:31 am

So basically this script could be fixed very easily:

Code: Select all

script 868 (void)
{
    int maxhealth = GetActorProperty(0, AProp_SpawnHealth);
    if (maxhealth == 0) maxhealth = 100;
    SetActorProperty(0, AProp_SpawnHealth, maxhealth+1);
}
And you're done.

Re: GetActorProperty APROP_SpawnHealth broke?

by Graf Zahl » Sun Sep 20, 2009 11:50 pm

You can't assume that this property is set. 0 is a default setting that translates to 'use the default', meaning, the value being set in Dehacked or 100. If you want to work with AProp_Spawnhealth you have to initialize it first to a meaningful start value or add special handling for the 0-case.

Re: GetActorProperty APROP_SpawnHealth broke?

by Zhs2 » Sun Sep 20, 2009 6:04 pm

Admittedly, I did not think of that. A quick insert of that line does indeed reveal that the maxhealth variable is equal to zero. Fortunately, changing the topic to reflect that only required one character...!

Fixed test attached. =(
sadface.pk3

Re: SetActorProperty APROP_SpawnHealth broke?

by HotWax » Sun Sep 20, 2009 5:41 pm

Did you bother to check the value of maxhealth after assigning it the return value from GetActorProperty? I suspect GAP is returning 0 (which may or may not be a bug...) and so you're setting the player's new max value to 1. Of course that means that as long as the player is alive, he's at or higher than his max health, so only those items which are allowed to go over that would work.

You can test the value of maxhealth by plugging in a print statement:

Code: Select all

script 868 (void)
{
    int maxhealth = GetActorProperty(0, AProp_SpawnHealth);
    print (i:maxhealth);
    SetActorProperty(0, AProp_SpawnHealth, maxhealth+1);
}

GetActorProperty APROP_SpawnHealth broke?

by Zhs2 » Sat Sep 19, 2009 9:48 pm

Confirmed using r1857 and 2.3.1. Apparently, attempting to set the player's maximum health using SetActorProperty APROP_SpawnHealth has a strange effect. The player cannot pick up health restoring items that don't raise health above max, such as Medikits and Stimpacks, after having SetActorProperty called on him.

Relevant code:

Code: Select all

#library "sadface"
#include "zcommon.acs"

script 868 (void)
{
    int maxhealth = GetActorProperty(0, AProp_SpawnHealth);
    SetActorProperty(0, AProp_SpawnHealth, maxhealth+1);
} 
My first attempt, didn't work either:

Code: Select all

script 868 (void)
{
    SetActorProperty(0, AProp_SpawnHealth, (GetActorProperty(0,AProp_SpawnHealth)+1));
} 
A compiled version of the top code. Run, "]puke 868", and "]summon medikit". "]Take health 1" and attempt to pick up for further proof.
sadface.pk3

Top