Shuffle spawn positions as well
This commit is contained in:
parent
1f3424289e
commit
797111174b
@ -8,6 +8,8 @@ local countdown = false
|
|||||||
local registrants = {}
|
local registrants = {}
|
||||||
local currGame = {}
|
local currGame = {}
|
||||||
|
|
||||||
|
local spots_shuffled = {}
|
||||||
|
|
||||||
local timer_hudids = {}
|
local timer_hudids = {}
|
||||||
|
|
||||||
local timer = nil
|
local timer = nil
|
||||||
@ -222,7 +224,7 @@ local start_game_now = function(contestants)
|
|||||||
if spawning.is_spawn("player_"..i) then
|
if spawning.is_spawn("player_"..i) then
|
||||||
spawning.spawn(player, "player_"..i)
|
spawning.spawn(player, "player_"..i)
|
||||||
end
|
end
|
||||||
end, {player, i})
|
end, {player, spots_shuffled[i]})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
minetest.chat_send_all("The Hungry Games has begun!")
|
minetest.chat_send_all("The Hungry Games has begun!")
|
||||||
@ -265,8 +267,8 @@ local start_game = function()
|
|||||||
print("filling chests...")
|
print("filling chests...")
|
||||||
random_chests.refill()
|
random_chests.refill()
|
||||||
--Find out how many spots there are to spawn
|
--Find out how many spots there are to spawn
|
||||||
local spots = get_spots()
|
local nspots = get_spots()
|
||||||
local diff = spots-table.getn(registrants)
|
local diff = nspots-table.getn(registrants)
|
||||||
local contestants = {}
|
local contestants = {}
|
||||||
|
|
||||||
-- Shuffle players
|
-- Shuffle players
|
||||||
@ -281,6 +283,20 @@ local start_game = function()
|
|||||||
players_shuffled[j] = players[shuffle_free[rnd]]
|
players_shuffled[j] = players[shuffle_free[rnd]]
|
||||||
table.remove(shuffle_free, rnd)
|
table.remove(shuffle_free, rnd)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Shuffle spots as well
|
||||||
|
shuffle_free = {}
|
||||||
|
spots_shuffled = {}
|
||||||
|
for j=1,nspots do
|
||||||
|
shuffle_free[j] = j
|
||||||
|
end
|
||||||
|
for j=1,nspots do
|
||||||
|
local rnd = math.random(1, #shuffle_free)
|
||||||
|
spots_shuffled[j] = shuffle_free[rnd]
|
||||||
|
table.remove(shuffle_free, rnd)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Spawn players
|
||||||
for p=1,#players_shuffled do
|
for p=1,#players_shuffled do
|
||||||
local player = players_shuffled[p]
|
local player = players_shuffled[p]
|
||||||
if diff > 0 then
|
if diff > 0 then
|
||||||
@ -300,7 +316,7 @@ local start_game = function()
|
|||||||
else
|
else
|
||||||
minetest.chat_send_player(name, "There are no spots for you to spawn!")
|
minetest.chat_send_player(name, "There are no spots for you to spawn!")
|
||||||
end
|
end
|
||||||
end, {player, i})
|
end, {player, spots_shuffled[i]})
|
||||||
if registrants[player:get_player_name()] then i = i + 1 end
|
if registrants[player:get_player_name()] then i = i + 1 end
|
||||||
end
|
end
|
||||||
minetest.setting_set("enable_damage", "false")
|
minetest.setting_set("enable_damage", "false")
|
||||||
@ -308,8 +324,8 @@ local start_game = function()
|
|||||||
set_timer("starting", hungry_games.countdown)
|
set_timer("starting", hungry_games.countdown)
|
||||||
for i=1, (hungry_games.countdown-1) do
|
for i=1, (hungry_games.countdown-1) do
|
||||||
minetest.after(i, function(list)
|
minetest.after(i, function(list)
|
||||||
contestants = list[1]
|
local contestants = list[1]
|
||||||
i = list[2]
|
local i = list[2]
|
||||||
local time_left = hungry_games.countdown-i
|
local time_left = hungry_games.countdown-i
|
||||||
if time_left%4==0 and time_left >= 16 then
|
if time_left%4==0 and time_left >= 16 then
|
||||||
minetest.sound_play("hungry_games_starting_drum")
|
minetest.sound_play("hungry_games_starting_drum")
|
||||||
@ -322,7 +338,7 @@ local start_game = function()
|
|||||||
if spawning.is_spawn("player_"..i) then
|
if spawning.is_spawn("player_"..i) then
|
||||||
spawning.spawn(player, "player_"..i)
|
spawning.spawn(player, "player_"..i)
|
||||||
end
|
end
|
||||||
end, {player, i})
|
end, {player, spots_shuffled[i]})
|
||||||
end
|
end
|
||||||
end, {contestants,i})
|
end, {contestants,i})
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user