This commit is contained in:
Timo Smit 2016-02-13 12:20:14 +01:00
parent ecddc1dd04
commit 5dcc5d2a82
10 changed files with 107 additions and 35 deletions

View file

@ -16,7 +16,7 @@ REQUIREMENTS
INSTRUCTIONS (NEW)
* Unpack the /luascripts folder into your /nq directory
* Unpack the /luascripts folder into /nq/luascripts/wolfadmin
* Unpack the contents of the /config folder into your /nq directory (or
/.etwolf/nq on Linux systems)
* Optionally, copy the contents of the cvars.cfg to your own server

View file

@ -15,6 +15,8 @@
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
require "luascripts.wolfadmin.util.debug"
local util = require "luascripts.wolfadmin.util.util"
local events = require "luascripts.wolfadmin.util.events"
local files = require "luascripts.wolfadmin.util.files"
@ -187,7 +189,44 @@ function commands.onclientcommand(clientId, cmdText)
local shrubArguments = {}
local shrubArgumentsOffset = 0
if wolfCmd == "adminchat" or wolfCmd == "ac" then
if wolfCmd == "m" or wolfCmd == "pm" then
if et.trap_Argc() > 2 then
local cmdClient
if tonumber(et.trap_Argv(1)) == nil then
cmdClient = et.ClientNumberFromString(et.trap_Argv(1))
else
cmdClient = tonumber(et.trap_Argv(1))
end
if cmdClient ~= -1 and et.gentity_get(cmdClient, "pers.netname") then
stats.set(cmdClient, "lastMessageFrom", clientId)
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..cmdClient.." \"^9reply: ^7r [^2message^7]\";")
end
end
elseif wolfCmd == "r" then
if et.trap_Argc() == 1 then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^9usage: ^7"..wolfCmd.." [^2message^7]\";")
else
local recipient = stats.get(clientId, "lastMessageFrom")
if et.gentity_get(recipient, "pers.netname") then
local message = {}
for i = 1, et.trap_Argc() - 1 do
message[i] = et.trap_Argv(i)
end
stats.set(recipient, "lastMessageFrom", clientId)
et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat "..recipient.." \"^7"..et.gentity_get(clientId, "pers.netname").."^7 -> "..recipient.." (1 recipients): ^3"..table.concat(message, " ").."\";")
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..recipient.." \"^9reply: ^7r [^2message^7]\";")
end
end
return 1
elseif wolfCmd == "adminchat" or wolfCmd == "ac" then
if et.G_shrubbot_permission(clientId, "~") == 1 then
if et.trap_Argc() == 1 then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^9usage: ^7"..wolfCmd.." [^2message^7]\";")

View file

@ -21,9 +21,9 @@ local settings = require "luascripts.wolfadmin.util.settings"
local greetings = require "luascripts.wolfadmin.players.greetings"
function commandGreeting(clientId, cmdArguments)
local greetingText = greetings.get(clientId)
local greeting = greetings.get(clientId)
if greetingText then
if greeting then
greetings.show(clientId)
else
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dgreeting: ^9you do not have a personal greeting.\";")

View file

@ -16,12 +16,19 @@
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
local commands = require "luascripts.wolfadmin.commands"
local game = require "luascripts.wolfadmin.game.game"
local sprees = require "luascripts.wolfadmin.game.sprees"
function commandResetSprees(clientId, cmdArguments)
sprees.reset()
et.trap_SendConsoleCommand(et.EXEC_APPEND, "chat \"^dresetsprees: ^9spree records have been reset.\";")
if cmdArguments[1] and cmdArguments[1] == "all" then
sprees.reset(true)
et.trap_SendConsoleCommand(et.EXEC_APPEND, "chat \"^dresetsprees: ^9all spree records have been reset.\";")
else
sprees.reset()
et.trap_SendConsoleCommand(et.EXEC_APPEND, "chat \"^dresetsprees: ^9spree records have been reset for map '^7"..game.getMap().."^9'.\";")
end
return true
end

View file

