aboutsummaryrefslogtreecommitdiff
path: root/advtrains/advtrains/wagons.lua
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/advtrains/wagons.lua
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/advtrains/wagons.lua')
-rw-r--r--advtrains/advtrains/wagons.lua13
1 files changed, 11 insertions, 2 deletions
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