diff options
author | orwell96 <mono96.mml@gmail.com> | 2017-01-10 22:54:10 +0100 |
---|---|---|
committer | orwell96 <mono96.mml@gmail.com> | 2017-01-10 22:54:10 +0100 |
commit | ddd42163be2f845cd1f201a2fb7b6fb2267b3705 (patch) | |
tree | ad75b4b63ffc2b67388642944366f41ef6929353 /advtrains/advtrains/wagons.lua | |
parent | c2a92608fa896d805a8e7cf4c13846c06e987b4f (diff) | |
download | advtrains-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.lua | 13 |
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
|