2
0

death_screen.lua 924 B

12345678910111213141516171819202122232425262728293031
  1. local F = core.formspec_escape
  2. local S = core.get_translator("__builtin")
  3. function core.show_death_screen(player, _reason)
  4. local fs = {
  5. "formspec_version[1]",
  6. "size[11,5.5,true]",
  7. "bgcolor[#320000b4;true]",
  8. "label[4.85,1.35;", F(S("You died")), "]",
  9. "button_exit[4,3;3,0.5;btn_respawn;", F(S("Respawn")), "]",
  10. }
  11. core.show_formspec(player:get_player_name(), "__builtin:death", table.concat(fs, ""))
  12. end
  13. core.register_on_dieplayer(function(player, reason)
  14. core.show_death_screen(player, reason)
  15. end)
  16. core.register_on_joinplayer(function(player)
  17. if player:get_hp() == 0 then
  18. core.show_death_screen(player, nil)
  19. end
  20. end)
  21. core.register_on_player_receive_fields(function(player, formname, fields)
  22. if formname == "__builtin:death" and fields.quit and player:get_hp() == 0 then
  23. player:respawn()
  24. core.log("action", player:get_player_name() .. " respawns at " ..
  25. player:get_pos():to_string())
  26. end
  27. end)