-
Notifications
You must be signed in to change notification settings - Fork 4
/
Commands.lua
186 lines (127 loc) · 4.87 KB
/
Commands.lua
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
function HandleSelectCommand(a_Split, a_Player)
if (a_Split[3] == nil) then
a_Player:SendMessage(cChatColor.Rose .. "Usage: /hg select [ArenaName]")
return true
end
local ArenaName = table.concat(a_Split, " ", 3)
if (not ArenaExist(ArenaName)) then
a_Player:SendMessage(cChatColor.Rose .. "The arena doesn't exist")
return true
end
local PlayerState = GetPlayerState(a_Player:GetName())
PlayerState:SelectArena(ArenaName)
a_Player:SendMessage(cChatColor.LightGreen .. "Selected arena \"" .. ArenaName .. "\".")
return true
end
function HandleCreateCommand(a_Split, a_Player)
if (a_Split[3] == nil) then
a_Player:SendMessage(cChatColor.Rose .. "Usage: /hg create [ArenaName]")
return true
end
local ArenaName = table.concat(a_Split, " ", 3)
if (ArenaExist(ArenaName)) then
a_Player:SendMessage(cChatColor.Rose .. "The arena already exists")
return true
end
local ArenaState = CreateArenaState(ArenaName, a_Player:GetWorld():GetName())
ArenaState:SetLobbyCoordinates(a_Player:GetPosition())
local PlayerState = GetPlayerState(a_Player:GetName())
PlayerState:SelectArena(ArenaName)
a_Player:SendMessage(cChatColor.LightGreen .. "You created \"" .. ArenaName .. "\".")
return true
end
function HandleAddCommand(a_Split, a_Player)
local PlayerState = GetPlayerState(a_Player:GetName())
if (not PlayerState:HasArenaSelected()) then
a_Player:SendMessage(cChatColor.Rose .. "You haven't selected an arena yet.")
return true
end
local ArenaState = GetArenaState(PlayerState:GetSelectedArena())
if (not ArenaState) then
a_Player:SendMessage(cChatColor.Rose .. "The arena you had selected doesn't exist anymore.")
return true
end
ArenaState:AddSpawnPoint(a_Player:GetPosition())
a_Player:SendMessage(cChatColor.LightGreen .. "You added an spawnpoint.")
return true
end
function HandleSetBoundingBoxCommand(a_Split, a_Player)
if (not a_Split[3]) then
a_Player:SendMessage(cChatColor.Rose .. "Usage: /hg setsize [Point]. The point can either be 1 or 2.")
return true
end
local PlayerState = GetPlayerState(a_Player:GetName())
if (not PlayerState:HasArenaSelected()) then
a_Player:SendMessage(cChatColor.Rose .. "You haven't selected an arena yet.")
return true
end
local ArenaState = GetArenaState(PlayerState:GetSelectedArena())
if (not ArenaState) then
a_Player:SendMessage(cChatColor.Rose .. "The arena you had selected doesn't exist anymore.")
return true
end
local Succes, errmsg = ArenaState:SetArenaSize(Vector3i(a_Player:GetPosition()), a_Split[3])
if (Succes) then
a_Player:SendMessage(cChatColor.LightGreen .. "Set point " .. a_Split[3] .. " to your current position.")
else
a_Player:SendMessage(cChatColor.Rose .. errmsg)
end
return true
end
function HandleJoinCommand(a_Split, a_Player)
if (not a_Split[3]) then
a_Player:SendMessage(cChatColor.Rose .. "Usage: /hg join [ArenaName]")
return true
end
local PlayerState = GetPlayerState(a_Player:GetName())
if (PlayerState:DidJoinArena()) then
a_Player:SendMessage(cChatColor.Rose .. "You already joined an arena.")
return true
end
local ArenaName = table.concat(a_Split, " ", 3)
if (not ArenaExist(ArenaName)) then
a_Player:SendMessage(cChatColor.Rose .. "The arena \"" .. ArenaName .. "\" doesn't exist.")
return true
end
local ArenaState = GetArenaState(ArenaName)
if (ArenaState:GetNumSpawnPoints() <= 1) then
a_Player:SendMessage(cChatColor.Rose .. "The arena doesn't have enough spawnpoints. Please contact an admin.")
return true
end
PlayerState:JoinArena(ArenaName)
ArenaState:AddPlayer(a_Player)
a_Player:SendMessage(cChatColor.LightGreen .. "You joined " .. ArenaName)
return true
end
function HandleLeaveCommand(a_Split, a_Player)
local PlayerState = GetPlayerState(a_Player:GetName())
if (not PlayerState:DidJoinArena()) then
a_Player:SendMessage(cChatColor.Rose .. "You didn't join an arena.")
return true
end
local ArenaState = GetArenaState(PlayerState:GetJoinedArena())
if (not ArenaState) then
a_Player:SendMessage(cChatColor.Rose .. "The arena you were in doesn't exist anymore.")
return true
end
PlayerState:LeaveArena()
ArenaState:RemovePlayer(a_Player)
a_Player:SendMessage(cChatColor.LightGreen .. "You left the arena")
return true
end
function HandleSetLobbyCommand(a_Split, a_Player)
local PlayerState = GetPlayerState(a_Player:GetName())
if (not PlayerState:HasArenaSelected()) then
a_Player:SendMessage(cChatColor.Rose .. "You didn't select an arena.")
return true
end
local ArenaState = GetArenaState(PlayerState:GetSelectedArena())
if (not ArenaState) then
a_Player:SendMessage(cChatColor.Rose .. "The arena you had selected doesn't exist anymore.")
return true
end
ArenaState:SetLobbyWorld(a_Player:GetWorld():GetName())
ArenaState:SetLobbyCoordinates(a_Player:GetPosition())
a_Player:SendMessage(cChatColor.LightGreen .. "You changed the position of the lobby.")
return true
end