chat.lua 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. function lobby.send(name, msg)
  2. local map = lobby.game[name]
  3. for _, player in pairs(minetest.get_connected_players()) do
  4. local rname = player:get_player_name()
  5. if lobby.game[rname] == map then
  6. minetest.chat_send_player(rname, "<"..name.."> "..msg)
  7. end
  8. end
  9. minetest.log("action", "CHAT: ".."<"..name.."> "..msg)
  10. -- Prevent from sending normally
  11. return true
  12. end
  13. function lobby.message_to_level(map_id, message)
  14. for _, player in pairs(minetest.get_connected_players()) do
  15. local rname = player:get_player_name()
  16. if lobby.game[rname] == map_id then
  17. minetest.chat_send_player(rname, message)
  18. end
  19. end
  20. end
  21. minetest.register_on_chat_message(function(name, msg)
  22. return lobby.send(name, msg)
  23. end)
  24. minetest.register_chatcommand('survivors', {
  25. description = 'See what players are still on the level',
  26. func = function(name)
  27. local map_id = lobby.game[name]
  28. local survivors = lobby.players_on_level(map_id)
  29. minetest.chat_send_player(name, survivors..' are left on this map.')
  30. end
  31. })
  32. minetest.register_chatcommand('spawn', {
  33. description = 'Teleport to 0,0,0. (Builders only)',
  34. privs = {creative=true},
  35. func = function (name)
  36. local player = minetest.get_player_by_name(name)
  37. player:setpos({x=0, y=0, z=0})
  38. end
  39. })
  40. minetest.register_chatcommand('msg', {
  41. description = 'prevents people from sending private messages.',
  42. func = function(name)
  43. minetest.chat_send_player(name, 'Private messages are disabled here.')
  44. end
  45. })
  46. minetest.register_chatcommand('lobby', {
  47. description = 'Travel back to the lobby when a ghost.',
  48. func = function(name)
  49. local player = minetest.get_player_by_name(name)
  50. local ghost = player:get_attribute('ghost')
  51. if ghost == 'true' then
  52. gamer.player_set_textures(player,{'gamer_skin.png'})
  53. player:set_nametag_attributes({
  54. color = {a = 255, r = 255, g = 255, b = 255}
  55. })
  56. player:set_properties({visual_size = {x = 1, y = 1}, collisionbox = {-0.3, 0.0, -0.3, 0.3, 1.7, 0.3}})
  57. player:setpos({x=0, y=0, z=0})
  58. minetest.chat_send_player(name, 'Here you are.')
  59. player:set_attribute('ghost', 'false')
  60. else
  61. minetest.chat_send_player(name, 'You can only run this command when you are a ghost.')
  62. end
  63. end
  64. })
  65. minetest.register_chatcommand('kick', {
  66. description = 'Kick somebody, hopefully the traitor, from the level.',
  67. func = function(name, params)
  68. local map_id = lobby.game[name]
  69. if map_id ~= 'lobby' then
  70. local survivors = lobby.players_on_level(map_id)
  71. local actual_votes = lobby.votes[map_id] or 0
  72. if not lobby.voted[name] then
  73. lobby.vote_timer[map_id] = 1800
  74. minetest.register_globalstep(function(dtime)
  75. if lobby.vote_timer[map_id] == 0 then
  76. lobby.vote_timer[map_id] = lobby.vote_timer[map_id] - 1
  77. lobby.message_to_level(map_id, 'Voting time is over.')
  78. lobby.vote(map_id, true)
  79. elseif lobby.vote_timer[map_id] == 300 then
  80. lobby.vote_timer[map_id] = lobby.vote_timer[map_id] - 1
  81. lobby.message_to_level(map_id, 'Thirty seconds left to vote.')
  82. elseif lobby.vote_timer[map_id] == 600 then
  83. lobby.vote_timer[map_id] = lobby.vote_timer[map_id] - 1
  84. lobby.message_to_level(map_id, 'One minute left to vote.')
  85. elseif lobby.vote_timer[map_id] == 1200 then
  86. lobby.vote_timer[map_id] = lobby.vote_timer[map_id] - 1
  87. lobby.message_to_level(map_id, 'Two minutes left to vote')
  88. end
  89. end)
  90. if params == 'skip' then --players opts to not vote
  91. minetest.chat_send_player(name, 'You skipped voting this round.')
  92. lobby.voted[name] = true
  93. lobby.votes[map_id] = actual_votes + 1
  94. lobby.vote(map_id)
  95. elseif params ~= '' then
  96. if string.find(survivors, params) then --player inputs a player name
  97. minetest.chat_send_player(name, 'Thanks for your vote.')
  98. lobby.voted[name] = true
  99. lobby.votes[map_id] = actual_votes + 1
  100. lobby.suspect[params] = lobby.suspect[params] + 1
  101. lobby.vote(map_id)
  102. else --player votes for an invalid username
  103. minetest.chat_send_player(name, 'Check your spelling and try again.')
  104. end
  105. end
  106. else
  107. minetest.chat_send_player(name, 'You can\'t vote right now.')
  108. end
  109. end
  110. end
  111. })