init.lua 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. lobby = {}
  2. lobby.map = {} --Holds number of players in a level.
  3. lobby.voted = {} --Holds player names, and if they have voted.
  4. lobby.votes = {}
  5. lobby.suspect = {} --Holds number of votes a player has marking them as suspect
  6. lobby.game = {} --Holds player names and what map they are on.
  7. lobby.xp = {} --The current XP amount for each level.
  8. lobby.traitors = {} --
  9. lobby.corpses = {}
  10. lobby.vote_timer = {}
  11. --Yes I know these table names are not very clear.
  12. --[[
  13. Saving data:
  14. local data = {}
  15. data.level_pos = {x = pos_x, y = pos_y, z = pos_z}
  16. data.xp = tonumber(fields.xp)
  17. lobby.savedata.IDs[map_id] = true
  18. lobby.savedata.data[map_id] = data
  19. ----
  20. Retriving data:
  21. local game_data = lobby.savedata.data[map_id]
  22. local game_pos = game_data['level_pos']
  23. ]]
  24. dofile(minetest.get_modpath('lobby')..'/chat.lua')
  25. dofile(minetest.get_modpath('lobby')..'/corpse.lua')
  26. dofile(minetest.get_modpath('lobby')..'/functions.lua')
  27. dofile(minetest.get_modpath('lobby')..'/nodes_active.lua')
  28. dofile(minetest.get_modpath('lobby')..'/tool.lua')
  29. local function not_builder(player)
  30. local name = player:get_player_name()
  31. return not minetest.check_player_privs(name, { creative = true })
  32. end
  33. minetest.register_on_joinplayer(function(player)
  34. local name = player:get_player_name()
  35. lobby.suspect[name] = 0
  36. lobby.game[name] = 'lobby'
  37. lobby.voted[name] = true
  38. player:set_hp(40)
  39. player:set_attribute('ghost', 'false')
  40. if not_builder(player) then
  41. local player_inv = player:get_inventory()
  42. player_inv:set_list('main', {})
  43. local game_pos = {x=0, y=0, z=0}
  44. player:setpos({x=game_pos.x+(math.random(-2,2)),y=game_pos.y,z=game_pos.z+(math.random(-2,2))})
  45. end
  46. end)
  47. minetest.register_on_dieplayer(function(player)
  48. local name = player:get_player_name()
  49. local map_id = lobby.game[name]
  50. player:set_physics_override({speed=1})
  51. local player_inv = player:get_inventory()
  52. player_inv:set_list('main', {})
  53. if map_id ~= 'lobby' then
  54. local traitor = lobby.traitors[map_id]
  55. local pos = vector.round(player:get_pos())
  56. local param2 = minetest.dir_to_facedir(player:get_look_dir())
  57. local pos_node = minetest.get_node(pos)
  58. if pos_node.name ~= 'air' then
  59. local air = minetest.find_node_near(pos, 1, {"air"})
  60. minetest.set_node(air, {name = "lobby:corpse", param2 = param2})
  61. lobby.corpse_entry(air, map_id)
  62. else
  63. minetest.set_node(pos, {name = "lobby:corpse", param2 = param2})
  64. lobby.corpse_entry(pos, map_id)
  65. end
  66. local meta = minetest.get_meta(pos)
  67. meta:set_string('infotext', name..'\'s Corpse.')
  68. gamer.player_set_textures(player,{'lobby_ghost.png'})
  69. player:set_nametag_attributes({
  70. color = {a = 0, r = 255, g = 255, b = 255}
  71. })
  72. player:set_properties({visual_size = {x = 0, y = 0}, collisionbox = {-0.3, 0.0, -0.3, 0.3, .2, 0.3}})
  73. player:set_attribute('ghost', 'true')
  74. minetest.chat_send_player(name, 'You\'re now a ghost. Return to the lobby with the /lobby chat command.')
  75. lobby.game[name] = 'lobby'
  76. lobby.update_maps(map_id)
  77. if name == traitor then
  78. lobby.team_win(map_id)
  79. end
  80. end
  81. end)
  82. minetest.register_on_leaveplayer(function(player, timed_out)
  83. local name = player:get_player_name()
  84. local map = lobby.game[name]
  85. if map ~= 'lobby' then
  86. local traitor = lobby.traitors[map]
  87. minetest.chat_send_all('somebody quit the '..map..' level')
  88. local player_inv = player:get_inventory()
  89. player_inv:set_list('main', {})
  90. lobby.update_maps(map)
  91. if traitor == name then
  92. lobby.team_win(map)
  93. end
  94. end
  95. end)
  96. lobby.load()
  97. minetest.register_on_shutdown(lobby.save)