capturetheflag/mods/ctf_match/vote.lua

61 lines
1.6 KiB
Lua
Raw Normal View History

2015-11-29 00:05:37 +00:00
ctf_match.registered_on_skip_map = {}
function ctf_match.register_on_skip_map(func)
if ctf._mt_loaded then
error("You can't register callbacks at game time!")
end
table.insert(ctf_match.registered_on_skip_map, func)
end
2015-12-01 18:18:29 +00:00
function ctf_match.vote_next(name, params)
if minetest.global_exists("irc") then
local tname = ctf.player(name).team or "none"
irc:say("Vote started by " .. name .. " (team " .. tname .. ")")
end
2016-01-02 16:10:52 +00:00
return vote.new_vote(name, {
2015-12-01 18:18:29 +00:00
description = "Skip to next match",
help = "/yes, /no or /abstain",
duration = 60,
perc_needed = 0.5,
unanimous = 5,
on_result = function(self, result, results)
if result == "yes" then
minetest.chat_send_all("Vote to skip match passed, " ..
#results.yes .. " to " .. #results.no)
for i = 1, #ctf_match.registered_on_skip_map do
ctf_match.registered_on_skip_map[i]()
end
ctf_match.next()
else
minetest.chat_send_all("Vote to skip match failed, " ..
#results.no .. " to " .. #results.yes)
end
end,
on_vote = function(self, voter, value)
minetest.chat_send_all(voter .. " voted " .. value .. " to '" ..
2015-12-01 18:18:29 +00:00
self.description .. "'")
end
})
end
minetest.register_chatcommand("vote", {
2015-07-17 17:10:17 +00:00
privs = {
2016-04-06 15:07:04 +00:00
interact = true,
vote_starter = true
2015-07-17 17:10:17 +00:00
},
2015-12-01 18:18:29 +00:00
func = ctf_match.vote_next
})
2015-07-17 17:10:17 +00:00
2015-12-01 18:18:29 +00:00
minetest.register_on_chat_message(function(name, msg)
2016-04-06 15:07:04 +00:00
if msg == "/vote_next" and minetest.check_player_privs(name,
{interact=true, vote_starter=true}) then
local _, vmsg = ctf_match.vote_next(name)
if vmsg then
minetest.chat_send_player(name, vmsg)
2016-01-02 16:10:52 +00:00
end
2015-12-01 18:18:29 +00:00
return true
2015-07-17 17:10:17 +00:00
end
2015-12-01 18:18:29 +00:00
end)