Compare commits

...

7 Commits
1 ... main

Author SHA1 Message Date
5f8cf99fc4 Доработать функцию отправки игрока в тюрьму (#1)
- добавлена проверка на корректность введенного имени игрока;
- добавлена отправка в тюрьму игрока, который оффлайн.

Co-authored-by: Aleksandr Avdeev <reload-gtn@mail.ru>
Reviewed-on: https://git.minetestserver.ru/MTSR/jail/pulls/1
Reviewed-by: Koldun <koldun@noreply.git.minetestserver.ru>
Co-authored-by: Александр Авдеев <reload@minetestserver.ru>
Co-committed-by: Александр Авдеев <reload@minetestserver.ru>
2024-10-16 17:00:42 +03:00
Vitaliy Olkhin
fae274cdab
Added the ability to release the player if not in the game 2024-06-15 13:13:11 +05:00
Vitaliy Olkhin
219b6ff552
added a form for quickly managing prisoners, removed unnecessary variables and added the ability to configure the prison without changing the source code 2024-06-15 13:13:11 +05:00
Vitaliy Olkhin
3dd901f850
add "tp" privs by chatcommand "release" 2024-06-15 13:13:11 +05:00
Vitaliy Olkhin
6d890a00c5
форма для управления заключенными 2024-06-15 13:13:10 +05:00
Vitaliy Olkhin
5e5ab53707
saved the notice for the convicted person 2024-06-15 13:13:10 +05:00
Vitaliy Olkhin
58daf49b82
Добавил опцию приватного сообщения для админов по привилегии ban и подправил позиции тюрьмы 2024-06-15 13:13:10 +05:00
6 changed files with 240 additions and 61 deletions

164
init.lua
View File

@ -1,11 +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} --Начало глубины принудительных работ
local 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 = tonumber(minetest.settings:get("jail_lower_prison_limit")) or -5
dofile(minetest.get_modpath("jail") .. "/nodes.lua")
@ -26,26 +35,66 @@ jail.set_permissions_for_the_jail = function (player)
})
end
jail.add_jail = function(self_player_name, player_name)
if (minetest.player_exists(player_name)) then
for i = 1, #prisoners_list do
if prisoners_list[i] == player_name then
minetest.chat_send_player(self_player_name, S("The player is already in jail"))
return
end
end
table.insert(prisoners_list, player_name)
jail.set_permissions_for_the_jail(player_name)
local player = minetest.env:get_player_by_name(player_name)
minetest.chat_send_all(minetest.colorize("red",
"" .. player_name .. " " .. S("has been sent to jail by") .. " " .. self_player_name))
if (player) then
player:setpos(jail.jailpos)
minetest.chat_send_player(player_name, minetest.colorize("red", S("You have been sent to jail")))
end
else
minetest.chat_send_player(self_player_name, minetest.colorize("red", S("The player '") .. player_name .. S("' does not exist, check that the nickname is correct")))
end
end
jail.set_release_privs = function(self_name, player, prisoners_list_id)
minetest.set_player_privs(player, {
interact = true,
shout = true,
home = true,
spawn = true,
tp = true
})
minetest.chat_send_all(minetest.colorize("green",
"" .. player .. " " .. S("has been released from jail by") .. " " .. self_name))
table.remove(prisoners_list, prisoners_list_id)
end
jail.release = function(self_name, id_player)
local id = tonumber(id_player)
local playername = prisoners_list[id]
if (id == nil or id > #prisoners_list or id <= 0) then
minetest.chat_send_player(self_name, S("Invalid ID"))
return
end
local player = minetest.env:get_player_by_name(playername)
if (player) then
player:setpos(releasepos)
minetest.chat_send_player(playername, minetest.colorize("green", S("You have been released from jail")))
jail.set_release_privs(self_name, playername, id)
else
jail.set_release_privs(self_name, playername, id)
end
end
minetest.register_chatcommand("jail", {
params = "<player>",
description = S("Sends a player to Jail"),
privs = { jail = true },
func = function(name, param)
for i = 1, #prisoners_list do
if prisoners_list[i] == param then
minetest.chat_send_player(name, S("The player is already in jail"))
return
end
end
local player = minetest.env:get_player_by_name(param)
if (player) then
table.insert(prisoners_list, param)
player:setpos(jailpos)
minetest.chat_send_player(param, minetest.colorize("red", S("You have been sent to jail")))
minetest.chat_send_all(minetest.colorize("red",
"" .. param .. " " .. S("has been sent to jail by") .. " " .. name))
jail.set_permissions_for_the_jail(param)
end
jail.add_jail(name, param)
end,
})
@ -75,26 +124,7 @@ minetest.register_chatcommand("release", {
description = S("Releases a player from Jail by ID"),
privs = { jail = true },
func = function(name, param)
local id = tonumber(param)
local playername = prisoners_list[id]
if (id == nil or id > #prisoners_list or id <= 0) then
minetest.chat_send_player(name, S("Invalid ID"))
return
end
local player = minetest.env:get_player_by_name(playername)
if (player) then
player:setpos(releasepos)
minetest.chat_send_player(playername, minetest.colorize("green", S("You have been released from jail")))
minetest.chat_send_all(minetest.colorize("green",
"" .. playername .. " " .. S("has been released from jail by") .. " " .. name))
minetest.set_player_privs(playername, {
interact = true,
shout = true,
home = true,
spawn = true
})
table.remove(prisoners_list, id)
end
jail.release(name, param)
end,
})
@ -118,8 +148,8 @@ minetest.register_chatcommand("jailb_on", {
jail = true,
},
func = function(name, del_node)
minetest.set_node(jailpos, { name = "jail:borders" })
minetest.set_node(jail.jailpos, { name = "jail:borders" })
return true, 'Border display'
end
})
@ -130,7 +160,7 @@ minetest.register_chatcommand("jailb_off", {
interact = true,
},
func = function(name, del_node)
minetest.remove_node(jailpos) --удаление
minetest.remove_node(jail.jailpos) --удаление
return true, S('The border is hidden')
end
})
@ -140,9 +170,27 @@ minetest.register_on_shutdown(function()
mod_storage:set_string("prisoners", prisoners)
end)
jail.private_messages_with_privilege = function(list_privs, msg)
local player_name = 'player_name'
for _, player in ipairs(minetest.get_connected_players()) do
player_name = player:get_player_name()
boolean = minetest.check_player_privs(player:get_player_name(), list_privs)
if boolean then
minetest.chat_send_player(player_name, msg)
end
end
end
minetest.register_globalstep(function(dtime)
local forced_labor = 0
local forced_labor = jail.forced_labor.y + 1000
local max_pos_x = jail.jailpos.x + jail.escape_boundary
local min_pos_x = jail.jailpos.x - jail.escape_boundary
local max_pos_y = jail.jailpos.x + jail.escape_boundary
local max_pos_z = jail.jailpos.z + jail.escape_boundary
local min_pos_z = jail.jailpos.z - jail.escape_boundary
local msg = ''
-- every 5 seconds
if timer > os.time() then
@ -156,32 +204,32 @@ minetest.register_globalstep(function(dtime)
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 max_pos_z = jail.display_node.z + jail.escape_boundary
local min_pos_z = jail.display_node.z - jail.escape_boundary
forced_labor = jail.forced_labor.y + 1000
if (max_pos_x < pos.x or pos.x < min_pos_x or max_pos_z < pos.z or pos.z < min_pos_z) and pos.y > -5 then
object:set_pos(jailpos)
minetest.chat_send_all(minetest.colorize("red", S("Escape attempt: ") .. prisoners_list[i]))
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])
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])
end
--Проверка если игрок копает в низ по кординатам тюрьмы
if pos.y < -5 and pos.y > forced_labor then
object:set_pos(jailpos)
minetest.chat_send_all(minetest.colorize("red", prisoners_list[i] .. S(": He dug under the prison")))
if pos.y < lower_prison_limit and pos.y > forced_labor then
object:set_pos(jail.jailpos)
msg = minetest.colorize("red", prisoners_list[i] .. S(": He dug under the prison"))
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])
end
--Условие если игрок находится взаданом параметре jail.forced_labor.y под землей
if pos.y > jail.forced_labor.y and pos.y < -10 then
object:set_pos(jailpos)
object:set_pos(jail.jailpos)
minetest.chat_send_player(prisoners_list[i], minetest.colorize("red", S("You are prohibited from leaving this area")))
jail.set_permissions_for_the_jail(prisoners_list[i])
end
end
end
end)
dofile(minetest.get_modpath("jail") .. "/main_form.lua")

