Spoiler function initArray(m)
local array = {}
for i = 1, m do
array[i]=0
end
return array
end
C=initArray(32)
B=initArray(32)
voted=initArray(32)
function string.split(text,b)
local cmd = {}
if b then
b = b
else
b = "%s"
end
b = "[^"..b.."]+"
for o in string.gmatch(text,b) do
table.insert(cmd,o)
end
return cmd
end
function voteshow()
for id = 1,32 do
if (player(id,"exists")) then
parse('hudtxt2 '..id..' 39 "©255255255Cool : '..C[id]..' Players " 30 135')
parse('hudtxt2 '..id..' 42 "©255255255Bored : '..B[id]..' Players " 30 150')
end
end
end
-----------------------
-- Serveraction --
-----------------------
addhook("serveraction","coolorbored")
function coolorbored(id,action)
if action == 3 then
votemenu(id)
end
end
-------------
-- Menu --
-------------
function votemenu(id)
menu(id,"Server rating, Cool server|"..C[id]..", Boring server|"..B[id].."")
end
----------------------
-- Menu Function --
----------------------
addhook("menu","voting")
function voting(id,title,button)
if title == "Server rating" then
if sel == 1 then
if (player(id,"usgn")>0) and voted[id]==0 then
C[id]=1
msg(id,"©000255000"..player(id,"name").." Voted this server to Cool")
voted[id]=1
elseif voted[id]==1 then
msg(id,"©255000000You already Voted this server!@C")
end
end
if sel == 2 then
if (player(id,"usgn")>0) and voted[id]==0 then
B[id]=1
msg(id,"©255000000"..player(id,"name").." Voted this server to Bored")
voted[id]=1
elseif voted[id]==1 then
msg2(id,"©255000000You already Voted this server!@C")
end
end
end
end
------------------------
-- Kill and spawn --
------------------------
addhook("spawn","vott")
function vott(id)
voteshow(id)
end
--------------------------
-- save/load vote --
--------------------------
addhook("leave","save_leave") -- When you leave it saves
function save_leave(id)
if (player(id,"usgn")>0) then
io.output(io.open("sys/lua/votetes/"..player(id,"usgn")..".txt","w+"))
io.write(C[id].." "..B[id].." "..voted[id])
io.close()
end
end
addhook("join","save_join") -- When join load
function save_join(id)
if (player(id,"usgn")>0) then
local filename = "sys/lua/votetes/%s.txt"
local file = io.open(filename:format(player(id,"usgn"), "r"))
local line
if not file then
line = {0, 1, 2}
else
line = file:read("*a"):split()
end
C[id] = tonumber(line[1]) or 0
B[id] = tonumber(line[2]) or 1
voted[id] = tonumber(line[3]) or 2
else
msg2(id,"©255000000No USGN found! Please check your USGN account at unrealsoftware.de!")
msg2(id,"©255000000If you not logged in, you can't Vote this server!")
voted[id]=1
end
end