emergency_buttons.lua 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. function lobby.press_button(pos, node, clicker)
  2. local name = clicker:get_player_name()
  3. local player_attributes = clicker:get_meta()
  4. local voting = player_attributes:get_string('voting')
  5. local mode = player_attributes:get_string('mode')
  6. local map_id = lobby.game[name]
  7. if voting == 'false' then
  8. if map_id ~= 'lobby' and (mode == 'player' or mode == 'traitor') then
  9. local game_data = lobby.savedata.data[map_id]
  10. local game_pos = game_data['level_pos']
  11. lobby.votes[map_id] = 0
  12. minetest.log('action', name..' just called an emergency meeting.')
  13. for _, player in pairs(minetest.get_connected_players()) do
  14. local rname = player:get_player_name()
  15. local player_attributes = player:get_meta()
  16. if lobby.game[rname] == map_id then
  17. lobby.voted[rname] = false
  18. local vel = player:get_velocity()
  19. local vel_x = vel.x * -1
  20. local vel_y = vel.y * -1
  21. local vel_z = vel.z * -1
  22. player:add_velocity({x=vel_x, y=vel_y, z=vel_z})
  23. player:set_pos({x=game_pos.x+(math.random(-2.5,2.5)),y=game_pos.y-1,z=game_pos.z+(math.random(-2.5,2.5))})
  24. player:set_physics_override({speed=.001})
  25. player:set_armor_groups({immortal=1})
  26. player_attributes:set_string('voting', 'true')
  27. minetest.chat_send_player(rname, minetest.colorize('#FF0000', name..' called an emergency meeting!'))
  28. minetest.show_formspec(rname, 'lobby:voting', lobby.voting_formspec(map_id, true))
  29. end
  30. end
  31. end
  32. else
  33. minetest.chat_send_player(name, 'Sorry, you can\'t do that now.')
  34. end
  35. end
  36. minetest.register_node('lobby:emergency_button', {
  37. description = 'Emergency Button',
  38. drawtype = 'mesh',
  39. mesh = 'lobby_emergency_button.obj',
  40. tiles = {'lobby_button_frame.png', 'lobby_button_button.png'},
  41. use_texture_alpha = 'clip',
  42. groups = {breakable=1},
  43. paramtype = 'light',
  44. paramtype2 = 'facedir',
  45. selection_box = {
  46. type = 'fixed',
  47. fixed = {-.5, -.5, -.5, .5, -.3, .5},
  48. },
  49. collision_box = {
  50. type = 'fixed',
  51. fixed = {-.5, -.5, -.5, .5, -.3, .5},
  52. },
  53. on_place = minetest.rotate_and_place,
  54. on_rightclick = lobby.press_button,
  55. on_punch = lobby.press_button,
  56. })