init.lua 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. jail = {}
  2. local storage = minetest.get_mod_storage()
  3. function release_prisoners(name)
  4. local player = minetest.get_player_by_name(name)
  5. if not player then
  6. return
  7. end
  8. minetest.chat_send_player(name, '<Jail Staff> We hope you enjoyed your stay.')
  9. minetest.set_player_privs(name, {shout=true, home=true})
  10. player:setpos({x=2555, y=2002, z=4442})
  11. minetest.log('action', name..' was freed from jail')
  12. storage:set_string(name, '')
  13. storage:set_string(name..'_length', '')
  14. minetest.show_formspec(name, 'rules', spawn_rules_formspec)
  15. end
  16. minetest.register_privilege('warden', {
  17. description = 'Can send people to jail',
  18. give_to_singleplayer = false
  19. })
  20. minetest.register_chatcommand('release', {
  21. params = '<name>',
  22. privs = {warden=true},
  23. func = function(warden, name)
  24. release_prisoners(name)
  25. end,
  26. })
  27. minetest.register_chatcommand('jail', {
  28. params = '<name> [<time>] [<reason>]',
  29. description = 'Send player to jail.',
  30. privs = {warden=true},
  31. func = function(warden, param)
  32. local params = param:split(',')
  33. local name = params[1]
  34. local time = params[2] or 300
  35. local reason = params[3] or 'reasons'
  36. local player = minetest.get_player_by_name(name)
  37. if not player then
  38. minetest.chat_send_player(warden, 'That player is not here!')
  39. return
  40. end
  41. minetest.log('action', name..' was jailed by '..warden)
  42. minetest.set_player_privs(name, {shout=true}) --revoke all privs but shout
  43. local jail_cells = { --locations of the cells that players can be placed in.
  44. {x=2562, y=2001, z=4438},
  45. {x=2562, y=2001, z=4442},
  46. {x=2562, y=2001, z=4446},
  47. }
  48. local cell_loc = jail_cells[math.random(3)]
  49. local sign_loc = {x = cell_loc.x-3, y = cell_loc.y+3, z = cell_loc.z}
  50. player:setpos(cell_loc)
  51. minetest.chat_send_player(name, 'You were sent to jail for '..time..' seconds for '..reason..'.')
  52. storage:set_string(name, 'jailed')
  53. storage:set_string(name..'_length', time)
  54. local meta = minetest.get_meta(sign_loc)
  55. meta:set_string('text', reason)
  56. meta:set_string('infotext', reason)
  57. minetest.after(time, function()
  58. release_prisoners(name)
  59. end)
  60. end,
  61. })
  62. minetest.register_on_joinplayer(function(player)
  63. local name = player:get_player_name()
  64. local jailed = storage:get_string(name)
  65. if jailed == 'jailed' then
  66. local time = tonumber(storage:get_string(name..'_length'))
  67. minetest.chat_send_player(name, 'So you thought you could evade serving your time? You have '..time..' seconds to serve')
  68. minetest.after(time, function()
  69. release_prisoners(name)
  70. end)
  71. end
  72. end)