Dimos7 Posted March 29, 2015 Share Posted March 29, 2015 (edited) -- -- racemidvote_server.lua -- -- Mid-race random map vote and -- NextMapVote handled in this file -- setter = "none" local lastVoteStarterName = '' local lastVoteStarterCount = 0 g_ForcedNextMap = nil ---------------------------------------------------------------------------- -- displayHilariarseMessage -- -- Comedy gold ---------------------------------------------------------------------------- function displayHilariarseMessage( player ) if not player then lastVoteStarterName = '' else local playerName = getPlayerName(player) local msg = '' if playerName == lastVoteStarterName then lastVoteStarterCount = lastVoteStarterCount + 1 if lastVoteStarterCount == 5 then msg = playerName .. ' started a vote. Hardly a suprise.' elseif lastVoteStarterCount == 10 then msg = 'Guess what! '..playerName .. ' started ANOTHER vote!' elseif lastVoteStarterCount < 5 then msg = playerName .. ' started another vote.' else msg = playerName .. ' continues to abuse the vote system.' end else lastVoteStarterCount = 0 lastVoteStarterName = playerName msg = playerName .. ' started a vote.' end outputRace( msg ) end end ---------------------------------------------------------------------------- -- displayKillerPunchLine -- -- Sewing kits available in the foyer ---------------------------------------------------------------------------- function displayKillerPunchLine( player ) if lastVoteStarterName ~= '' then outputRace( 'Offical news: Everybody hates ' .. lastVoteStarterName ) end end ---------------------------------------------------------------------------- -- startMidMapVoteForRandomMap -- -- Start the vote menu if during a race and more than 30 seconds from the end -- No messages if this was not started by a player ---------------------------------------------------------------------------- function startMidMapVoteForRandomMap(player) -- Check state and race time left if not stateAllowsRandomMapVote() or g_CurrentRaceMode:getTimeRemaining() < 30000 then if player then outputRace( "I'm afraid I can't let you do that, " .. getPlayerName(player) .. ".", player ) end return end displayHilariarseMessage( player ) exports.votemanager:stopPoll() -- Actual vote started here local pollDidStart = exports.votemanager:startPoll { title='Do you want to change to a random map?', percentage=51, timeout=15, allowchange=true, visibleTo=getRootElement(), [1]={'Yes', 'midMapVoteResult', getRootElement(), true}, [2]={'No', 'midMapVoteResult', getRootElement(), false;default=true}, } -- Change state if vote did start if pollDidStart then gotoState('MidMapVote') end end --addCommandHandler('new',startMidMapVoteForRandomMap) ---------------------------------------------------------------------------- -- event midMapVoteResult -- -- Called from the votemanager when the poll has completed ---------------------------------------------------------------------------- addEvent('midMapVoteResult') addEventHandler('midMapVoteResult', getRootElement(), function( votedYes ) -- Change state back if stateAllowsRandomMapVoteResult() then gotoState('Running') if votedYes then startRandomMap() else displayKillerPunchLine() end end end ) ---------------------------------------------------------------------------- -- startRandomMap -- -- Changes the current map to a random race map ---------------------------------------------------------------------------- function startRandomMap() -- Handle forced nextmap setting if maybeApplyForcedNextMap() then return end -- Get a random map chosen from the 10% of least recently player maps, with enough spawn points for all the players (if required) local map = getRandomMapCompatibleWithGamemode( getThisResource(), 10, g_GameOptions.ghostmode and 0 or getTotalPlayerCount() ) if map then g_IgnoreSpawnCountProblems = map -- Uber hack 4000 if not exports.mapmanager:changeGamemodeMap ( map, nil, true ) then problemChangingMap() end else outputWarning( 'startRandomMap failed' ) end end ---------------------------------------------------------------------------- -- outputRace -- -- Race color is defined in the settings ---------------------------------------------------------------------------- function outputRace(message, toElement) toElement = toElement or g_Root local r, g, b = getColorFromString(string.upper(get("color"))) if getElementType(toElement) == 'console' then outputServerLog(message) else if toElement == rootElement then outputServerLog(message) end if getElementType(toElement) == 'player' then message = '[PM] ' .. message end outputChatBox(message, toElement, r, g, b) end end ---------------------------------------------------------------------------- -- problemChangingMap -- -- Sort it ---------------------------------------------------------------------------- function problemChangingMap() outputRace( 'Changing to random map in 5 seconds' ) local currentMap = exports.mapmanager:getRunningGamemodeMap() TimerManager.createTimerFor("resource","mapproblem"):setTimer( function() -- Check that something else hasn't already changed the map if currentMap == exports.mapmanager:getRunningGamemodeMap() then startRandomMap() end end, math.random(4500,5500), 1 ) end -- -- -- NextMapVote -- -- -- local g_Poll ---------------------------------------------------------------------------- -- startNextMapVote -- -- Start a votemap for the next map. Should only be called during the -- race state 'NextMapSelect' ---------------------------------------------------------------------------- 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 table.insert(poll, {"Play again", 'nextMapVoteResult', getRootElement(), currentMap}) end -- Allow addons to modify the poll g_Poll = poll triggerEvent('onPollStarting', g_Root, poll ) poll = g_Poll g_Poll = Edited April 3, 2015 by Guest Link to comment
xXMADEXx Posted March 29, 2015 Share Posted March 29, 2015 Debug errors? (/debugscript 3) Link to comment
Dimos7 Posted March 29, 2015 Author Share Posted March 29, 2015 error line 26 attempt to compare nil with number Link to comment
Addlibs Posted March 29, 2015 Share Posted March 29, 2015 There is not comparison on line 26. You must have trimmed the code. Please check what is line 26 in your original file, and and tell us which line it is on the code you've sent. Link to comment
Dimos7 Posted March 29, 2015 Author Share Posted March 29, 2015 (edited) -- -- racemidvote_server.lua -- -- Mid-race random map vote and -- NextMapVote handled in this file -- setter = "none" local lastVoteStarterName = '' local lastVoteStarterCount = 0 g_ForcedNextMap = nil ---------------------------------------------------------------------------- -- displayHilariarseMessage -- -- Comedy gold ---------------------------------------------------------------------------- function displayHilariarseMessage( player ) if not player then lastVoteStarterName = '' else local playerName = getPlayerName(player) local msg = '' if playerName == lastVoteStarterName then lastVoteStarterCount = lastVoteStarterCount + 1 if lastVoteStarterCount == 5 then msg = playerName .. ' started a vote. Hardly a suprise.' elseif lastVoteStarterCount == 10 then msg = 'Guess what! '..playerName .. ' started ANOTHER vote!' elseif lastVoteStarterCount < 5 then msg = playerName .. ' started another vote.' else msg = playerName .. ' continues to abuse the vote system.' end else lastVoteStarterCount = 0 lastVoteStarterName = playerName msg = playerName .. ' started a vote.' end outputRace( msg ) end end ---------------------------------------------------------------------------- -- displayKillerPunchLine -- -- Sewing kits available in the foyer ---------------------------------------------------------------------------- function displayKillerPunchLine( player ) if lastVoteStarterName ~= '' then outputRace( 'Offical news: Everybody hates ' .. lastVoteStarterName ) end end ---------------------------------------------------------------------------- -- startMidMapVoteForRandomMap -- -- Start the vote menu if during a race and more than 30 seconds from the end -- No messages if this was not started by a player ---------------------------------------------------------------------------- function startMidMapVoteForRandomMap(player) -- Check state and race time left if not stateAllowsRandomMapVote() or g_CurrentRaceMode:getTimeRemaining() < 30000 then if player then outputRace( "I'm afraid I can't let you do that, " .. getPlayerName(player) .. ".", player ) end return end displayHilariarseMessage( player ) exports.votemanager:stopPoll() -- Actual vote started here local pollDidStart = exports.votemanager:startPoll { title='Do you want to change to a random map?', percentage=51, timeout=15, allowchange=true, visibleTo=getRootElement(), [1]={'Yes', 'midMapVoteResult', getRootElement(), true}, [2]={'No', 'midMapVoteResult', getRootElement(), false;default=true}, } -- Change state if vote did start if pollDidStart then gotoState('MidMapVote') end end --addCommandHandler('new',startMidMapVoteForRandomMap) ---------------------------------------------------------------------------- -- event midMapVoteResult -- -- Called from the votemanager when the poll has completed ---------------------------------------------------------------------------- addEvent('midMapVoteResult') addEventHandler('midMapVoteResult', getRootElement(), function( votedYes ) -- Change state back if stateAllowsRandomMapVoteResult() then gotoState('Running') if votedYes then startRandomMap() else displayKillerPunchLine() end end end ) ---------------------------------------------------------------------------- -- startRandomMap -- -- Changes the current map to a random race map ---------------------------------------------------------------------------- function startRandomMap() -- Handle forced nextmap setting if maybeApplyForcedNextMap() then return end -- Get a random map chosen from the 10% of least recently player maps, with enough spawn points for all the players (if required) local map = getRandomMapCompatibleWithGamemode( getThisResource(), 10, g_GameOptions.ghostmode and 0 or getTotalPlayerCount() ) if map then g_IgnoreSpawnCountProblems = map -- Uber hack 4000 if not exports.mapmanager:changeGamemodeMap ( map, nil, true ) then problemChangingMap() end else outputWarning( 'startRandomMap failed' ) end end ---------------------------------------------------------------------------- -- outputRace -- -- Race color is defined in the settings ---------------------------------------------------------------------------- function outputRace(message, toElement) toElement = toElement or g_Root local r, g, b = getColorFromString(string.upper(get("color"))) if getElementType(toElement) == 'console' then outputServerLog(message) else if toElement == rootElement then outputServerLog(message) end if getElementType(toElement) == 'player' then message = '[PM] ' .. message end outputChatBox(message, toElement, r, g, b) end end ---------------------------------------------------------------------------- -- problemChangingMap -- -- Sort it ---------------------------------------------------------------------------- function problemChangingMap() outputRace( 'Changing to random map in 5 seconds' ) local currentMap = exports.mapmanager:getRunningGamemodeMap() TimerManager.createTimerFor("resource","mapproblem"):setTimer( function() -- Check that something else hasn't already changed the map if currentMap == exports.mapmanager:getRunningGamemodeMap() then startRandomMap() end end, math.random(4500,5500), 1 ) end -- -- -- NextMapVote -- -- -- local g_Poll ---------------------------------------------------------------------------- -- startNextMapVote -- -- Start a votemap for the next map. Should only be called during the -- race state 'NextMapSelect' ---------------------------------------------------------------------------- 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 table.insert(poll, {"Play again", 'nextMapVoteResult', getRootElement(), currentMap}) end -- Allow addons to modify the poll g_Poll = poll triggerEvent('onPollStarting', g_Root, poll ) poll = g_Poll g_Poll = Edited April 4, 2015 by Guest Link to comment
Dimos7 Posted April 1, 2015 Author Share Posted April 1, 2015 Can someone help please? Link to comment
Dimos7 Posted April 3, 2015 Author Share Posted April 3, 2015 not make errors or wanring say the same name twice also 3/2 say 2 not 1 please help me Link to comment
MisterQuestions Posted April 6, 2015 Share Posted April 6, 2015 Why not use a voteredo different? That is the default one lel Link to comment
Dimos7 Posted April 6, 2015 Author Share Posted April 6, 2015 the dafaul i put it as adminredo Link to comment
SpecT Posted April 6, 2015 Share Posted April 6, 2015 https://community.multitheftauto.com/in ... s&id=10604 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