]> git.lizzy.rs Git - deathswap.git/blob - init.lua
Create README.md
[deathswap.git] / init.lua
1 deathswap = {}
2 deathswap.players = {}
3
4 minetest.register_on_prejoinplayer(function()
5         if #deathswap.players == 2 then
6                 return "Deathswap is full!"
7         end
8 end)
9
10 minetest.register_on_joinplayer(function(player)
11         deathswap.players[#deathswap.players + 1] = player
12         if #deathswap.players == 2 then
13                 deathswap.start_swap()
14         end
15 end)
16
17 minetest.register_on_leaveplayer(function(player)
18         if player == deathswap.players[1] then
19                 table.remove(deathswap.players, 1)
20         elseif player == deathswap.players[2] then
21                 table.remove(deathswap.players, 2)
22         end
23 end)
24
25 minetest.register_on_dieplayer(function(player)
26         minetest.kick_player(player:get_player_name(), "You died :-)")
27 end)
28
29 function deathswap.swap(seconds)
30         if #deathswap.players < 2 then
31                 return
32         end
33         if seconds == 0 then
34                 minetest.chat_send_all(minetest.colorize("#FF7300", "Swapping"))
35                 local pos1 = deathswap.players[1]:get_pos()
36                 local pos2 = deathswap.players[2]:get_pos()
37                 deathswap.players[1]:set_pos(pos2)
38                 deathswap.players[2]:set_pos(pos1)
39                 deathswap.start_swap()
40         else
41                 minetest.chat_send_all(minetest.colorize("#FF7300", "Swapping in " .. seconds .. " seconds"))
42                 minetest.after(1, deathswap.swap, seconds - 1)
43         end
44 end
45
46 function deathswap.start_swap()
47         minetest.after(5 * 60, deathswap.swap, 10)
48 end