TheBridge/setup.lua

58 lines
1.7 KiB
Lua
Raw Normal View History

2022-10-03 12:30:47 +02:00
local S = minetest.get_translator("the_bridge")
local function send_message(arena,num_str)
arena_lib.HUD_send_msg_all("title", arena, num_str, 1,nil,0xFF0000)
--arena_lib.HUD_send_msg_all(HUD_type, arena, msg, <duration>, <sound>, <color>)
end
function savemap(pos_min,pos_max,arena)
local manip = VoxelManip(pos_min,pos_max)
local emin, emax = manip:read_from_map(pos_min, pos_max)
local data = manip:get_data()
arena.mapdata = data
local a = VoxelArea:new{
MinEdge = emin,
MaxEdge = emax
}
for x = emin.x,emax.x do
for y = emin.y,emax.y do
for z = emin.z, emax.z do
local idx = a:index(x, y, z)
arena.mapdata[idx]=data[idx]
end
end
end
end
function restore_map(arena)
local manip = VoxelManip(arena.the_bridge_area_pos_1,arena.the_bridge_area_pos_2)
manip:set_data(arena.mapdata)
manip:write_to_map(true)
end
arena_lib.on_load("the_bridge", function(arena)
savemap(arena.the_bridge_area_pos_1,arena.the_bridge_area_pos_2,arena)--backup map
if not arena.teams_enabled then
send_message(arena,"cancelled!")
arena_lib.force_arena_ending("the_bridge", arena)
minetest.log("warning","The Bridge is not supposed to run without any teams!")
end --this game is not supposed to be used without teams!
send_message(arena,S("GO!"))
end)
arena_lib.on_enable("the_bridge", function(arena, p_name)
savemap(arena.the_bridge_area_pos_1,arena.the_bridge_area_pos_2,arena)
return true
end)
arena_lib.on_end("the_bridge", function(arena, players, winners, spectators, is_forced)
restore_map(arena)
end)
arena_lib.on_disable("the_bridge", function(arena, p_name)
restore_map(arena)
return true
end)