Advertisement
XDjackieXD

health.lua

Jul 3rd, 2016
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local shell=require("shell")
  2.  
  3. local component = require("component")
  4. local debug = component.debug
  5.  
  6. local args, options = shell.parse(...)
  7.  
  8.  
  9. -------------- Functions --------------
  10.  
  11. local function setHealth(player, health)
  12.   if player ~= nil and health ~= nil then
  13.     local p1 = debug.getPlayer(player)
  14.     local players = debug.getPlayers()
  15.     local f1 = false, false
  16.  
  17.     for i, v in ipairs(players) do
  18.       if v == player then f1 = true end
  19.     end
  20.  
  21.     if f1 then
  22.       if health <= p1.getMaxHealth() and health >= 0 then
  23.         p1.setHealth(health)
  24.       else
  25.         print("Invalid health (has to be between 0 and " .. p1.getMaxHealth() .. ")!")
  26.       end
  27.     else
  28.       print("Player not found!")
  29.     end
  30.   else
  31.     print("Player or health can't be nil!")
  32.   end
  33. end
  34.  
  35. local function getHealth(player)
  36.   if player ~= nil then
  37.     local p1 = debug.getPlayer(player)
  38.     local players = debug.getPlayers()
  39.     local f1 = false, false
  40.  
  41.     for i, v in ipairs(players) do
  42.       if v == player then f1 = true end
  43.     end
  44.  
  45.     if f1 then
  46.       return p1.getHealth()
  47.     else
  48.       print("Player not found!")
  49.       return nil
  50.     end
  51.   else
  52.     print("Player can't be nil!")
  53.     return nil
  54.   end
  55. end
  56.  
  57. -------------- Main Code --------------
  58.  
  59. if #args == 1 then
  60.   local gm = getHealth(args[1])
  61.   if gm ~= nil then
  62.     print(gm)
  63.   end
  64. elseif #args == 2 then
  65.   setHealth(args[1], tonumber(args[2]))
  66. else
  67.   print("Usage:")
  68.   print("health <username> [health]")
  69.   return 1
  70. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement