CreateChat "!voterestart" "" (15) [[
	msgc(player(id,"name").." made a poll for restart round", 0, 255, 0)
	CreateRestartPoll()
]]

restart_vote_yes = 0
restart_vote_no = 0
restart_delay = 15
restart_time = 0
restart_poll = false

restart_hud = GenerateHud()
restart_vote_hud = GenerateHud()

function CreateRestartPoll()
	restart_poll = true
	restart_vote_yes = 0
	restart_vote_no = 0
	restart_time = 0
	restart_vote_menu:OpenPlayer(0, 1)
end

restart_vote_menu = CreateMenu("Restart round?", "Yes,No")
function restart_vote_menu:click(id,b,p)
	if not USERTEMP[id]["vote"] then
		if b == 1 then
			msg(player(id,"name").." votes yes")
			USERTEMP[id]["vote"] = true
			
			restart_vote_yes = restart_vote_yes + 1
		elseif b == 2 then
			msg(player(id,"name").." votes no")
			USERTEMP[id]["vote"] = true
			
			restart_vote_no = restart_vote_no + 1
		end
	else
		ErrorMSG(id, "You already voted")
	end
end

addhook("second","RestartvoteSec")
function RestartvoteSec()
	if restart_time <= restart_delay and restart_poll then
		restart_time = restart_time + 1
		if restart_time > restart_delay then
			-- Check votes
			if restart_vote_yes > restart_vote_no then
				parse("sv_restart")
			end
			msg(restart_vote_yes.." voted yes; "..restart_vote_no.." voted no")
			
			for _, id in pairs(player(0,"table")) do
				USERTEMP[id]["vote"] = nil
			end
			
			Freehud(0, restart_hud)
			Freehud(0, restart_vote_hud)
			
			restart_poll = false
		else
			Hudtxt(restart_hud, "Vote count down: "..restart_time.."/"..restart_delay, 15, 115, 0, 255, 255, 255)
			Hudtxt(restart_vote_hud, "Yes: "..restart_vote_yes.." No: "..restart_vote_no, 15, 130)
		end		
	end
end