From 5d933862ab422824673f35aff9783c3d486058b6 Mon Sep 17 00:00:00 2001 From: Vitaliy Olkhin Date: Mon, 5 Feb 2024 15:54:53 +0500 Subject: [PATCH] jail update --- init.lua | 85 ++++++++++++++++++++----------------------------------- nodes.lua | 35 +++++++++++++++++++++++ 2 files changed, 65 insertions(+), 55 deletions(-) create mode 100644 nodes.lua diff --git a/init.lua b/init.lua index 6c3eec0..8d145ea 100644 --- a/init.lua +++ b/init.lua @@ -1,36 +1,12 @@ local S = minetest.get_translator("jail") -local escape_boundary = 50 --радиус обхвата тюрмы -local display_node = { x = 675, y = 3.55, z = 5 } +jail = {} +jail.escape_boundary = 50 --радиус обхвата тюрмы +jail.display_node = { x = 675, y = 3.55, z = 5 } +local jailpos = { x = 690, y = 5, z = -7 } +local releasepos = { x = 684, y = 5, z = -7 } +local timer = 0 -local x = escape_boundary -minetest.register_node("jail:borders", { - tiles = {"jail_display.png"}, - use_texture_alpha = "clip", - walkable = false, - drawtype = "nodebox", - node_box = { - type = "fixed", - fixed = { - -- sides - {-(x+.55), -(x+.55), -(x+.55), -(x+.45), (x+.55), (x+.55)}, - {-(x+.55), -(x+.55), (x+.45), (x+.55), (x+.55), (x+.55)}, - {(x+.45), -(x+.55), -(x+.55), (x+.55), (x+.55), (x+.55)}, - {-(x+.55), -(x+.55), -(x+.55), (x+.55), (x+.55), -(x+.45)}, - -- top - {-(x+.55), (x+.45), -(x+.55), (x+.55), (x+.55), (x+.55)}, - -- bottom - {-(x+.55), -(x+.55), -(x+.55), (x+.55), -(x+.45), (x+.55)}, - -- middle (surround protector) - {-.55,-.55,-.55, .55,.55,.55} - } - }, - selection_box = { - type = "regular", - }, - paramtype = "light", - groups = {dig_immediate = 3, not_in_creative_inventory = 1}, - drop = "" -}) +dofile(minetest.get_modpath("jail") .. "/nodes.lua") minetest.register_privilege("jail", { description = S("Allows one to send/release prisoners") }) @@ -42,9 +18,6 @@ for line in prisoners:gmatch("[^\n]+") do table.insert(prisoners_list, line) end -jailpos = { x = 690, y = 5, z = -7 } -local releasepos = { x = 684, y = 5, z = -7 } - minetest.register_chatcommand("jail", { params = "", description = S("Sends a player to Jail"), @@ -65,7 +38,7 @@ minetest.register_chatcommand("jail", { "" .. param .. " " .. S("has been sent to jail by") .. " " .. name)) minetest.set_player_privs(param, { interact = true, - shout = true + shout = true, }) end end, @@ -162,33 +135,35 @@ minetest.register_on_shutdown(function() mod_storage:set_string("prisoners", prisoners) end) -local timer = 0 - minetest.register_globalstep(function(dtime) -- every 5 seconds if timer > os.time() then return end - - timer = os.time() + 10 - + timer = os.time() + 5 + for i = 1, #prisoners_list do local object = minetest.env:get_player_by_name(prisoners_list[i]) - if not object then - return - end - - local pos = object:get_pos() - local max_pos_x = display_node.x + escape_boundary - local min_pos_x = display_node.x - escape_boundary - local max_pos_y = display_node.y + escape_boundary - local min_pos_y = display_node.y - escape_boundary - local max_pos_z = display_node.z + escape_boundary - local min_pos_z = display_node.z - escape_boundary - - if (max_pos_x < pos.x or pos.x < min_pos_x) or max_pos_y < pos.y or pos.y < min_pos_y or max_pos_z < pos.z or pos.z < min_pos_z then - object:set_pos(jailpos) - minetest.chat_send_all(minetest.colorize("red", S("Escape attempt: ") .. prisoners_list[i])) + + if object then + local pos = object:get_pos() + + local max_pos_x = jail.display_node.x + jail.escape_boundary + local min_pos_x = jail.display_node.x - jail.escape_boundary + local max_pos_y = jail.display_node.y + jail.escape_boundary + local min_pos_y = jail.display_node.y - jail.escape_boundary + local max_pos_z = jail.display_node.z + jail.escape_boundary + local min_pos_z = jail.display_node.z - jail.escape_boundary + + if (max_pos_x < pos.x or pos.x < min_pos_x) or max_pos_y < pos.y or pos.y < min_pos_y or max_pos_z < pos.z or pos.z < min_pos_z then + object:set_pos(jailpos) + + minetest.set_player_privs(prisoners_list[i], { + interact = true, + shout = true, + }) + minetest.chat_send_all(minetest.colorize("red", S("Escape attempt: ") .. prisoners_list[i])) + end end end end) diff --git a/nodes.lua b/nodes.lua new file mode 100644 index 0000000..e46df5d --- /dev/null +++ b/nodes.lua @@ -0,0 +1,35 @@ +--- +--- Generated by EmmyLua(https://github.com/EmmyLua) +--- Created by vinamin. +--- DateTime: 05.02.2024 12:12 +--- +local x = jail.escape_boundary + +minetest.register_node("jail:borders", { + tiles = {"jail_display.png"}, + use_texture_alpha = "clip", + walkable = false, + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = { + -- sides + {-(x+.55), -(x+.55), -(x+.55), -(x+.45), (x+.55), (x+.55)}, + {-(x+.55), -(x+.55), (x+.45), (x+.55), (x+.55), (x+.55)}, + {(x+.45), -(x+.55), -(x+.55), (x+.55), (x+.55), (x+.55)}, + {-(x+.55), -(x+.55), -(x+.55), (x+.55), (x+.55), -(x+.45)}, + -- top + {-(x+.55), (x+.45), -(x+.55), (x+.55), (x+.55), (x+.55)}, + -- bottom + {-(x+.55), -(x+.55), -(x+.55), (x+.55), -(x+.45), (x+.55)}, + -- middle (surround protector) + {-.55,-.55,-.55, .55,.55,.55} + } + }, + selection_box = { + type = "regular", + }, + paramtype = "light", + groups = {dig_immediate = 3, not_in_creative_inventory = 1}, + drop = "" +}) \ No newline at end of file