Forum

Sbar_DrawFace question

Discuss CSQC related programming.

Moderator: InsideQC Admins

Sbar_DrawFace question

Postby smd » Mon Feb 23, 2015 11:42 pm

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

Re: Sbar_DrawFace question

Postby Spike » Tue Feb 24, 2015 1:03 am

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

Re: Sbar_DrawFace question

Postby smd » Tue Feb 24, 2015 7:09 pm

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

Re: Sbar_DrawFace question

Postby PrimalLove » Tue Feb 24, 2015 8:59 pm

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

Re: Sbar_DrawFace question

Postby Spike » Tue Feb 24, 2015 9:21 pm

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

Re: Sbar_DrawFace question

Postby smd » Tue Feb 24, 2015 10:00 pm

thank you very much both of you guys!
it works great now!
nice :D
smd
 
Posts: 26
Joined: Sun Sep 23, 2007 2:58 pm

Re: Sbar_DrawFace question

Postby toneddu2000 » Wed Feb 25, 2015 12:13 pm

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?
toneddu2000
 
Posts: 1286
Joined: Tue Feb 24, 2009 4:39 pm
Location: Italy

Re: Sbar_DrawFace question

Postby Spike » Wed Feb 25, 2015 1:57 pm

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

Re: Sbar_DrawFace question

Postby toneddu2000 » Wed Feb 25, 2015 2:41 pm

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

Re: Sbar_DrawFace question

Postby Cobalt » Sat May 16, 2015 2:58 pm

That code works great Primallove, thank you.
User avatar
Cobalt
 
Posts: 445
Joined: Wed Jun 10, 2009 2:58 am
Location: New England, USA


Return to CSQC Programming

Who is online

Users browsing this forum: No registered users and 1 guest