krYshuT Posted January 17, 2011 Share Posted January 17, 2011 Hello, So I have this code that should remove the option "Play again" from vote, when one map was played 3 times in a row. But it doesn't work correct and I have no clue how to make it working. It removes "Play again" every third map, no matter if it was played more times than once. Example: Map 1 (people voted for Play again) > Map 1 (people voted for Play again) > Map 1 (Play again option disappeared) This is okay, it works. But when people vote each time for different map: Map 1 (people voted for Map 2) > Map 2 (people voted for Map 3) > Map 3 (Play Again option disappeared, but it shouldn't, cause they played it just once) Please help g_maxPlayAgain = 2 function startNextMapVote() exports.votemanager:stopPoll() -- Handle forced nextmap setting if maybeApplyForcedNextMap() then return end -- Get all maps local compatibleMaps = exports.mapmanager:getMapsCompatibleWithGamemode(getThisResource()) -- limit it to eight random maps if #compatibleMaps > 8 then math.randomseed(getTickCount()) repeat table.remove(compatibleMaps, math.random(1, #compatibleMaps)) until #compatibleMaps == 8 elseif #compatibleMaps < 2 then return false, errorCode.onlyOneCompatibleMap end -- mix up the list order for i,map in ipairs(compatibleMaps) do local swapWith = math.random(1, #compatibleMaps) local temp = compatibleMaps[i] compatibleMaps[i] = compatibleMaps[swapWith] compatibleMaps[swapWith] = temp end local poll = { title="Choose the next map:", visibleTo=getRootElement(), percentage=51, timeout=15, allowchange=true; } for index, map in ipairs(compatibleMaps) do local mapName = getResourceInfo(map, "name") or getResourceName(map) table.insert(poll, {mapName, 'nextMapVoteResult', getRootElement(), map}) end local currentMap = exports.mapmanager:getRunningGamemodeMap() if currentMap then if g_maxPlayAgain >= 2 then --table.insert(poll, {"Reached max play again times, chossing a random map.", 'nextMapVoteResult', getRootElement()}) g_maxPlayAgain = 0 else g_maxPlayAgain = g_maxPlayAgain + 1 table.insert(poll, {"Play again", 'nextMapVoteResult', getRootElement(), currentMap}) end end -- Allow addons to modify the poll g_Poll = poll triggerEvent('onPollStarting', g_Root, poll ) poll = g_Poll g_Poll = nil local pollDidStart = exports.votemanager:startPoll(poll) if pollDidStart then gotoState('NextMapVote') addEventHandler("onPollEnd", getRootElement(), chooseRandomMap) end return pollDidStart end Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now