diff --git a/README.txt b/README.txt index 87c5f8e..b7e0d91 100644 --- a/README.txt +++ b/README.txt @@ -63,6 +63,9 @@ This mod add some functions that you can use in other mods: maybe somehting like "explode" in the future (creeper)) arrow: if the attack_type="shoot" needed: the entity name of the arrow 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) This function adds the spawning of an animal (without it the registered animals and monster won't spawn!) diff --git a/api.lua b/api.lua index 8f873e3..f2d1af8 100644 --- a/api.lua +++ b/api.lua @@ -23,6 +23,7 @@ function mobs:register_mob(name, def) attack_type = def.attack_type, arrow = def.arrow, shoot_interval = def.shoot_interval, + sounds = def.sounds, timer = 0, attack = {player=nil, dist=nil}, @@ -85,6 +86,10 @@ function mobs:register_mob(name, def) self.timer = 0 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) 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, { @@ -215,6 +220,9 @@ function mobs:register_mob(name, def) if self.damage > 2 then d1 = 1/(self.damage-2) 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, { full_punch_interval=1.0, groupcaps={ @@ -251,6 +259,10 @@ function mobs:register_mob(name, def) if self.timer > self.shoot_interval and math.random(1, 100) <= 60 then 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 amount = (vec.x^2+vec.y^2+vec.z^2)^0.5 local v = obj:get_luaentity().velocity diff --git a/init.lua b/init.lua index 76bd69b..1047533 100644 --- a/init.lua +++ b/init.lua @@ -105,6 +105,9 @@ mobs:register_mob("mobs:sheep", { water_damage = 1, lava_damage = 5, light_damage = 0, + sounds = { + random = "mobs_sheep", + }, on_rightclick = function(self, clicker) if self.naked then @@ -241,6 +244,9 @@ mobs:register_mob("mobs:dungeon_master", { attack_type = "shoot", arrow = "mobs:fireball", shoot_interval = 2.5, + sounds = { + attack = "mobs_fireball", + }, }) mobs:register_spawn("mobs:dungeon_master", {"default:stone"}, 2, -1, 7000, 0) diff --git a/sounds/mobs_fireball.ogg b/sounds/mobs_fireball.ogg new file mode 100644 index 0000000..bdc4ac2 Binary files /dev/null and b/sounds/mobs_fireball.ogg differ diff --git a/sounds/mobs_sheep.ogg b/sounds/mobs_sheep.ogg new file mode 100644 index 0000000..4e7e232 Binary files /dev/null and b/sounds/mobs_sheep.ogg differ