View File

@ -21,4 +21,13 @@ Border display=Отображение границы
The border is hidden=Граница скрыта
Escape attempt: =Попытка побега:
: He dug under the prison=: Совершил подкоп под тюрьмой
You are prohibited from leaving this area=Вам запрещается покидать данный участок
You are prohibited from leaving this area=Вам запрещается покидать данный участок
Selected player:=Выбран игрок:
Prisoner selected=Выбран заключенный
Players online=Игроки онлайн
Prisoners=Заключенные
To jail=В тюрьму
To freedom=На свободу
Graphical prisoner management shell=Интерфейс управления заключенными
The player '=Игрока '
' does not exist, check that the nickname is correct=' не сущеcтвует, проверьте правильность ника

93
main_form.lua Normal file
View File

@ -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)

View File

@ -3,4 +3,4 @@ description = Adds jail for game
depends = default
min_minetest_version = 5.7
title = Jail
release = 1
release = 4

View File

@ -32,4 +32,17 @@ minetest.register_node("jail:borders", {
paramtype = "light",
groups = {dig_immediate = 3, not_in_creative_inventory = 1},
drop = ""
})
})
function dump(o)
if type(o) == 'table' then
local s = '{ '
for k,v in pairs(o) do
if type(k) ~= 'number' then k = '"'..k..'"' end
s = s .. '['..k..'] = ' .. dump(v) .. ','
end
return s .. '} '
else
return tostring(o)
end
end

16
settingtypes.txt Normal file
View File

@ -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