From ddd42163be2f845cd1f201a2fb7b6fb2267b3705 Mon Sep 17 00:00:00 2001 From: orwell96 Date: Tue, 10 Jan 2017 22:54:10 +0100 Subject: Prevent non-initialized wagons from accidentally polluting the world sometimes wagons get created/loaded but are not initialized. These stand around and can't be removed. Now if a wagon does not get initialized after 20 steps, something went wrong and the wagon is removed. --- advtrains/advtrains/init.lua | 4 ++-- advtrains/advtrains/wagons.lua | 13 +++++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) (limited to 'advtrains') diff --git a/advtrains/advtrains/init.lua b/advtrains/advtrains/init.lua index 03ec553..a415857 100644 --- a/advtrains/advtrains/init.lua +++ b/advtrains/advtrains/init.lua @@ -34,8 +34,8 @@ local function print_concat_table(a) end return str end ---atprint=function() end -atprint=function(t, ...) minetest.log("action", "[advtrains]"..print_concat_table({t, ...})) minetest.chat_send_all("[advtrains]"..print_concat_table({t, ...})) end +atprint=function() end +--atprint=function(t, ...) minetest.log("action", "[advtrains]"..print_concat_table({t, ...})) minetest.chat_send_all("[advtrains]"..print_concat_table({t, ...})) end sid=function(id) return string.sub(id, -4) end dofile(advtrains.modpath.."/helpers.lua"); diff --git a/advtrains/advtrains/wagons.lua b/advtrains/advtrains/wagons.lua index bedffda..13811ad 100644 --- a/advtrains/advtrains/wagons.lua +++ b/advtrains/advtrains/wagons.lua @@ -151,8 +151,17 @@ function wagon:init_shared() end end function wagon:ensure_init() - if self.initialized then return true end - self.object:setvelocity({x=0,y=0,z=0}) + if self.initialized then + if self.noninitticks then self.noninitticks=nil end + return true + end + if not self.noninitticks then self.noninitticks=0 end + self.noninitticks=self.noninitticks+1 + if self.noninitticks>20 then + self.object:remove() + else + self.object:setvelocity({x=0,y=0,z=0}) + end return false end -- cgit v1.2.3