math, depending on health [+rep]
#1

Hello,

I've got this little progress bar textdraw, and what it does , it shoes vehicle health(letter size according to vehicle health). Now what I don't understand is, how do I add or subtract R,G or B when the vehicle health changes, i.e I want it to be orange when its on half and if it is higher than a half, it should be more green-ish. Kind of a crappy explanation, but I hope you understand what I mean. I got rgb functions and other things I need.

0-255-0 //green
255-50-55 //red
Reply
#2

Bump. I kind of know the solution, but I'm not sure how do I need to get that formula. If anyone knows hyperbola,parabola.. f(x) formulas. I'd need this formula:

Reply
#3

Create 3 Progress Bars for vehicle health one with Green , Other two orange and red. When the vehicle health is greater than 500 show the green Progress bar with vehicle health amount. Add one more check if (vhealth < 500 && vhealth > 300) return showprogressbar the orange one with vhealth amount! Add one more check if the vhealth is < 300 then showprogressbar red one with vhealth amount!
Reply
#4

Thats a simple way of doing it, but I want for the color to change on each health loss/gain according to it's health.
Reply
#5

Quote:
Originally Posted by EV007
Посмотреть сообщение
Thats a simple way of doing it, but I want for the color to change on each health loss/gain according to it's health.
Simple but effective and You can do all that too with these 3 Bars too.
Reply
#6

I have those 3bars, but I prefer doing it the other way
Reply
#7

You would like this : https://sampforum.blast.hk/showthread.php?tid=113443
Reply
#8

I've made the bar myself already, everything works for now, except I need the color formula.
Reply
#9

ok, let me think out loudly a bit.. not a solution:
-car health goes from 1000 (or more if scripted) down to 0.0, the car burns at 250.0 HP (hard to move on if no /fix is there), i assume your player(s) will leave the car now.
-therefore, the color should be RED already when the car reached 250.0 HP, this...
-...difference is 750.0 HP for the "range" of colors. it can be changed later anyways
-health-250.0 will result in the range of 0 to 750..
-divided by 750, the range is normalized, you are working with health values from 0.0 (0/750) upto 1.0 (750/750), its very easy now, to...
-decide for a "resolution" for the color changes, ima do a quick color table:
7 colors (red>yellow>green)
Код:
0xff0000,
0xff5500,
0xffaa00,
0xffff00,
0xaaff00,
0x55ff00,
0x00ff00,
11 (red>yellow>green)
Код:
0xff0000,
0xff3300,
0xff6600,
0xff9900,
0xffcc00,
0xffff00,
0xccff00,
0x99ff00,
0x66ff00,
0x33ff00,
0x00ff00,
or a neater transition (red and green channel changing, this way the brightest yellow will be smoother):
Код:
new ColorBar[25]}{
0xff0000,//pure red for wither 250.0 ot 0.0 HP (depends on divisor 25 or 40 later)
0xff1100,
0xff2200,
0xff3300,
0xff4400,
0xff5500,
0xff6600,
0xff7700,
0xff8800,
0xff9900,
0xeeaa00,
0xddbb00,
0xcccc00,
0xbbdd00,
0xaaee00,
0x99ff00,
0x88ff00,
0x77ff00,
0x66ff00,
0x55ff00,
0x44ff00,
0x33ff00,
0x22ff00,
0x11ff00,
0x00ff00
}
oh, what a coincidence, its using EXACTLY 25 colors:
750/25= 30 HP per color, so lets modify the divisor 750 by the 30 (undo the normalizing):
pawn Код:
(VehicleHP-250)/30=a cell 0 to 24 //my stupid idea to assume the vehicle is "undriveable @ 250 HP)
or without the "dark red" color, which looks ugly anyways://aswell your player WILL die aswell when the vehicle goes 0.0 and explodes)
pawn Код:
VehicleHP/40=cell 0 to 24
and finally,
pawn Код:
new HealthBarResolution=40; //1000/40=25, the sizeof the color array

VehHP=floatround(GetVehicleHealth(blabla)/HealthBarResolution,floatround_floor);
SetBarColor(playerid,ColorBar[VehHP]);
Reply
#10

Thanks for the reply, I already made the function myself. Coffee made my head work again. But I'm still thankful.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)