View difference between Paste ID: J669qjZY and 9W7m5Zhc
SHOW: | | - or go back to the newest paste.
1-
local event=require("event")
1+
local shell=require("shell")
2-
2+
3-
local component = require("component")
3+
local component = require("component")
4-
local debug = component.debug
4+
local debug = component.debug
5-
5+
6-
6+
local args, options = shell.parse(...)
7-
--chat msg, uuid, name "chat_message"_
7+
8-
8+
9-
while true do
9+
-------------- Functions --------------
10-
  local ev, _ , name, msg = event.pull("chat_message")
10+
11-
11+
local function setGamemode(player, gamemode)
12-
  if msg:sub(1,3) == "tp " then
12+
  if player ~= nil and gamemode ~= nil then
13-
    local n1, n2 = string.match(msg, "tp%s([^%s]+)%s([^%s]+)")
13+
    if gamemode == "survival" or gamemode == "creative" or gamemode == "adventure" or gamemode == "spectator" then
14-
    print(n1,n2)
14+
      local p1 = debug.getPlayer(player)
15-
    if n1 == nil then
15+
      local players = debug.getPlayers()
16-
      n2 = string.match(msg, "tp%s([^%s]+)")
16+
      local f1 = false, false
17-
      n1 = name
17+
18-
    end
18+
      for i, v in ipairs(players) do
19-
19+
        if v == player then f1 = true end
20-
    if n1 ~= nil and n2 ~= nil then
20+
      end
21-
21+
22-
--    print(tostring(n1),tostring(n2))
22+
      if f1 then
23-
      local p1 = debug.getPlayer(n1)
23+
        p1.setGameType(gamemode)
24-
      local p2 = debug.getPlayer(n2)
24+
      else
25-
      local players = debug.getPlayers()
25+
        print("Player not found!")
26-
      local f1, f2 = false, false
26+
      end
27-
27+
    else
28-
      for i, v in ipairs(players) do
28+
      print("Invalid gamemode!")
29-
        if v == n1 then f1 = true end
29+
    end
30-
        if v == n2 then f2 = true end
30+
  else
31-
      end
31+
    print("Player or gamemode can't be nil!")
32-
32+
  end
33-
      if f1 and f2 then
33+
end
34-
        local posX, posY, posZ = p2.getPosition()
34+
35-
        p1.setPosition(posX, posY, posZ)
35+
local function getGamemode(player)
36-
      end
36+
  if player ~= nil then
37-
    end
37+
    local p1 = debug.getPlayer(player)
38-
  end
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()
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])
61
  if gm ~= nil then
62
    print(gm)
63
  end
64
elseif #args == 2 then
65
  if args[2] == "0" then
66
    args[2] = "survival"
67
  elseif args[2] == "1" then
68
    args[2] = "creative"
69
  elseif args[2] == "2" then
70
    args[2] = "adventure"
71
  elseif args[2] == "3" then
72
    args[2] = "spectator"
73
  end
74
  setGamemode(args[1], args[2])
75
else
76
  print("Usage:")
77
  print("gamemode <username> [gamemode]")
78
  return 1
79
end