forked from VoxeLibre/VoxeLibre
Added initial logic for damaging mob when it's on a magma block
This commit is contained in:
parent
15c2565f14
commit
f4ff86257f
|
@ -794,7 +794,27 @@ ___ ___ _ _ _
|
|||
]]--
|
||||
|
||||
--the main loop
|
||||
function mobs.mob_step(self, dtime)
|
||||
--this function will be called on every single globalstep, for each invidivual
|
||||
--instance of a mob object
|
||||
local timer = 0
|
||||
function mobs.mob_step(self, dtime) timer = timer + dtime;
|
||||
--gets the current position of the mob
|
||||
local cur_pos = self.object:get_pos()
|
||||
cur_pos['y'] = cur_pos['y'] - 1
|
||||
print(timer)
|
||||
|
||||
-- If the block below the mob is a magma block it gets hurt every half a second
|
||||
if minetest.get_node(cur_pos).name == 'mcl_nether:magma' and timer >= 0.5 then
|
||||
print(minetest.get_node(cur_pos).name)
|
||||
|
||||
-- If the mobs hp is greater than zero, it gets hurt.
|
||||
if self.health > 0 then
|
||||
mcl_util.deal_damage(self.object, 1, {type = "hot_floor"})
|
||||
timer = 0
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
--do not continue if non-existent
|
||||
if not self or not self.object or not self.object:get_luaentity() then
|
||||
|
@ -831,17 +851,28 @@ function mobs.mob_step(self, dtime)
|
|||
end
|
||||
|
||||
--color modifier which coincides with the pause_timer
|
||||
|
||||
--If self.old_health exists and self.health is less than self.old_health this will run
|
||||
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
|
||||
|
||||
--Basically here to make sure there is no way that the mob will get stuck
|
||||
--on the colorized red texture
|
||||
elseif self.health >= 0 then
|
||||
self.object:set_texture_mod("^[colorize:red:0")
|
||||
end
|
||||
|
||||
--Set the old_heath to the new health to make sure on the next loop
|
||||
--iteration things are evaluated correctly
|
||||
self.old_health = self.health
|
||||
|
||||
--do death logic (animation, poof, explosion, etc)
|
||||
if self.health <= 0 or self.dead then
|
||||
self.object:set_texture_mod("^[colorize:red:120")
|
||||
--play death sound once
|
||||
if not self.played_death_sound then
|
||||
self.dead = true
|
||||
|
|
Loading…
Reference in New Issue