From 1d9dfaa785002fd6f3591503c469bd4d7eb98ed0 Mon Sep 17 00:00:00 2001 From: brittm3 Date: Mon, 21 Nov 2016 13:18:21 -0600 Subject: [PATCH] Fix player sky race. Fixes a bug that would leave the player's sky permanently white after two lightning strikes occur in rapid succession. --- init.lua | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/init.lua b/init.lua index 4597ced..cc77de9 100644 --- a/init.lua +++ b/init.lua @@ -34,8 +34,9 @@ local revertsky = function() return end - for i = 1, table.getn(ps) do - ps[i].p:set_sky(ps[i].sky.bgcolor, ps[i].sky.type, ps[i].sky.textures) + for key, entry in pairs(ps) do + local sky = entry.sky + entry.p:set_sky(sky.bgcolor, sky.type, sky.textures) end ps = {} @@ -130,11 +131,18 @@ lightning.strike = function(pos) local playerlist = minetest.get_connected_players() for i = 1, #playerlist do + local player = playerlist[i] local sky = {} - sky.bgcolor, sky.type, sky.textures = playerlist[i]:get_sky() - table.insert(ps, { p = playerlist[i], sky = sky}) - playerlist[i]:set_sky(0xffffff, "plain", {}) + + sky.bgcolor, sky.type, sky.textures = player:get_sky() + + local name = player:get_player_name() + if ps[name] == nil then + ps[name] = {p = player, sky = sky} + player:set_sky(0xffffff, "plain", {}) + end end + -- trigger revert of skybox ttl = 5