Add sound

master
PilzAdam 2012-09-21 16:05:17 +02:00
parent e74cc2a6b0
commit b2e3d1f599
5 changed files with 21 additions and 0 deletions

View File

@ -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!)

12
api.lua
View File

@ -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

View File

@ -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)

BIN
sounds/mobs_fireball.ogg Normal file

Binary file not shown.

BIN
sounds/mobs_sheep.ogg Normal file

Binary file not shown.