Add prematch build time

This commit is contained in:
rubenwardy 2015-11-28 00:56:10 +00:00
parent fcd1f108e2
commit 9bbdc41967
9 changed files with 177 additions and 14 deletions

View file

@ -158,7 +158,7 @@ function chatplus.send(from, msg)
for i=1, #chatplus._handlers do for i=1, #chatplus._handlers do
if chatplus._handlers[i] then if chatplus._handlers[i] then
res = chatplus._handlers[i](from,key,msg) res = chatplus._handlers[i](from,key,msg)
if res ~= nil then if res ~= nil then
break break
end end

View file

@ -7,21 +7,45 @@ minetest.register_node("ctf_barrier:ind_glass", {
sunlight_propagates = true, sunlight_propagates = true,
is_ground_content = false, is_ground_content = false,
walkable = true, walkable = true,
buildable_to = false,
pointable = false,
groups = {immortal = 1}, groups = {immortal = 1},
sounds = default.node_sound_glass_defaults() sounds = default.node_sound_glass_defaults()
}) })
minetest.register_node("ctf_barrier:ind_glass_red", {
description = "You cheater you!",
drawtype = "glasslike",
tiles = {"ctf_barrier_red.png"},
inventory_image = minetest.inventorycube("default_glass.png"),
paramtype = "light",
sunlight_propagates = true,
is_ground_content = false,
walkable = true,
buildable_to = false,
use_texture_alpha = false,
alpha = 0,
pointable = false,
groups = {immortal = 1},
sounds = default.node_sound_glass_defaults()
})
local lim = ctf.setting("match.map_reset_limit") local lim = ctf.setting("match.map_reset_limit")
local c_glass = minetest.get_content_id("ctf_barrier:ind_glass") local c_glass = minetest.get_content_id("ctf_barrier:ind_glass")
local c_glass_red = minetest.get_content_id("ctf_barrier:ind_glass_red")
local c_water = minetest.get_content_id("default:water_source")
local c_water_f = minetest.get_content_id("default:water_flowing")
local c_stone = minetest.get_content_id("ctf_flag:ind_base") local c_stone = minetest.get_content_id("ctf_flag:ind_base")
local c_air = minetest.get_content_id("air") local c_air = minetest.get_content_id("air")
local r = tonumber(minetest.setting_get("barrier")) local r = tonumber(minetest.setting_get("barrier"))
minetest.register_on_generated(function(minp, maxp, seed) minetest.register_on_generated(function(minp, maxp, seed)
if not ((minp.x < -r and maxp.x > -r) if not ((minp.x <= -r and maxp.x >= -r)
or (minp.x < r and maxp.x > r) or (minp.x <= r and maxp.x >= r)
or (minp.y < -r and maxp.x > -r) or (minp.y <= -r and maxp.x >= -r)
or (minp.y < r and maxp.x > r) or (minp.y <= r and maxp.x >= r)
or (minp.z < -r and maxp.z > -r) or (minp.z <= -r and maxp.z >= -r)
or (minp.z < r and maxp.z > r)) then or (minp.z <= 0 and maxp.z >= 0)
or (minp.z <= r and maxp.z >= r and ctf_match.build_timer > 0)) then
return return
end end
@ -33,10 +57,9 @@ minetest.register_on_generated(function(minp, maxp, seed)
MaxEdge={x=emax.x, y=emax.y, z=emax.z}, MaxEdge={x=emax.x, y=emax.y, z=emax.z},
} }
local data = vm:get_data() local data = vm:get_data()
local dist = 3
-- Left -- Left
if minp.x < -r and maxp.x > -r then if minp.x <= -r and maxp.x >= -r then
local x = -r local x = -r
for z = minp.z, maxp.z do for z = minp.z, maxp.z do
for y = minp.y, maxp.y do for y = minp.y, maxp.y do
@ -52,7 +75,7 @@ minetest.register_on_generated(function(minp, maxp, seed)
end end
-- Right -- Right
if minp.x < r and maxp.x > r then if minp.x <= r and maxp.x >= r then
local x = r local x = r
for z = minp.z, maxp.z do for z = minp.z, maxp.z do
for y = minp.y, maxp.y do for y = minp.y, maxp.y do
@ -67,7 +90,7 @@ minetest.register_on_generated(function(minp, maxp, seed)
end end
-- Front -- Front
if minp.z < -r and maxp.z > -r then if minp.z <= -r and maxp.z >= -r then
local z = -r local z = -r
for x = minp.x, maxp.x do for x = minp.x, maxp.x do
for y = minp.y, maxp.y do for y = minp.y, maxp.y do
@ -82,7 +105,7 @@ minetest.register_on_generated(function(minp, maxp, seed)
end end
-- Back -- Back
if minp.z < r and maxp.z > r then if minp.z <= r and maxp.z >= r then
local z = r local z = r
for x = minp.x, maxp.x do for x = minp.x, maxp.x do
for y = minp.y, maxp.y do for y = minp.y, maxp.y do
@ -96,6 +119,73 @@ minetest.register_on_generated(function(minp, maxp, seed)
end end
end end
-- Barrier
if minp.z <= 0 and maxp.z >= 0 and ctf_match.build_timer > 0 then
local z = 0
local x1 = minp.x
if x1 < -r then x1 = -r end
local x2 = maxp.x
if x2 > r then x2 = r end
for x = x1, x2 do
for y = minp.y, maxp.y do
local vi = a:index(x, y, z)
local node = data[vi]
if node == c_air or node == c_glass_red or
node == c_water or node == c_water_f then
data[vi] = c_glass_red
end
end
end
end
vm:set_data(data) vm:set_data(data)
vm:write_to_map(data) vm:write_to_map(data)
end) end)
ctf_match.register_on_build_time_end(function()
local min = {
x = -r + 1,
y = -r,
z = -1
}
local max = {
x = r - 1,
y = r,
z = 1
}
local vm = minetest.get_voxel_manip()
local emin, emax = vm:read_from_map(min, max)
local a = VoxelArea:new{
MinEdge = emin,
MaxEdge = emax
}
local data = vm:get_data()
for x = min.x, max.x do
for y = min.y, max.y do
local vi = a:index(x, y, 0)
if data[vi] == c_glass_red then
data[vi] = c_air
end
end
end
print(n .. " invalid nodes out of " .. t .. " (" .. (t-n) .. " valid)")
vm:set_data(data)
vm:write_to_map(data)
vm:update_map()
end)
--[[minetest.register_abm({
nodenames = {"ctf_barrier:ind_glass_red"},
interval = 10.0, -- Run every 10 seconds
chance = 2, -- Select every 1 in 50 nodes
action = function(pos, node, active_object_count, active_object_count_wider)
if ctf_match.build_timer > 0 then
return
end
minetest.set_node(pos, {name = "air"})
end
})]]

Binary file not shown.

After

Width:  |  Height:  |  Size: 179 B

View file

@ -0,0 +1,56 @@
ctf.register_on_init(function()
ctf._set("match.build_time", 10)
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.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)
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
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.")
minetest.setting_set("enable_pvp", "false")
end)
ctf_match.register_on_build_time_end(function()
minetest.chat_send_all("Build time over! Attack and defend!")
minetest.setting_set("enable_pvp", "true")
end)

View file

@ -6,6 +6,7 @@ for i, flag in pairs(claimed) do
end end
dofile(minetest.get_modpath("ctf_match") .. "/matches.lua") dofile(minetest.get_modpath("ctf_match") .. "/matches.lua")
dofile(minetest.get_modpath("ctf_match") .. "/buildtime.lua")
dofile(minetest.get_modpath("ctf_match") .. "/reset.lua") dofile(minetest.get_modpath("ctf_match") .. "/reset.lua")
dofile(minetest.get_modpath("ctf_match") .. "/chat.lua") dofile(minetest.get_modpath("ctf_match") .. "/chat.lua")
dofile(minetest.get_modpath("ctf_match") .. "/vote.lua") dofile(minetest.get_modpath("ctf_match") .. "/vote.lua")

View file

@ -6,8 +6,21 @@ ctf.register_on_init(function()
ctf._set("match.clear_inv", false) ctf._set("match.clear_inv", false)
end) 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
-- Load next match. May be overrided -- Load next match. May be overrided
function ctf_match.next() 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.reset()
-- Note: ctf.reset calls register_on_new_game, below. -- Note: ctf.reset calls register_on_new_game, below.
end end

@ -1 +1 @@
Subproject commit b16d5c3b6589a88e04e4a0b914873638e489285c Subproject commit e672344383aeb9bea2a5b21f79ad66219db03116

View file

@ -157,6 +157,9 @@ minetest.register_on_generated(function(minp, maxp, seed)
if ground~=nil then if ground~=nil then
local chest_pos = {x=pos.x,y=ground+1, z=pos.z} local chest_pos = {x=pos.x,y=ground+1, z=pos.z}
if chest_pos.z == 0 then
chest_pos.z = -1
end
local nn = minetest.get_node(chest_pos).name -- chest node name (before it becomes a chest) local nn = minetest.get_node(chest_pos).name -- chest node name (before it becomes a chest)
if nn == "air" or nn == "default:water_source" then if nn == "air" or nn == "default:water_source" then
-->>>> chest spawning starts here <<<<-- -->>>> chest spawning starts here <<<<--

View file

@ -29,7 +29,7 @@
"match.break_alliances" true "match.break_alliances" true
"match.clear_inv" true "match.clear_inv" true
"match.destroy_team" true "match.destroy_team" true
"match.map_reset_limit" 60 "match.map_reset_limit" 200
"match.remove_player_on_leave" true "match.remove_player_on_leave" true
"match.teams" "red, red, 15, 7, 39; blue, blue, -9, 9, -43" "match.teams" "red, red, 15, 7, 39; blue, blue, -9, 9, -43"
"maximum_in_team" -1 "maximum_in_team" -1

Can't render this file because it contains an unexpected character in line 1 and column 15.