Post by Java on Nov 9, 2014 12:42:54 GMT 5.5
Hero is the Code
if BB==nil then BB={} end
BB.mapvote={}
function initArray(m)
local array = {}
for i = 1, m
do array[i]=0
end
return array
end
maps = {}
---------------WRITE YOUR MAPS DOWN HERE LIKE I DID ALREADY :D---------------
---------------Example: maps = {"de_dust","blau is cool","aim_shotgun"}
maps = {"de_dust","de_dust2","de_cs2d"}
---------------Settings---------------
voted=initArray(32)
count_down = 60
endsec = 30
votestarted = 0
voteend = 0
no = 0
yes = 0
locked=false
---------------Menus---------------
function selectmenu(id, page)
local page = page or 1
local pages = math.ceil(#maps / 6)
if page < 1 then page = pages end
if page > pages then page = 1 end
local m = 'Vote for map'.. page
for i = 6 * page - 5, 6 * page do
if maps[i] then m = m ..', '.. maps[i] else m = m ..',' end
end
if page == pages then m = m ..',,<<- First page' else m = m ..',,Next page -->' end
if page == 1 then m = m ..',Last page ->>' else m = m ..',<-- Previvius page' end
menu(id, m)
end
addhook("menu", "BB.mapvote.mapmenu")
function BB.mapvote.mapmenu(id, title, button)
local page = title:match('Vote for map([%d]+)')
if page ~= nil then
page = tonumber(page)
if locked == false then
if button == 8 then selectmenu(id, page + 1) end
if button == 9 then selectmenu(id, page - 1) end
if button <= 6 then
maptovote = (page - 1) * 6 + button
msg("©000255000"..player(id,"name").." called a vote to "..maps[maptovote].."")
msg("©255255255Press [F3] for YES, [F4] for NO!")
msg("©255000000"..player(id,"name").." voted YES!")
yes = yes+1
voted[id] = 1
parse('hudtxt 42 "©000255000"..player(id,"name").."Called a vote For: '..maps[maptovote]..'" 5 410')
votestarted = 1
locked=true
end
end
end
end
addhook("second","BB.mapvote.countdown")
function BB.mapvote.countdown()
if votestarted == 1 then
if count_down == 0 then
if yes > no then
voteend = 1
msg("©000255000The poll is ACCEPTED!")
parse("sv_sound The mapvote system/end9.ogg")
parse('hudtxt 42 "" 5 410')
parse('hudtxt 43 "" 200 410')
addhook("second","BB.mapvote.lastseconds")
end
if yes < no then
msg("©255000000The poll is REJECTED!")
parse("sv_sound The mapvote system/rj.ogg")
locked=false
parse('hudtxt 42 "" 5 410')
parse('hudtxt 43 "" 200 410')
end
votestarted = 0
count_down = 60
for all = 1,32 do
voted[all] = 0
end
no = 0
yes = 0
else
parse('hudtxt 43 "©255255255Time: '..count_down..' YES: '..yes..' NO: '..no..'" 5 423')
count_down=count_down-1
end
end
if voteend == 1 then
endsec = endsec-1
end
if endsec == -1 then
parse("map "..maps[maptovote].."")
endsec = 30
yes = 0
no = 0
count_down = 60
end
end
addhook("serveraction","BB.mapvote.votemenu")
function BB.mapvote.votemenu(id,action)
if action == 1 then
if locked == false then
selectmenu(id, 1)
end
end
end
function BB.mapvote.lastseconds()
for id=1,32 do
parse('hudtxt 2 "©000255000Mapchange to '..maps[maptovote]..' in '..endsec..' seconds" 5 425')
end
end
---------------Player votes---------------
addhook("serveraction","BB.mapvote.votechoose")
function BB.mapvote.votechoose(id,action)
if action == 2 then
if voted[id] == 0 then
if votestarted == 1 then
yes = yes+1
voted[id] = 1
msg("©255255255"..player(id,"name").." voted YES!")
parse("sv_sound2 "..id.." The mapvote system/voted.ogg")
end
else
msg2(id,"©255000000You can't vote now!")
end
elseif action == 3 then
if voted[id] == 0 then
if votestarted == 1 then
no = no+1
voted[id] = 1
msg("©255000000"..player(id,"name").." voted NO!")
parse("sv_sound2 "..id.." The mapvote system/voted.ogg")
end
else
msg2(id,"©255000000You can't vote now!")
end
end
end
addhook("join","BB.mapvote.join")
function BB.mapvote.join(id)
if votestarted == 1 then
voted[id] = 1
end
end