mirror of
https://github.com/Poikilos/mobs.git
synced 2023-10-03 07:28:50 -07:00
Merge pull request #4 from HybridDog/dm_sound
Add dm shoot sound 2015 HybridDog
This commit is contained in:
commit
7d880e3ee5
119
api.lua
119
api.lua
@ -29,7 +29,7 @@ function mobs:register_mob(name, def)
|
||||
animation = def.animation,
|
||||
follow = def.follow,
|
||||
jump = def.jump or true,
|
||||
|
||||
|
||||
timer = 0,
|
||||
env_damage_timer = 0, -- only if state = "attack"
|
||||
attack = {player=nil, dist=nil},
|
||||
@ -38,7 +38,7 @@ function mobs:register_mob(name, def)
|
||||
old_y = nil,
|
||||
lifetimer = 600,
|
||||
tamed = false,
|
||||
|
||||
|
||||
set_velocity = function(self, v)
|
||||
local yaw = self.object:getyaw()
|
||||
if self.drawtype == "side" then
|
||||
@ -48,12 +48,12 @@ function mobs:register_mob(name, def)
|
||||
local z = math.cos(yaw) * v
|
||||
self.object:setvelocity({x=x, y=self.object:getvelocity().y, z=z})
|
||||
end,
|
||||
|
||||
|
||||
get_velocity = function(self)
|
||||
local v = self.object:getvelocity()
|
||||
return (v.x^2 + v.z^2)^(0.5)
|
||||
end,
|
||||
|
||||
|
||||
set_animation = function(self, type)
|
||||
if not self.animation then
|
||||
return
|
||||
@ -111,12 +111,12 @@ function mobs:register_mob(name, def)
|
||||
end
|
||||
end
|
||||
end,
|
||||
|
||||
|
||||
on_step = function(self, dtime)
|
||||
if self.type == "monster" and minetest.setting_getbool("only_peaceful_mobs") then
|
||||
self.object:remove()
|
||||
end
|
||||
|
||||
|
||||
self.lifetimer = self.lifetimer - dtime
|
||||
if self.lifetimer <= 0 and not self.tamed then
|
||||
local player_count = 0
|
||||
@ -130,7 +130,7 @@ function mobs:register_mob(name, def)
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
if self.object:getvelocity().y > 0.1 then
|
||||
local yaw = self.object:getyaw()
|
||||
if self.drawtype == "side" then
|
||||
@ -142,7 +142,7 @@ function mobs:register_mob(name, def)
|
||||
else
|
||||
self.object:setacceleration({x=0, y=-10, z=0})
|
||||
end
|
||||
|
||||
|
||||
if self.disable_fall_damage and self.object:getvelocity().y == 0 then
|
||||
if not self.old_y then
|
||||
self.old_y = self.object:getpos().y
|
||||
@ -158,7 +158,7 @@ function mobs:register_mob(name, def)
|
||||
self.old_y = self.object:getpos().y
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
self.timer = self.timer+dtime
|
||||
if self.state ~= "attack" then
|
||||
if self.timer < 1 then
|
||||
@ -166,15 +166,15 @@ function mobs:register_mob(name, def)
|
||||
end
|
||||
self.timer = 0
|
||||
end
|
||||
|
||||
|
||||
if self.sounds and self.sounds.random and math.random(1, 100) <= 1 then
|
||||
minetest.sound_play(self.sounds.random, {object = self.object})
|
||||
end
|
||||
|
||||
|
||||
local do_env_damage = function(self)
|
||||
local pos = self.object:getpos()
|
||||
local n = minetest.env:get_node(pos)
|
||||
|
||||
|
||||
if self.light_damage and self.light_damage ~= 0
|
||||
and pos.y>0
|
||||
and minetest.env:get_node_light(pos)
|
||||
@ -187,7 +187,7 @@ function mobs:register_mob(name, def)
|
||||
self.object:remove()
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
if self.water_damage and self.water_damage ~= 0 and
|
||||
minetest.get_item_group(n.name, "water") ~= 0
|
||||
then
|
||||
@ -196,7 +196,7 @@ function mobs:register_mob(name, def)
|
||||
self.object:remove()
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
if self.lava_damage and self.lava_damage ~= 0 and
|
||||
minetest.get_item_group(n.name, "lava") ~= 0
|
||||
then
|
||||
@ -206,7 +206,7 @@ function mobs:register_mob(name, def)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
self.env_damage_timer = self.env_damage_timer + dtime
|
||||
if self.state == "attack" and self.env_damage_timer > 1 then
|
||||
self.env_damage_timer = 0
|
||||
@ -214,7 +214,7 @@ function mobs:register_mob(name, def)
|
||||
elseif self.state ~= "attack" then
|
||||
do_env_damage(self)
|
||||
end
|
||||
|
||||
|
||||
if self.type == "monster" and minetest.setting_getbool("enable_damage") then
|
||||
for _,player in pairs(minetest.get_connected_players()) do
|
||||
local s = self.object:getpos()
|
||||
@ -235,7 +235,7 @@ function mobs:register_mob(name, def)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
if self.follow ~= "" and not self.following then
|
||||
for _,player in pairs(minetest.get_connected_players()) do
|
||||
local s = self.object:getpos()
|
||||
@ -246,7 +246,7 @@ function mobs:register_mob(name, def)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
if self.following and self.following:is_player() then
|
||||
if self.following:get_wielded_item():get_name() ~= self.follow then
|
||||
self.following = nil
|
||||
@ -290,7 +290,7 @@ function mobs:register_mob(name, def)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
if self.state == "stand" then
|
||||
if math.random(1, 4) == 1 then
|
||||
self.object:setyaw(self.object:getyaw()+((math.random(0,360)-180)/180*math.pi))
|
||||
@ -337,7 +337,7 @@ function mobs:register_mob(name, def)
|
||||
else
|
||||
self.attack.dist = dist
|
||||
end
|
||||
|
||||
|
||||
local vec = {x=p.x-s.x, y=p.y-s.y, z=p.z-s.z}
|
||||
local yaw = math.atan(vec.z/vec.x)+math.pi/2
|
||||
if self.drawtype == "side" then
|
||||
@ -394,7 +394,7 @@ function mobs:register_mob(name, def)
|
||||
else
|
||||
self.attack.dist = dist
|
||||
end
|
||||
|
||||
|
||||
local vec = {x=p.x-s.x, y=p.y-s.y, z=p.z-s.z}
|
||||
local yaw = math.atan(vec.z/vec.x)+math.pi/2
|
||||
if self.drawtype == "side" then
|
||||
@ -405,16 +405,16 @@ function mobs:register_mob(name, def)
|
||||
end
|
||||
self.object:setyaw(yaw)
|
||||
self.set_velocity(self, 0)
|
||||
|
||||
|
||||
if self.timer > self.shoot_interval and math.random(1, 100) <= 60 then
|
||||
self.timer = 0
|
||||
|
||||
|
||||
self:set_animation("punch")
|
||||
|
||||
|
||||
if self.sounds and self.sounds.attack then
|
||||
minetest.sound_play(self.sounds.attack, {object = self.object})
|
||||
end
|
||||
|
||||
|
||||
local p = self.object:getpos()
|
||||
p.y = p.y + (self.collisionbox[2]+self.collisionbox[5])/2
|
||||
local obj = minetest.env:add_entity(p, self.arrow)
|
||||
@ -428,7 +428,7 @@ function mobs:register_mob(name, def)
|
||||
end
|
||||
end
|
||||
end,
|
||||
|
||||
|
||||
on_activate = function(self, staticdata, dtime_s)
|
||||
self.object:set_armor_groups({fleshy=self.armor})
|
||||
self.object:setacceleration({x=0, y=-10, z=0})
|
||||
@ -452,7 +452,7 @@ function mobs:register_mob(name, def)
|
||||
self.object:remove()
|
||||
end
|
||||
end,
|
||||
|
||||
|
||||
get_staticdata = function(self)
|
||||
local tmp = {
|
||||
lifetimer = self.lifetimer,
|
||||
@ -460,7 +460,7 @@ function mobs:register_mob(name, def)
|
||||
}
|
||||
return minetest.serialize(tmp)
|
||||
end,
|
||||
|
||||
|
||||
on_punch = function(self, hitter)
|
||||
if self.object:get_hp() <= 0 then
|
||||
if hitter and hitter:is_player() and hitter:get_inventory() then
|
||||
@ -472,7 +472,7 @@ function mobs:register_mob(name, def)
|
||||
end
|
||||
end
|
||||
end,
|
||||
|
||||
|
||||
})
|
||||
end
|
||||
|
||||
@ -514,7 +514,7 @@ function mobs:register_spawn(name, nodes, max_light, min_light, chance, active_o
|
||||
if spawn_func and not spawn_func(pos, node) then
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
if minetest.setting_getbool("display_mob_spawn") then
|
||||
minetest.chat_send_all("[mobs] Add "..name.." at "..minetest.pos_to_string(pos))
|
||||
end
|
||||
@ -532,10 +532,56 @@ function mobs:register_arrow(name, def)
|
||||
velocity = def.velocity,
|
||||
hit_player = def.hit_player,
|
||||
hit_node = def.hit_node,
|
||||
|
||||
|
||||
count = 0,
|
||||
sounds = {},
|
||||
|
||||
on_step = function(self, dtime)
|
||||
self.object:set_properties({textures = {"mobs_fireball.png^[transform"..math.random(0,7)}})
|
||||
local vel = self.object:getvelocity()
|
||||
local quiet = vector.equals(vel, {x=0,y=0,z=0})
|
||||
if quiet
|
||||
and (not self.vel or vector.equals(self.vel, {x=0,y=0,z=0})) then
|
||||
for _,i in pairs(self.sounds) do
|
||||
minetest.sound_stop(i)
|
||||
end
|
||||
self.object:remove()
|
||||
return
|
||||
end
|
||||
if not self.vel then
|
||||
self.vel = vel
|
||||
self.object:setvelocity({x=0,y=0,z=0})
|
||||
local newp = vector.normalize({x=vel.x, y=0, z=vel.z})
|
||||
self.object:setpos(vector.add(self.object:getpos(), newp))
|
||||
for _,i in pairs(self.sounds) do
|
||||
minetest.sound_stop(i)
|
||||
end
|
||||
end
|
||||
local pos = self.object:getpos()
|
||||
if minetest.env:get_node(self.object:getpos()).name ~= "air" then
|
||||
if quiet then
|
||||
local count = self.count
|
||||
if count >= 60 then
|
||||
minetest.sound_play("mobs_fireball", {pos = pos})
|
||||
for _,i in pairs(self.sounds) do
|
||||
minetest.sound_stop(i)
|
||||
end
|
||||
self.object:setvelocity(self.vel)
|
||||
return
|
||||
end
|
||||
count = count+1
|
||||
self.sounds[count] = minetest.sound_play("mobs_dm", {
|
||||
pos = pos,
|
||||
gain = count/50,
|
||||
loop = true
|
||||
})
|
||||
self.count = count
|
||||
return
|
||||
end
|
||||
for _,i in pairs(self.sounds) do
|
||||
minetest.sound_stop(i)
|
||||
end
|
||||
|
||||
if minetest.env:get_node(pos).name ~= "air" then
|
||||
self.hit_node(self, pos, node)
|
||||
self.object:remove()
|
||||
return
|
||||
@ -548,6 +594,13 @@ function mobs:register_arrow(name, def)
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
end,
|
||||
|
||||
on_serialize = function(self)
|
||||
self.object:remove()
|
||||
for _,i in pairs(self.sounds) do
|
||||
minetest.sound_stop(i)
|
||||
end
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
14
init.lua
14
init.lua
@ -201,7 +201,7 @@ mobs:register_mob("mobs:sheep", {
|
||||
},
|
||||
follow = "farming:wheat",
|
||||
view_range = 5,
|
||||
|
||||
|
||||
on_rightclick = function(self, clicker)
|
||||
local item = clicker:get_wielded_item()
|
||||
if item:get_name() == "farming:wheat" then
|
||||
@ -275,7 +275,7 @@ mobs:register_mob("mobs:rat", {
|
||||
water_damage = 0,
|
||||
lava_damage = 1,
|
||||
light_damage = 0,
|
||||
|
||||
|
||||
on_rightclick = function(self, clicker)
|
||||
if clicker:is_player() and clicker:get_inventory() then
|
||||
clicker:get_inventory():add_item("main", "mobs:rat")
|
||||
@ -288,7 +288,7 @@ mobs:register_spawn("mobs:rat", {"default:dirt_with_grass", "default:stone"}, 20
|
||||
minetest.register_craftitem("mobs:rat", {
|
||||
description = "Rat",
|
||||
inventory_image = "mobs_rat_inventory.png",
|
||||
|
||||
|
||||
on_place = function(itemstack, placer, pointed_thing)
|
||||
if pointed_thing.above then
|
||||
minetest.env:add_entity(pointed_thing.above, "mobs:rat")
|
||||
@ -297,11 +297,11 @@ minetest.register_craftitem("mobs:rat", {
|
||||
return itemstack
|
||||
end,
|
||||
})
|
||||
|
||||
|
||||
minetest.register_craftitem("mobs:rat_cooked", {
|
||||
description = "Cooked Rat",
|
||||
inventory_image = "mobs_cooked_rat.png",
|
||||
|
||||
|
||||
on_use = minetest.item_eat(3),
|
||||
})
|
||||
|
||||
@ -376,9 +376,9 @@ mobs:register_mob("mobs:dungeon_master", {
|
||||
attack_type = "shoot",
|
||||
arrow = "mobs:fireball",
|
||||
shoot_interval = 2.5,
|
||||
sounds = {
|
||||
--[[sounds = {
|
||||
attack = "mobs_fireball",
|
||||
},
|
||||
},--]]
|
||||
animation = {
|
||||
stand_start = 0,
|
||||
stand_end = 19,
|
||||
|
BIN
sounds/mobs_dm.ogg
Normal file
BIN
sounds/mobs_dm.ogg
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user