1
0
Fork 0

Add in random sounds/hurt/death sounds and stop mobs from reviving on server restart again

This commit is contained in:
jordan4ibanez 2021-04-25 01:14:48 -04:00
parent 0a380265c8
commit 7733e05a12
10 changed files with 53 additions and 12 deletions

View File

@ -264,7 +264,6 @@ function mobs:register_mob(name, def)
tamed = false, tamed = false,
pause_timer = 0, pause_timer = 0,
gotten = false, gotten = false,
health = 0,
reach = def.reach or 3, reach = def.reach or 3,
htimer = 0, htimer = 0,
texture_list = def.textures, texture_list = def.textures,
@ -362,6 +361,10 @@ function mobs:register_mob(name, def)
ignores_cobwebs = def.ignores_cobwebs, ignores_cobwebs = def.ignores_cobwebs,
breath = def.breath_max or 6, breath = def.breath_max or 6,
--random_sound_timer = 0,
random_sound_timer_min = 3,
random_sound_timer_max = 10,
--end j4i stuff --end j4i stuff
-- MCL2 extensions -- MCL2 extensions

View File

@ -829,9 +829,18 @@ mobs.mob_step = function(self, dtime)
end end
end end
--do death logic (animation, poof, explosion, etc) --color modifier which coincides with the pause_timer
if self.health <= 0 then if self.old_health and self.health < self.old_health then
self.object:set_texture_mod("^[colorize:red:120")
--fix double death sound
if self.health > 0 then
mobs.play_sound(self,"damage")
end
end
self.old_health = self.health
--do death logic (animation, poof, explosion, etc)
if self.health <= 0 or self.dead then
--play death sound once --play death sound once
if not self.played_death_sound then if not self.played_death_sound then
self.dead = true self.dead = true
@ -855,12 +864,9 @@ mobs.mob_step = function(self, dtime)
return return
end end
--color modifier which coincides with the pause_timer mobs.random_sound_handling(self,dtime)
if self.old_health and self.health < self.old_health then
self.object:set_texture_mod("^[colorize:red:120")
mobs.play_sound(self,"damage")
end
self.old_health = self.health
--mobs drowning mechanic --mobs drowning mechanic

View File

@ -137,10 +137,17 @@ mobs.mob_activate = function(self, staticdata, def, dtime)
} }
end end
if not self.dead and self.health == 0 then --stop mobs from reviving
if not self.dead and not self.health then
self.health = math_random (self.hp_min, self.hp_max) self.health = math_random (self.hp_min, self.hp_max)
end end
if not self.random_sound_timer then
self.random_sound_timer = math_random(self.random_sound_timer_min,self.random_sound_timer_max)
end
if self.breath == nil then if self.breath == nil then
self.breath = self.breath_max self.breath = self.breath_max
end end
@ -178,13 +185,21 @@ mobs.mob_activate = function(self, staticdata, def, dtime)
self.opinion_sound_cooloff = 0 -- used to prevent sound spam of particular sound types self.opinion_sound_cooloff = 0 -- used to prevent sound spam of particular sound types
self.texture_mods = {} self.texture_mods = {}
self.object:set_texture_mod("")
self.v_start = false self.v_start = false
self.timer = 0 self.timer = 0
self.blinktimer = 0 self.blinktimer = 0
self.blinkstatus = false self.blinkstatus = false
--continue mob effect on server restart
if self.dead or self.health <= 0 then
self.object:set_texture_mod("^[colorize:red:120")
else
self.object:set_texture_mod("")
end
-- check existing nametag -- check existing nametag
if not self.nametag then if not self.nametag then
self.nametag = def.nametag self.nametag = def.nametag

View File

@ -22,11 +22,26 @@ end
--generic sound handler for mobs --generic sound handler for mobs
mobs.play_sound_handler = function(self, sound) mobs.play_sound_handler = function(self, sound)
local pitch = (100 + math_random(-15,15) + math_random()) / 100 local pitch = (100 + math_random(-15,15) + math_random()) / 100
local distance = self.sounds.distance or 16
minetest.sound_play(sound, { minetest.sound_play(sound, {
object = self.object, object = self.object,
gain = 1.0, gain = 1.0,
max_hear_distance = self.sounds.distance, max_hear_distance = distance,
pitch = pitch, pitch = pitch,
}, true) }, true)
end
--random sound timing handler
mobs.random_sound_handling = function(self,dtime)
self.random_sound_timer = self.random_sound_timer - dtime
--play sound and reset timer
if self.random_sound_timer <= 0 then
mobs.play_sound(self,"random")
self.random_sound_timer = math_random(self.random_sound_timer_min,self.random_sound_timer_max)
end
end end

View File

@ -971,6 +971,8 @@ mobs:register_mob("mobs_mc:villager", {
-- TODO: sounds -- TODO: sounds
sounds = { sounds = {
random = "mobs_mc_villager", random = "mobs_mc_villager",
damage = "mobs_mc_villager_hurt",
death = "mobs_mc_villager_hurt",
distance = 10, distance = 10,
}, },
animation = { animation = {