Sbar_DrawFace question

Discuss CSQC related programming.
Post Reply
smd
Posts: 26
Joined: Sun Sep 23, 2007 2:58 pm

Sbar_DrawFace question

Post 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);
Spike
Posts: 2914
Joined: Fri Nov 05, 2004 3:12 am
Location: UK
Contact:

Re: Sbar_DrawFace question

Post 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.
smd
Posts: 26
Joined: Sun Sep 23, 2007 2:58 pm

Re: Sbar_DrawFace question

Post 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!
PrimalLove
Posts: 14
Joined: Sun Oct 19, 2014 2:37 am

Re: Sbar_DrawFace question

Post 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.
Spike
Posts: 2914
Joined: Fri Nov 05, 2004 3:12 am
Location: UK
Contact:

Re: Sbar_DrawFace question

Post 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.
smd
Posts: 26
Joined: Sun Sep 23, 2007 2:58 pm

Re: Sbar_DrawFace question

Post by smd »

thank you very much both of you guys!
it works great now!
nice :D
toneddu2000
Posts: 1395
Joined: Tue Feb 24, 2009 4:39 pm
Location: Italy

Re: Sbar_DrawFace question

Post 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?
Meadow Fun!! - my first commercial game, made with FTEQW game engine
Spike
Posts: 2914
Joined: Fri Nov 05, 2004 3:12 am
Location: UK
Contact:

Re: Sbar_DrawFace question

Post 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).
toneddu2000
Posts: 1395
Joined: Tue Feb 24, 2009 4:39 pm
Location: Italy

Re: Sbar_DrawFace question

Post 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
Meadow Fun!! - my first commercial game, made with FTEQW game engine
Cobalt
Posts: 445
Joined: Wed Jun 10, 2009 2:58 am
Location: New England, USA
Contact:

Re: Sbar_DrawFace question

Post by Cobalt »

That code works great Primallove, thank you.
Post Reply