Reorganise game into modpacks
This commit is contained in:
parent
86a5266bb5
commit
b38a89c2fe
762 changed files with 9 additions and 8 deletions
111
mods/ctf/ctf_match/buildtime.lua
Normal file
111
mods/ctf/ctf_match/buildtime.lua
Normal file
|
@ -0,0 +1,111 @@
|
|||
ctf.register_on_init(function()
|
||||
ctf._set("match.build_time", 60)
|
||||
end)
|
||||
|
||||
ctf_match.registered_on_build_time_start = {}
|
||||
function ctf_match.register_on_build_time_start(func)
|
||||
if ctf._mt_loaded then
|
||||
error("You can't register callbacks at game time!")
|
||||
end
|
||||
table.insert(ctf_match.registered_on_build_time_start, func)
|
||||
end
|
||||
|
||||
ctf_match.registered_on_build_time_end = {}
|
||||
function ctf_match.register_on_build_time_end(func)
|
||||
if ctf._mt_loaded then
|
||||
error("You can't register callbacks at game time!")
|
||||
end
|
||||
table.insert(ctf_match.registered_on_build_time_end, func)
|
||||
end
|
||||
|
||||
ctf_match.build_timer = 0
|
||||
|
||||
function ctf_match.is_in_build_time()
|
||||
return ctf_match.build_timer > 0
|
||||
end
|
||||
|
||||
ctf_match.register_on_new_match(function()
|
||||
ctf_match.build_timer = ctf.setting("match.build_time")
|
||||
end)
|
||||
ctf.register_on_new_game(function()
|
||||
ctf_match.build_timer = ctf.setting("match.build_time")
|
||||
if ctf_match.build_timer > 0 then
|
||||
for i = 1, #ctf_match.registered_on_build_time_start do
|
||||
ctf_match.registered_on_build_time_start[i]()
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
local function get_m_s_from_s(s)
|
||||
local m = math.floor(s / 60)
|
||||
s = math.floor(s - m * 60)
|
||||
|
||||
return m .. "m " .. s .. "s"
|
||||
end
|
||||
|
||||
local last = 0
|
||||
minetest.register_globalstep(function(delta)
|
||||
if ctf_match.build_timer > 0 then
|
||||
ctf_match.build_timer = ctf_match.build_timer - delta
|
||||
if ctf_match.build_timer <= 0 then
|
||||
for i = 1, #ctf_match.registered_on_build_time_end do
|
||||
ctf_match.registered_on_build_time_end[i]()
|
||||
end
|
||||
end
|
||||
local rbt = math.floor(ctf_match.build_timer)
|
||||
if last ~= rbt then
|
||||
local text = get_m_s_from_s(ctf_match.build_timer) .. " until match begins!"
|
||||
for _, player in pairs(minetest.get_connected_players()) do
|
||||
ctf.hud:change(player, "ctf_match:countdown", "text", text)
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
minetest.register_on_punchplayer(function(_, hitter)
|
||||
if ctf_match.is_in_build_time() then
|
||||
minetest.chat_send_player(hitter:get_player_name(), "Match hasn't started yet!")
|
||||
return true
|
||||
end
|
||||
end)
|
||||
|
||||
ctf_match.register_on_build_time_start(function()
|
||||
minetest.chat_send_all("Prepare your base! Match starts in " ..
|
||||
ctf.setting("match.build_time") .. " seconds.")
|
||||
end)
|
||||
|
||||
ctf_match.register_on_build_time_end(function()
|
||||
if minetest.global_exists("chatplus") then
|
||||
chatplus.log("Build time over!")
|
||||
end
|
||||
minetest.chat_send_all("Build time over! Attack and defend!")
|
||||
for _, player in pairs(minetest.get_connected_players()) do
|
||||
ctf.hud:remove(player, "ctf_match:countdown")
|
||||
end
|
||||
end)
|
||||
|
||||
ctf_flag.register_on_prepick_up(function(name, flag)
|
||||
if ctf_match.is_in_build_time() then
|
||||
minetest.chat_send_player(name, "Match hasn't started yet!")
|
||||
ctf.move_to_spawn(name)
|
||||
return false
|
||||
else
|
||||
return true
|
||||
end
|
||||
end)
|
||||
|
||||
ctf.hud.register_part(function(player, name, tplayer)
|
||||
if ctf_match.build_timer <= 0 then
|
||||
ctf.hud:remove(player, "ctf_match:countdown")
|
||||
elseif not ctf.hud:exists(player, "ctf_match:countdown") then
|
||||
ctf.hud:add(player, "ctf_match:countdown", {
|
||||
hud_elem_type = "text",
|
||||
position = {x = 0.5, y = 0.5},
|
||||
scale = {x = 0, y = 70},
|
||||
text = get_m_s_from_s(ctf_match.build_timer) .. " until match begins!",
|
||||
number = 0xFFFFFF,
|
||||
offset = {x = -20, y = 20},
|
||||
alignment = {x = 0.2, y = 0}
|
||||
})
|
||||
end
|
||||
end)
|
81
mods/ctf/ctf_match/chat.lua
Normal file
81
mods/ctf/ctf_match/chat.lua
Normal file
|
@ -0,0 +1,81 @@
|
|||
minetest.register_privilege("ctf_match", {
|
||||
description = "can skip matches"
|
||||
})
|
||||
|
||||
minetest.register_chatcommand("ctf_next", {
|
||||
description = "Skip to the next match",
|
||||
privs = {
|
||||
ctf_match = true
|
||||
},
|
||||
func = function(name, param)
|
||||
ctf_match.next()
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_chatcommand("ctf_start", {
|
||||
description = "End build time",
|
||||
privs = {
|
||||
ctf_match = true
|
||||
},
|
||||
func = function(name, param)
|
||||
ctf_match.build_timer = 0.01
|
||||
end
|
||||
})
|
||||
|
||||
|
||||
minetest.register_chatcommand("ctf_respawn", {
|
||||
description = "Respawn a player (clean inv, send to base)",
|
||||
privs = {
|
||||
ctf_team_mgr = true
|
||||
},
|
||||
func = function(name, param)
|
||||
minetest.log("action", name .. " ran /ctf_respawn " .. param)
|
||||
local tplayer = ctf.player_or_nil(param)
|
||||
if tplayer then
|
||||
local player = minetest.get_player_by_name(param)
|
||||
if player then
|
||||
ctf.move_to_spawn(param)
|
||||
give_initial_stuff(player)
|
||||
minetest.chat_send_player(param,
|
||||
"You were sent back to base and your inventory wiped (by " .. name .. ")")
|
||||
return true, "Moved player to spawn and wiped inventory."
|
||||
else
|
||||
return false, "Player is not online."
|
||||
end
|
||||
else
|
||||
return false, "Player does not exist or is not in any teams."
|
||||
end
|
||||
end
|
||||
})
|
||||
|
||||
local restart_on_next_match = false
|
||||
local restart_on_next_match_by = nil
|
||||
minetest.register_chatcommand("ctf_queue_restart", {
|
||||
description = "Queue server restart",
|
||||
privs = {
|
||||
server = true
|
||||
},
|
||||
func = function(name, param)
|
||||
restart_on_next_match = true
|
||||
restart_on_next_match_by = name
|
||||
return true, "Restart queued."
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_chatcommand("ctf_unqueue_restart", {
|
||||
description = "Unqueue server restart",
|
||||
privs = {
|
||||
server = true
|
||||
},
|
||||
func = function(name, param)
|
||||
restart_on_next_match = false
|
||||
return true, "Restart cancelled."
|
||||
end
|
||||
})
|
||||
|
||||
ctf_match.register_on_new_match(function()
|
||||
if restart_on_next_match then
|
||||
minetest.chat_send_player(restart_on_next_match_by, "Shutting down now!")
|
||||
minetest.request_shutdown("Restarting server at operator request.", true)
|
||||
end
|
||||
end)
|
7
mods/ctf/ctf_match/depends.txt
Normal file
7
mods/ctf/ctf_match/depends.txt
Normal file
|
@ -0,0 +1,7 @@
|
|||
ctf
|
||||
ctf_flag
|
||||
ctf_inventory
|
||||
ctf_alloc
|
||||
vote
|
||||
hudkit
|
||||
irc?
|
42
mods/ctf/ctf_match/init.lua
Normal file
42
mods/ctf/ctf_match/init.lua
Normal file
|
@ -0,0 +1,42 @@
|
|||
ctf_match = {}
|
||||
|
||||
local claimed = ctf_flag.collect_claimed()
|
||||
for i, flag in pairs(claimed) do
|
||||
flag.claimed = nil
|
||||
end
|
||||
|
||||
dofile(minetest.get_modpath("ctf_match") .. "/matches.lua")
|
||||
dofile(minetest.get_modpath("ctf_match") .. "/buildtime.lua")
|
||||
dofile(minetest.get_modpath("ctf_match") .. "/chat.lua")
|
||||
dofile(minetest.get_modpath("ctf_match") .. "/vote.lua")
|
||||
|
||||
ctf.register_on_init(function()
|
||||
ctf._set("match.remove_player_on_leave", false)
|
||||
minetest.settings:set_bool("enable_pvp", true)
|
||||
end)
|
||||
|
||||
ctf_match.register_on_build_time_end(function()
|
||||
minetest.sound_play({name="ctf_match_attack"}, { gain = 1.0 })
|
||||
end)
|
||||
|
||||
minetest.register_on_leaveplayer(function(player)
|
||||
if ctf.setting("match.remove_player_on_leave") then
|
||||
ctf.remove_player(player:get_player_name())
|
||||
end
|
||||
end)
|
||||
|
||||
if minetest.global_exists("irc") then
|
||||
ctf_match.register_on_winner(function(winner)
|
||||
if not irc.connected then return end
|
||||
irc:say("Team " .. winner .. " won!")
|
||||
end)
|
||||
|
||||
ctf.register_on_new_game(function()
|
||||
if not irc.connected then return end
|
||||
irc:say("Next round!")
|
||||
end)
|
||||
end
|
||||
|
||||
minetest.after(5, function()
|
||||
ctf_match.next()
|
||||
end)
|
98
mods/ctf/ctf_match/matches.lua
Normal file
98
mods/ctf/ctf_match/matches.lua
Normal file
|
@ -0,0 +1,98 @@
|
|||
ctf.register_on_init(function()
|
||||
ctf._set("match", false)
|
||||
ctf._set("match.destroy_team", false)
|
||||
ctf._set("match.break_alliances", true)
|
||||
ctf._set("match.teams", 2)
|
||||
ctf._set("match.team.1", "red")
|
||||
ctf._set("match.team.1.color", "red")
|
||||
ctf._set("match.team.1.pos", "7,65,93")
|
||||
ctf._set("match.team.2", "blue")
|
||||
ctf._set("match.team.2.color", "blue")
|
||||
ctf._set("match.team.2.pos", "-22,66,-78")
|
||||
ctf._set("match.clear_inv", false)
|
||||
end)
|
||||
|
||||
ctf_match.registered_on_new_match = {}
|
||||
function ctf_match.register_on_new_match(func)
|
||||
if ctf._mt_loaded then
|
||||
error("You can't register callbacks at game time!")
|
||||
end
|
||||
table.insert(ctf_match.registered_on_new_match, func)
|
||||
end
|
||||
|
||||
ctf_match.registered_on_winner = {}
|
||||
function ctf_match.register_on_winner(func)
|
||||
if ctf._mt_loaded then
|
||||
error("You can't register callbacks at game time!")
|
||||
end
|
||||
table.insert(ctf_match.registered_on_winner, func)
|
||||
end
|
||||
|
||||
|
||||
-- Load next match. May be overrided
|
||||
function ctf_match.next()
|
||||
for i = 1, #ctf_match.registered_on_new_match do
|
||||
ctf_match.registered_on_new_match[i]()
|
||||
end
|
||||
|
||||
ctf.reset()
|
||||
|
||||
ctf_match.create_teams()
|
||||
|
||||
ctf_alloc.set_all()
|
||||
|
||||
minetest.set_timeofday(0.4)
|
||||
|
||||
minetest.chat_send_all("Next round!")
|
||||
if minetest.global_exists("chatplus") then
|
||||
chatplus.log("Next round!")
|
||||
end
|
||||
end
|
||||
|
||||
-- Check for winner
|
||||
local game_won = false
|
||||
function ctf_match.check_for_winner()
|
||||
local winner
|
||||
for name, team in pairs(ctf.teams) do
|
||||
if winner then
|
||||
return
|
||||
end
|
||||
winner = name
|
||||
end
|
||||
|
||||
-- There is a winner!
|
||||
if not game_won then
|
||||
game_won = true
|
||||
ctf.action("match", winner .. " won!")
|
||||
minetest.chat_send_all("Team " .. winner .. " won!")
|
||||
for i = 1, #ctf_match.registered_on_winner do
|
||||
ctf_match.registered_on_winner[i](winner)
|
||||
end
|
||||
minetest.after(2, function()
|
||||
game_won = false
|
||||
if ctf.setting("match") then
|
||||
ctf_match.next()
|
||||
end
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
-- This is overriden by ctf_map
|
||||
function ctf_match.create_teams()
|
||||
error("Error! Unimplemented")
|
||||
end
|
||||
|
||||
ctf_flag.register_on_capture(function(attname, flag)
|
||||
if not ctf.setting("match.destroy_team") then
|
||||
return
|
||||
end
|
||||
|
||||
local fl_team = ctf.team(flag.team)
|
||||
if fl_team and #fl_team.flags == 0 then
|
||||
ctf.action("match", flag.team .. " was defeated.")
|
||||
ctf.remove_team(flag.team)
|
||||
minetest.chat_send_all(flag.team .. " has been defeated!")
|
||||
end
|
||||
|
||||
ctf_match.check_for_winner()
|
||||
end)
|
BIN
mods/ctf/ctf_match/sounds/ctf_match_attack.ogg
Normal file
BIN
mods/ctf/ctf_match/sounds/ctf_match_attack.ogg
Normal file
Binary file not shown.
62
mods/ctf/ctf_match/vote.lua
Normal file
62
mods/ctf/ctf_match/vote.lua
Normal file
|
@ -0,0 +1,62 @@
|
|||
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
|
||||
|
||||
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
|
||||
|
||||
return vote.new_vote(name, {
|
||||
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 '" ..
|
||||
self.description .. "'")
|
||||
end
|
||||
})
|
||||
end
|
||||
|
||||
ctf_match.register_on_new_match(vote.clear_vote)
|
||||
|
||||
minetest.register_chatcommand("vote", {
|
||||
privs = {
|
||||
interact = true,
|
||||
vote_starter = true
|
||||
},
|
||||
func = ctf_match.vote_next
|
||||
})
|
||||
|
||||
minetest.register_on_chat_message(function(name, msg)
|
||||
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)
|
||||
end
|
||||
return true
|
||||
end
|
||||
end)
|
Loading…
Add table
Add a link
Reference in a new issue