#RooTs Posted December 30, 2014 Posted December 30, 2014 (edited) hello friends, I do not know how to do this calculation, I have my script below, that. the color white is going to the red. I want to color 01 going, to color, 02 01 - color(103, 188, 107) 02 - color(255, 0, 0) function getHealthColor() local health = getElementHealth(localPlayer) if (health) then local r = 255 local g = (255/100) * health local b = (255/100) * health return r, g, b else return 0, 255, 0 end end Edited January 6, 2015 by Guest
#RooTs Posted December 30, 2014 Author Posted December 30, 2014 views: +24 response: 0 someone there?
#RooTs Posted December 31, 2014 Author Posted December 31, 2014 views: +40 oh my god, nobody knows this calculation?
Tete omar Posted December 31, 2014 Posted December 31, 2014 function getHealthColor() local health = getElementHealth(localPlayer) if (health) then local r, g, b = interpolateBetween ( 255, 0, 0, 103, 188, 107, health / 100, "Linear" ) return r, g, b else return 0, 255, 0 end end Enjoy
WASSIm. Posted December 31, 2014 Posted December 31, 2014 function getHealthColor() local health = getElementHealth(localPlayer) if (health) then local r, g, b = interpolateBetween ( 255, 0, 0, 103, 188, 107, health / 100, "Linear" ) return r, g, b else return 0, 255, 0 end end Enjoy you forget use getPedMaxHealth to get max health
#RooTs Posted December 31, 2014 Author Posted December 31, 2014 function getHealthColor() local health = getElementHealth(localPlayer) if (health) then local r, g, b = interpolateBetween ( 255, 0, 0, 103, 188, 107, health / 100, "Linear" ) return r, g, b else return 0, 255, 0 end end Enjoy @Tete omar, Thanks man, and Health in 200% ?? local r, g, b = interpolateBetween ( 255, 0, 0, 103, 188, 107, health / 200, "Linear" ) I tried the following function getHealthColor() local health = getElementHealth(localPlayer) if (health) then local r, g, b = interpolateBetween ( 255, 0, 0, 103, 188, 107, health / 100, "Linear" ) and function getHealthColor2() local health = getElementHealth(localPlayer) if (health) then local r, g, b = interpolateBetween ( 255, 0, 0, 103, 188, 107, health / 200, "Linear" ) more when the getHealthColor2 is at 100% it turns orange
MTA Team botder Posted December 31, 2014 MTA Team Posted December 31, 2014 function getVehicleHealthColor(vehicle) if (not isElement(vehicle)) then return end if (getElementType(vehicle) ~= "vehicle") then return end local health = getElementHealth(vehicle) local f = math.max(0, math.min(1, health / 1000)) return math.min(255, (510 * (1-f))), math.min(255, 510 * f), 0 end
Banex Posted December 31, 2014 Posted December 31, 2014 an example of how you can do this: function getHealthColor() local healthRelative = health*rate/100 local health = getElementHealth(localPlayer) local rate = 500/getPedStat(localPlayer,24) local v = health*rate return (100-v)*2.55, (v*2.55), 0 end
#RooTs Posted January 2, 2015 Author Posted January 2, 2015 nothing resolved @Necktrox, its function has nothing to do. @banex, where are the colors my son? return (100-v)*2.55, (v*2.55), 0 --these are the colors? omg
Mizudori Posted January 2, 2015 Posted January 2, 2015 @Lek this function should be real time for players hp or vehicle?
#RooTs Posted January 2, 2015 Author Posted January 2, 2015 @Lek this function should be real time for players hp or vehicle? are for players
#RooTs Posted January 2, 2015 Author Posted January 2, 2015 @Mizudori, the calculation of @Tete omar worked perfectly in 100% Health now at 200% non
WASSIm. Posted January 2, 2015 Posted January 2, 2015 @Mizudori, the calculation of @Tete omar worked perfectly in 100% Healthnow at 200% non look at my post function getHealthColor() local health = getElementHealth(localPlayer) if (health) then local r, g, b = interpolateBetween ( 255, 0, 0, 103, 188, 107, health / 100, "Linear" ) return r, g, b else return 0, 255, 0 end end Enjoy you forget use getPedMaxHealth to get max health
Dealman Posted January 2, 2015 Posted January 2, 2015 more when the getHealthColor2 is at 100% it turns orange If you tried to understand the examples given to you, and read about the functions they used - you would know why. interpolateBetween has a progress argument, where you need to provide a float between 0 and 1. In this case a progress of 1 would mean full health, green. 100/100 = 1.0 (100%) 100/200 = 0.5 (50%) That's why it showed as orange when at 100%.
#RooTs Posted January 2, 2015 Author Posted January 2, 2015 @WASSIm. sorry, you post. is for me? or for @Tete Omar anyway if I did not understand the etPedMaxHealth
MTA Team botder Posted January 2, 2015 MTA Team Posted January 2, 2015 function getPlayerHealthColor(player) if not isElement(player) or getElementType(player) ~= "player" then return 255, 0, 0 end local health = math.max(0, getElementHealth(player)) local stat = getPedStat(player, 24) local maxhealth = math.max(1, 100 + (stat - 569) / 4.31) local f = math.max(0, math.min(1, health / maxhealth)) return math.min(255, (510 * (1-f))), math.min(255, 510 * f), 0 end
RenanPG Posted January 2, 2015 Posted January 2, 2015 Try this one, i'm not sure: function getHealthColor ( ) local progress = getElementHealth ( localPlayer ) / -- getPedMaxHealth ( localPlayer ) -- getPedMaxHealth server-sided, and triggered. local r, g, b = interpolateBetween ( 255, 0, 0, 103, 188, 107, progress, "Linear" ) return r, g, b end
MTA Team botder Posted January 3, 2015 MTA Team Posted January 3, 2015 getPedMaxHealth should work clientside too, because getPedStat is a client- and serverside function.
RenanPG Posted January 3, 2015 Posted January 3, 2015 getPedMaxHealth should work clientside too, because getPedStat is a client- and serverside function. Probably works(i've never tried before), try it LekRoots. function getHealthColor ( ) local progress = getElementHealth ( localPlayer ) / getPedMaxHealth ( localPlayer ) local r, g, b = interpolateBetween ( 255, 0, 0, 103, 188, 107, progress, "Linear" ) return r, g, b end function getPedMaxHealth(ped) local stat = getPedStat(ped, 24) local maxhealth = 100 + (stat - 569) / 4.31 return math.max(1, maxhealth) end
Banex Posted January 3, 2015 Posted January 3, 2015 nothing resolved@Necktrox, its function has nothing to do. @banex, where are the colors my son? return (100-v)*2.55, (v*2.55), 0 --these are the colors? omg Yes, these are the colors
#RooTs Posted January 5, 2015 Author Posted January 5, 2015 still continues.. the error stats 100% orange
#RooTs Posted January 6, 2015 Author Posted January 6, 2015 managed to solve with the function of ( RageScripting/FuriouZ and Tete Omar) @FuriouZ, without want, you helped me Thanks man if ( playerHealth <= 50) then HP_Colour = tocolor(200, 0, 0, 190) HP_Alpha = tocolor(200, 0, 0, 100) else HP_Colour = tocolor(102, 204, 102, 190) HP_Alpha = tocolor(102, 204, 102, 100) end My function function getHealthColor() local health = getElementHealth(getLocalPlayer()) if (health) then local r, g, b = interpolateBetween ( 255, 0, 0, 103, 188, 107, health / 50, "Linear" ) return r, g, b else return 0, 255, 0 end end --within the render local sz1, sz2, sz3 = getHealthColor() local health = math.floor( getElementHealth( getLocalPlayer() )) if ( health <= 50) then HP_Colour = tocolor(sz1, sz2, sz3, 255) HP_Alpha = tocolor(sz1, sz2, sz3, 100) else HP_Colour = tocolor(103, 188, 107, 255) HP_Alpha = tocolor(103, 188, 107, 100) end local stat = getPedStat ( getLocalPlayer(), 24 ) if stat < 1000 then dxDrawRectangle(sW*72, sH*698, sW*115, sH*8, HP_Alpha, false) --fundo dxDrawRectangle(sW*72, sH*698, sW*115/100*health, sH*8, HP_Colour, false) else dxDrawRectangle(sW*72, sH*698, sW*115, sH*8, HP_Alpha, false) --fundo dxDrawRectangle(sW*72, sH*698, sW*115/200*health, sH*8, HP_Colour, false) end @FuriouZ, if you want to use my calculation, stay the will
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now