death and drops,

fixed hp
master
Izzy 2019-07-28 16:15:37 -06:00
parent 257a737f92
commit db0afa6a4c
3 changed files with 107 additions and 12 deletions

View File

@ -328,8 +328,7 @@ function mobehavior:register_mob_fast(name, def)
end
local mdef = {
hp_max = 1,
health = 1,
hp = 14,
rotate = 0,
reach = 3,
physical = true,
@ -358,6 +357,39 @@ function mobehavior:register_mob_fast(name, def)
jump_timer = 0,
walk_timer = 0,
on_death = function(self, killer)
-- print("died")
local p = self
local obj = self.object
if not p then return end
local drops = p.drops
if not drops then return end
local pos = obj:get_pos()
if type(drops) == "string" then
minetest.add_item(pos, drops)
return
end
local total = 0
for _,d in ipairs(drops) do
if type(d) == string then
minetest.add_item(pos, d)
else
if 1 == math.random(d.chance or 1) then
minetest.add_item(pos, {name=d.name, count=d.min + math.random(d.max-d.min)})
end
end
end
end,
on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, dir)
-- print("punched")
end,
on_step = step,
on_activate = function(self, staticdata, dtime_s)
@ -457,8 +489,8 @@ function mobehavior:register_mob_fast(name, def)
}
end
if self.health == 0 then
self.health = math.random (self.hp_min, self.hp_max)
if not self.health or self.health == 0 then
self.health = math.random(self.hp_min, self.hp_max)
end
self.object:set_hp(self.health)

View File

@ -3,10 +3,11 @@ function make_bunny(name, behavior_fn)
mobehavior:register_mob_fast(mn..":"..name, {
type = "animal",
name = name,
passive = true,
reach = 1,
hp_min = 1,
hp_max = 4,
hp_min = 12,
hp_max = 14,
armor = 200,
collisionbox = {-0.268, -0.5, -0.268, 0.268, 0.167, 0.268},
visual = "mesh",
@ -65,6 +66,7 @@ function make_wolf(name, behavior_fn)
mobehavior:register_mob_fast(mn..":"..name, {
type = "animal",
name = name,
passive = false,
reach = 1,
hp_min = 12,
@ -125,6 +127,7 @@ function make_sheep(name, behavior_fn)
mobehavior:register_mob_fast(mn..":"..name, {
type = "animal",
name = name,
passive = false,
reach = 1,
hp_min = 12,
@ -189,6 +192,7 @@ function make_bear(name, behavior_fn)
mobehavior:register_mob_fast(mn..":"..name, {
type = "animal",
name = name,
passive = false,
reach = 1,
hp_min = 100,
@ -251,6 +255,7 @@ function make_rat(name, behavior_fn)
mobehavior:register_mob_fast(mn..":"..name, {
type = "animal",
name = name,
climbs_ladders = false,
passive = true,
reach = 1,
@ -301,6 +306,7 @@ function make_deer(name, behavior_fn)
mobehavior:register_mob_fast(mn..":"..name, {
type = "animal",
name = name,
passive = true,
reach = 1,
hp_min = 1,
@ -347,6 +353,7 @@ function make_buck(name, behavior_fn)
mobehavior:register_mob_fast(mn..":"..name, {
type = "animal",
name = name,
passive = true,
reach = 1,
hp_min = 1,
@ -395,6 +402,7 @@ function make_NPC(name, behavior_fn)
-- mobs:register_simple_mob(mn..":"..name, {
mobehavior:register_mob_fast(mn..":"..name, {
type = "monster",
name = name,
climbs_ladders = true,
passive = false,
attack_type = "dogfight",

View File

@ -65,12 +65,22 @@ minetest.register_abm({
return
end
local nearobjs = minetest.get_objects_inside_radius(pos, 50)
if #nearobjs > 3 then
-- print("too many near objs")
local nearobjs = minetest.get_objects_inside_radius(pos, 40)
if #nearobjs > 0 then
-- print("------")
for _,o in ipairs(nearobjs) do
local p = o:get_luaentity()
if p and p.name == "wolf" then
count = count + 1
if count > 1 then
return
end
end
end
--print("too many near objs")
return
end
--print("----------spawning rat")
local p = minetest.find_node_near(pos, 3, "air")
if p then
@ -92,8 +102,8 @@ minetest.register_abm({
"default:silver_sand",
},
neighbors = {"air"},
interval = 45,
chance = 800,
interval = 4,
chance = 80,
catch_up = false,
action = function(pos, node, active_object_count, active_object_count_wider)
@ -117,3 +127,48 @@ minetest.register_abm({
})
-- brown bears
minetest.register_abm({
nodenames = {
"default:dirt_with_grass",
"seasons:spring_default_dirt_with_grass",
"default:dirt_with_coniferous_litter",
},
neighbors = {"air"},
interval = 6,
chance = 150,
catch_up = false,
action = function(pos, node, active_object_count, active_object_count_wider)
if active_object_count > 5 then
--print("too many local objs " .. active_object_count)
return
end
local nearobjs = minetest.get_objects_inside_radius(pos, 40)
if #nearobjs > 0 then
-- print("------")
for _,o in ipairs(nearobjs) do
local p = o:get_luaentity()
if p and p.name == "bear" then
count = count + 1
if count > 1 then
return
end
end
end
--print("too many near objs")
return
end
--print("----------spawning rat")
local p = minetest.find_node_near(pos, 3, "air")
if p then
local mob = minetest.add_entity(p, "mobehavior:bear")
end
end
})