math, depending on health [+rep]
#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


Messages In This Thread
math, depending on health - by EV007 - 30.07.2012, 14:41
Re: math, depending on health [+rep] - by EV007 - 31.07.2012, 06:33
Re: math, depending on health [+rep] - by Ballu Miaa - 31.07.2012, 06:46
Re: math, depending on health [+rep] - by EV007 - 31.07.2012, 06:53
Re: math, depending on health [+rep] - by Ballu Miaa - 31.07.2012, 07:04
Re: math, depending on health [+rep] - by EV007 - 31.07.2012, 07:06
Re: math, depending on health [+rep] - by [MM]RoXoR[FS] - 31.07.2012, 07:08
Re: math, depending on health [+rep] - by EV007 - 31.07.2012, 07:11
Re: math, depending on health [+rep] - by Babul - 31.07.2012, 09:20
Re: math, depending on health [+rep] - by EV007 - 31.07.2012, 10:00

Forum Jump:


Users browsing this thread: 1 Guest(s)