Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented combis for multikills/multirevives (refs #95)
- Loading branch information
Showing
6 changed files
with
230 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters