-- Made by AquaMonkey#1470, updated 27 may 2021 -- Update for configurable vote options and do_vote command by Fl_GUI#5136, 17 april 2022 (also some cleanup) -- changelog: -- 0.4: add command to toggle ranking, and add help command. both prefixed with aqm (aqm_help, aqm_enabled) -- : add aqm_resetmessage to toggle a message stating votes were wiped -- 0.5: add configurable vote options, usage: aqm_new_option , aqm_resetmessage to return to default -- is the string that is shown in chat and the message players have to type to vote. -- is a number representing the vote, negative numbers for negative votes, positive numbers for positive votes -- : add extra command aqm_do_vote to allow for players to bind keys to vote, usage: aqm_do_vote -- is the string you would type in chat -- 1.0: allow players to vote directly after they finished a race by holding either DRIFT (positive) or BRAKE (negative) -- this will only work with the default voting options for now!!! -- 1.1: change the blue header above the map's name when a player is done racing to not say LIKED but a random option -- now also hides the text after a few seconds local mapVotingActive = false local mapVotingAnnounced = false local mapVotesStoredPositive = 0 local mapVotesStoredNegative = 0 local mapID = '' local mapTitle = '' local zoneTitle = '' -- why no work -- nvm, it work -- nvm, still sometimes no work local mapVoteTable = {} -- Store votes in a table. This one stores nodes, local mapVoteTableNames = {} -- while this one stores player names. local mapVoteTableStore = {} local mapVoteTableOptions = {} local mapVoteTableOptionsDisplay = {} local mapVoteTableOptionsCount = 0 local voteCount = 0 local randomAsk = nil local randomAskNum = nil -- configuration -- local defaultMapVoteTableOptions = { ["++"] = 1, ["11"] = 1, ["=="] = 1, ["--"] = -1, ["00"] = -1 } local defaultMapVoteTableOptionsDisplay = { [1] = "++", [-1] = "--" } local TEXT = "\x88" local NEG = "\x87" local POS = "\x83" local WHITE = "\x80" local gfxAsks = { "ENJOYED", "HAD FUN ON", "DID YOU LIKE", "DID YOU ENJOY" } -- CVARS -- local toggleEnabled = CV_RegisterVar({ name = "aqm_enabled", defaultvalue = "on", flags = CV_NETVAR, PossibleValue = {off=0,on=1}, }) local resetMessage = CV_RegisterVar({ name = "aqm_resetmessage", defaultvalue = "off", flags = CV_NETVAR, PossibleValue = {off=0,on=1}, }) -- functions -- local StringJoiner = function(sep) local factory = { text = "", sep = sep, parts = 0 } function factory:addText(text) if self.text == "" then self.text = text else self.text = self.text..self.sep..text end self.parts = self.parts + 1 end function factory:result() return self.text end function factory:length() return self.parts end return factory; end local norm = function(value) if value < 0 then return -1 elseif value == 0 then return 0 elseif value > 0 then return 1 end end local getVoteOptionTables = function() if next(mapVoteTableOptions) then -- options set, use that return mapVoteTableOptions, mapVoteTableOptionsDisplay else -- no options set, use default return defaultMapVoteTableOptions, defaultMapVoteTableOptionsDisplay end end local getLevelFullName = function() return mapTitle..(zoneTitle and " "..zoneTitle or "") end -- metatable fun local voteValueToColor = {} voteValueToColor.prototype = { [-1] = NEG, [0] = WHITE, [1] = POS } voteValueToColor.mt = { __index = function(t, val) return voteValueToColor.prototype[norm(val)] end } local mapVoteRecord = function(vote, player) -- Record a node's vote together with the associated name if #player ~= 0 then mapVoteTableNames[#player] = player.name mapVoteTable[#player] = vote end end setmetatable(voteValueToColor, voteValueToColor.mt) -- console commands -- local consoleHelp = function(player) local voteOptions = getVoteOptionTables() local votes = { [-1] = StringJoiner(" / "), [0] = StringJoiner(" / "), [1] = StringJoiner(" / "), } for k,v in pairs(voteOptions) do local n = norm(v) votes[n]:addText(k) end local string = "\136Aqua's Map Ranking Script\128\ After every race, you can vote on whether you enjoyed a map.\ ---\ Vote by holding either DRIFT (to vote positive) or BRAKE (to vote negative) after you finished,\ or by typing one of the following options in chat during intermission:" if votes[1]:length() ~= 0 then string = $.."\n"..POS.."Voting positive: "..WHITE..votes[1]:result() end if votes[0]:length() ~= 0 then string = $.."\n".."Voting neutral: "..votes[0]:result() end if votes[-1]:length() ~= 0 then string = $.."\n"..NEG.."Voting negative: "..WHITE..votes[-1]:result() end -- TODO: allow people to include a link where to see results --string = $.."\nResults are posted at \129https://srb2kart.aqua.fyi/maps.html" CONS_Printf(player, string) end local addVoteOption = function(player, arg1, arg2) if not (IsPlayerAdmin(player) or player == server) then return end; if arg1 == nil or arg2 == nil then CONS_Printf(player, "usage: aqm_new_option