Forum

> > CS2D > Scripts > [script] hudtxt gradation
Forums overviewCS2D overview Scripts overviewLog in to reply

English [script] hudtxt gradation

4 replies
To the start Previous 1 Next To the start

old [script] hudtxt gradation

_oops
User Off Offline

Quote
I'm looking for help for make hudtxt gradation depends on specified variable ( which represent percentage or progress.)

It works identical as cs2d player's health. Its color is green if percentage is full and changes to red if it is low.
By stages : Green - Orange - Yellow - Red gradation.
Also it uses hudtxt without hudtxtcolorfade only using color code \169

I tried to make it but I have no great idea for this

1
2
3
4
5
6
7
8
9
10
11
12
Pr = 100;

function display()
local r,g,b = convert(Pr)
parse("hudtxt 0 \"\169"..r.. ""..g...""..b..""..Pr.."%\" 480 10 1")
end

function convert(percentage)
local r, g, b
-- no idea about this part ;(
return r, g, b,
end

It would be great if you give me the answer but I also appreciate you if you give me hint for solution.

old Re: [script] hudtxt gradation

Cure Pikachu
User Off Offline

Quote
Maybe...
1
2
3
4
5
6
7
function convert(percentage)
	local r, g, b
	g = math.floor((percentage/100) * 255)
	r = 255 - g
	b = 0
	return r, g, b
end

old Re: [script] hudtxt gradation

DC
Admin Off Offline

Quote
The green value decreases too quickly in your code, which leads to the missing yellow tones.

Here's the formula used by CS2D if you want it to match perfectly:
1
2
3
red = (100-health)*5.1
green = health*5.1
blue = 0
With health being a value from 0 - 100 and assuming that colors need to be in the range from 0-255. Note that the results actually range from 0 to 510. So depending on how you use them you might have to limit them to a max of 255.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview