Half-Life-style damage indicator in ZScript?

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!)
User avatar
wildweasel
Posts: 21706
Joined: Tue Jul 15, 2003 7:33 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): A lot of them
Graphics Processor: Not Listed

Half-Life-style damage indicator in ZScript?

Post by wildweasel »

So, I'm working on polishing off the to-do list for ww-cola3 finally, and one of the items that is vexing me atm is my method for displaying the direction of incoming damage. I'm currently hijacking the mugshot for this, but things like player skins and other IWADs are messing with this. I can add +NOSKIN to my player class, but this has undesirable side-effects at the moment. Is there a better way to handle it using ZScript?
User avatar
Matt
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia

Re: Half-Life-style damage indicator in ZScript?

Post by Matt »

angleto(inflictor), then storing that somewhere on the custom playerpawn and accessing it on the hud?
User avatar
wildweasel
Posts: 21706
Joined: Tue Jul 15, 2003 7:33 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): A lot of them
Graphics Processor: Not Listed

Re: Half-Life-style damage indicator in ZScript?

Post by wildweasel »

That sounds like it has some merit, but I'm afraid I'm not very good at ZScript in order to put that into practice, and poring through gzdoom.pk3 for examples has left me a bit clueless. Would you mind elaborating a bit for me?
User avatar
m8f
 
 
Posts: 1446
Joined: Fri Dec 29, 2017 4:15 am
Preferred Pronouns: He/Him
Operating System Version (Optional): Manjaro Linux
Location: Siberia (UTC+7)

Re: Half-Life-style damage indicator in ZScript?

Post by m8f »

Damage Direction Overlay has an example of displaying the direction of incoming damage in ZScript.
User avatar
wildweasel
Posts: 21706
Joined: Tue Jul 15, 2003 7:33 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): A lot of them
Graphics Processor: Not Listed

Re: Half-Life-style damage indicator in ZScript?

Post by wildweasel »

Well, if that's literally just a drop-in mod, Cola3 has little business importing it as-is...can't make much sense of the code to adapt for my needs, either. Thank you for the pointer, though.
User avatar
Matt
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia

Re: Half-Life-style damage indicator in ZScript?

Post by Matt »

To get the relative angle, first we need to get the direction the thing inflicting damage is coming from. The simplest way I can think of is by overriding the player's DamageMobj(), so somewhere in your playerpawn definition you would have:

Code: Select all

    double angletoinflictor; //used to store the damage angle
    override int damagemobj
    (
        actor inflictor,actor source,int damage,
        name mod,int flags,double angle
    ){
        //calculate the relative angle
        if(inflictor)
        {
            angletoinflictor = deltaangle (angle, angleto(inflictor));
        }

        //do all the regular stuff
        return super.damagemobj
        (
            inflictor,source,damage,mod,flags,angle
        );
    }
Then in your HUD you would access the player's "angletoinflictor". There are so many ways that this could be set up I'm a bit stuck writing an example; you can even use SBARINFO and give the appropriate inventory dummy items in the above DamageMobj call (including "DamagedForward", etc. so you could pass on the angletoinflictor info - in which case you could just demote the angletoinflictor variable to a local variable called only in the function and not stored on the actor).
User avatar
wildweasel
Posts: 21706
Joined: Tue Jul 15, 2003 7:33 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): A lot of them
Graphics Processor: Not Listed

Re: Half-Life-style damage indicator in ZScript?

Post by wildweasel »

Well, I'm still running into problems, though not with any of the code given to me here - I just can't get it to a point where I can even display anything on screen, and I'm positive it's because I'm doing literally everything else wrong.

https://drive.google.com/file/d/1iUY5D8 ... sp=sharing - Here's a link to the project as it stands. Most of the problem code is commented out, so it doesn't crash on startup, but I have literally no idea what I'm doing with any of it.
User avatar
Matt
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia

Re: Half-Life-style damage indicator in ZScript?

Post by Matt »

What's DamageTimer and where is it supposed to be defined?
User avatar
wildweasel
Posts: 21706
Joined: Tue Jul 15, 2003 7:33 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): A lot of them
Graphics Processor: Not Listed

Re: Half-Life-style damage indicator in ZScript?

Post by wildweasel »

Matt wrote:What's DamageTimer and where is it supposed to be defined?
damageTimer gets pulled from within the player class in /zscript/ColaPlayer.txt. Or at least, I think it does, I don't think I've quite done that correctly.
User avatar
Matt
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia

Re: Half-Life-style damage indicator in ZScript?

Post by Matt »

If it's a property of WWColaPlayer then it has to be called through a casted pointer.

I see that's already been done further down in the bigger version of DrawDamageIndicator, but before that there's a missing set of conditionals for the block starting with "damageAlpha = current / 35.0;". I'll change that from "if" to "if(1)".

I'm going to guess that the while loop at the end is intended to fade the thing over time. That won't work, because all of this is going to be done in the same tic. I'll change that to an if.

You've got 2 variables both based on playerpawn damageTimer. I'm going to just use one for both of them to the playerpawn.

Remember that if you define a variable within a function, it's going to remember only what happened during that function call - next time it's called you start fresh, and it can't be accessed in another function.

I can't find where DamageTimer is being changed (should be added every DamageMobj and reduced by 1 every tick) so I'm just going to add them.
You do not have the required permissions to view the files attached to this post.
Last edited by Matt on Sat Jun 09, 2018 12:05 pm, edited 1 time in total.
User avatar
Nash
 
 
Posts: 17465
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia

Re: Half-Life-style damage indicator in ZScript?

Post by Nash »

@ Matt -

I've put something together based on the info your gave, but my problem is that it's only accurate for projectile monsters and melee monsters. For hitscanners, the direction seems to be way off. Any ideas?
You do not have the required permissions to view the files attached to this post.
User avatar
Matt
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia

Re: Half-Life-style damage indicator in ZScript?

Post by Matt »

No idea!

The worst part is that if I do this:

Code: Select all

//debug
actor ppp=Spawn("InflictorPosition",inflictor.pos);
ppp.angle=AngleTo(inflictor)+180;

            // update the HUD's damage indicator
            lastDamageAngle = DeltaAngle(Angle, AngleTo(ppp));
            wasDamaged = true;
...
class InflictorPosition:Actor{
    default{+nointeraction renderstyle "add";scale 0.4;}
    states{spawn:BAL7 A 10 bright A_FadeOut(0.1);wait;}
}
it actually works fine!

Something to do with the bullet puff disappearing for blood maybe?

Return to “Scripting”