chat_commands.lua 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. minetest.register_chatcommand('survivors', {
  2. description = 'See what players are still on the level',
  3. func = function(name)
  4. local map_id = lobby.game[name]
  5. if map_id ~= 'lobby' then
  6. minetest.show_formspec(name, 'lobby:survivors', lobby.survivors_formspec(map_id))
  7. end
  8. end
  9. })
  10. minetest.register_chatcommand('spawn', {
  11. description = 'Teleport to spawn. (Builders only)',
  12. privs = {creative=true},
  13. func = function (name)
  14. local player = minetest.get_player_by_name(name)
  15. player:set_pos(lobby.spawn_pos)
  16. lobby.game[name] = 'lobby'
  17. end
  18. })
  19. minetest.register_chatcommand('msg', {
  20. description = 'prevents people from sending private messages.',
  21. func = function(name)
  22. minetest.chat_send_player(name, 'Private messages are disabled here.')
  23. end
  24. })
  25. minetest.register_chatcommand('placeblock', {
  26. description = 'Places a block where player stands.',
  27. privs = {creative=true},
  28. func = function(name)
  29. local user = minetest.get_player_by_name(name)
  30. local pos = user:get_pos()
  31. if minetest.is_protected(pos, name) then
  32. minetest.chat_send_player(name, 'Try again. You can\'t run this in a protected area.')
  33. else
  34. minetest.set_node(pos, {name='color:white'})
  35. minetest.chat_send_player(name, 'Placed starter block for you. Have fun building.')
  36. end
  37. end
  38. })
  39. minetest.register_chatcommand('lobby', {
  40. description = 'Travel back to the lobby when a ghost or playing solo.',
  41. func = function(name)
  42. local player = minetest.get_player_by_name(name)
  43. local player_attributes = player:get_meta()
  44. local mode = player_attributes:get_string('mode')
  45. if mode == 'ghost' or mode == 'solo' then
  46. player:set_nametag_attributes({
  47. color = {a = 255, r = 255, g = 255, b = 255}
  48. })
  49. player:set_properties({visual_size = {x = 10, y = 10}, collisionbox = {-0.3, 0.0, -0.3, 0.3, 1.7, 0.3}})
  50. player:set_pos(lobby.spawn_pos)
  51. lobby.game[name] = 'lobby'
  52. minetest.chat_send_player(name, 'Here you are.')
  53. -- if player is a builder, restore builder mode
  54. if lobby.is_builder(player) then
  55. lobby.player_to_builder(player)
  56. else
  57. -- restore normal player mode
  58. player_attributes:set_string('mode', 'solo')
  59. local player_inv = player:get_inventory()
  60. player_inv:set_list('main', {})
  61. end
  62. else
  63. minetest.chat_send_player(name, 'You can only run this command when you are a ghost or playing solo.')
  64. end
  65. end
  66. })
  67. minetest.register_chatcommand('kick', {
  68. description = 'Kick somebody, hopefully the traitor, from the level.',
  69. func = function(name, params)
  70. local map_id = lobby.game[name]
  71. local player = minetest.get_player_by_name(name)
  72. local player_attributes = player:get_meta()
  73. local mode = player_attributes:get_string('mode')
  74. if map_id ~= 'lobby' and mode == 'player' then
  75. if name == params then
  76. local traitor = lobby.traitors[map_id]
  77. local player = minetest.get_player_by_name(name)
  78. player:set_pos(lobby.spawn_pos)
  79. player:set_physics_override({speed=1})
  80. local player_inv = player:get_inventory()
  81. player_inv:set_list('main', {})
  82. lobby.game[name] = 'lobby'
  83. lobby.update_maps(map_id)
  84. if name == traitor then
  85. lobby.team_win(map_id)
  86. end
  87. end
  88. local survivors = lobby.players_on_level(map_id)
  89. local actual_votes = lobby.votes[map_id] or 0
  90. if not lobby.voted[name] then
  91. lobby.vote_timer[map_id] = 1800
  92. minetest.log('action', name..' just voted and reset the timer to 1800.')
  93. minetest.register_globalstep(function(dtime)
  94. if lobby.vote_timer[map_id] == 1 then
  95. lobby.message_to_level(map_id, 'Voting time is over.')
  96. minetest.log('action', 'Voting has ended')
  97. lobby.vote(map_id, true)
  98. elseif lobby.vote_timer[map_id] == 300 then
  99. lobby.message_to_level(map_id, 'Thirty seconds left to vote.')
  100. minetest.log('action', '30 seconds left to vote.')
  101. elseif lobby.vote_timer[map_id] == 600 then
  102. lobby.message_to_level(map_id, 'One minute left to vote.')
  103. minetest.log('action', '60 seconds left to vote.')
  104. elseif lobby.vote_timer[map_id] == 1200 then
  105. lobby.message_to_level(map_id, 'Two minutes left to vote')
  106. minetest.log('action', '120 seconds left to vote.')
  107. end
  108. if lobby.vote_timer[map_id] >= 0 then
  109. lobby.vote_timer[map_id] = lobby.vote_timer[map_id] - 1
  110. end
  111. end)
  112. if params ~= '' then
  113. if string.find(survivors, params) then --player inputs a player name
  114. minetest.chat_send_player(name, 'Thanks for your vote.')
  115. lobby.voted[name] = true
  116. lobby.votes[map_id] = actual_votes + 1
  117. lobby.suspect[params] = lobby.suspect[params] + 1
  118. lobby.vote(map_id)
  119. else --player votes for an invalid username
  120. minetest.chat_send_player(name, 'Check your spelling and try again.')
  121. end
  122. end
  123. else
  124. minetest.chat_send_player(name, 'You can\'t vote right now.')
  125. end
  126. end
  127. end
  128. })
  129. minetest.register_chatcommand('skip', {
  130. description = 'Skip voting in a kick vote.',
  131. func = function(name)
  132. local map_id = lobby.game[name]
  133. if map_id ~= 'lobby' then
  134. local actual_votes = lobby.votes[map_id] or 0
  135. if not lobby.voted[name] then
  136. minetest.log('action', name..' just skipped voting and reset the timer to 1800.')
  137. lobby.vote_timer[map_id] = 1800
  138. minetest.chat_send_player(name, 'You skipped voting this round.')
  139. lobby.voted[name] = true
  140. lobby.votes[map_id] = actual_votes + 1
  141. lobby.vote(map_id)
  142. else
  143. minetest.chat_send_player(name, 'You can\'t vote right now.')
  144. end
  145. end
  146. end
  147. })
  148. minetest.register_chatcommand('givexp', {--
  149. description = 'Gives a player XP',
  150. params = '[player, xp]',
  151. func = function(name, params)
  152. local recipient, xp_input = params:match('^(%S+)%s(.+)$')
  153. local xp = tonumber(xp_input)
  154. if recipient and xp then
  155. if minetest.player_exists(recipient) then
  156. local player = minetest.get_player_by_name(name)
  157. if minetest.check_player_privs(player, {server = true}) then
  158. if not minetest.get_player_by_name(recipient) then
  159. minetest.chat_send_player(name, recipient..' is not online right now. They will be given XP when they join next.')
  160. lobby.queue_xp(recipient, xp)
  161. else
  162. local player = minetest.get_player_by_name(recipient)
  163. lobby.give_xp(player, xp)
  164. minetest.chat_send_player(recipient, 'You just were awarded '..xp..' XP.')
  165. minetest.chat_send_player(name, 'You just sent '..recipient..' '..xp..' XP.')
  166. end
  167. else
  168. if lobby.take_xp(player, xp) then
  169. if not minetest.get_player_by_name(recipient) then
  170. minetest.chat_send_player(name, recipient..' is not online right now. They will be given XP when they join next.')
  171. lobby.queue_xp(recipient, xp)
  172. else
  173. local player = minetest.get_player_by_name(recipient)
  174. lobby.give_xp(player, xp)
  175. minetest.chat_send_player(recipient, 'You just were awarded '..xp..' XP.')
  176. minetest.chat_send_player(name, 'You just sent '..recipient..' '..xp..' XP.')
  177. end
  178. else
  179. minetest.chat_send_player(name, 'You can\'t give more XP than you have.')
  180. end
  181. end
  182. end
  183. end
  184. end
  185. })
  186. minetest.register_chatcommand('checkxp', {
  187. description = 'Check the current XP on a level.',
  188. func = function(name)
  189. local map_id = lobby.game[name]
  190. if map_id ~= 'lobby' then
  191. local xp = lobby.xp[map_id]
  192. local game_data = lobby.savedata.data[map_id]
  193. local required_xp = game_data['xp']
  194. if xp then
  195. minetest.chat_send_player(name, 'You currently have '..xp..' xp on this level. A total of '..required_xp..' is needed to defeat the traitor.')
  196. else
  197. minetest.chat_send_player(name, 'Welp, no XP here?')
  198. end
  199. else
  200. minetest.chat_send_player(name, 'Can\'t do that here.')
  201. end
  202. end
  203. })
  204. minetest.register_chatcommand('level_help', {
  205. description = 'Show level building help screen.',
  206. func = function(name)
  207. minetest.show_formspec(name, 'lobby:get_started', lobby.getting_started)
  208. end
  209. })
  210. minetest.override_chatcommand('fixlight', {
  211. privs = {creative = true}
  212. })