Jump to content

Any Number???


Recommended Posts

Right so I take the simple setPedArmour FOR EXAMPLE!!

function givePlayerArmor ( player, command ) 
    setPedArmor ( player, 100 )    -- Set player's armor to 100 when he types the command 'addarmor' 
end 
addCommandHandler ( "addarmor", givePlayerArmor ) 
  
function removePlayerArmor ( player, command ) 
    setPedArmor ( player, 0 )      -- Set player's armor to 0 when he types the command 'removearmor' 
end 
addCommandHandler ( "removearmor", removePlayerArmor )  

Okay Now I change it so It works with health...

function setPlayerHealth ( player, command ) 
    setElementHealth ( player, 100 )    -- Set player's health to 100 when he types the command 'health100' 
end 
addCommandHandler ( "health100", setPlayerHealth ) 
  
function setPlayerHealth ( player, command ) 
    setElementHealth ( player, 0 )      -- Set player's health to 0 when he types the command 'dienow' 
end 
addCommandHandler ( "dienow", removePlayerArmor ) 

(ignore anymistakes in the script!!)

Now my question is.... Instead of Typing set health 100, (as in a solid number) how can i make it so they choose the health, as in health "then what they type for their health" i think its VAR but i am not sure,

example but defo wrong!!!

setElementHealth ( player, var )      -- Set player's health to 0 when he types the command 'dienow' 
addCommandHandler ( "dienow", "var" , removePlayerArmor ) 

Sorry for the stupid questions but you guys on the forums keep me alive!!!

Link to comment

thePlayer - the person who wrote the command [server side script btw]

cmd - a STRING of what the cmd is (this currently is "health")

amount - (any variables after cmd are the variables a user type in after command)

We convert amount to number and stop if not a number

We check if its <0 or >255 and stopif so

We set the health

function setHealth(thePlayer, cmd, amount) 
     amount=tonumber(amount); 
     if not amount then return end 
     if (amount<0) or (amount>255) then return end 
     setElementHealth(thePlayer, amount) 
end 
addCommandHandler("health", setHealth) 

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