Skip to content

Commit

Permalink
Implemented combis for multikills/multirevives (refs #95)
Browse files Browse the repository at this point in the history
  • Loading branch information
timosmit committed Feb 5, 2019
1 parent c27381b commit f5d71d7
Show file tree
Hide file tree
Showing 6 changed files with 230 additions and 0 deletions.
24 changes: 24 additions & 0 deletions config/combis.toml
@@ -0,0 +1,24 @@
[[kill]]
amount = 3
msg = "^7!!!! ^1MULTI KILL ^7> ^7[N] ^7< ^1MULTI KILL ^7!!!!"
sound = "multikill.wav"

[[kill]]
amount = 4
msg = "^7!!!! ^1ULTRA KILL ^7> ^7[N] ^7< ^ULTRA KILL ^7!!!!"
sound = "ultrakill.wav"

[[kill]]
amount = 5
msg = "^7!!!! ^1MONSTER KILL ^7> ^7[N] ^7< ^1MONSTER KILL ^7!!!!"
sound = "monsterkill.wav"

[[kill]]
amount = 6
msg = "^7!!!! ^1MEGA KILL ^7> ^7[N] ^7< ^1MEGA KILL ^7!!!!"
sound = "megakill.wav"

[[kill]]
amount = 7
msg = "^7!!!! ^1LUDICROUS KILL ^7> ^7[N] ^7< ^1LUDICROUS KILL ^7!!!!"
sound = "ludicrouskill.wav"
6 changes: 6 additions & 0 deletions config/wolfadmin.toml
Expand Up @@ -68,6 +68,12 @@ bots = 1
[records]
bots = 1

[combis]
file = "combis.toml"
messages = 3
sounds = 3
time = 1000

[sprees]
file = "sprees.toml"
messages = 7
Expand Down
187 changes: 187 additions & 0 deletions luascripts/wolfadmin/game/combis.lua
@@ -0,0 +1,187 @@

-- WolfAdmin module for Wolfenstein: Enemy Territory servers.
-- Copyright (C) 2015-2019 Timo 'Timothy' Smit

-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- at your option any later version.

-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.

-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.

local db = wolfa_requireModule("db.db")

local game = wolfa_requireModule("game.game")

local players = wolfa_requireModule("players.players")

local bits = wolfa_requireModule("util.bits")
local constants = wolfa_requireModule("util.constants")
local events = wolfa_requireModule("util.events")
local settings = wolfa_requireModule("util.settings")
local timers = wolfa_requireModule("util.timers")

local toml = wolfa_requireLib("toml")

local combis = {}

combis.COMBI_KILL = 0
combis.COMBI_REVIVE = 1
combis.COMBI_NUM = 2

combis.SOUND_PLAY_SELF = 0
combis.SOUND_PLAY_PUBLIC = 1

combis.COMBI_KILL_NAME = "kill"
combis.COMBI_REVIVE_NAME = "revive"

local combiNames = {
[combis.COMBI_KILL] = combis.COMBI_KILL_NAME,
[combis.COMBI_REVIVE] = combis.COMBI_REVIVE_NAME
}

local combiTypes = {
[combis.COMBI_KILL_NAME] = combis.COMBI_KILL,
[combis.COMBI_REVIVE_NAME] = combis.COMBI_REVIVE
}

local combiMessages = {}
local combiMessagesByType = {}

local playerCombis = {}

function combis.getRecordNameByType(type)
return combiNames[type]
end

function combis.getRecordTypeByName(name)
return combiTypes[name]
end

function combis.load()
for i = 0, combis.COMBI_NUM - 1 do
combiMessages[i] = {}
combiMessagesByType[i] = {}
end

local fileName = settings.get("g_fileCombis")

if fileName == "" then
return 0
end

if string.find(fileName, ".toml") == string.len(fileName) - 4 then
local fileDescriptor, fileLength = et.trap_FS_FOpenFile(fileName, et.FS_READ)

if fileLength == -1 then
return 0
end

local fileString = et.trap_FS_Read(fileDescriptor, fileLength)

et.trap_FS_FCloseFile(fileDescriptor)

local fileTable = toml.parse(fileString)

local amount = 0

for name, block in pairs(fileTable) do
for _, combi in ipairs(block) do
if combi["msg"] then
table.insert(combiMessagesByType[combis.getRecordTypeByName(name)], combi)

combiMessages[combis.getRecordTypeByName(name)][combi["amount"]] = combi

amount = amount + 1
end
end
end

return amount
end

return 0
end

function combis.printCombi(clientId, type)
local currentCombi = playerCombis[clientId][type]["total"]

if bits.hasbit(settings.get("g_combiMessages"), 2^type) and #combiMessagesByType[type] > 0 then
local combiMessage = combiMessages[type][currentCombi]

if combiMessage then
local msg = string.gsub(combiMessage["msg"], "%[N%]", players.getName(clientId))

if settings.get("g_combiSounds") > 0 and combiMessage["sound"] and combiMessage["sound"] ~= "" then
if bits.hasbit(settings.get("g_combiSounds"), combis.SOUND_PLAY_PUBLIC) then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "playsound \"sound/combi/"..combiMessage["sound"].."\";")
else
et.trap_SendConsoleCommand(et.EXEC_APPEND, "playsound "..clientId.." \"sound/combi/"..combiMessage["sound"].."\";")
end
end

