suicide.lua 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. function serveressentials.do_suicide(pname, param)
  2. local pref = minetest.get_player_by_name(pname)
  3. if not pref or not pref:is_player() then
  4. return
  5. end
  6. if param == "confirm" then
  7. local meta = pref:get_meta()
  8. local last_recall = meta:get_int("time_of_last_suicide")
  9. local death_time = os.time()
  10. local cooldown = 60*60*24*1
  11. local death_pos = vector.round(pref:get_pos())
  12. if (last_recall + cooldown) >= death_time then
  13. local hours = (last_recall + cooldown) - death_time
  14. hours = math.ceil(hours / (60*60))
  15. local hstr = "hours"
  16. if hours == 1 then
  17. hstr = "hour"
  18. end
  19. minetest.log("action", "Suicide attempt from " .. pname .. " denied: cooldown")
  20. minetest.chat_send_player(pname, "# Server: Cooldown in progress. Cannot seppuku at this time.")
  21. minetest.chat_send_player(pname, "# Server: Command will be available in " .. hours .. " " .. hstr .. ".")
  22. return
  23. end
  24. minetest.log("action", pname .. " commits suicide at " .. minetest.pos_to_string(death_pos))
  25. -- Do it.
  26. meta:set_int("time_of_last_suicide", death_time)
  27. pref:set_hp(0, {reason="suicide"})
  28. if pref:get_hp() > 0 then
  29. minetest.chat_send_player(pname, "# Server: Failure. Seppuku not committed. Honor not gained.")
  30. else
  31. local data = skins.get_gender_strings(pname)
  32. minetest.chat_send_all("# Server: <" .. rename.gpn(pname) .. "> ended " .. data.himself .. ".")
  33. end
  34. return
  35. end
  36. minetest.chat_send_player(pname, "# Server: type \"/suicide confirm\" to run this command. You will DIE.")
  37. minetest.chat_send_player(pname, "# Server: The command cannot be used again for one realtime day.")
  38. end
  39. if not serveressentials.suicide_command_registered then
  40. serveressentials.suicide_command_registered = true
  41. minetest.register_chatcommand("suicide", {
  42. params = "[confirm]",
  43. description = "Get yourself unstuck from an impossible situation. By self-murder.",
  44. privs = {interact=true},
  45. func = function(...)
  46. return serveressentials.do_suicide(...)
  47. end
  48. })
  49. end