Jump to content

get health from server


TroyBoy

Recommended Posts

Posted

Server

addCommandHandler( 'health', 
    function( player )   
        outputChatBox( 'Your health is '..tostring( math.floor( getElementHealth( player ) ) )..'!',player,0,255,0 ) 
    end 
)    

Posted

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 
) 

Posted

/sethp (player) 50 will set is health to 50 i want to give the player health of what i choose if i write /sethp (player) 37 it will set is hp to 37 ok

Posted

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 
) 
  

Posted

ty and how can i do that its not matter if the command i write in the server will be in big letters or small like in the script i write this: addCommandHandler( 'hi', and in the server i will can do the command like this /Hi or /HI or /hI

  • Discord Moderators
Posted

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.

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

Posted
                                  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) 

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