2024-01-06 14:18:17 +03:00
local S = minetest.get_translator ( " jail " )
2024-02-26 14:48:39 +03:00
2024-02-05 13:54:53 +03:00
jail = { }
2024-02-26 14:48:39 +03:00
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
}
2024-02-05 13:54:53 +03:00
local timer = 0
2024-02-26 14:48:39 +03:00
local lower_prison_limit = tonumber ( minetest.settings : get ( " jail_lower_prison_limit " ) ) or - 5
2024-02-05 13:54:53 +03:00
dofile ( minetest.get_modpath ( " jail " ) .. " /nodes.lua " )
2024-01-06 14:18:17 +03:00
minetest.register_privilege ( " jail " , { description = S ( " Allows one to send/release prisoners " ) } )
local mod_storage = minetest.get_mod_storage ( )
local prisoners = mod_storage : get_string ( " prisoners " )
prisoners_list = { }
for line in prisoners : gmatch ( " [^ \n ]+ " ) do
table.insert ( prisoners_list , line )
end
2024-02-12 15:12:12 +03:00
jail.set_permissions_for_the_jail = function ( player )
minetest.set_player_privs ( player , {
interact = true ,
} )
end
2024-02-25 12:35:33 +03:00
jail.add_jail = function ( self_player_name , player_name )
2024-10-16 17:00:42 +03:00
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
2024-02-25 12:35:33 +03:00
end
table.insert ( prisoners_list , player_name )
jail.set_permissions_for_the_jail ( player_name )
2024-10-16 17:00:42 +03:00
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
2024-02-25 12:35:33 +03:00
else
2024-10-16 17:00:42 +03:00
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 " ) ) )
2024-02-25 12:35:33 +03:00
end
end
2024-03-01 12:17:44 +03:00
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
2024-10-21 13:18:21 +03:00
jail.release_id = function ( self_name , id_player )
2024-02-25 12:35:33 +03:00
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
2024-03-01 12:17:44 +03:00
2024-02-25 12:35:33 +03:00
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 " ) ) )
2024-03-01 12:17:44 +03:00
jail.set_release_privs ( self_name , playername , id )
else
jail.set_release_privs ( self_name , playername , id )
2024-02-25 12:35:33 +03:00
end
end
2024-10-21 13:18:21 +03:00
jail.release = function ( self_name , player_name )
for i = 1 , # prisoners_list do
if player_name == prisoners_list [ i ] then
local player = minetest.env : get_player_by_name ( player_name )
if ( player ) then
player : setpos ( releasepos )
minetest.chat_send_player ( player_name , minetest.colorize ( " green " , S ( " You have been released from jail " ) ) )
end
jail.set_release_privs ( self_name , player_name , i )
return
else
minetest.chat_send_player ( self_name , S ( " Invalid playername " ) )
end
end
end
2024-01-06 14:18:17 +03:00
minetest.register_chatcommand ( " jail " , {
params = " <player> " ,
description = S ( " Sends a player to Jail " ) ,
privs = { jail = true } ,
func = function ( name , param )
2024-02-25 12:35:33 +03:00
jail.add_jail ( name , param )
2024-01-06 14:18:17 +03:00
end ,
} )
minetest.register_chatcommand ( " jail_return " , {
params = " <ID prisoners> " ,
description = S ( " Return a prisoner to jail " ) ,
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 ( jailpos )
minetest.chat_send_player ( playername , minetest.colorize ( " red " , S ( " You have been return to jail " ) ) )
minetest.chat_send_all ( minetest.colorize ( " red " ,
" " .. param .. " " .. S ( " has been return to jail by " ) .. " " .. name ) )
end
end ,
} )
minetest.register_chatcommand ( " release " , {
2024-10-21 13:18:21 +03:00
params = " <nickname prisoners> " ,
description = S ( " Releases a player from Jail by nickname " ) ,
privs = { jail = true } ,
func = function ( name , param )
jail.release ( name , param )
end ,
} )
minetest.register_chatcommand ( " release_id " , {
2024-01-06 14:18:17 +03:00
params = " <ID prisoners> " ,
description = S ( " Releases a player from Jail by ID " ) ,
privs = { jail = true } ,
func = function ( name , param )
2024-10-21 13:18:21 +03:00
jail.release_id ( name , param )
2024-01-06 14:18:17 +03:00
end ,
} )
minetest.register_chatcommand ( " jail_list " , {
description = S ( " List of prisoners " ) ,
privs = {
jail = true ,
} ,
func = function ( name )
minetest.chat_send_player ( name , minetest.colorize ( " cyan " , S ( " Prisoners: " ) ) )
for i = 1 , # prisoners_list do
minetest.chat_send_player ( name , i .. " - " .. prisoners_list [ i ] )
end
return true , S ( " Total number of prisoners: " ) .. " " .. # prisoners_list
end
} )
minetest.register_chatcommand ( " jailb_on " , {
description = S ( " Show border " ) ,
privs = {
jail = true ,
} ,
func = function ( name , del_node )
2024-02-25 12:35:33 +03:00
minetest.set_node ( jail.jailpos , { name = " jail:borders " } )
2024-02-26 14:48:39 +03:00
2024-01-06 14:18:17 +03:00
return true , ' Border display '
end
} )
minetest.register_chatcommand ( " jailb_off " , {
description = S ( " remove " ) ,
privs = {
interact = true ,
} ,
func = function ( name , del_node )
2024-02-25 12:35:33 +03:00
minetest.remove_node ( jail.jailpos ) --удаление
2024-01-06 14:18:17 +03:00
return true , S ( ' The border is hidden ' )
end
} )
minetest.register_on_shutdown ( function ( )
local prisoners = table.concat ( prisoners_list , " \n " )
mod_storage : set_string ( " prisoners " , prisoners )
end )
2024-02-15 12:59:53 +03:00
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
2024-02-12 15:12:12 +03:00
2024-01-06 14:18:17 +03:00
minetest.register_globalstep ( function ( dtime )
2024-02-15 12:59:53 +03:00
local forced_labor = jail.forced_labor . y + 1000
2024-02-25 12:35:33 +03:00
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
2024-02-15 13:12:06 +03:00
local msg = ' '
2024-02-12 15:12:12 +03:00
2024-01-06 14:18:17 +03:00
-- every 5 seconds
if timer > os.time ( ) then
return
end
2024-02-05 13:54:53 +03:00
timer = os.time ( ) + 5
2024-01-06 14:18:17 +03:00
for i = 1 , # prisoners_list do
local object = minetest.env : get_player_by_name ( prisoners_list [ i ] )
2024-02-05 13:54:53 +03:00
if object then
local pos = object : get_pos ( )
2024-02-15 12:59:53 +03:00
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
2024-02-25 12:35:33 +03:00
object : set_pos ( jail.jailpos )
2024-02-26 14:48:39 +03:00
msg = minetest.colorize ( " red " , S ( " Escape attempt: " ) .. " " .. prisoners_list [ i ] )
2024-02-15 13:12:06 +03:00
jail.private_messages_with_privilege ( { ban = true } , msg )
minetest.chat_send_player ( prisoners_list [ i ] , msg )
2024-02-12 15:12:12 +03:00
jail.set_permissions_for_the_jail ( prisoners_list [ i ] )
end
--Проверка если игрок копает в низ по кординатам тюрьмы
2024-02-15 12:59:53 +03:00
if pos.y < lower_prison_limit and pos.y > forced_labor then
2024-02-25 12:35:33 +03:00
object : set_pos ( jail.jailpos )
2024-02-15 13:12:06 +03:00
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 )
2024-02-12 15:12:12 +03:00
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
2024-02-25 12:35:33 +03:00
object : set_pos ( jail.jailpos )
2024-02-12 15:12:12 +03:00
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 ] )
2024-02-05 13:54:53 +03:00
end
2024-01-06 14:18:17 +03:00
end
end
end )
2024-02-25 12:35:33 +03:00
2024-02-26 14:48:39 +03:00
dofile ( minetest.get_modpath ( " jail " ) .. " /main_form.lua " )