zzx Posted March 15, 2014 Share Posted March 15, 2014 hi guys, the map doesn't restart, and i'm testing it on the default race, any help? playerVotes = {} local i = 0 addCommandHandler( "vr", function(source) if(playerVotes[source] == true) then return outputChatBox("#ff8800[REDO]: #ffffffYou have already voted", getRootElement(), 255,0,0, true, source) end if not i then i = 0 end if i >= 4 then outputChatBox("", getRootElement(), 255,0,0, true) outputChatBox("#ff8800[REDO]: #ffffffThe map will be restarted!", getRootElement(), 255,0,0, true) else playerVotes[source] = true i = i + 1 end if i == 3 then outputChatBox("", getRootElement(), 255,0,0, true) outputChatBox("#ff8800[REDO]: "..getPlayerName(source).."#ffffff voted for redo! ["..i.."/3]", getRootElement(), 255,0,0, true) outputChatBox("", getRootElement(), 255,0,0, true) outputChatBox("#ff8800[REDO]: #ffffffThis map will be restarted by vote!", getRootElement(), 255,0,0, true) g_ForcedNextMap = currentMap setTimer(function() i = 0 end, 150*1000,1) playerVotes = {3} elseif i <= 2 then outputChatBox("", getRootElement(), 255,0,0, true) outputChatBox("#ff8800[REDO]: "..getPlayerName(source).." #ffffffvoted for redo! ["..i.."/3]", getRootElement(), 255,0,0, true) end end) Link to comment
Moderators Citizen Posted March 15, 2014 Moderators Share Posted March 15, 2014 Ok try this: local playerVotes = {} local nbVotes = 0 addCommandHandler( "vr", function( player ) if(playerVotes[player] == true) then return outputChatBox("#ff8800[REDO]: #ffffffYou have already voted", source, 255, 0, 0, true) end if not nbVotes then nbVotes = 0 end playerVotes[player] = true nbVotes = nbVotes + 1 if nbVotes >= 4 then outputChatBox("", root, 255, 0, 0, true) outputChatBox("#ff8800[REDO]: #ffffffThe map will be restarted!", root, 255, 0, 0, true) elseif nbVotes == 3 then outputChatBox("", root, 255, 0, 0, true) outputChatBox("#ff8800[REDO]: "..getPlayerName(player).."#ffffff voted for redo! ["..nbVotes.."/3]", root, 255, 0, 0, true) outputChatBox("", root, 255, 0, 0, true) outputChatBox("#ff8800[REDO]: #ffffffThis map will be restarted by vote!", root, 255, 0, 0, true) g_ForcedNextMap = currentMap outputChatBox("DEBUG: Next map: "..tostring( getMapName(g_ForcedNextMap) ) ) setTimer(function() nbVotes = 0 end, 150*1000, 1) playerVotes = 3 else outputChatBox("", root, 255, 0, 0, true) outputChatBox("#ff8800[REDO]: "..getPlayerName(player).." #ffffffvoted for redo! ["..nbVotes.."/3]", root, 255, 0, 0, true) end end) Be sure to put this script inside de race resource (in racevoting_server.lua for example) Tell me if it works, or if it's not, the errors and all the outputs in the chatbox (espacially the "DEBUG: Next map: " one). Link to comment
zzx Posted March 15, 2014 Author Share Posted March 15, 2014 When i write /vr it shows in the chat: [REDO]: You have already voted [REDO]: zeldak voted for redo! [1/3], I want to remove the [REDO]: You have already voted when i type it for the first time, and when i re-type /vr it says [REDO]: You have already voted twice. what should i do ? Link to comment
Moderators Citizen Posted March 15, 2014 Moderators Share Posted March 15, 2014 The code is correct but the problem is that its already existing somewhere else. Please remove the other one. Link to comment
zzx Posted March 16, 2014 Author Share Posted March 16, 2014 Thanks you, how can i set the votes as much as players in the server, example, 10 players in the server, then the goal of the votes to restart the map is 10, and like that. Link to comment
JR10 Posted March 16, 2014 Share Posted March 16, 2014 if nbVotes >= 4 then Change that line to: if nbVotes >= getPlayerCount() then Link to comment
Moderators Citizen Posted March 16, 2014 Moderators Share Posted March 16, 2014 example, 10 players in the server, then the goal of the votes to restart the map is 10 You can use the JR10 but I just wanted to say that most of the time, you won't get all the players to do the /vr because there is sometimes an afk, or the 1st player who doesn't want to restart because he is 1st. And even if you thought using it at the end of the map, there will be another guy who doesn't want to restart because he hates this map. So I would suggest half (1/2) or 2/3 of the player count. Also, use a variable to use it in the if statement of JR10 and in the outputs (I mean the "blabla ["..nbVotes.."/3]" ) local voteRequired = math.roof(getPlayerCount()/2) --for 1/2 -- or local voteRequired = math.roof(getPlayerCount()*2 / 3) --for 2/3 Link to comment
zzx Posted March 16, 2014 Author Share Posted March 16, 2014 Please give me the entire code. Link to comment
Moderators Citizen Posted March 17, 2014 Moderators Share Posted March 17, 2014 That's not gonna happen 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