Implement sound api and some sounds
- Level crossing bell - Horns - Subway train driving and door sounds ...to be continued...master
parent
be8aca9fb8
commit
dc67ff7226
|
@ -57,10 +57,14 @@ advtrains.register_wagon(name, prototype, description, inventory_image)
|
||||||
open={
|
open={
|
||||||
[-1]={frames={x=0, y=20}, time=1}, -- open left doors
|
[-1]={frames={x=0, y=20}, time=1}, -- open left doors
|
||||||
[1]={frames={x=40, y=60}, time=1} -- open right doors
|
[1]={frames={x=40, y=60}, time=1} -- open right doors
|
||||||
|
sound = <simpleSoundSpec>
|
||||||
|
^- The sound file of the doors opening. If none is specified, nothing is played.
|
||||||
},
|
},
|
||||||
close={
|
close={
|
||||||
[-1]={frames={x=20, y=40}, time=1}, -- close left doors
|
[-1]={frames={x=20, y=40}, time=1}, -- close left doors
|
||||||
[1]={frames={x=60, y=80}, time=1} -- close right doors
|
[1]={frames={x=60, y=80}, time=1} -- close right doors
|
||||||
|
sound = <simpleSoundSpec>
|
||||||
|
^- The sound file of the doors closing. If none is specified, nothing is played.
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
door_entry={ 1.5, -1.5 }
|
door_entry={ 1.5, -1.5 }
|
||||||
|
@ -77,6 +81,8 @@ advtrains.register_wagon(name, prototype, description, inventory_image)
|
||||||
extent_v = 2,
|
extent_v = 2,
|
||||||
^- Determines the collision box extent in y direction. Defaults to 2 (=3).
|
^- Determines the collision box extent in y direction. Defaults to 2 (=3).
|
||||||
^- The actual bounding box size is extent_v+1, so 0 means 1, 1 means 2, 2 means 3 a.s.o.
|
^- The actual bounding box size is extent_v+1, so 0 means 1, 1 means 2, 2 means 3 a.s.o.
|
||||||
|
horn_sound = <simpleSoundSpec>,
|
||||||
|
^- The sound file of the horn. If none is specified, this wagon can't sound a horn. The specified sound file will be looped.
|
||||||
|
|
||||||
drops = {"default:steelblock 3"}
|
drops = {"default:steelblock 3"}
|
||||||
^- List of itemstrings what to drop when the wagon is destroyed
|
^- List of itemstrings what to drop when the wagon is destroyed
|
||||||
|
|
|
@ -262,7 +262,7 @@ ndb.restore_all = function()
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
ndb.clear(pos)
|
ndb.clear(pos)
|
||||||
atwarn("Found ghost node (former",ndbnode.name,") @",pos,"deleting")
|
atwarn("Found ghost node (former",ndbnode and ndbnode.name,") @",pos,"deleting")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -225,3 +225,19 @@ minetest.register_node("advtrains:across_on", {
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
minetest.register_abm(
|
||||||
|
{
|
||||||
|
label = "Sound for Level Crossing",
|
||||||
|
nodenames = {"advtrains:across_on"},
|
||||||
|
interval = 3,
|
||||||
|
chance = 1,
|
||||||
|
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||||
|
minetest.sound_play("advtrains_crossing_bell", {
|
||||||
|
pos = pos,
|
||||||
|
gain = 1.0, -- default
|
||||||
|
max_hear_distance = 16, -- default, uses an euclidean metric
|
||||||
|
})
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
Binary file not shown.
|
@ -270,6 +270,18 @@ function wagon:on_step(dtime)
|
||||||
if has_driverstand then
|
if has_driverstand then
|
||||||
--regular driver stand controls
|
--regular driver stand controls
|
||||||
advtrains.on_control_change(pc, self:train(), self.wagon_flipped)
|
advtrains.on_control_change(pc, self:train(), self.wagon_flipped)
|
||||||
|
--sound horn when required
|
||||||
|
if self.horn_sound and pc.aux1 and not pc.sneak and not self.horn_handle then
|
||||||
|
self.horn_handle = minetest.sound_play(self.horn_sound, {
|
||||||
|
object = self.object,
|
||||||
|
gain = 1.0, -- default
|
||||||
|
max_hear_distance = 128, -- default, uses an euclidean metric
|
||||||
|
loop = true,
|
||||||
|
})
|
||||||
|
elseif not pc.aux1 and self.horn_handle then
|
||||||
|
minetest.sound_stop(self.horn_handle)
|
||||||
|
self.horn_handle = nil
|
||||||
|
end
|
||||||
else
|
else
|
||||||
-- If on a passenger seat and doors are open, get off when W or D pressed.
|
-- If on a passenger seat and doors are open, get off when W or D pressed.
|
||||||
local pass = self.seatp[seatno] and minetest.get_player_by_name(self.seatp[seatno])
|
local pass = self.seatp[seatno] and minetest.get_player_by_name(self.seatp[seatno])
|
||||||
|
@ -322,10 +334,12 @@ function wagon:on_step(dtime)
|
||||||
-- if changed from 0 to +-1, play open anim. if changed from +-1 to 0, play close.
|
-- if changed from 0 to +-1, play open anim. if changed from +-1 to 0, play close.
|
||||||
-- if changed from +-1 to -+1, first close and set 0, then it will detect state change again and run open.
|
-- if changed from +-1 to -+1, first close and set 0, then it will detect state change again and run open.
|
||||||
if self.door_state == 0 then
|
if self.door_state == 0 then
|
||||||
|
if self.doors.open.sound then minetest.sound_play(self.doors.open.sound, {object = self.object}) end
|
||||||
at=self.doors.open[dstate]
|
at=self.doors.open[dstate]
|
||||||
self.object:set_animation(at.frames, at.speed or 15, at.blend or 0, false)
|
self.object:set_animation(at.frames, at.speed or 15, at.blend or 0, false)
|
||||||
self.door_state = dstate
|
self.door_state = dstate
|
||||||
else
|
else
|
||||||
|
if self.doors.close.sound then minetest.sound_play(self.doors.close.sound, {object = self.object}) end
|
||||||
at=self.doors.close[self.door_state or 1]--in case it has not been set yet
|
at=self.doors.close[self.door_state or 1]--in case it has not been set yet
|
||||||
self.object:set_animation(at.frames, at.speed or 15, at.blend or 0, false)
|
self.object:set_animation(at.frames, at.speed or 15, at.blend or 0, false)
|
||||||
self.door_state = 0
|
self.door_state = 0
|
||||||
|
|
|
@ -39,6 +39,7 @@ advtrains.register_wagon("engine_industrial", {
|
||||||
is_locomotive=true,
|
is_locomotive=true,
|
||||||
collisionbox = {-1.0,-0.5,-1.0, 1.0,2.5,1.0},
|
collisionbox = {-1.0,-0.5,-1.0, 1.0,2.5,1.0},
|
||||||
drops={"default:steelblock 4"},
|
drops={"default:steelblock 4"},
|
||||||
|
horn_sound = "advtrains_industrial_horn",
|
||||||
}, S("Industrial Train Engine"), "advtrains_engine_industrial_inv.png")
|
}, S("Industrial Train Engine"), "advtrains_engine_industrial_inv.png")
|
||||||
advtrains.register_wagon("wagon_tank", {
|
advtrains.register_wagon("wagon_tank", {
|
||||||
mesh="advtrains_wagon_tank.b3d",
|
mesh="advtrains_wagon_tank.b3d",
|
||||||
|
|
Binary file not shown.
|
@ -72,6 +72,7 @@ advtrains.register_wagon("engine_japan", {
|
||||||
is_locomotive=true,
|
is_locomotive=true,
|
||||||
collisionbox = {-1.0,-0.5,-1.0, 1.0,2.5,1.0},
|
collisionbox = {-1.0,-0.5,-1.0, 1.0,2.5,1.0},
|
||||||
drops={"default:steelblock 4"},
|
drops={"default:steelblock 4"},
|
||||||
|
horn_sound = "advtrains_japan_horn",
|
||||||
}, S("Japanese Train Engine"), "advtrains_engine_japan_inv.png")
|
}, S("Japanese Train Engine"), "advtrains_engine_japan_inv.png")
|
||||||
|
|
||||||
advtrains.register_wagon("wagon_japan", {
|
advtrains.register_wagon("wagon_japan", {
|
||||||
|
|
Binary file not shown.
|
@ -71,6 +71,7 @@ advtrains.register_wagon("newlocomotive", {
|
||||||
})
|
})
|
||||||
end,
|
end,
|
||||||
drops={"default:steelblock 4"},
|
drops={"default:steelblock 4"},
|
||||||
|
horn_sound = "advtrains_steam_whistle",
|
||||||
}, S("Steam Engine"), "advtrains_engine_steam_inv.png")
|
}, S("Steam Engine"), "advtrains_engine_steam_inv.png")
|
||||||
|
|
||||||
advtrains.register_wagon("detailed_steam_engine", {
|
advtrains.register_wagon("detailed_steam_engine", {
|
||||||
|
@ -139,6 +140,7 @@ advtrains.register_wagon("detailed_steam_engine", {
|
||||||
})
|
})
|
||||||
end,
|
end,
|
||||||
drops={"default:steelblock 4"},
|
drops={"default:steelblock 4"},
|
||||||
|
horn_sound = "advtrains_steam_whistle",
|
||||||
}, S("Detailed Steam Engine"), "advtrains_detailed_engine_steam_inv.png")
|
}, S("Detailed Steam Engine"), "advtrains_detailed_engine_steam_inv.png")
|
||||||
|
|
||||||
advtrains.register_wagon("wagon_default", {
|
advtrains.register_wagon("wagon_default", {
|
||||||
|
|
Binary file not shown.
|
@ -59,11 +59,13 @@ advtrains.register_wagon("subway_wagon", {
|
||||||
doors={
|
doors={
|
||||||
open={
|
open={
|
||||||
[-1]={frames={x=0, y=20}, time=1},
|
[-1]={frames={x=0, y=20}, time=1},
|
||||||
[1]={frames={x=40, y=60}, time=1}
|
[1]={frames={x=40, y=60}, time=1},
|
||||||
|
sound = "advtrains_subway_dopen",
|
||||||
},
|
},
|
||||||
close={
|
close={
|
||||||
[-1]={frames={x=20, y=40}, time=1},
|
[-1]={frames={x=20, y=40}, time=1},
|
||||||
[1]={frames={x=60, y=80}, time=1}
|
[1]={frames={x=60, y=80}, time=1},
|
||||||
|
sound = "advtrains_subway_dclose",
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
door_entry={-1, 1},
|
door_entry={-1, 1},
|
||||||
|
@ -73,10 +75,26 @@ advtrains.register_wagon("subway_wagon", {
|
||||||
collisionbox = {-1.0,-0.5,-1.0, 1.0,2.5,1.0},
|
collisionbox = {-1.0,-0.5,-1.0, 1.0,2.5,1.0},
|
||||||
is_locomotive=true,
|
is_locomotive=true,
|
||||||
drops={"default:steelblock 4"},
|
drops={"default:steelblock 4"},
|
||||||
--custom_on_activate = function(self, dtime_s)
|
horn_sound = "advtrains_subway_horn",
|
||||||
-- atprint("subway custom_on_activate")
|
custom_on_velocity_change = function(self, velocity, old_velocity)
|
||||||
-- self.object:set_animation({x=1,y=80}, 15, 0, true)
|
if old_velocity == 0 and velocity > 0 then
|
||||||
--end,
|
minetest.sound_play("advtrains_subway_depart", {object = self.object})
|
||||||
|
end
|
||||||
|
if velocity < 2 and (old_velocity >= 2 or old_velocity == velocity) and not self.sound_arrive_handle then
|
||||||
|
self.sound_arrive_handle = minetest.sound_play("advtrains_subway_arrive", {object = self.object})
|
||||||
|
elseif (velocity > old_velocity) and self.sound_arrive_handle then
|
||||||
|
minetest.sound_stop(self.sound_arrive_handle)
|
||||||
|
self.sound_arrive_handle = nil
|
||||||
|
end
|
||||||
|
if velocity > 0 and not self.sound_loop_handle then
|
||||||
|
self.sound_loop_handle = minetest.sound_play({name="advtrains_subway_loop", gain=0.3}, {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
|
||||||
|
end
|
||||||
|
end,
|
||||||
}, S("Subway Passenger Wagon"), "advtrains_subway_wagon_inv.png")
|
}, S("Subway Passenger Wagon"), "advtrains_subway_wagon_inv.png")
|
||||||
|
|
||||||
--wagons
|
--wagons
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -24,6 +24,13 @@ Inventory images : mbb
|
||||||
Small code contributions : NaruTrey
|
Small code contributions : NaruTrey
|
||||||
Major code contributions : gpcf
|
Major code contributions : gpcf
|
||||||
Mod Description : hajo
|
Mod Description : hajo
|
||||||
|
Sounds:
|
||||||
|
advtrains_crossing_bell : Codesound
|
||||||
|
advtrains_japan_horn : Codesound
|
||||||
|
advtrains_steam_whistle : googol
|
||||||
|
advtrains_subway_horn : https://freesound.org/people/Mullumbimby/sounds/385283/
|
||||||
|
advtrains_subway_* : Gabriel (gpcf, gbl08ma)
|
||||||
|
|
||||||
If I forgot someone please punish me for that.
|
If I forgot someone please punish me for that.
|
||||||
|
|
||||||
You can see this mod in action on Linuxworks Next Generation server.
|
You can see this mod in action on Linuxworks Next Generation server.
|
||||||
|
|
Loading…
Reference in New Issue