-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmode.lua
More file actions
117 lines (91 loc) · 3.04 KB
/
mode.lua
File metadata and controls
117 lines (91 loc) · 3.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
-- mode.lua
-- Handles the gamemode-switching /mode command.
-- Translate gamemodes into strings.
local GameModeNameTable =
{
-- [gmSurvival] = "survival",
[gmCreative] = "creative",
-- [gmAdventure] = "adventure",
[gmSpectator] = "spectator",
}
-- Translate strings to their gamemodes.
-- Survival and adventure mode have been disabled on the server.
local GameModeTable =
{
-- ["0"] = gmSurvival,
-- ["survival"] = gmSurvival,
-- ["s"] = gmSurvival,
["1"] = gmCreative,
["creative"] = gmCreative,
["c"] = gmCreative,
-- ["2"] = gmAdventure,
-- ["adventure"] = gmAdventure,
-- ["a"] = gmAdventure,
["3"] = gmSpectator,
["spectator"] = gmSpectator,
["sp"] = gmSpectator,
}
local MessageFailure = "Couldn't find that player."
-- Changes a given player's gamemode / mode.
--
-- @param GameMode is the gamemode to change to.
-- @param PlayerName is the player name of the player to change the gamemode of.
--
-- @return true if player was found and gamemode successfully changed, false otherwise.
local function ChangeGameMode(GameMode, PlayerName)
local GMChanged = false
local lcPlayerName = string.lower(PlayerName)
-- Look for online players that match the given PlayerName.
-- Change their gamemode.
cRoot:Get():FindAndDoWithPlayer(PlayerName,
function(PlayerMatch)
if string.lower(PlayerMatch:GetName()) == lcPlayerName then
PlayerMatch:SetGameMode(GameMode)
SendMessageSuccess(PlayerMatch, "Set your gamemode to " .. GameModeNameTable[GameMode] .. ".")
GMChanged = true
end
return true
end
)
return GMChanged
end
--- Handles the in-game command.
function HandleChangeGMCommand(Split, Player)
-- Check parameters...
local GameMode = GameModeTable[Split[2]]
if not GameMode then
SendMessage(Player, cChatColor.LightGray .. "Usage: " .. Split[1] .. " <creative | spectator> [player]")
return true
end
local PlayerToChange = Split[3] or Player:GetName()
-- Report success or failure.
if ChangeGameMode( GameMode, PlayerToChange ) then
local Message = PlayerToChange .. "'s gamemode was set to " .. GameModeNameTable[GameMode]
local MessageTail = " by " .. Player:GetName()
if PlayerToChange ~= Player:GetName() then
SendMessageSuccess(cChatColor.LightGray .. Player, Message .. ".")
end
LOGINFO(Message .. MessageTail .. ".")
else
SendMessageFailure(Player, cChatColor.LightGray .. MessageFailure)
end
return true
end
-- Handles the console command.
function HandleConsoleGamemode(a_Split)
-- Check parameters...
local GameMode = GameModeTable[a_Split[2]]
local PlayerToChange = a_Split[3]
if not PlayerToChange or not GameMode then
return true, "Usage: " .. a_Split[1] .. " <creative | spectator> <player>"
end
-- Report success or failure.
if ChangeGameMode(GameMode, PlayerToChange) then
local Message = PlayerToChange .. "'s gamemode was set to " .. GameModeNameTable[GameMode]
local MessageTail = " by " .. "the console"
LOG(Message .. MessageTail .. ".")
else
LOG(MessageFailure)
end
return true
end