diff options
author | Gabriel Pérez-Cerezo <gabriel@gpcf.eu> | 2019-12-01 12:09:04 +0100 |
---|---|---|
committer | Gabriel Pérez-Cerezo <gabriel@gpcf.eu> | 2019-12-01 12:09:04 +0100 |
commit | 0518fbbf3ae388631cb21f238068f2a6b3785972 (patch) | |
tree | 0a70cd4c3a480d32af005f7e1b67cd0e1c30976f /advtrains_train_steam | |
parent | b71c72b4ab4d50c8f3a3a6ccbe15427548e1d2ff (diff) | |
parent | 2157a7ef365902162336540d89d91049c5d3a394 (diff) | |
download | advtrains-0518fbbf3ae388631cb21f238068f2a6b3785972.tar.gz advtrains-0518fbbf3ae388631cb21f238068f2a6b3785972.tar.bz2 advtrains-0518fbbf3ae388631cb21f238068f2a6b3785972.zip |
Merge branch 'master' of https://git.bananach.space/advtrains
Diffstat (limited to 'advtrains_train_steam')
-rwxr-xr-x | advtrains_train_steam/init.lua | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/advtrains_train_steam/init.lua b/advtrains_train_steam/init.lua index db2d087..5d6955c 100755 --- a/advtrains_train_steam/init.lua +++ b/advtrains_train_steam/init.lua @@ -5,6 +5,9 @@ else S = function(s,a,...)a={a,...}return s:gsub("@(%d+)",function(n)return a[tonumber(n)]end)end end +-- length of the steam engine loop sound +local SND_LOOP_LEN = 5 + advtrains.register_wagon("newlocomotive", { mesh="advtrains_engine_steam.b3d", textures = {"advtrains_engine_steam.png"}, @@ -111,14 +114,20 @@ advtrains.register_wagon("detailed_steam_engine", { self.object:set_animation({x=1,y=80}, advtrains.abs_ceil(velocity)*15, 0, true) self.old_anim_velocity=advtrains.abs_ceil(velocity) end - if velocity > 0 and not self.sound_loop_handle then - self.sound_loop_handle = minetest.sound_play({name="advtrains_steam_loop", gain=2}, {object = self.object, loop=true}) - elseif velocity==0 then - if self.sound_loop_handle then - minetest.sound_stop(self.sound_loop_handle) - self.sound_loop_handle = nil + end, + custom_on_step=function(self, dtime) + if self:train().velocity > 0 then -- First make sure that the train isn't standing + if not self.sound_loop_tmr or self.sound_loop_tmr <= 0 then + -- start the sound if it was never started or has expired + self.sound_loop_handle = minetest.sound_play({name="advtrains_steam_loop", gain=2}, {object=self.object}) + self.sound_loop_tmr = SND_LOOP_LEN end - end + --decrease the sound timer + self.sound_loop_tmr = self.sound_loop_tmr - dtime + else + -- If the train is standing, the sound will be stopped in some time. We do not need to interfere with it. + self.sound_loop_tmr = nil + end end, custom_on_activate = function(self, staticdata_table, dtime_s) minetest.add_particlespawner({ |