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.
master
orwell96 2017-01-10 22:54:10 +01:00
parent c2a92608fa
commit ddd42163be
2 changed files with 13 additions and 4 deletions

View File

@ -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");

View File

@ -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