Jump to content

Vote redo problem


zzx

Recommended Posts

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

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

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
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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...