From 56d822b417a7359cc5e72c04fdedca38d2ee0977 Mon Sep 17 00:00:00 2001 From: Timo Smit Date: Wed, 8 Feb 2017 14:32:00 +0100 Subject: [PATCH] Added more levels to bot difficulties consistent with omnibot's own naming (refs #77) --- luamods/wolfadmin/game/voting.lua | 68 +++++++++++++++++-------------- pk3/ui/ingame_vote_wolfadmin.menu | 2 +- 2 files changed, 39 insertions(+), 31 deletions(-) diff --git a/luamods/wolfadmin/game/voting.lua b/luamods/wolfadmin/game/voting.lua index a4aea14..a39295c 100644 --- a/luamods/wolfadmin/game/voting.lua +++ b/luamods/wolfadmin/game/voting.lua @@ -16,12 +16,12 @@ -- along with this program. If not, see . local auth = require (wolfa_getLuaPath()..".auth.auth") + local constants = require (wolfa_getLuaPath()..".util.constants") -local util = require (wolfa_getLuaPath()..".util.util") local events = require (wolfa_getLuaPath()..".util.events") -local timers = require (wolfa_getLuaPath()..".util.timers") local settings = require (wolfa_getLuaPath()..".util.settings") -local bots = require (wolfa_getLuaPath()..".game.bots") +local timers = require (wolfa_getLuaPath()..".util.timers") +local util = require (wolfa_getLuaPath()..".util.util") local voting = {} @@ -34,7 +34,7 @@ function voting.allow(type, value) et.trap_Cvar_Set("vote_allow_"..type, value) end -function voting.isallowed(type) +function voting.isAllowed(type) return (allowed[type] == 1) end @@ -43,15 +43,15 @@ function voting.force(type) voting.allow(type, 1) end -function voting.isforced(type) +function voting.isForced(type) return (forced[type] == 1) end -function voting.isrestricted(type) +function voting.isRestricted(type) return (restricted[type] == 1) end -function voting.disablenextmap() +function voting.disableNextMap() et.trap_SendConsoleCommand(et.EXEC_APPEND, "cchat -1 \"^dvote: ^9next map voting has automatically been disabled.\";") voting.allow("nextmap", 0) @@ -62,43 +62,43 @@ function voting.load() allowed[type] = tonumber(et.trap_Cvar_Get("vote_allow_"..type)) forced[type] = 0 end - + local restrictedVotes = util.split(settings.get("g_restrictedVotes"), ",") - + for _, type in pairs(restrictedVotes) do restricted[type] = 1 end end -function voting.oninit(levelTime, randomSeed, restartMap) +function voting.onGameInit(levelTime, randomSeed, restartMap) voting.load() - + if settings.get("g_voteNextMapTimeout") > 0 then voting.allow("nextmap", 1) end end -events.handle("onGameInit", voting.oninit) +events.handle("onGameInit", voting.onGameInit) -function voting.ongamestatechange(gameState) +function voting.onGameStateChange(gameState) if gameState == 0 and settings.get("g_voteNextMapTimeout") > 0 then - timers.add(voting.disablenextmap, settings.get("g_voteNextMapTimeout") * 1000, 1) + timers.add(voting.disableNextMap, settings.get("g_voteNextMapTimeout") * 1000, 1) end end -events.handle("onGameStateChange", voting.ongamestatechange) +events.handle("onGameStateChange", voting.onGameStateChange) -function voting.oncallvote(clientId, type, args) +function voting.onCallvote(clientId, type, args) if et.gentity_get(clientId, "sess.sessionTeam") == constants.TEAM_SPECTATORS or args[1] == "?" then return 0 - elseif voting.isrestricted(type) and not auth.isPlayerAllowed(clientId, PERM_NOVOTELIMIT) then + elseif voting.isRestricted(type) and not auth.isPlayerAllowed(clientId, auth.PERM_NOVOTELIMIT) then et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"callvote: you are not allowed to call this type of vote.\";") et.trap_SendServerCommand(clientId, "cp \"You are not allowed to call this type of vote.") - + return 1 end end -events.handle("onCallvote", voting.oncallvote) +events.handle("onCallvote", voting.onCallvote) -function voting.onpollfinish(passed, poll) +function voting.onPollFinish(passed, poll) if passed then if poll == "enable bots" then et.trap_SendConsoleCommand(et.EXEC_APPEND, "needbots") @@ -106,7 +106,7 @@ function voting.onpollfinish(passed, poll) et.trap_SendConsoleCommand(et.EXEC_APPEND, "kickbots") elseif string.find(poll, "put bots") == 1 then local team = string.sub(poll, 10) - + if team == "axis" then team = constants.TEAM_AXIS_SC elseif team == "allies" then @@ -114,27 +114,35 @@ function voting.onpollfinish(passed, poll) else return end - + et.trap_SendConsoleCommand(et.EXEC_APPEND, "putbots "..team) elseif string.find(poll, "set bot difficulty") == 1 then local difficulty = string.sub(poll, 20) - - if difficulty == "epic" then + + if tonumber(difficulty) then + difficulty = tonumber(difficulty) + elseif difficulty == "uber" then difficulty = 6 - elseif difficulty == "hard" then + elseif difficulty == "professional" then difficulty = 5 - elseif difficulty == "normal" then + elseif difficulty == "standard" then difficulty = 4 + elseif difficulty == "easy frag" then + difficulty = 3 + elseif difficulty == "poor" then + difficulty = 2 + elseif difficulty == "very poor" then + difficulty = 1 + elseif difficulty == "poorest" then + difficulty = 0 else return end - + et.trap_SendConsoleCommand(et.EXEC_APPEND, "bot difficulty "..difficulty) - -- else - -- et.trap_SendConsoleCommand(et.EXEC_APPEND, command) end end end -events.handle("onPollFinish", voting.onpollfinish) +events.handle("onPollFinish", voting.onPollFinish) return voting diff --git a/pk3/ui/ingame_vote_wolfadmin.menu b/pk3/ui/ingame_vote_wolfadmin.menu index c48bc86..ba01edc 100644 --- a/pk3/ui/ingame_vote_wolfadmin.menu +++ b/pk3/ui/ingame_vote_wolfadmin.menu @@ -40,7 +40,7 @@ menuDef { // right side buttons BUTTONEXT( 6+.5*(WINDOW_WIDTH-18)+6, 68, .5*(WINDOW_WIDTH-18), 14, "PUTBOTS ALLIES", .24, 11, exec "cmd callvote poll put bots allies"; uiScript closeingame, voteFlag CV_SVF_POLL ) - MULTILEFT( 8, 86+2, .80*(WINDOW_WIDTH-18), 10, "Bot difficulty:", .2, 8, "ui_poll", cvarStrList { "Epic"; "set bot difficulty epic"; "Hard"; "set bot difficulty hard"; "Normal"; "set bot difficulty normal" } voteflag CV_SVF_POLL, "Select the difficulty to vote on" ) + MULTILEFT( 8, 86+2, .80*(WINDOW_WIDTH-18), 10, "Bot difficulty:", .2, 8, "ui_poll", cvarStrList { "Uber"; "set bot difficulty uber"; "Professional"; "set bot difficulty professional"; "Standard"; "set bot difficulty standard"; "Easy frag"; "set bot difficulty easy frag"; "Poor"; "set bot difficulty poor"; "Very poor"; "set bot difficulty very poor"; "Poorest"; "set bot difficulty poorest" } voteflag CV_SVF_POLL, "Select the difficulty to vote on" ) NAMEDBUTTONEXT( "bttnextBotDifficulty", 6+.80*(WINDOW_WIDTH-18)+6, 86, .20*(WINDOW_WIDTH-18), 14, "OK", .24, 11, uiScript votePoll; uiScript closeingame, voteflag CV_SVF_POLL ) BUTTON( 6, WINDOW_HEIGHT-24, WINDOW_WIDTH-12, 18, "BACK", .3, 14, close ingame_vote_wolfadmin ; open ingame_vote )