Add chatcommand to update lobbies, slightly better lobbies.
This commit is contained in:
parent
d5585d20b8
commit
503db23766
Binary file not shown.
Binary file not shown.
@ -641,6 +641,9 @@ function boxes.end_box(player)
|
|||||||
players_in_boxes[name] = nil
|
players_in_boxes[name] = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
minetest.register_on_leaveplayer(function(player)
|
||||||
|
boxes.end_box(player)
|
||||||
|
end)
|
||||||
|
|
||||||
minetest.register_chatcommand("enter", {
|
minetest.register_chatcommand("enter", {
|
||||||
params = "<boxid>",
|
params = "<boxid>",
|
||||||
@ -670,6 +673,83 @@ minetest.register_chatcommand("leave", {
|
|||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
local lobby_updates = {}
|
||||||
|
minetest.register_chatcommand("update_lobby", {
|
||||||
|
params = "entry|exit",
|
||||||
|
description = "Set corresponding lobby. Use without parameter to start updating a lobby",
|
||||||
|
privs = {server = true},
|
||||||
|
func = function(name, param)
|
||||||
|
if param ~= "entry" and param ~= "exit" and param ~= "" then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if param == "" then
|
||||||
|
lobby_updates[name] = {}
|
||||||
|
else
|
||||||
|
local pos1 = lobby_updates[name].pos1
|
||||||
|
local pos2 = lobby_updates[name].pos2
|
||||||
|
local pos3 = lobby_updates[name].pos3
|
||||||
|
if not pos1 or not pos2 or not pos3 then
|
||||||
|
minetest.chat_send_player(name, "Not all positions have been set.")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local minp = vector.min(pos1, pos2)
|
||||||
|
local maxp = vector.max(pos1, pos2)
|
||||||
|
local data = boxes.save(minp, maxp)
|
||||||
|
local p3 = vector.subtract(pos3, minp)
|
||||||
|
if param == "exit" then
|
||||||
|
if p3.x < 0 or p3.y < 0 or p3.z < 0 then
|
||||||
|
minetest.chat_send_player(name, "The entry is not inside the lobby.")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
exit_lobby_data = boxes.write_box({
|
||||||
|
size = boxes.extent(data),
|
||||||
|
entry = p3,
|
||||||
|
exit = p3,
|
||||||
|
data = data,
|
||||||
|
})
|
||||||
|
write_file(worldpath .. "/exit.box", exit_lobby_data)
|
||||||
|
else
|
||||||
|
local player = minetest.get_player_by_name(name)
|
||||||
|
local entry = vector.subtract(vector.round(player:get_pos()), minp)
|
||||||
|
p3.x = p3.x + 1
|
||||||
|
if entry.x < 0 or entry.y < 0 or entry.z < 0 then
|
||||||
|
minetest.chat_send_player(name, "You're not standing inside the lobby.")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if p3.x < 0 or p3.y < 0 or p3.z < 0 then
|
||||||
|
minetest.chat_send_player(name, "The exit is not inside the lobby.")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
entry_lobby_data = boxes.write_box({
|
||||||
|
size = boxes.extent(data),
|
||||||
|
entry = entry,
|
||||||
|
exit = p3,
|
||||||
|
data = data,
|
||||||
|
})
|
||||||
|
write_file(worldpath .. "/entry.box", entry_lobby_data)
|
||||||
|
end
|
||||||
|
minetest.chat_send_player(name, "Updated.")
|
||||||
|
lobby_updates[name] = nil
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
minetest.register_on_punchnode(function(pos, node, puncher, pointed_thing)
|
||||||
|
if not puncher then return end
|
||||||
|
local name = puncher:get_player_name()
|
||||||
|
if not lobby_updates[name] then return end
|
||||||
|
if not lobby_updates[name].pos1 then
|
||||||
|
lobby_updates[name].pos1 = pos
|
||||||
|
minetest.chat_send_player(name, "Position 1 set to " .. dump(pos) .. ".")
|
||||||
|
elseif not lobby_updates[name].pos2 then
|
||||||
|
lobby_updates[name].pos2 = pos
|
||||||
|
minetest.chat_send_player(name, "Position 2 set to " .. dump(pos) .. ".")
|
||||||
|
elseif not lobby_updates[name].pos3 then
|
||||||
|
lobby_updates[name].pos3 = pos
|
||||||
|
minetest.chat_send_player(name, "Position 3 set to " .. dump(pos) .. ".")
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
-- old test code
|
-- old test code
|
||||||
--[[
|
--[[
|
||||||
|
Loading…
x
Reference in New Issue
Block a user