Add sound
This commit is contained in:
parent
e74cc2a6b0
commit
b2e3d1f599
@ -63,6 +63,9 @@ This mod add some functions that you can use in other mods:
|
|||||||
maybe somehting like "explode" in the future (creeper))
|
maybe somehting like "explode" in the future (creeper))
|
||||||
arrow: if the attack_type="shoot" needed: the entity name of the arrow
|
arrow: if the attack_type="shoot" needed: the entity name of the arrow
|
||||||
shoot_interval: the minimum shoot interval
|
shoot_interval: the minimum shoot interval
|
||||||
|
sounds: this is a table with sounds of the mob
|
||||||
|
random: a sound that is played randomly
|
||||||
|
attack: a sound that is played when a mob hits a player
|
||||||
2. mobs:register_spawn(name, nodes, max_light, min_light, chance, mobs_per_30_block_radius)
|
2. mobs:register_spawn(name, nodes, max_light, min_light, chance, mobs_per_30_block_radius)
|
||||||
This function adds the spawning of an animal (without it the
|
This function adds the spawning of an animal (without it the
|
||||||
registered animals and monster won't spawn!)
|
registered animals and monster won't spawn!)
|
||||||
|
12
api.lua
12
api.lua
@ -23,6 +23,7 @@ function mobs:register_mob(name, def)
|
|||||||
attack_type = def.attack_type,
|
attack_type = def.attack_type,
|
||||||
arrow = def.arrow,
|
arrow = def.arrow,
|
||||||
shoot_interval = def.shoot_interval,
|
shoot_interval = def.shoot_interval,
|
||||||
|
sounds = def.sounds,
|
||||||
|
|
||||||
timer = 0,
|
timer = 0,
|
||||||
attack = {player=nil, dist=nil},
|
attack = {player=nil, dist=nil},
|
||||||
@ -85,6 +86,10 @@ function mobs:register_mob(name, def)
|
|||||||
self.timer = 0
|
self.timer = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if self.sounds and self.sounds.random and math.random(1, 100) <= 10 then
|
||||||
|
minetest.sound_play(self.sounds.random, {object = self.object})
|
||||||
|
end
|
||||||
|
|
||||||
local do_env_damage = function(self)
|
local do_env_damage = function(self)
|
||||||
if self.light_damage and self.light_damage ~= 0 and self.object:getpos().y>0 and minetest.env:get_node_light(self.object:getpos()) > 3 then
|
if self.light_damage and self.light_damage ~= 0 and self.object:getpos().y>0 and minetest.env:get_node_light(self.object:getpos()) > 3 then
|
||||||
self.object:punch(self.object, 1.0, {
|
self.object:punch(self.object, 1.0, {
|
||||||
@ -215,6 +220,9 @@ function mobs:register_mob(name, def)
|
|||||||
if self.damage > 2 then
|
if self.damage > 2 then
|
||||||
d1 = 1/(self.damage-2)
|
d1 = 1/(self.damage-2)
|
||||||
end
|
end
|
||||||
|
if self.sounds and self.sounds.attack then
|
||||||
|
minetest.sound_play(self.sounds.attack, {object = self.object})
|
||||||
|
end
|
||||||
self.attack.player:punch(self.object, 1.0, {
|
self.attack.player:punch(self.object, 1.0, {
|
||||||
full_punch_interval=1.0,
|
full_punch_interval=1.0,
|
||||||
groupcaps={
|
groupcaps={
|
||||||
@ -251,6 +259,10 @@ function mobs:register_mob(name, def)
|
|||||||
if self.timer > self.shoot_interval and math.random(1, 100) <= 60 then
|
if self.timer > self.shoot_interval and math.random(1, 100) <= 60 then
|
||||||
self.timer = 0
|
self.timer = 0
|
||||||
|
|
||||||
|
if self.sounds and self.sounds.attack then
|
||||||
|
minetest.sound_play(self.sounds.attack, {object = self.object})
|
||||||
|
end
|
||||||
|
|
||||||
local obj = minetest.env:add_entity(self.object:getpos(), self.arrow)
|
local obj = minetest.env:add_entity(self.object:getpos(), self.arrow)
|
||||||
local amount = (vec.x^2+vec.y^2+vec.z^2)^0.5
|
local amount = (vec.x^2+vec.y^2+vec.z^2)^0.5
|
||||||
local v = obj:get_luaentity().velocity
|
local v = obj:get_luaentity().velocity
|
||||||
|
6
init.lua
6
init.lua
@ -105,6 +105,9 @@ mobs:register_mob("mobs:sheep", {
|
|||||||
water_damage = 1,
|
water_damage = 1,
|
||||||
lava_damage = 5,
|
lava_damage = 5,
|
||||||
light_damage = 0,
|
light_damage = 0,
|
||||||
|
sounds = {
|
||||||
|
random = "mobs_sheep",
|
||||||
|
},
|
||||||
|
|
||||||
on_rightclick = function(self, clicker)
|
on_rightclick = function(self, clicker)
|
||||||
if self.naked then
|
if self.naked then
|
||||||
@ -241,6 +244,9 @@ mobs:register_mob("mobs:dungeon_master", {
|
|||||||
attack_type = "shoot",
|
attack_type = "shoot",
|
||||||
arrow = "mobs:fireball",
|
arrow = "mobs:fireball",
|
||||||
shoot_interval = 2.5,
|
shoot_interval = 2.5,
|
||||||
|
sounds = {
|
||||||
|
attack = "mobs_fireball",
|
||||||
|
},
|
||||||
})
|
})
|
||||||
mobs:register_spawn("mobs:dungeon_master", {"default:stone"}, 2, -1, 7000, 0)
|
mobs:register_spawn("mobs:dungeon_master", {"default:stone"}, 2, -1, 7000, 0)
|
||||||
|
|
||||||
|
BIN
sounds/mobs_fireball.ogg
Normal file
BIN
sounds/mobs_fireball.ogg
Normal file
Binary file not shown.
BIN
sounds/mobs_sheep.ogg
Normal file
BIN
sounds/mobs_sheep.ogg
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user