From 219b6ff5524542b851e0fde9e6ea6ac6b6bc8861 Mon Sep 17 00:00:00 2001 From: Vitaliy Olkhin Date: Mon, 26 Feb 2024 16:48:39 +0500 Subject: [PATCH] added a form for quickly managing prisoners, removed unnecessary variables and added the ability to configure the prison without changing the source code --- init.lua | 122 +++++++--------------------------------------- locale/jail.ru.tr | 9 +++- main_form.lua | 93 +++++++++++++++++++++++++++++++++++ mod.conf | 2 +- settingtypes.txt | 16 ++++++ 5 files changed, 135 insertions(+), 107 deletions(-) create mode 100644 main_form.lua create mode 100644 settingtypes.txt diff --git a/init.lua b/init.lua index bc560f2..bbecb04 100644 --- a/init.lua +++ b/init.lua @@ -1,12 +1,20 @@ local S = minetest.get_translator("jail") + jail = {} -jail.escape_boundary = 50 --радиус обхвата тюрмы -jail.display_node = { x = 675, y = 3.55, z = 5 } -jail.forced_labor = {y = -14848} --Начало глубины принудительных работ -jail.jailpos = { x = 690, y = 5, z = -7 } -local releasepos = { x = 684, y = 5, z = -7 } +jail.forced_labor = {y = tonumber(minetest.settings:get("jail_upper_limit_underground_y")) or -14848} +jail.jailpos = { + x = tonumber(minetest.settings:get("jail_prison_spawn_point_x")) or 690, + y = tonumber(minetest.settings:get("jail_prison_spawn_point_y")) or 5, + z = tonumber(minetest.settings:get("jail_prison_spawn_point_z")) or -7 +} +jail.escape_boundary = tonumber(minetest.settings:get("jail_wrap_radius")) or 50 +local releasepos = { + x = tonumber(minetest.settings:get("jail_releasepos_x")) or 684, + y = tonumber(minetest.settings:get("jail_releasepos_y")) or 5, + z = tonumber(minetest.settings:get("jail_releasepos_z")) or -7 +} local timer = 0 -local lower_prison_limit = -5 +local lower_prison_limit = tonumber(minetest.settings:get("jail_lower_prison_limit")) or -5 dofile(minetest.get_modpath("jail") .. "/nodes.lua") @@ -131,6 +139,7 @@ minetest.register_chatcommand("jailb_on", { }, func = function(name, del_node) minetest.set_node(jail.jailpos, { name = "jail:borders" }) + return true, 'Border display' end }) @@ -188,7 +197,7 @@ minetest.register_globalstep(function(dtime) if (max_pos_x < pos.x or pos.x < min_pos_x or max_pos_z < pos.z or pos.z < min_pos_z or pos.y > max_pos_y) and pos.y > lower_prison_limit then object:set_pos(jail.jailpos) - msg = minetest.colorize("red", S("Escape attempt: ") .. prisoners_list[i]) + msg = minetest.colorize("red", S("Escape attempt: ") .. " " .. prisoners_list[i]) jail.private_messages_with_privilege({ban = true}, msg) minetest.chat_send_player(prisoners_list[i], msg) jail.set_permissions_for_the_jail(prisoners_list[i]) @@ -213,101 +222,4 @@ minetest.register_globalstep(function(dtime) end end) -local function split(input, sep) - -- Если разделитель не указан, то ставим разделителем пробел - if sep == nil then - sep = "%s" - end - - local t = {} - -- С помощью regex выделяем нужные куски - for str in string.gmatch(input, "([^" .. sep .. "]+)") do - -- и вставляем из в таблицу - table.insert(t, str) - end - return t -end - -local select_player_jail_id = '' -local select_player_name_to_jail = '' -local online_players_list = {} - -local function get_formspec_main(name) - local form_list_persones = "" - local online_player = '' - - for k, player in ipairs(minetest.get_connected_players()) do - online_player = online_player .. player:get_player_name() .. "," - table.insert(online_players_list, k, player:get_player_name()) - end - - for i = 1, #prisoners_list do - form_list_persones = form_list_persones .. i .. " " ..prisoners_list[i] .."," - end - - local formspec = { - "size[13,11]", - "label[0.3,0.3;Игроки онлайн]", - "textlist[0.3,0.7;4.9,9.8;online;" .. online_player .. ";1;false]", - "label[7.9,0.3;Заключеные]", - "textlist[7.9,0.7;4.8,9.8;jail_players;" .. form_list_persones .. ";1;false]", - "button[5.4,0.7;2.3,0.8;add;В тюрьму]", - "button[5.4,1.8;2.3,0.8;release;На свободу]" - } - -- table.concat is faster than string concatenation - `..` - return table.concat(formspec, "") -end - -minetest.register_chatcommand("jailgui", { - func = function(name) - minetest.show_formspec(name, "jail:formspec_main", get_formspec_main(name)) - end -}) - -minetest.register_on_player_receive_fields(function(player, formname, fields) - local event = '' - local pars = {} - local pname = player:get_player_name() - local player_name = '' - - if formname ~= "jail:formspec_main" then - return - end - - if fields.add then - minetest.chat_send_all("Выбран id заключеного: " .. dump(select_player_name_to_jail)) - jail.add_jail(pname, select_player_name_to_jail) - minetest.show_formspec(pname, "jail:formspec_main", get_formspec_main(pname)) - - select_player_name_to_jail = '' - end - - --TODO: выбор игрока для помещения в тюрьму - if fields.online then - event = minetest.explode_textlist_event(fields.online) - if event.type == 'CHG' then - select_player_name_to_jail = online_players_list[event.index] - - minetest.chat_send_player(pname, "Выбран Игрок:" .. " " .. dump(select_player_name_to_jail)) - end - end - - --TODO: выбор игрока для освобождения - if fields.jail_players then - event = minetest.explode_textlist_event(fields.jail_players) - - if event.type == 'CHG' then - select_player_jail_id = event.index - if type(array) ~= 'nil' then - minetest.chat_send_all("Выбран заключеный" .." id:".. dump(select_player_jail_id) .. - " name:" .. prisoners_list[select_player_jail_id]) - end - end - end - - if fields.release then - jail.release(pname, select_player_jail_id) - minetest.show_formspec(pname, "jail:formspec_main", get_formspec_main(pname)) - select_player_jail_id = '' - end -end) \ No newline at end of file +dofile(minetest.get_modpath("jail") .. "/main_form.lua") \ No newline at end of file diff --git a/locale/jail.ru.tr b/locale/jail.ru.tr index b1e249d..95bcf48 100644 --- a/locale/jail.ru.tr +++ b/locale/jail.ru.tr @@ -21,4 +21,11 @@ Border display=Отображение границы The border is hidden=Граница скрыта Escape attempt: =Попытка побега: : He dug under the prison=: Совершил подкоп под тюрьмой -You are prohibited from leaving this area=Вам запрещается покидать данный участок \ No newline at end of file +You are prohibited from leaving this area=Вам запрещается покидать данный участок +Selected player:=Выбран игрок: +Prisoner selected=Выбран заключенный +Players online=Игроки онлайн +Prisoners=Заключенные +To jail=В тюрьму +To freedom=На свободу +Graphical prisoner management shell=Графическая оболочка управления заключенными \ No newline at end of file diff --git a/main_form.lua b/main_form.lua new file mode 100644 index 0000000..90c9a24 --- /dev/null +++ b/main_form.lua @@ -0,0 +1,93 @@ +--- +--- Generated by EmmyLua(https://github.com/EmmyLua) +--- Created by vinamin. +--- DateTime: 26.02.2024 13:32 +--- + +local S = minetest.get_translator("jail") + +local select_player_jail_id = '' +local select_player_name_to_jail = '' +local online_players_list = {} + +local function get_formspec_main(name) + local form_list_persones = "" + local online_player = '' + + for k, player in ipairs(minetest.get_connected_players()) do + online_player = online_player .. player:get_player_name() .. "," + table.insert(online_players_list, k, player:get_player_name()) + end + + for i = 1, #prisoners_list do + form_list_persones = form_list_persones .. i .. " " ..prisoners_list[i] .."," + end + + local formspec = { + "size[13,11]", + "label[0.3,0.3;" .. S("Players online") .. "]", + "textlist[0.3,0.7;4.9,9.8;online;" .. online_player .. "]", + "label[7.9,0.3;" .. S("Prisoners") .. "]", + "textlist[7.9,0.7;4.8,9.8;jail_players;" .. form_list_persones .. "]", + "button[5.4,0.7;2.3,0.8;add;".. S("To jail") .. "]", + "button[5.4,1.8;2.3,0.8;release;".. S("To freedom") .. "]" + } + + return table.concat(formspec, "") +end + +minetest.register_chatcommand("jailgui", { + description = S("Graphical prisoner management shell"), + privs = { jail = true }, + func = function(name) + minetest.show_formspec(name, "jail:formspec_main", get_formspec_main(name)) + end +}) + +minetest.register_on_player_receive_fields(function(player, formname, fields) + local event = '' + local pname = player:get_player_name() + + if formname ~= "jail:formspec_main" then + return + end + + if fields.add then + if select_player_name_to_jail == '' then return end + jail.add_jail(pname, select_player_name_to_jail) + minetest.show_formspec(pname, "jail:formspec_main", get_formspec_main(pname)) + + select_player_name_to_jail = '' + end + + --TODO: choosing a player to put in jail + if fields.online then + event = minetest.explode_textlist_event(fields.online) + if event.type == 'CHG' then + select_player_name_to_jail = online_players_list[event.index] + + minetest.chat_send_player(pname, S("Selected player:") .. " " .. select_player_name_to_jail) + end + end + + --TODO: selecting a player to release + if fields.jail_players then + event = minetest.explode_textlist_event(fields.jail_players) + + if event.type == 'CHG' then + select_player_jail_id = event.index + if type(array) ~= 'nil' then + minetest.chat_send_all(S("Prisoner selected") .." id: ".. select_player_jail_id .. + ", name:" .. prisoners_list[select_player_jail_id]) + end + end + end + + if fields.release then + if select_player_jail_id == '' then return end + + jail.release(pname, select_player_jail_id) + minetest.show_formspec(pname, "jail:formspec_main", get_formspec_main(pname)) + select_player_jail_id = '' + end +end) \ No newline at end of file diff --git a/mod.conf b/mod.conf index 61480fa..1f0e06d 100644 --- a/mod.conf +++ b/mod.conf @@ -3,4 +3,4 @@ description = Adds jail for game depends = default min_minetest_version = 5.7 title = Jail -release = 2 \ No newline at end of file +release = 3 \ No newline at end of file diff --git a/settingtypes.txt b/settingtypes.txt new file mode 100644 index 0000000..9826513 --- /dev/null +++ b/settingtypes.txt @@ -0,0 +1,16 @@ +[Prison spawn point] +jail_prison_spawn_point_x (Position X) int 690 +jail_prison_spawn_point_y (Position Y) int 5 +jail_prison_spawn_point_z (Position z) int -7 + +[End of the border] +jail_wrap_radius (Wrap radius) int 50 +jail_lower_prison_limit (Lower prison limit) int -5 + +[Boundary of forced labor] +jail_upper_limit_underground_y (Lower prison limit) int -14848 + +[Release] +jail_releasepos_x (Position X) int 684 +jail_releasepos_y (Position Y) int 5 +jail_releasepos_z (Position Z) int -7