home_gui.lua 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. -- Load support for intllib.
  2. local MP = minetest.get_modpath(minetest.get_current_modname())
  3. local S = minetest.get_translator and minetest.get_translator("inventory_plus") or
  4. dofile(MP .. "/intllib.lua")
  5. -- static spawn position
  6. local statspawn = minetest.string_to_pos(minetest.settings:get("static_spawnpoint"))
  7. or {x = 0, y = 12, z = 0}
  8. local home_gui = {}
  9. -- get_formspec
  10. home_gui.get_formspec = function(player)
  11. local formspec = "size[6,2]"
  12. .. default.gui_bg
  13. .. default.gui_bg_img
  14. .. default.gui_slots
  15. .. "button[0,0;2,0.5;main;" .. S("Back") .. "]"
  16. .. "button_exit[0,1.5;2,0.5;home_gui_set;" .. S("Set Home") .. "]"
  17. .. "button_exit[2,1.5;2,0.5;home_gui_go;Go " .. S("Home") .. "]"
  18. .. "button_exit[4,1.5;2,0.5;home_gui_spawn;" .. S("Spawn") .. "]"
  19. local home = sethome.get( player:get_player_name() )
  20. if home then
  21. formspec = formspec
  22. .."label[2.5,-0.2;" .. S("Home set to:") .. "]"
  23. .."label[2.5,0.4;".. minetest.pos_to_string(vector.round(home)) .. "]"
  24. end
  25. return formspec
  26. end
  27. -- add inventory_plus page when player joins
  28. minetest.register_on_joinplayer(function(player)
  29. inventory_plus.register_button(player, "home_gui", S("Home Pos"))
  30. end)
  31. -- what to do when we press da buttons
  32. minetest.register_on_player_receive_fields(function(player, formname, fields)
  33. local privs = minetest.get_player_privs(player:get_player_name()).home
  34. if privs and fields.home_gui_set then
  35. sethome.set(player:get_player_name(), player:get_pos())
  36. end
  37. if privs and fields.home_gui_go then
  38. sethome.go(player:get_player_name())
  39. end
  40. if privs and fields.home_gui_spawn then
  41. player:set_pos(statspawn)
  42. end
  43. if fields.home_gui or fields.home_gui_set or fields.home_gui_go then
  44. inventory_plus.set_inventory_formspec(player, home_gui.get_formspec(player))
  45. end
  46. end)
  47. -- spawn command
  48. minetest.register_chatcommand("spawn", {
  49. description = S("Go to Spawn"),
  50. privs = {home = true},
  51. func = function(name)
  52. local player = minetest.get_player_by_name(name)
  53. player:set_pos(statspawn)
  54. end,
  55. })