commit
737b769307
20
init.lua
20
init.lua
|
@ -414,10 +414,26 @@ function mobkit.animate(self,anim)
|
|||
end
|
||||
|
||||
function mobkit.make_sound(self, sound)
|
||||
if self.sounds and self.sounds[sound] then
|
||||
minetest.sound_play(self.sounds[sound], {object=self.object})
|
||||
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]
|
||||
|
|
|
@ -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
|
||||
|
@ -336,6 +359,7 @@ 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
|
||||
--returns sound handle
|
||||
|
||||
function mobkit.go_forward_horizontal(self,speed)
|
||||
-- sets an entity's horizontal velocity in yaw direction. Vertical velocity unaffected.
|
||||
|
|
Loading…
Reference in New Issue