et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat -1 \""..msg.."\";")
end
end
end

function combis.onGameInit(levelTime, randomSeed, restartMap)
combis.load()

events.handle("onGameStateChange", combis.onGameStateChange)
end
events.handle("onGameInit", combis.onGameInit)

function combis.onClientConnect(clientId, firstTime, isBot)
playerCombis[clientId] = {}

for i = 0, combis.COMBI_NUM - 1 do
playerCombis[clientId][i] = {["last"] = nil, ["total"] = 0, ["timer"] = nil}
end
end
events.handle("onClientConnect", combis.onClientConnect)

function combis.onClientDisconnect(clientId)
playerCombis[clientId] = nil
end
events.handle("onClientDisconnect", combis.onClientDisconnect)

function combis.onGameStateChange(gameState)
if gameState == constants.GAME_STATE_RUNNING then
events.handle("onPlayerDeath", combis.onPlayerDeath)
events.handle("onPlayerRevive", combis.onPlayerRevive)
events.handle("onPlayerCombi", combis.onPlayerCombi)
end
end

function combis.onPlayerCombi(clientId, type, sourceId)
if not playerCombis[clientId][type]["last"] or et.trap_Milliseconds() - playerCombis[clientId][type]["last"] > settings.get("g_combiTime") then
playerCombis[clientId][type]["total"] = 0
elseif playerCombis[clientId][type]["timer"] then
timers.remove(playerCombis[clientId][type]["timer"])
end

playerCombis[clientId][type]["last"] = et.trap_Milliseconds()
playerCombis[clientId][type]["total"] = playerCombis[clientId][type]["total"] + 1
playerCombis[clientId][type]["timer"] = timers.add(combis.printCombi, settings.get("g_combiTime"), 1, clientId, type)
end

function combis.onPlayerDeath(victimId, attackerId, meansOfDeath)
if attackerId ~= 1022 and victimId ~= attackerId then
if et.gentity_get(victimId, "sess.sessionTeam") ~= et.gentity_get(attackerId, "sess.sessionTeam") then
events.trigger("onPlayerCombi", attackerId, combis.COMBI_KILL)
end
end
end

function combis.onPlayerRevive(clientMedic, clientVictim)
events.trigger("onPlayerCombi", clientMedic, combis.COMBI_REVIVE)
end

return combis
2 changes: 2 additions & 0 deletions luascripts/wolfadmin/main.lua
Expand Up @@ -31,6 +31,7 @@ local db
local commands

local bots
local combis
local fireteams
local game
local sprees
Expand Down Expand Up @@ -124,6 +125,7 @@ function et_InitGame(levelTime, randomSeed, restartMap)
commands = wolfa_requireModule("commands.commands")

bots = wolfa_requireModule("game.bots")
combis = wolfa_requireModule("game.combis")
game = wolfa_requireModule("game.game")
fireteams = wolfa_requireModule("game.fireteams")
sprees = wolfa_requireModule("game.sprees")
Expand Down
1 change: 1 addition & 0 deletions luascripts/wolfadmin/util/events.lua
Expand Up @@ -131,6 +131,7 @@ events.add("onPlayerRevive")

events.add("onPlayerSkillUpdate")

events.add("onPlayerCombi")
events.add("onPlayerSpree")
events.add("onPlayerSpreeEnd")

Expand Down
10 changes: 10 additions & 0 deletions luascripts/wolfadmin/util/settings.lua
Expand Up @@ -27,11 +27,15 @@ local data = {
["g_fileCensor"] = "censor.toml",
["g_fileGreetings"] = "greetings.toml",
["g_fileRules"] = "rules.toml",
["g_fileCombis"] = "combis.toml",
["g_fileSprees"] = "sprees.toml",
["g_playerHistory"] = 1,
["g_censorMode"] = 1,
["g_censorMute"] = 60,
["g_censorKick"] = 1,
["g_combiMessages"] = 3,
["g_combiSounds"] = 3,
["g_combiTime"] = 1000,
["g_spreeMessages"] = 7,
["g_spreeSounds"] = 3,
["g_spreeRecords"] = 1,
Expand Down Expand Up @@ -125,6 +129,12 @@ local cfgStructure = {
["records"] = {
["bots"] = "g_botRecords"
},
["combis"] = {
["file"] = "g_fileCombis",
["messages"] = "g_combiMessages",
["sounds"] = "g_combiSounds",
["time"] = "g_combiTime"
},
["sprees"] = {
["file"] = "g_fileSprees",
["messages"] = "g_spreeMessages",
Expand Down

0 comments on commit f5d71d7

Please sign in to comment.