Jump to content

get health from server


TroyBoy

Recommended Posts

You mean give the player health? example: player has 50 HP, and you write /health 20 and the player health will be 70 HP? if so:

addCommandHandler( 'health', 
    function( player, cmd, theHealth )  
        local theHealth = tonumber(theHealth) 
        if (theHealth) then 
            setElementHealth(player, getElementHealth( player ) + theHealth) 
            outputChatBox( 'Your health is now '..tostring( math.floor( getElementHealth( player ) ) )..'!',player,0,255,0 ) 
        end 
    end 
) 

Link to comment

So use:

  
addCommandHandler( 'health', 
    function( player, cmd, theHealth )  
        local theHealth = tonumber(theHealth) 
        if (theHealth) then 
            setElementHealth(player, theHealth) 
            outputChatBox( 'Your health is now '..tostring( math.floor( getElementHealth( player ) ) )..'!',player,0,255,0 ) 
        end 
    end 
) 
  

Link to comment
  • Discord Moderators

Fourth parameter in addCommandHandler.

Also, don't you want (admins) to be able to set health of other people, and not only themselves?

How about this:

function setHealthCmd (player, cmd, ...) 
    local targetPlayer 
    local health = tonumber(arg[2]) or 100 
     
    if (arg[1]) then 
        targetPlayer = getPlayerFromName (arg[1]) 
        if not targetPlayer then 
            if ((not arg[2]) and tonumber(arg[1])) then 
                health = tonumber (arg[1]) 
                targetPlayer = player 
            else 
                outputChatBox (string.format('Invalid player `%s`', arg[1]), player, 255, 0, 0) 
             
                return 
            end 
        end 
    else 
        targetPlayer = player 
    end 
  
     
    setElementHealth (targetPlayer, health) 
    outputChatBox (string.format('`%s` has set your health to %s', getPlayerName(player), health), targetPlayer, 0, 255, 0) 
end 
addCommandHandler ('sethp', setHealthCmd, true, false) 

It will set your health if you specify no player or a number alone.

As you can read on the wiki page, the third parameter is whether to block access for everyone but those with access to the command in acl.xml.

Link to comment
                                  function hel(player, command) 
  
              outputChatBox ("* ("..getPlayerName(player)..") say /myhealth he is health : ("..getElementHealth(player)..")", player, 255, 12, 15) 
  
    end 
        addCommandHandler("myhealth", hel) 
  

Link to comment
                                  function hel(player, command) 
  
              outputChatBox ("* ("..getPlayerName(player)..") say /myhealth he is health : ("..getElementHealth(player)..")", player, 255, 12, 15) 
  
    end 
        addCommandHandler("myhealth", hel) 
  

WTF! Can you speak English and tabulate your code? :lol:

Your code:

function health(player,cmd) 
         outputChatBox("* ("..getPlayerName(player..") typed /myhealth. His health is: "..getElementHealth(player),root,255,12,15,false) 
end 
addCommandHandler('myhealth',health) 

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