commit
737b769307
22
init.lua
22
init.lua
|
@ -413,12 +413,28 @@ function mobkit.animate(self,anim)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function mobkit.make_sound(self,sound)
|
function mobkit.make_sound(self, sound)
|
||||||
if self.sounds and self.sounds[sound] then
|
local spec = self.sounds[sound]
|
||||||
minetest.sound_play(self.sounds[sound], {object=self.object})
|
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
|
end
|
||||||
|
return minetest.sound_play(spec, param_table)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function mobkit.is_neighbor_node_reachable(self,neighbor) -- todo: take either number or pos
|
function mobkit.is_neighbor_node_reachable(self,neighbor) -- todo: take either number or pos
|
||||||
local offset = neighbors[neighbor]
|
local offset = neighbors[neighbor]
|
||||||
local pos=mobkit.get_stand_pos(self)
|
local pos=mobkit.get_stand_pos(self)
|
||||||
|
|
|
@ -208,9 +208,32 @@ minetest.register_entity("mod:name",{
|
||||||
...
|
...
|
||||||
}
|
}
|
||||||
sounds = {
|
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
|
max_speed = [num], -- m/s
|
||||||
jump_height = [num], -- nodes/meters
|
jump_height = [num], -- nodes/meters
|
||||||
view_range = [num], -- nodes/meters
|
view_range = [num], -- nodes/meters
|
||||||
|
@ -336,6 +359,7 @@ function mobkit.animate(self,anim)
|
||||||
function mobkit.make_sound(self,sound)
|
function mobkit.make_sound(self,sound)
|
||||||
-- sound is string, see entity definition
|
-- 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)
|
function mobkit.go_forward_horizontal(self,speed)
|
||||||
-- sets an entity's horizontal velocity in yaw direction. Vertical velocity unaffected.
|
-- sets an entity's horizontal velocity in yaw direction. Vertical velocity unaffected.
|
||||||
|
|
Loading…
Reference in New Issue