aboutsummaryrefslogtreecommitdiff
path: root/advtrains
diff options
context:
space:
mode:
authororwell96 <mono96.mml@gmail.com>2017-01-10 22:54:10 +0100
committerorwell96 <mono96.mml@gmail.com>2017-01-10 22:54:10 +0100
commitddd42163be2f845cd1f201a2fb7b6fb2267b3705 (patch)
treead75b4b63ffc2b67388642944366f41ef6929353 /advtrains
parentc2a92608fa896d805a8e7cf4c13846c06e987b4f (diff)
downloadadvtrains-ddd42163be2f845cd1f201a2fb7b6fb2267b3705.tar.gz
advtrains-ddd42163be2f845cd1f201a2fb7b6fb2267b3705.tar.bz2
advtrains-ddd42163be2f845cd1f201a2fb7b6fb2267b3705.zip
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.
Diffstat (limited to 'advtrains')
-rw-r--r--advtrains/advtrains/init.lua4
-rw-r--r--advtrains/advtrains/wagons.lua13
2 files changed, 13 insertions, 4 deletions
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