With csqc, you can make your own HUD. This is a small noob explanation on how you can draw a string that represents your health. A bonus: Whenever your health reaches 25, it will pulse a red color! Neat, huh?
As usual, my code is heavily commented for your learning:
Code: Select all
//=================
vector healthcolor;
float healthtoggle;
//=================
//above is for pulsing health (a boolean float and the gradually changing vector(every pulsing item needs a separate set)
vector hpos;//position health text
float(float ccolor, float colortoggle, float minc, float maxc, float pulsespeed) valuepulse = //my nifty pulsing code (can be used to pulse anything, not just colors. can be used with alpha as well!)
{
if (ccolor >= maxc)//if your color reaches the max allowed
colortoggle = FALSE;//make the toggle false
else if (ccolor <= minc)//if your color reaches the minimum allowed
colortoggle = TRUE;//make toggle true
if (colortoggle == TRUE)//if toggle is true
ccolor = ccolor + pulsespeed;//increase color by desired speed
else
ccolor = ccolor - pulsespeed;//otherwise, decrease color by desired speed
return ccolor;//give color value
}
void() DrawHealth =
{
float currenthealth;
string healthstring;
currenthealth = getstati(STAT_HEALTH);//gets your health value
hpos_x = vid_size_x * 0.0150;
hpos_y = vid_size_y * 0.8500;//positions health string
healthcolor_x = 1;//set this to the color you want to pulse it to (x = red, y = green, z = blue). if you change, be sure you adjust the other healthcolor_'s ac
if (currenthealth > 25)//if your health is above 25
healthcolor_y = 1;//don't pulse
else
healthcolor_y = valuepulse(healthcolor_y, healthtoggle, 0.25, 1, 0.05);//else start pulsing. explanation on how to use:
/*
healthcolor_y: which float to pulse
healthtoggle: which float to use as boolean(switch)
0.25: lowest allowed number for float to reach before pulsing up
1: highest allowed number for float to reach before pulsing down
0.05: speed of pulse (higher number = faster pulse)
*/
healthcolor_z = healthcolor_y;//make sure the other value (z in this case) equals the pulsing value
healthstring = ftos(currenthealth);//makes your health a string so you can print it.
if (currenthealth > 0)//if you are alive
drawstring(hpos, healthstring, '10 10 0', healthcolor, 0.75, 0);//draw your health string
}
Then in the View.qc file, in the function CSQC_UpdateView (maybe called something else in FTE), add this to the bottom of it:
explaining how to drawstring:
look at this example: drawstring(where, what, howbig, whatcolor, howopaque, flag);
where: this is the position of the text(vector)
what: this is the text to write(string)
howbig: this is the size of text(vector)(example: '10 10 0', which is width x height). never mess with the last value and keep it a zero since this is the z value (depth). it is invalid here since the text is 2d.
whatcolor: this is the color of text(vector). in my code: if health is above 0, it's white. otherwise, it pulses red.
howopaque: alpha of text(float). AKA how transparent the text is. lower values = more transparent.
flag: this is a boolean flag(float). if its set to a number besides 0, your text's transparency will be affected by it's color vector. basically a text with it's color '0.4 0.1 0.2' will be more transparent than a text with it's color '1 0.7 0.5'
Enjoy! More posts coming soon!