123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 |
- if not minetest.global_exists("jail") then jail = {} end
- jail.modpath = minetest.get_modpath("jail")
- jail.noclip_radius = 15
- local vector_distance = vector.distance
- local vector_round = vector.round
- local vector_add = vector.add
- function jail.notify_jail_destruct(pos)
- local p1 = vector_add(pos, {x=-1, y=0, z=-1})
- local p2 = vector_add(pos, {x=1, y=0, z=1})
- local positions, counts = minetest.find_nodes_in_area(p1, p2, "city_block:cityblock")
- for k, v in ipairs(positions) do
- city_block.erase_jail(v)
- end
- end
- function jail.get_nearest_jail_pos(player)
- local pp = vector_round(player:get_pos())
-
- local jails = city_block:nearest_jails_to_position(pp, 1, 3000)
- if jails[1] then
- return vector_add(jails[1].pos, {x=0, y=1, z=0})
- end
- end
- function jail.on_player_escaped_jail(pref)
- local jp = jail.get_nearest_jail_pos(pref)
- if not jp then
-
-
- jail.notify_player_death(pref)
- return
- end
- default.detach_player_if_attached(pref)
- local pname = pref:get_player_name()
- local cb = function(pname)
- local pref = minetest.get_player_by_name(pname)
- if pref then
-
-
- pref:set_pos(jp)
- pref:set_hp(pref:get_hp() - (1*500))
- minetest.chat_send_player(
- pname, "# Server: Nope. You go right back to jail, crook!")
- end
- end
- preload_tp.execute({
- player_name = pname,
- target_position = jp,
- emerge_radius = 8,
- post_teleport_callback = cb,
- callback_param = pname,
- force_teleport = true,
- send_blocks = false,
- particle_effects = false,
- })
- end
- function jail.is_player_in_jail(pref)
- local jp = jail.get_nearest_jail_pos(pref)
- if not jp then
- return false
- end
- local pp = pref:get_pos()
- local dt = vector_distance(jp, pp)
- if dt > jail.noclip_radius then
- return false
- end
- return true
- end
- function jail.check_player_in_jail(pname)
- local pref = minetest.get_player_by_name(pname)
- if pref then
- local meta = pref:get_meta()
- if meta:get_int("should_be_in_jail") == 1 then
-
- if not jail.is_player_in_jail(pref) then
- jail.on_player_escaped_jail(pref)
- end
-
- minetest.after(1, jail.check_player_in_jail, pname)
- end
- end
-
- end
- function jail.go_to_jail(player, bcb)
- local pname = player:get_player_name()
- local fwrap = function(...)
- local pref = minetest.get_player_by_name(pname)
- if pref then
- jail.notify_sent_to_jail(pref)
- end
- if bcb then
- bcb(...)
- end
- end
- local jailpos = jail.get_nearest_jail_pos(player)
- if not jailpos then
- return
- end
- preload_tp.execute({
- player_name = pname,
- target_position = jailpos,
- emerge_radius = 32,
- post_teleport_callback = fwrap,
- force_teleport = true,
- send_blocks = true,
- particle_effects = true,
- })
-
- return true
- end
- function jail.notify_sent_to_jail(pref)
-
-
- local meta = pref:get_meta()
- meta:set_int("should_be_in_jail", 1)
- minetest.after(1, jail.check_player_in_jail, pref:get_player_name())
- end
- function jail.notify_player_death(pref)
- local meta = pref:get_meta()
- meta:set_int("should_be_in_jail", 0)
- end
- jail.discharge_pref = jail.notify_player_death
- if not jail.registered then
- local c = "jail:core"
- local f = jail.modpath .. "/init.lua"
- reload.register_file(c, f, false)
- local jail_data = {
- name = "Jail",
- codename = "jail:jail",
- position = function(...) return jail.get_nearest_jail_pos(...) end,
- min_dist = 30,
- }
- jail_data.on_success = function(name)
- local pref = minetest.get_player_by_name(name)
- if pref then
- jail.notify_sent_to_jail(pref)
- local dname = rename.gpn(name)
- minetest.chat_send_all("# Server: <" .. dname .. "> sent to jail for no particular reason.")
- end
- end
- jail_data.suppress = function(name)
- local player = minetest.get_player_by_name(name)
- if player and player:is_player() then
- if jail.is_player_in_jail(player) then
- minetest.chat_send_player(name, "# Server: Error: security override. Recall is disabled within convict re-education block.")
- easyvend.sound_error(name)
- return true
- end
- end
- end
- jail.suppress = jail_data.suppress
-
-
- passport.register_recall(jail_data)
- minetest.register_on_joinplayer(function(pref)
- minetest.after(5, jail.check_player_in_jail, pref:get_player_name())
- end)
- jail.registered = true
- end
|