Jump to content

showElementHealth


Klesh

Recommended Posts

Hi to everyone, im doing a health script and this shows the health of the player on the scoreboard but some code is wrong and is not showing, here is the code:

Server-Side:

addEventHandler("onResourceStart", getResourceRootElement(getThisResource()),  
function() 
  exports.scoreboard:addScoreboardColumn("Health") 
end) 
  
function scoreboardHealthUpdate(a,b,c) 
  if getElementType(source) == "player" then 
    player = source 
  elseif getElementHealth(source) == "player" then 
    player = getElementHealth(source) 
     
  end 
  if player and player then  
    local damage = 0 
    if not b and not c then damage = a end 
    local health = math.floor((getElementHealth(player)-250-damage)/750*100) 
    setElementData(player, "Health", health.."%") 
  elseif player then 
    setElementData(player, "Health", "---")   
  end 
end 
  
addEventHandler("onPlayerDamage", getRootElement(), scoreboardHealthUpdate) 
addEventHandler("onPlayerSpawn", getRootElement(), scoreboardHealthUpdate) 
addEventHandler("onPlayerLogin", getRootElement(), scoreboardHealthUpdate) 
addEventHandler("onPlayerWasted", getRootElement(), scoreboardHealthUpdate) 
  

Link to comment

I don't know why you do all that, it's useless.

addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), 
function() 
  exports.scoreboard:addScoreboardColumn("Health") 
end) 
  
function scoreboardHealthUpdate() 
  if source and getElementType(source) == "player" then 
    local health = math.floor(getElementHealth(source)) 
    setElementData(source, "Health", health.."%") 
  end 
end 
  
addEventHandler("onPlayerDamage", getRootElement(), scoreboardHealthUpdate) 
addEventHandler("onPlayerSpawn", getRootElement(), scoreboardHealthUpdate) 
addEventHandler("onPlayerLogin", getRootElement(), scoreboardHealthUpdate) 
addEventHandler("onPlayerWasted", getRootElement(), scoreboardHealthUpdate) 

Link to comment
Its only in-game the health player have and to know if this is hack or not:

Example: I kill someone with Hunter or grenades but i cant see the player with that you see the player health.

he is not talking about that your function had useless things, i think.

Link to comment

Yes works fine, thanks a lot castillo and my error was here:

if player and player then 
    local damage = 0 
    if not b and not c then damage = a end 
    local health = math.floor((getElementHealth(player)-250-damage)/750*100) 
    setElementData(player, "Health", health.."%") 
  elseif player then 
    setElementData(player, "Health", "---")   
  end 
end 

The Fix:

function scoreboardHealthUpdate() 
  if source and getElementType(source) == "player" then 
    local health = math.floor(getElementHealth(source)) 
    setElementData(source, "Health", health.."%") 
  end 
end 

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...