commands.lua 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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({breath_max = 40})
  43. player:set_breath(40)
  44. if has_interact(player) then
  45. local player_name = player:get_player_name()
  46. 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')
  47. minetest.show_formspec(player_name, 'rules', spawn_rules_formspec)
  48. else
  49. local player_name = player:get_player_name()
  50. local info_count = tonumber(spawn.storage:get_string(player_name..'_info_count')) or 10
  51. if info_count < 15 then
  52. local new_count = (info_count + 1)
  53. spawn.storage:set_string(player_name..'_info_count', new_count)
  54. minetest.show_formspec(player_name, '_info_message', spawn_info_formspec)
  55. end
  56. end
  57. end)
  58. local function drown(player, air)
  59. local new_breath = (air-4)
  60. breath_value[player] = new_breath
  61. player:set_breath(new_breath)
  62. end
  63. minetest.register_playerevent(function(player, event)
  64. local air = player:get_breath()
  65. local old_air = breath_value[player] or 40
  66. if event == "breath_changed" then
  67. if old_air > air then --Drowning
  68. drown(player, air)
  69. else --Filling lungs with air
  70. breath_value[player] = air
  71. end
  72. end
  73. end)