Jump to content

Some maths help :D


.:HyPeX:.

Recommended Posts

Hey guys, who can help me work this thingy out?

I want to display health(0-100) to R(0-255) but inverted, (like 100 = 0)

Basically i did this, but idk how to invert it.

  
local health = getElementHealth(player) 
local health = math.floor((health)/1) 
local health = math.ceil(health) 
local health = health / 100 
local health = health * 255 
  

Ths makes that at 100% health, the R will be 255, how can i make it the other way arround?

Link to comment

Try:

local maxRedCol = 255 
local health = getElementHealth(player) 
local red = maxRedCol - ((health*255) /100) 
red = math.ceil(red) 

But you still have to adjust with getPedStat(thePlayer, 24), if player's health returns a value greater than 100.

Link to comment
Try:
local maxRedCol = 255 
local health = getElementHealth(player) 
local red = maxRedCol - ((health*255) /100) 
red = math.ceil(red) 

But you still have to adjust with getPedStat(thePlayer, 24), if player's health returns a value greater than 100.

it should never get greater than 100, (my script stops it at 99.9)

Link to comment
it should never get greater than 100, (my script stops it at 99.9)

Well, if you've done a system for that (as you said), then ok.

But keep in mind, if the max health stat is more than 569, then player's max health will be greater than 100%.

Link to comment
i don 't really get what you're trying to do.

Just make the screen turn red when you're on low health

function addRednessOnDamage ( ) 
    local playerHealth = getElementHealth ( source ) 
   local theVehicle = getPedOccupiedVehicle(source) 
    if playerHealth<=20 then 
      fadeCamera ( source, false, 2.5, 255, 0, 0 )         -- fade the player's camera to red over a period of 1 second 
      setTimer ( fadeCamera2, 900, 1, source )   -- don't let it go to opaque red, interrupt it after half a second and fade back to normal 
    else 
      fadeCamera ( source, false, 2.5, 255, 0, 0 )         -- fade the player's camera to red over a period of 1 second 
      setTimer ( fadeCameraDelayed, 500, 1, source )   -- don't let it go to opaque red, interrupt it after half a second and fade back to normal 
     end 
end 
addEventHandler ( "onPlayerDamage", getRootElement(), addRednessOnDamage ) 
  
function fadeCameraDelayed(player) -- This function prevents debug warnings when the player disconnects while the timer is running. 
      if (isElement(player)) then 
            fadeCamera(player, true, 1.0) 
      end 
end 
  
function fadeCamera2(player) 
      if (isElement(player)) then 
            fadeCamera(player, true, 20.0) 
      end 
end 

Link to comment
i don 't really get what you're trying to do.

Just make the screen turn red when you're on low health

function addRednessOnDamage ( ) 
    local playerHealth = getElementHealth ( source ) 
   local theVehicle = getPedOccupiedVehicle(source) 
    if playerHealth<=20 then 
      fadeCamera ( source, false, 2.5, 255, 0, 0 )         -- fade the player's camera to red over a period of 1 second 
      setTimer ( fadeCamera2, 900, 1, source )   -- don't let it go to opaque red, interrupt it after half a second and fade back to normal 
    else 
      fadeCamera ( source, false, 2.5, 255, 0, 0 )         -- fade the player's camera to red over a period of 1 second 
      setTimer ( fadeCameraDelayed, 500, 1, source )   -- don't let it go to opaque red, interrupt it after half a second and fade back to normal 
     end 
end 
addEventHandler ( "onPlayerDamage", getRootElement(), addRednessOnDamage ) 
  
function fadeCameraDelayed(player) -- This function prevents debug warnings when the player disconnects while the timer is running. 
      if (isElement(player)) then 
            fadeCamera(player, true, 1.0) 
      end 
end 
  
function fadeCamera2(player) 
      if (isElement(player)) then 
            fadeCamera(player, true, 20.0) 
      end 
end 

Pretty much unuseful if you're being spammed with an M4..

Link to comment
function addRednessOnDamage ( ) 
    local playerHealth = getElementHealth ( source ) 
   local theVehicle = getPedOccupiedVehicle(source) 
    if playerHealth<=20 then 
      fadeCamera ( source, false, 2.5, 255, 0, 0 )         -- fade the player's camera to red over a period of 1 second 
      setTimer ( fadeCamera2, 900, 1, source )   -- don't let it go to opaque red, interrupt it after half a second and fade back to normal 
    else 
      fadeCamera ( source, false, 2.5, 255, 0, 0 )         -- fade the player's camera to red over a period of 1 second 
      setTimer ( fadeCameraDelayed, 500, 1, source )   -- don't let it go to opaque red, interrupt it after half a second and fade back to normal 
     end 
end 
addEventHandler ( "onPlayerDamage", getRootElement(), addRednessOnDamage ) 
  
function fadeCameraDelayed(player) -- This function prevents debug warnings when the player disconnects while the timer is running. 
      if (isElement(player)) then 
            fadeCamera(player, true, 1.0) 
      end 
end 
  
function fadeCamera2(player) 
      if (isElement(player)) then 
            fadeCamera(player, true, 20.0) 
      end 
end 

Pretty much unuseful if you're being spammed with an M4..

I made it quickly based on what is put on the MTA Wiki. You can change it however you wish. I'm just showing you a example you could use to build your own.

Link to comment
function addRednessOnDamage ( ) 
    local playerHealth = getElementHealth ( source ) 
   local theVehicle = getPedOccupiedVehicle(source) 
    if playerHealth<=20 then 
      fadeCamera ( source, false, 2.5, 255, 0, 0 )         -- fade the player's camera to red over a period of 1 second 
      setTimer ( fadeCamera2, 900, 1, source )   -- don't let it go to opaque red, interrupt it after half a second and fade back to normal 
    else 
      fadeCamera ( source, false, 2.5, 255, 0, 0 )         -- fade the player's camera to red over a period of 1 second 
      setTimer ( fadeCameraDelayed, 500, 1, source )   -- don't let it go to opaque red, interrupt it after half a second and fade back to normal 
     end 
end 
addEventHandler ( "onPlayerDamage", getRootElement(), addRednessOnDamage ) 
  
function fadeCameraDelayed(player) -- This function prevents debug warnings when the player disconnects while the timer is running. 
      if (isElement(player)) then 
            fadeCamera(player, true, 1.0) 
      end 
end 
  
function fadeCamera2(player) 
      if (isElement(player)) then 
            fadeCamera(player, true, 20.0) 
      end 
end 

Pretty much unuseful if you're being spammed with an M4..

I made it quickly based on what is put on the MTA Wiki. You can change it however you wish. I'm just showing you a example you could use to build your own.

if you read carefully, i wanted the maths part, not the script imo. (even the topic name says so)

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...