Author Topic: Using Port's RTBtoHEX (Solved)  (Read 732 times)

(http://forum.blockland.us/index.php?topic=214415.msg6259102#msg6259102)
I have been using this to fade a better color than a red to a weird green then to a green. I am having issues. Is there a better way then this?

   %hp = %target.getHealth();

   %dmgPer = %target.getDamageLevel();
   %dmgPer = %dmgPer / %target.getDatablock().maxDamage;
   %percent = 1 - %dmgPer;
   if(%percent <= 1)
   {
      %green = %percent; // The higher the health (percent), the more green.
      %red = %dmgPer; // The higher the damage (dmgPer), the more red.
      
      %hpcol = %red SPC %green SPC "0";
   }
   else
      %hpcol = "1 1 1";
« Last Edit: July 19, 2014, 07:54:43 PM by Advanced Bot »

I made the exact same effect in my RC biplane. I originally tried to find a script that could make it change HSV to RGB from red to green, then use this to change it to Hex, but I ended up making my own little function to change the colors which ended up being much easier.

%a is 1 - %target.getDamagePercent();.
Code: [Select]
function greenToRed(%a)
{
%r = 1;
%g = 1;
if(%a >= (1/2))
{
%r = mAbs(%a - 1) * 2;
}
if(%a < (1/2))
{
%g = %a * 2;
}
return %r SPC %g SPC "0";
}
You just have to plug that into Port's function and it should give it to you in RGB Hex.
« Last Edit: July 20, 2014, 03:24:10 PM by Crysist »