Merge pull request #7 from NetherEran/make-sound-enhancement

Make sound enhancement
master
TheTermos 2019-11-02 20:03:47 +01:00 committed by GitHub
commit 737b769307
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 46 additions and 6 deletions

View File

@ -413,12 +413,28 @@ function mobkit.animate(self,anim)
end
end
function mobkit.make_sound(self,sound)
if self.sounds and self.sounds[sound] then
minetest.sound_play(self.sounds[sound], {object=self.object})
function mobkit.make_sound(self, sound)
local spec = self.sounds[sound]
local param_table = {object=self.object}
if type(spec) == 'table' then
--pick random sound if it's a spec for random sounds
if #spec > 0 then spec = spec[random(#spec)] end
--returns value or a random value within the range [value[1], value[2])
local function in_range(value)
return type(value) == 'table' and value[1]+random()*(value[2]-value[1]) or value
end
--pick random values within a range if they're a table
param_table.gain = in_range(spec.gain)
param_table.fade = in_range(spec.fade)
param_table.pitch = in_range(spec.pitch)
end
return minetest.sound_play(spec, param_table)
end
function mobkit.is_neighbor_node_reachable(self,neighbor) -- todo: take either number or pos
local offset = neighbors[neighbor]
local pos=mobkit.get_stand_pos(self)

View File

@ -208,9 +208,32 @@ minetest.register_entity("mod:name",{
...
}
sounds = {
[name] = [string filename],
[name] = [string filename], --single, simple,
[name] = { --single, more powerful. All fields but 'name' are optional
name = [string filename],
gain=[num or range], --range is a table of the format {left_bound, right_bound}
fade=[num or range],
pitch=[num or range],
},
[name] = { --variant, sound is chosen randomly
{
name = [string filename],
gain=[num or range],
fade=[num or range],
pitch=[num or range],
},
{
name = [string filename],
gain=[num or range],
fade=[num or range],
pitch=[num or range],
},
...
},
...
}
},
max_speed = [num], -- m/s
jump_height = [num], -- nodes/meters
view_range = [num], -- nodes/meters
@ -335,7 +358,8 @@ function mobkit.animate(self,anim)
function mobkit.make_sound(self,sound)
-- sound is string, see entity definition
-- makes an entity play sound, or does nothing if not defined
-- makes an entity play sound, or does nothing if not defined
--returns sound handle
function mobkit.go_forward_horizontal(self,speed)
-- sets an entity's horizontal velocity in yaw direction. Vertical velocity unaffected.