Jump to content
  • 0

minus money and give hp


A3kri

Question

Hello ..

I'm a beginner lua developer, but I have a background in javascript.

I want when the player types health his health becomes 100% and he gets 150 taken freom his money, else if he don't have 150 his health doesn't become 100% but an outputChatBox gets printed.

this is what I ended up to

local money = getPlayerMoney(thePlayer)             
if (money > 150) then 
takePlayerMoney ( thePlayer, tonumber(150) ) 
setElementHealth ( thePlayer, getElementHealth(thePlayer) + 100 ) 
else  
        outputChatBox("You need 150coins.", thePlayer)    
end 

sorry for my noobishness x.x

Link to comment

1 answer to this question

Recommended Posts

  • 0

Hey!

Alright so basically you are missing the function itself and the command handler, which is used to trigger functions.

Try this code.

Server-side

addCommandHandler("health", -- Create a command "health" 
    function(thePlayer, cmd) -- Do the function when they type the command, "thePlayer" = the player who used the command, "cmd" = a string, returning the command name 
        local money = getPlayerMoney(thePlayer) -- Get the player's money 
        if (money >= 150) then -- If the player has exactly or more 150 coins, proceed 
            takePlayerMoney(thePlayer, 150) -- Take 150 coins from the player 
            setElementHealth(thePlayer, 100) -- Set their health to 100 
        else -- Their money is less than 150 coins 
            outputChatBox("You need 150 coins.", thePlayer) -- Output a message to the player 
        end 
    end, false, false 
) 
 

Additionally this is the wrong board to post your problems in ;) You should post here in the future.

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