forked from mtcontrib/mobs_redo
death check added, cooks drops if died in fire/lava/pick_lava
This commit is contained in:
parent
7de8bc4c24
commit
646020db94
108
api.lua
108
api.lua
@ -1,8 +1,9 @@
|
|||||||
|
|
||||||
-- Mobs Api (12th May 2017)
|
-- Mobs Api (27th May 2017)
|
||||||
|
|
||||||
mobs = {}
|
mobs = {}
|
||||||
mobs.mod = "redo"
|
mobs.mod = "redo"
|
||||||
|
mobs.version = "20170527"
|
||||||
|
|
||||||
|
|
||||||
-- Intllib
|
-- Intllib
|
||||||
@ -316,13 +317,60 @@ function update_tag(self)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
-- drop items
|
||||||
|
function item_drop(self, cooked)
|
||||||
|
|
||||||
|
local obj, ent, item, num
|
||||||
|
local pos = self.object:getpos()
|
||||||
|
|
||||||
|
self.drops = self.drops or {} -- nil check
|
||||||
|
|
||||||
|
for n = 1, #self.drops do
|
||||||
|
|
||||||
|
if random(1, self.drops[n].chance) == 1 then
|
||||||
|
|
||||||
|
num = random(self.drops[n].min, self.drops[n].max)
|
||||||
|
item = self.drops[n].name
|
||||||
|
|
||||||
|
-- cook items when true
|
||||||
|
if cooked then
|
||||||
|
|
||||||
|
local output = minetest.get_craft_result({
|
||||||
|
method = "cooking", width = 1, items = {item}})
|
||||||
|
|
||||||
|
if output and output.item and not output.item:is_empty() then
|
||||||
|
item = output.item:get_name()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- add item if it exists
|
||||||
|
obj = minetest.add_item(pos, ItemStack(item .. " " .. num))
|
||||||
|
ent = obj:get_luaentity()
|
||||||
|
|
||||||
|
if ent then
|
||||||
|
|
||||||
|
obj:setvelocity({
|
||||||
|
x = random(-10, 10) / 9,
|
||||||
|
y = 6,
|
||||||
|
z = random(-10, 10) / 9,
|
||||||
|
})
|
||||||
|
else
|
||||||
|
obj:remove() -- item does not exist
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
self.drops = {}
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
-- check if mob is dead or only hurt
|
-- check if mob is dead or only hurt
|
||||||
function check_for_death(self)
|
function check_for_death(self, cause)
|
||||||
|
|
||||||
-- has health actually changed?
|
-- has health actually changed?
|
||||||
if self.health == self.old_health then
|
-- if self.health == self.old_health then
|
||||||
return
|
-- return
|
||||||
end
|
-- end
|
||||||
|
|
||||||
self.old_health = self.health
|
self.old_health = self.health
|
||||||
|
|
||||||
@ -352,28 +400,10 @@ function check_for_death(self)
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
-- drop items when dead
|
if cause == "lava" then
|
||||||
local obj
|
item_drop(self, true)
|
||||||
local pos = self.object:getpos()
|
else
|
||||||
self.drops = self.drops or {} -- nil check
|
item_drop(self, nil)
|
||||||
|
|
||||||
for n = 1, #self.drops do
|
|
||||||
|
|
||||||
if random(1, self.drops[n].chance) == 1 then
|
|
||||||
|
|
||||||
obj = minetest.add_item(pos,
|
|
||||||
ItemStack(self.drops[n].name .. " "
|
|
||||||
.. random(self.drops[n].min, self.drops[n].max)))
|
|
||||||
|
|
||||||
if obj then
|
|
||||||
|
|
||||||
obj:setvelocity({
|
|
||||||
x = random(-10, 10) / 9,
|
|
||||||
y = 6,
|
|
||||||
z = random(-10, 10) / 9,
|
|
||||||
})
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
mob_sound(self, self.sounds.death)
|
mob_sound(self, self.sounds.death)
|
||||||
@ -511,6 +541,8 @@ do_env_damage = function(self)
|
|||||||
self.health = self.health - self.light_damage
|
self.health = self.health - self.light_damage
|
||||||
|
|
||||||
effect(pos, 5, "tnt_smoke.png")
|
effect(pos, 5, "tnt_smoke.png")
|
||||||
|
|
||||||
|
if check_for_death(self, "light") then return end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- what is mob standing in?
|
-- what is mob standing in?
|
||||||
@ -539,6 +571,8 @@ do_env_damage = function(self)
|
|||||||
|
|
||||||
effect(pos, 5, "bubble.png", nil, nil, 1, nil)
|
effect(pos, 5, "bubble.png", nil, nil, 1, nil)
|
||||||
|
|
||||||
|
if check_for_death(self, "water") then return end
|
||||||
|
|
||||||
-- lava or fire
|
-- lava or fire
|
||||||
elseif self.lava_damage ~= 0
|
elseif self.lava_damage ~= 0
|
||||||
and (nodef.groups.lava
|
and (nodef.groups.lava
|
||||||
@ -549,6 +583,8 @@ do_env_damage = function(self)
|
|||||||
|
|
||||||
effect(pos, 5, "fire_basic_flame.png", nil, nil, 1, nil)
|
effect(pos, 5, "fire_basic_flame.png", nil, nil, 1, nil)
|
||||||
|
|
||||||
|
if check_for_death(self, "lava") then return end
|
||||||
|
|
||||||
-- damage_per_second node check
|
-- damage_per_second node check
|
||||||
-- elseif minetest.registered_nodes[self.standing_in].damage_per_second ~= 0 then
|
-- elseif minetest.registered_nodes[self.standing_in].damage_per_second ~= 0 then
|
||||||
|
|
||||||
@ -560,7 +596,7 @@ do_env_damage = function(self)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
check_for_death(self)
|
check_for_death(self, "")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -1835,6 +1871,8 @@ local do_states = function(self, dtime)
|
|||||||
vec.z = vec.z * (v / amount)
|
vec.z = vec.z * (v / amount)
|
||||||
|
|
||||||
obj:setvelocity(vec)
|
obj:setvelocity(vec)
|
||||||
|
else
|
||||||
|
obj:remove() -- arrow entity does not exist
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -1893,7 +1931,7 @@ local falling = function(self, pos)
|
|||||||
|
|
||||||
effect(pos, 5, "tnt_smoke.png", 1, 2, 2, nil)
|
effect(pos, 5, "tnt_smoke.png", 1, 2, 2, nil)
|
||||||
|
|
||||||
if check_for_death(self) then
|
if check_for_death(self, "fall") then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -2017,9 +2055,15 @@ local mob_punch = function(self, hitter, tflp, tool_capabilities, dir)
|
|||||||
-- do damage
|
-- do damage
|
||||||
self.health = self.health - floor(damage)
|
self.health = self.health - floor(damage)
|
||||||
|
|
||||||
-- exit here if dead
|
-- exit here if dead, special item check
|
||||||
if check_for_death(self) then
|
if weapon:get_name() == "mobs:pick_lava" then
|
||||||
return
|
if check_for_death(self, "lava") then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if check_for_death(self, "hit") then
|
||||||
|
return
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--[[ add healthy afterglow when hit (can cause hit lag with larger textures)
|
--[[ add healthy afterglow when hit (can cause hit lag with larger textures)
|
||||||
|
@ -22,6 +22,7 @@ Lucky Blocks: 9
|
|||||||
|
|
||||||
|
|
||||||
Changelog:
|
Changelog:
|
||||||
|
- 1.36- Death check added, if mob dies in fire/lava/with lava pick then drops are cooked
|
||||||
- 1.35- Added owner_loyal flag for owned mobs to attack player enemies, also fixed group_attack
|
- 1.35- Added owner_loyal flag for owned mobs to attack player enemies, also fixed group_attack
|
||||||
- 1.34- Added function to fly mob using directional movement (thanks D00Med for flying code)
|
- 1.34- Added function to fly mob using directional movement (thanks D00Med for flying code)
|
||||||
- 1.33- Added functions to mount ride mobs (mobs.attach, mobs.detach, mobs.drive) many thanks to Blert2112
|
- 1.33- Added functions to mount ride mobs (mobs.attach, mobs.detach, mobs.drive) many thanks to Blert2112
|
||||||
|
Loading…
Reference in New Issue
Block a user