Jump to content

Polls system


Recommended Posts

I'm trying to make a polls system with "/vote y" and "/vote n" commands when someone starts a poll with "/createpoll name" command, I'm not asking to make it but if anyone can guide me on how to do it..

I am amazed you have 1700 + posts here and you don't know how to make this.....

Create the function "createPoll" and make i return the poll element and start the timer. Use setElementData when people /vote, when time is up compare the 2 options "yes" and "no" to see which one has more vote

Link to comment

You are not forced to use it, you could just see how it works

btw i haven't tested it

local pollSystem = { 
    settings  = { 
              pollState = false -- Don't change it 
              pollTime = 1*(60*1000), -- in milliseconds - 1*(60*1000) = 1 minute 
                } 
    votes     = { 
              voted = {} 
              Yes = 0, 
              No = 0, 
               } 
} 
  
function startPoll(player,cmd,...) 
    if hasObjectPermissionTo(player,"command.kick") then 
        if pollSystem.settings.pollState == false then 
            local question = table.concat({...}," ") 
            pollSystem.settings.pollState = true 
            addCommandHandler("yes",vote) 
            addCommandHandler("no",vote) 
            outputChatBox(getPlayerName(player).."#FFFFFF Has started poll: "..question,root,255,255,255,true) 
            outputChatBox("Use /yes OR /no to vote",root,255,255,255,true) 
            setTimer(function() 
                pollSystem.settings.pollState = false 
                pollSystem.votes.voted = {} 
                removeEventHandler("yes",vote) 
                removeEventHandler("no",vote) 
                local result = (pollSystem.votes.Yes == pollSystem.votes.No and "Tie") or (pollSystem.votes.Yes > pollSystem.votes.No and "Yes") or  "No" 
                outputChatBox("The poll has been ended with "..result,root,255,255,255,true) 
            end,pollSystem.settings.pollTime,1) 
        else 
            outputChatBox("There's already poll running right now, try later",player,255,255,255,true) 
        end 
    end 
end 
  
function vote(player,cmd) 
    if pollSystem.settings.pollState == true then 
        if not pollSystem.votes.voted[getPlayerSerial(player)] then 
            if cmd == "yes" then 
                pollSystem.votes.Yes = pollSystem.votes.Yes+1 
            elseif cmd == "no" then 
                pollSystem.votes.No = pollSystem.votes.No+1 
            end 
            pollSystem.votes.voted[getPlayerSerial(player)] = true 
        end 
    end 
end 

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