Page 1 of 1

Sbar_DrawFace question

Posted: Mon Feb 23, 2015 11:42 pm
by smd
Hi!

I have edited my HUD in darkplaces, all works fine except the little animation for the gfx/face!

It only changes to face1, face2, face3, face4, face5, it misses the face_p1, face_p2, face_p3, face_p4, face_p5 when i get hit!

Maybe someone can help, would be great

Here is what i got:


health = GetStat_FLOAT_TRUNCATED(STAT_HEALTH);
if (health < 0)
health = 0;
if (health >= 100)
f = 4;
else
f = floor(health / 20);

Sbar_DrawPic('-208 24 0', strcat("gfx/face", ftos(5 - f)), ALPHA_FULL, 1);

Re: Sbar_DrawFace question

Posted: Tue Feb 24, 2015 1:03 am
by Spike
dp has dmg_take, dmg_save, dmg_origin globals in its csqc.
if take or save is set, make a note of the time and if it happened within the last second or so, insert an extra _p into the drawpic image name.

Re: Sbar_DrawFace question

Posted: Tue Feb 24, 2015 7:09 pm
by smd
thanks for your help but im a newbie.

how can i set this dmg_values and where to put them?

its annoying i know, sorry!

Re: Sbar_DrawFace question

Posted: Tue Feb 24, 2015 8:59 pm
by PrimalLove
This is just an example poorly written but you can clean it up:

Code: Select all

// Global
float	 dmg_take;
float	 dmg_save;
float dmg_origin;
float PainTime;

// Put this or something similar in your HUD display function. 
// Local
string Icon
Health = getstati(STAT_HEALTH);
	if(dmg_take)
		PainTime = time + 0.3;
	if(Health < 20)
	{
		if(PainTime > time)
			Icon = "gfx/face_p5";
		else
			Icon = "gfx/face5";
	}
	else if(Health < 40)
	{
		if(PainTime > time)
			Icon = "gfx/face_p4";
		else
			Icon = "gfx/face4";
	}
	else if(Health < 60)
	{
		if(PainTime > time)
			Icon = "gfx/face_p3";
		else
			Icon = "gfx/face3";
	}
	else if(Health < 80)
	{
		if(PainTime > time)
			strIcon = "gfx/face_p2";
		else
		    strIcon = "gfx/face2";
	}
	else
	{
		if(PainTime > time)
			Icon = "gfx/face_p1";
		else
			Icon = "gfx/face1";
	}

	Sbar_DrawPic('-208 24 0', Icon, ALPHA_FULL, 1);

dmg_take is the global value Spike mentioned. Hope this helps.

Re: Sbar_DrawFace question

Posted: Tue Feb 24, 2015 9:21 pm
by Spike
smd wrote:how can i set this dmg_values
*YOU* don't. The engine sets them.
Somewhere in your csqc's defs, define them as:

Code: Select all

float dmg_take, dmg_save; //engine-set
float dmg_time; //qc-set
And just inside your CSQC_UpdateView function, put

Code: Select all

if (dmg_take || dmg_save)
    dmg_time = time + 0.1;
then your drawpic becomes:

Code: Select all

Sbar_DrawPic('-208 24 0', strcat("gfx/face", (dmg_time > time)?"_p":"", ftos(5 - f)), ALPHA_FULL, 1);
or, if you want to get really compact, you can use this to replace your entire code in your original paste:

Code: Select all

Sbar_DrawPic('-208 24 0', strcat("gfx/face", (dmg_time > time)?"_p":"", ftos(5 - floor(bound(0, GetStat_FLOAT_TRUNCATED(STAT_HEALTH)/20, 4)))), ALPHA_FULL, 1);
I should probably also mention that I consider depending upon drawgetimagesize (for anything other than aspect) to be a bad practise, as it assumes that artwork conforms to a specific scale.

Re: Sbar_DrawFace question

Posted: Tue Feb 24, 2015 10:00 pm
by smd
thank you very much both of you guys!
it works great now!
nice :D

Re: Sbar_DrawFace question

Posted: Wed Feb 25, 2015 12:13 pm
by toneddu2000
Spike wrote:*YOU* don't. The engine sets them.
Wow.Didn't know that. Is it the same for FTEQW? Does FTE set them too?

Re: Sbar_DrawFace question

Posted: Wed Feb 25, 2015 1:57 pm
by Spike
no. they are fields in ssqc and thus I refuse to make them non-fields in csqc as it would force inconsistancies.
I'll add a CSQC_Parse_Damage as compensation, allowing you to emulate it (or easily inhibit it).

Re: Sbar_DrawFace question

Posted: Wed Feb 25, 2015 2:41 pm
by toneddu2000
yeah, imo what FTEQW really needs is documentation: a solid documentation that explains in details all the CSQC_ builtin fuctions, one by one. I'm trying to do it by myself but I'm too noob to do the task all on my own. Because, for what I understood, the power of CSQC_ builtins is that you can use them as class-parented methods in Object-Oriented languages. If you let them unchanged, the default method will be applied. If you modify it, you'll ovveride default method. Which it's awesome, imo, but maybe that'd need a little documentation more

Re: Sbar_DrawFace question

Posted: Sat May 16, 2015 2:58 pm
by Cobalt
That code works great Primallove, thank you.