commands.lua 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. local breath_value = {}
  2. minetest.register_chatcommand('spawn', {
  3. description = 'Teleport to spawn',
  4. privs = {home=true},
  5. func = function (name)
  6. local player = minetest.get_player_by_name(name)
  7. player:setpos({x=1473, y=2486, z=2970})
  8. end,
  9. })
  10. minetest.register_chatcommand('interact', {
  11. description = 'Gives player interact',
  12. params = 'keyword',
  13. privs = {home=true},
  14. func = function(name, params)
  15. if params == 'yellowsnow' then
  16. local privs = minetest.get_player_privs(name)
  17. privs.interact = true
  18. minetest.set_player_privs(name, privs)
  19. minetest.chat_send_player(name, 'Enjoy your stay on the Epic server!')
  20. else
  21. minetest.chat_send_player(name, 'Check your spelling and try again.')
  22. end
  23. end,
  24. })
  25. minetest.register_chatcommand('rules', {
  26. description = 'Shows player rules',
  27. func = function(name)
  28. minetest.show_formspec(name, 'rules', spawn_rules_formspec)
  29. end,
  30. })
  31. minetest.register_chatcommand('news', {
  32. description = 'Shows player news',
  33. func = function(name)
  34. minetest.show_formspec(name, 'news', spawn_news_formspec)
  35. end,
  36. })
  37. local function has_interact(player)
  38. local name = player:get_player_name()
  39. return not minetest.check_player_privs(name, { interact = true })
  40. end
  41. minetest.register_on_joinplayer(function(player)
  42. player:set_properties({hp_max = 50})
  43. player:set_properties({breath_max = 40})
  44. player:set_breath(40)
  45. if has_interact(player) then
  46. local player_name = player:get_player_name()
  47. minetest.chat_send_player(player_name, 'Read the rules for information on how to get interact. Para español visite https://www.nathansalapat.com/server/epic-server_es')
  48. minetest.show_formspec(player_name, 'rules', spawn_rules_formspec)
  49. else
  50. local player_name = player:get_player_name()
  51. local info_count = tonumber(spawn.storage:get_string(player_name..'_info_count')) or 10
  52. if info_count < 15 then
  53. local new_count = (info_count + 1)
  54. spawn.storage:set_string(player_name..'_info_count', new_count)
  55. minetest.show_formspec(player_name, '_info_message', spawn_info_formspec)
  56. end
  57. end
  58. end)
  59. local function drown(player, air)
  60. local new_breath = (air-4)
  61. breath_value[player] = new_breath
  62. player:set_breath(new_breath)
  63. end
  64. minetest.register_playerevent(function(player, event)
  65. local air = player:get_breath()
  66. local old_air = breath_value[player] or 40
  67. if event == "breath_changed" then
  68. if old_air > air then --Drowning
  69. drown(player, air)
  70. else --Filling lungs with air
  71. breath_value[player] = air
  72. end
  73. end
  74. end)