diff --git a/luascripts/admin/admin.lua b/luascripts/admin/admin.lua
index 16931de..1c6c572 100644
--- a/luascripts/admin/admin.lua
+++ b/luascripts/admin/admin.lua
@@ -28,12 +28,6 @@ local util = require "luascripts.wolfadmin.util.util"
local admin = {}
-local teamLocks = {
- [constants.TEAM_AXIS] = false,
- [constants.TEAM_ALLIES] = false,
- [constants.TEAM_SPECTATORS] = false,
-}
-
function admin.putPlayer(clientId, teamId)
et.trap_SendConsoleCommand(et.EXEC_APPEND, "forceteam "..clientId.." "..util.getTeamCode(teamId)..";")
end
@@ -50,14 +44,6 @@ function admin.kickPlayer(victimId, invokerId, reason)
et.trap_DropClient(victimId, "You have been kicked, Reason: "..(reason and reason or "kicked by admin"), 0)
end
-function admin.lockTeam(teamId)
- teamLocks[teamId] = false
-end
-
-function admin.unlockTeam(teamId)
- teamLocks[teamId] = false
-end
-
function admin.setPlayerLevel(clientId, level, adminId)
local playerid = db.getplayer(players.getGUID(clientId))["id"]
local adminid = db.getplayer(players.getGUID(clientId))["id"]
diff --git a/luascripts/commands/admin/lock.lua b/luascripts/commands/admin/lock.lua
index db286e9..9b51262 100644
--- a/luascripts/commands/admin/lock.lua
+++ b/luascripts/commands/admin/lock.lua
@@ -16,26 +16,55 @@
-- along with this program. If not, see .
local auth = require "luascripts.wolfadmin.auth.auth"
+
+local commands = require "luascripts.wolfadmin.commands.commands"
+
+local teams = require "luascripts.wolfadmin.game.teams"
+
local util = require "luascripts.wolfadmin.util.util"
local constants = require "luascripts.wolfadmin.util.constants"
-local commands = require "luascripts.wolfadmin.commands.commands"
-local admin = require "luascripts.wolfadmin.admin.admin"
function commandLock(clientId, cmdArguments)
if cmdArguments[1] == nil or (cmdArguments[1] ~= constants.TEAM_AXIS_SC and cmdArguments[1] ~= constants.TEAM_ALLIES_SC and cmdArguments[1] ~= constants.TEAM_SPECTATORS_SC and cmdArguments[1] ~= "all") then
return false
end
-
+
if cmdArguments[1] == "all" then
- admin.lockTeam(constants.TEAM_AXIS)
- admin.lockTeam(constants.TEAM_ALLIES)
- admin.lockTeam(constants.TEAM_SPECTATORS)
-
+ teams.lock(constants.TEAM_AXIS)
+ teams.lock(constants.TEAM_ALLIES)
+ teams.lock(constants.TEAM_SPECTATORS)
+
return false
end
-
- admin.lockTeam(util.getTeamFromCode(cmdArguments[1]))
-
+
+ teams.lock(util.getTeamFromCode(cmdArguments[1]))
+
return false
end
commands.addadmin("lock", commandLock, auth.PERM_LOCKTEAM, "lock one or all of the teams from players joining", "^9[^3r|b|s|all#^9]", true)
+
+function commandLock(clientId, cmdArguments)
+ if cmdArguments[1] == nil or (cmdArguments[1] ~= constants.TEAM_AXIS_SC and cmdArguments[1] ~= constants.TEAM_ALLIES_SC and cmdArguments[1] ~= constants.TEAM_SPECTATORS_SC and cmdArguments[1] ~= "all") then
+ et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dlock usage: "..commands.getadmin("lock")["syntax"].."\";")
+
+ return true
+ end
+
+ if cmdArguments[1] == "all" then
+ teams.lock(constants.TEAM_AXIS)
+ teams.lock(constants.TEAM_ALLIES)
+ teams.lock(constants.TEAM_SPECTATORS)
+
+ et.trap_SendConsoleCommand(et.EXEC_APPEND, "chat \"^dlock: ^9all teams have been locked.\";")
+
+ return false
+ end
+
+ local team = util.getTeamFromCode(cmdArguments[1])
+ teams.lock(team)
+
+ et.trap_SendConsoleCommand(et.EXEC_APPEND, "chat \"^dlock: "..util.getTeamColor(team).util.getTeamName(team).." ^9team has been locked.\";")
+
+ return false
+end
+commands.addadmin("lock", commandLock, auth.PERM_LOCKTEAM, "lock one or all of the teams from players joining", "^9[^3r|b|s|all#^9]", (settings.get("g_standalone") == 0))
diff --git a/luascripts/commands/admin/unlock.lua b/luascripts/commands/admin/unlock.lua
index a88565b..6932200 100644
--- a/luascripts/commands/admin/unlock.lua
+++ b/luascripts/commands/admin/unlock.lua
@@ -16,10 +16,13 @@
-- along with this program. If not, see .
local auth = require "luascripts.wolfadmin.auth.auth"
+
+local commands = require "luascripts.wolfadmin.commands.commands"
+
+local teams = require "luascripts.wolfadmin.game.teams"
+
local util = require "luascripts.wolfadmin.util.util"
local constants = require "luascripts.wolfadmin.util.constants"
-local commands = require "luascripts.wolfadmin.commands.commands"
-local admin = require "luascripts.wolfadmin.admin.admin"
function commandUnlock(clientId, cmdArguments)
if cmdArguments[1] == nil or (cmdArguments[1] ~= constants.TEAM_AXIS_SC and cmdArguments[1] ~= constants.TEAM_ALLIES_SC and cmdArguments[1] ~= constants.TEAM_SPECTATORS_SC and cmdArguments[1] ~= "all") then
@@ -27,15 +30,41 @@ function commandUnlock(clientId, cmdArguments)
end
if cmdArguments[1] == "all" then
- admin.unlockTeam(constants.TEAM_AXIS)
- admin.unlockTeam(constants.TEAM_ALLIES)
- admin.unlockTeam(constants.TEAM_SPECTATORS)
+ teams.unlock(constants.TEAM_AXIS)
+ teams.unlock(constants.TEAM_ALLIES)
+ teams.unlock(constants.TEAM_SPECTATORS)
return false
end
- admin.unlockTeam(util.getTeamFromCode(cmdArguments[1]))
+ teams.unlock(util.getTeamFromCode(cmdArguments[1]))
return false
end
commands.addadmin("unlock", commandUnlock, auth.PERM_LOCKTEAM, "unlock one or all locked teams", "^9[^3r|b|s|all#^9]", true)
+
+function commandUnlock(clientId, cmdArguments)
+ if cmdArguments[1] == nil or (cmdArguments[1] ~= constants.TEAM_AXIS_SC and cmdArguments[1] ~= constants.TEAM_ALLIES_SC and cmdArguments[1] ~= constants.TEAM_SPECTATORS_SC and cmdArguments[1] ~= "all") then
+ et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dunlock usage: "..commands.getadmin("unlock")["syntax"].."\";")
+
+ return true
+ end
+
+ if cmdArguments[1] == "all" then
+ teams.unlock(constants.TEAM_AXIS)
+ teams.unlock(constants.TEAM_ALLIES)
+ teams.unlock(constants.TEAM_SPECTATORS)
+
+ et.trap_SendConsoleCommand(et.EXEC_APPEND, "chat \"^dlock: ^9all teams have been unlocked.\";")
+
+ return false
+ end
+
+ local team = util.getTeamFromCode(cmdArguments[1])
+ teams.unlock(team)
+
+ et.trap_SendConsoleCommand(et.EXEC_APPEND, "chat \"^dlock: "..util.getTeamColor(team).util.getTeamName(team).." ^9team has been unlocked.\";")
+
+ return false
+end
+commands.addadmin("unlock", commandUnlock, auth.PERM_LOCKTEAM, "unlock one or all locked teams", "^9[^3r|b|s|all#^9]", (settings.get("g_standalone") == 0))
diff --git a/luascripts/commands/commands.lua b/luascripts/commands/commands.lua
index 19b0253..3d593bb 100644
--- a/luascripts/commands/commands.lua
+++ b/luascripts/commands/commands.lua
@@ -21,6 +21,8 @@ local admin = require "luascripts.wolfadmin.admin.admin"
local auth = require "luascripts.wolfadmin.auth.auth"
+local teams = require "luascripts.wolfadmin.game.teams"
+
local players = require "luascripts.wolfadmin.players.players"
local util = require "luascripts.wolfadmin.util.util"
@@ -218,6 +220,16 @@ function commands.onclientcommand(clientId, cmdText)
return 1
end
+
+ local team = util.getTeamFromCode(et.trap_Argv(1))
+ if teams.isLocked(team) then
+ local teamName = util.getTeamName(team)
+ local teamColor = util.getTeamColor(team)
+
+ et.trap_SendServerCommand(clientId, "cp \""..teamColor..teamName.." ^7team is locked")
+
+ return 1
+ end
elseif wolfCmd == "callvote" then
local voteArguments = {}
for i = 2, et.trap_Argc() - 1 do
diff --git a/luascripts/game/teams.lua b/luascripts/game/teams.lua
index b85fd39..0cae270 100644
--- a/luascripts/game/teams.lua
+++ b/luascripts/game/teams.lua
@@ -21,51 +21,69 @@ local events = require "luascripts.wolfadmin.util.events"
local teams = {}
-local data = {
+local players = {
[constants.TEAM_AXIS] = {},
[constants.TEAM_ALLIES] = {},
[constants.TEAM_SPECTATORS] = {}
}
+local locks = {
+ [constants.TEAM_AXIS] = false,
+ [constants.TEAM_ALLIES] = false,
+ [constants.TEAM_SPECTATORS] = false
+}
+
function teams.get()
- return data
+ return players
end
function teams.count(team)
- return #data[team]
+ return #players[team]
end
function teams.difference()
return math.abs(teams.count(constants.TEAM_AXIS) - teams.count(constants.TEAM_ALLIES))
end
+function teams.lock(teamId)
+ locks[teamId] = true
+end
+
+function teams.unlock(teamId)
+ locks[teamId] = false
+end
+
+function teams.isLocked(teamId)
+ return locks[teamId]
+end
+
function teams.onconnect(clientId, firstTime, isBot)
local team = tonumber(et.gentity_get(clientId, "sess.sessionTeam"))
- if not tables.contains(data[team], clientId) then
- table.insert(data[team], clientId)
+ if not tables.contains(players[team], clientId) then
+ table.insert(players[team], clientId)
end
end
events.handle("onClientConnect", teams.onconnect)
function teams.ondisconnect(clientId)
local team = tonumber(et.gentity_get(clientId, "sess.sessionTeam"))
- local idx = tables.find(data[team], clientId)
+ local idx = tables.find(players[team], clientId)
if idx then
- table.remove(data[team], idx)
+ table.remove(players[team], idx)
end
end
events.handle("onClientDisconnect", teams.ondisconnect)
function teams.onclientteamchange(clientId, old, new)
- local idx = tables.find(data[old], clientId)
+ local idx = tables.find(players[old], clientId)
if idx then
- table.remove(data[old], idx)
+ table.remove(players[old], idx)
end
- table.insert(data[new], clientId)
+ table.insert(players[new], clientId)
end
events.handle("onClientTeamChange", teams.onclientteamchange)
diff --git a/luascripts/util/constants.lua b/luascripts/util/constants.lua
index 30b2a67..718c925 100644
--- a/luascripts/util/constants.lua
+++ b/luascripts/util/constants.lua
@@ -35,10 +35,17 @@ constants.TEAM_AXIS_SC = "r"
constants.TEAM_ALLIES_SC = "b"
constants.TEAM_SPECTATORS_SC = "s"
+constants.TEAM_AXIS_NAME = "axis"
+constants.TEAM_ALLIES_NAME = "allies"
+constants.TEAM_SPECTATORS_NAME = "spectator"
+
constants.TEAM_AXIS_COLOR = "^1"
constants.TEAM_ALLIES_COLOR = "^4"
constants.TEAM_SPECTATORS_COLOR = "^2"
+constants.TEAM_AXIS_COLOR_NAME = "red"
+constants.TEAM_ALLIES_COLOR_NAME = "blue"
+
constants.CLASS_SOLDIER = 0
constants.CLASS_MEDIC = 1
constants.CLASS_ENGINEER = 2
diff --git a/luascripts/util/util.lua b/luascripts/util/util.lua
index 03ae8df..4d6f423 100644
--- a/luascripts/util/util.lua
+++ b/luascripts/util/util.lua
@@ -61,11 +61,11 @@ function util.getTeamName(teamId)
end
function util.getTeamFromCode(teamCode)
- if teamCode == constants.TEAM_AXIS_SC then
+ if teamCode == constants.TEAM_AXIS_SC or teamCode == constants.TEAM_AXIS_NAME or teamCode == constants.TEAM_AXIS_COLOR_NAME then
return constants.TEAM_AXIS
- elseif teamCode == constants.TEAM_ALLIES_SC then
+ elseif teamCode == constants.TEAM_ALLIES_SC or teamCode == constants.TEAM_ALLIES_NAME or teamCode == constants.TEAM_ALLIES_COLOR_NAME then
return constants.TEAM_ALLIES
- elseif teamCode == constants.TEAM_SPECTATORS_SC then
+ elseif teamCode == constants.TEAM_SPECTATORS_SC or teamCode == constants.TEAM_SPECTATORS_NAME then
return constants.TEAM_SPECTATORS
else
return 0