@ -63,6 +63,10 @@ function cfg.updaterecord(mapid, recorddate, recordtype, record, playerid)
records[mapid][typestr.."name"] = playerid
end
function cfg.removeallrecords()
records = {}
end
function cfg.removerecords(mapid)
records[mapid] = {
["map"] = records[mapid]["map"],

View file

@ -55,6 +55,10 @@ function mysql.updaterecord(mapid, recorddate, recordtype, record, playerid)
cur = assert(con:execute("UPDATE `records` SET `date`="..tonumber(recorddate)..", `record`="..tonumber(record)..", `player`="..tonumber(playerid).." WHERE `mapid`="..tonumber(mapid).." AND `type`="..tonumber(recordtype)..""))
end
function mysql.removeallrecords()
cur = assert(con:execute("TRUNCATE `records`"))
end
function mysql.removerecords(mapid)
cur = assert(con:execute("DELETE FROM `records` WHERE `mapid`="..tonumber(mapid)..""))
end
@ -130,10 +134,6 @@ function mysql.getplayerid(clientid)
return mysql.getplayer(stats.get(clientid, "playerGUID"))["id"]
end
function mysql.isplayerbot(clientid)
return mysql.getplayer(stats.get(clientid, "playerGUID"))["bot"] == 1
end
function mysql.getplayer(guid)
cur = assert(con:execute("SELECT * FROM `players` WHERE `guid`='"..util.escape(guid).."'"))

View file

@ -63,8 +63,12 @@ function sprees.get()
return records
end
function sprees.reset()
db.removerecords(currentMapId)
function sprees.reset(truncate)
if truncate then
db.removeallrecords()
else
db.removerecords(currentMapId)
end
currentRecords = db.getrecords(currentMapId)
end
@ -86,12 +90,13 @@ function sprees.load()
end
function sprees.oninit(levelTime, randomSeed, restartMap)
if (settings.get("db_type") == "cfg" and settings.get("g_fileSprees") ~= "") or (settings.get("db_type") ~= "cfg" and settings.get("g_spreeRecords") ~= 0) then
if
(settings.get("db_type") == "cfg" and settings.get("g_fileSprees") ~= "") or
(settings.get("db_type") ~= "cfg" and settings.get("g_spreeRecords") ~= 0)
then
sprees.load()
events.handle("onGameStateChange", sprees.ongamestatechange)
events.handle("onPlayerDeath", sprees.ondeath)
events.handle("onPlayerRevive", sprees.onrevive)
end
end
events.handle("onGameInit", sprees.oninit)
@ -107,7 +112,10 @@ end
events.handle("onClientConnect", sprees.onconnect)
function sprees.ongamestatechange(gameState)
if gameState == 3 then
if gameState == constants.GAME_RUNNING then
events.handle("onPlayerDeath", sprees.ondeath)
events.handle("onPlayerRevive", sprees.onrevive)
elseif gameState == constants.GAME_INTERMISSION then
if currentRecords["ksrecord"] and currentRecords["ksrecord"] > 0 then
if db.getrecord(currentMapId, constants.RECORD_KILL) then
db.updaterecord(currentMapId, os.time(), constants.RECORD_KILL, currentRecords["ksrecord"], currentRecords["ksplayer"])
@ -156,7 +164,7 @@ function sprees.ondeath(victimId, killerId, mod)
stats.set(victimId, "longestDeathSpree", stats.get(victimId, "currentDeathSpree") > stats.get(victimId, "longestDeathSpree") and stats.get(victimId, "currentDeathSpree") or stats.get(victimId, "longestDeathSpree"))
if (settings.get("g_botRecords") == 1 or not db.isplayerbot(victimId)) and (not currentRecords["dsrecord"] or stats.get(victimId, "longestDeathSpree") > currentRecords["dsrecord"]) then
if (settings.get("g_botRecords") == 1 or not stats.get(victimId, "isBot")) and (not currentRecords["dsrecord"] or stats.get(victimId, "longestDeathSpree") > currentRecords["dsrecord"]) then
currentRecords["dsplayer"] = db.getplayerid(victimId)
currentRecords["dsrecord"] = stats.get(victimId, "longestDeathSpree")
end
@ -169,7 +177,7 @@ function sprees.ondeath(victimId, killerId, mod)
stats.set(killerId, "longestKillSpree", stats.get(killerId, "currentKillSpree") > stats.get(killerId, "longestKillSpree") and stats.get(killerId, "currentKillSpree") or stats.get(killerId, "longestKillSpree"))
if (settings.get("g_botRecords") == 1 or not db.isplayerbot(killerId)) and (not currentRecords["ksrecord"] or stats.get(killerId, "longestKillSpree") > currentRecords["ksrecord"]) then
if (settings.get("g_botRecords") == 1 or not stats.get(killerId, "isBot")) and (not currentRecords["ksrecord"] or stats.get(killerId, "longestKillSpree") > currentRecords["ksrecord"]) then
currentRecords["ksplayer"] = db.getplayerid(killerId)
currentRecords["ksrecord"] = stats.get(killerId, "longestKillSpree")
end
@ -184,7 +192,7 @@ function sprees.ondeath(victimId, killerId, mod)
stats.set(victimId, "longestDeathSpree", stats.get(victimId, "currentDeathSpree") > stats.get(victimId, "longestDeathSpree") and stats.get(victimId, "currentDeathSpree") or stats.get(victimId, "longestDeathSpree"))
if (settings.get("g_botRecords") == 1 or not db.isplayerbot(victimId)) and (not currentRecords["dsrecord"] or stats.get(victimId, "longestDeathSpree") > currentRecords["dsrecord"]) then
if (settings.get("g_botRecords") == 1 or not stats.get(victimId, "isBot")) and (not currentRecords["dsrecord"] or stats.get(victimId, "longestDeathSpree") > currentRecords["dsrecord"]) then
currentRecords["dsplayer"] = db.getplayerid(victimId)
currentRecords["dsrecord"] = stats.get(victimId, "longestDeathSpree")
end
@ -200,7 +208,7 @@ function sprees.onrevive(clientMedic, clientVictim)
et.trap_SendConsoleCommand(et.EXEC_APPEND, "chat \"^1REVIVE SPREE! ^*"..stats.get(clientMedic, "playerName").." ^*"..revivespreeMessages[stats.get(clientMedic, "currentReviveSpree")]["msg"].." ^d(^3"..stats.get(clientMedic, "currentReviveSpree").." ^drevives in a row!)\";")
end
if (settings.get("g_botRecords") == 1 or not db.isplayerbot(clientMedic)) and (not currentRecords["rsrecord"] or stats.get(clientMedic, "longestReviveSpree") > currentRecords["rsrecord"]) then
if (settings.get("g_botRecords") == 1 or not stats.get(clientMedic, "isBot")) and (not currentRecords["rsrecord"] or stats.get(clientMedic, "longestReviveSpree") > currentRecords["rsrecord"]) then
currentRecords["rsplayer"] = db.getplayerid(clientMedic)
currentRecords["rsrecord"] = stats.get(clientMedic, "longestReviveSpree")
end

View file

@ -40,8 +40,8 @@ local voting = require "luascripts.wolfadmin.game.voting"
local stats = require "luascripts.wolfadmin.players.stats"
local greetings = require "luascripts.wolfadmin.players.greetings"
local version = "1.0.0"
local release = "25 January 2016"
local version = "1.0.1"
local release = "8 February 2016"
local basepath = nil

View file

@ -45,31 +45,35 @@ function greetings.get(clientId)
end
function greetings.show(clientId)
local greetingText = greetings.get(clientId)
local greeting = greetings.get(clientId)
if greetingText then
if greeting then
local prefix = (util.getAreaName(settings.get("g_greetingArea")) ~= "cp") and "^dgreeting: ^9" or "^7"
local greeting = prefix..greetingText:gsub("%[N%]", et.gentity_get(clientId, "pers.netname"))
local text = prefix..greeting["text"]:gsub("%[N%]", et.gentity_get(clientId, "pers.netname"))
local out = ""
while util.getAreaName(settings.get("g_greetingArea")) == "cp" and string.len(greeting) > constants.MAX_LENGTH_CP do
local sub = greeting:sub(1, constants.MAX_LENGTH_CP)
while util.getAreaName(settings.get("g_greetingArea")) == "cp" and string.len(text) > constants.MAX_LENGTH_CP do
local sub = text:sub(1, constants.MAX_LENGTH_CP)
local rev = sub:reverse()
local pos = rev:find(" [^^]") -- some epic smiley exclusion here
if pos then
pos = constants.MAX_LENGTH_CP - pos
out = out..greeting:sub(1, pos).."\\n"
greeting = greeting:sub(pos + 2)
out = out..text:sub(1, pos).."\\n"
text = text:sub(pos + 2)
else
pos = sub:len()
out = out..greeting:sub(1, pos).."\\n"
greeting = greeting:sub(pos + 1)
out = out..text:sub(1, pos).."\\n"
text = text:sub(pos + 1)
end
end
et.trap_SendConsoleCommand(et.EXEC_APPEND, util.getAreaName(settings.get("g_greetingArea")).." \""..out..greeting.."\";")
if greeting["sound"] then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "playsound \"/sound/"..greeting["sound"].."\";")
end
et.trap_SendConsoleCommand(et.EXEC_APPEND, util.getAreaName(settings.get("g_greetingArea")).." \""..out..text.."\";")
end
end
@ -81,11 +85,17 @@ function greetings.load()
if amount == 0 then return 0 end
for id, greeting in ipairs(array["level"]) do
levelGreetings[tonumber(greeting["level"])] = greeting["greeting"]
levelGreetings[tonumber(greeting["level"])] = {
["text"] = greeting["greeting"],
["sound"] = greeting["sound"],
}
end
for id, greeting in ipairs(array["user"]) do
userGreetings[greeting["guid"]] = greeting["greeting"]
userGreetings[greeting["guid"]] = {
["text"] = greeting["greeting"],
["sound"] = greeting["sound"],
}
end
return amount

View file

@ -17,6 +17,10 @@
local constants = {}
constants.GAME_RUNNING = 0
constants.GAME_WARMUP = 1
constants.GAME_STATE_INTERMISSION = 3
constants.COLOR_MAIN = "^7"
constants.MAX_LENGTH_CP = 56