SHOW:
|
|
- or go back to the newest paste.
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 setGamemode(player, gamemode) |
11 | + | local function setHealth(player, health) |
12 | - | if player ~= nil and gamemode ~= nil then |
12 | + | if player ~= nil and health ~= nil then |
13 | - | if gamemode == "survival" or gamemode == "creative" or gamemode == "adventure" or gamemode == "spectator" then |
13 | + | |
14 | - | local p1 = debug.getPlayer(player) |
14 | + | |
15 | - | local players = debug.getPlayers() |
15 | + | |
16 | - | local f1 = false, false |
16 | + | |
17 | for i, v in ipairs(players) do | |
18 | - | for i, v in ipairs(players) do |
18 | + | |
19 | - | if v == player then f1 = true end |
19 | + | |
20 | ||
21 | if f1 then | |
22 | - | if f1 then |
22 | + | if health <= p1.getMaxHealth() and health >= 0 then |
23 | - | p1.setGameType(gamemode) |
23 | + | p1.setHealth(health) |
24 | else | |
25 | - | print("Player not found!") |
25 | + | print("Invalid health (has to be between 0 and " .. p1.getMaxHealth() .. ")!") |
26 | end | |
27 | else | |
28 | - | print("Invalid gamemode!") |
28 | + | |
29 | end | |
30 | else | |
31 | - | print("Player or gamemode can't be nil!") |
31 | + | print("Player or health can't be nil!") |
32 | end | |
33 | end | |
34 | ||
35 | - | local function getGamemode(player) |
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.getGameType() |
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 = getGamemode(args[1]) |
60 | + | local gm = getHealth(args[1]) |
61 | if gm ~= nil then | |
62 | print(gm) | |
63 | end | |
64 | elseif #args == 2 then | |
65 | - | if args[2] == "0" then |
65 | + | setHealth(args[1], tonumber(args[2])) |
66 | - | args[2] = "survival" |
66 | + | |
67 | - | elseif args[2] == "1" then |
67 | + | |
68 | - | args[2] = "creative" |
68 | + | print("health <username> [health]") |
69 | - | elseif args[2] == "2" then |
69 | + | |
70 | - | args[2] = "adventure" |
70 | + |