Jump to content

Set Hp


Recommended Posts

Right Guys, i tried to create a resource to set a players hp, could you tell me whats wrong,

lol the console says it could even find the resource,

here is the serverside

function setElementHealth ( sourcePlayer, command, targetPlayerName) 
        --look up the player whos health has to be set 
        local targetPlayer = getPlayerFromName ( targetPlayerName ) 
        --if there is a player with such name subtract tonumber from their health, 
        if targetPlayer then 
        setElementHealth ( getElementID, getElementHealth, - ( tonumber(setElementHealth) ) 
        --check if the players health returned "false" 
        if (setElementHealth == false) then 
                -- if so, output a message to the chatbox, but only to this player. 
                outputChatBox ("Failed to set players hp." ,thePlayer) 
        end 
end 
addCommandHandler("sethp", setElementHealth) 

here is the meta

     "llsd" type="script" name="hpslap" description="set hp" /> 
     

Could you correct me in with any errors

thanks lloyd

Link to comment

1: This should be at the "Scripting" section.

2: Never call a function like a MTA native one, unless you want to replace it with your own.

3:

setElementHealth ( getElementID, getElementHealth, - ( tonumber(setElementHealth) ) 

That makes no sense, instead of getElementID it should be targetPlayer. Also, this makes no sense:

tonumber(setElementHealth) 

4:

if (setElementHealth == false) then 

You should define:

setElementHealth ( getElementID, getElementHealth, - ( tonumber(setElementHealth) ) 

in order to check later if it was successfully set.

5: I recommend you to learn the basics of Lua.

Link to comment
function setHealth(source,_,targetPlayerName,newHealth) 
    if not newHealth then return end 
    local targetPlayer = getPlayerFromName(targetPlayerName) or return 
    local healthSet = setElementHealth(targetPlayer,tonumber(newHealth)) or outputChatBox ("Failed to set players hp.",source) 
end 
addCommandHandler("sethp",setHealth) 

4:
if (setElementHealth == false) then 

You can simply use

if not var then 

Link to comment
function setHealth(source,_,targetPlayerName,newHealth) 
    if not newHealth then return end 
    local targetPlayer = getPlayerFromName(targetPlayerName) or return 
    local healthSet = setElementHealth(targetPlayer,tonumber(newHealth)) or outputChatBox ("Failed to set players hp.",source) 
end 
addCommandHandler("sethp",setHealth) 

4:
if (setElementHealth == false) then 

You can simply use

if not var then 

Thanks Alot

Link to comment
4:
if (setElementHealth == false) then 

You can simply use

if not var then 

I don't understand how "If not var then" is more simple, it just depends on person how he wants to use it....both good

I find the == false quite ugly, like using 'if (var == true) then' when you can just use 'if var then'.

Link to comment
4:
if (setElementHealth == false) then 

You can simply use

if not var then 

I don't understand how "If not var then" is more simple, it just depends on person how he wants to use it....both good

I find the == false quite ugly, like using 'if (var == true) then' when you can just use 'if var then'.

same thing...., what a shame many lazy people around these days

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