More work in progress
parent
5ec83138e8
commit
e35bfb121a
30
init.lua
30
init.lua
|
@ -64,6 +64,7 @@ animals.create = function(pos, species)
|
|||
end
|
||||
local ent = obj:get_luaentity()
|
||||
|
||||
ent.hp_regen = 30
|
||||
ent.species = species
|
||||
ent.name = species .. animals.nextnum()
|
||||
ent.props["mesh"] = spinfo["mesh"]
|
||||
|
@ -127,6 +128,11 @@ minetest.register_entity("animals:animal", {
|
|||
if restored.action then
|
||||
self.action = restored.action
|
||||
end
|
||||
if restored.hp_regen then
|
||||
self.hp_regen = restored.hp_regen
|
||||
else
|
||||
self.hp_regen = 1
|
||||
end
|
||||
if restored.wait then
|
||||
self.wait = restored.wait
|
||||
end
|
||||
|
@ -162,6 +168,7 @@ minetest.register_entity("animals:animal", {
|
|||
name = self.name,
|
||||
species = self.species,
|
||||
action = self.action,
|
||||
hp_regen = self.hp_regen,
|
||||
wait = self.wait,
|
||||
props = self.props,
|
||||
}
|
||||
|
@ -202,6 +209,17 @@ minetest.register_entity("animals:animal", {
|
|||
end
|
||||
local spinfo = animals.species[self.species]
|
||||
|
||||
-- Slowly regenerate health
|
||||
self.hp_regen = self.hp_regen - dtime
|
||||
if self.hp_regen < 0 then
|
||||
self.hp_regen = 30
|
||||
local hp = self.object:get_hp()
|
||||
if hp < spinfo.hp_max then
|
||||
hp = hp + 1
|
||||
self.object:set_hp(hp)
|
||||
end
|
||||
end
|
||||
|
||||
if self.wait ~= 0 then
|
||||
if minetest.get_gametime() < self.wait then return end
|
||||
dbg.v3(self.species.." finished wait at "..minetest.get_gametime())
|
||||
|
@ -253,6 +271,9 @@ minetest.register_entity("animals:animal", {
|
|||
-- select automatically
|
||||
anim = nil,
|
||||
|
||||
-- In - 0, Out - damage to be applied.
|
||||
damage = 0,
|
||||
|
||||
-- In - the entity, in case anything needs to be called on it (avoid
|
||||
-- that if possible, but for example, getting the last collision
|
||||
-- result is currently done this way)
|
||||
|
@ -291,6 +312,15 @@ minetest.register_entity("animals:animal", {
|
|||
end
|
||||
end
|
||||
|
||||
if state.damage > 0 then
|
||||
local hp = self.object:get_hp()
|
||||
hp = hp - state.damage
|
||||
if hp <= 0 then
|
||||
dbg.v3(state.ent.name.."died")
|
||||
self.object:remove()
|
||||
end
|
||||
self.object:set_hp(hp)
|
||||
end
|
||||
|
||||
if state.wait ~= 0 then
|
||||
self.wait = minetest.get_gametime() + state.wait
|
||||
|
|
Binary file not shown.
|
@ -9,7 +9,7 @@ animals.species["rat"] = {
|
|||
textures = {"animals_rat.png"},
|
||||
collisionbox = {-0.25,0,-0.25, 0.25,0.35,0.25},
|
||||
|
||||
hp_max = 10,
|
||||
hp_max = 7,
|
||||
dead_drops = {"animals:dead_rat"},
|
||||
|
||||
-- These two are used to deal with model discrepancies, until I
|
||||
|
|
|
@ -0,0 +1,124 @@
|
|||
local dbg
|
||||
if moddebug then dbg=moddebug.dbg("animals") else dbg={v1=function() end,v2=function() end,v3=function() end} end
|
||||
|
||||
animals.species["wolf"] = {
|
||||
|
||||
shortdesc = "Wolf",
|
||||
|
||||
mesh = "animals_wolf.b3d",
|
||||
textures = {"animals_wolf_mesh.png"},
|
||||
collisionbox = {-0.5,0,-0.5, 0.5,1,0.5},
|
||||
animations = {
|
||||
stand = { x= 0, y= 60},
|
||||
walk = { x= 61, y=120},
|
||||
sleep = { x=121, y=180}
|
||||
},
|
||||
|
||||
hp_max = 10,
|
||||
dead_drops = {},
|
||||
|
||||
-- These two are used to deal with model discrepancies, until I
|
||||
-- can be arsed to fix the models.
|
||||
yoffset = 0.5,
|
||||
yawoffset = math.pi / 2,
|
||||
|
||||
on_activate = function(ent)
|
||||
end,
|
||||
|
||||
on_act = function(ent)
|
||||
|
||||
local pos = ent.object:getpos()
|
||||
|
||||
-- See if there's a player nearby to attack...
|
||||
local objs = minetest.get_objects_inside_radius(pos, 8)
|
||||
local nearestplayer = nil
|
||||
local nearestdist = 999
|
||||
for _,v in ipairs(objs) do
|
||||
if v:is_player() then
|
||||
local dist = vector.distance(v:getpos(), pos)
|
||||
if dist < nearestdist then
|
||||
nearestplayer = v:get_player_name()
|
||||
nearestdist = dist
|
||||
end
|
||||
end
|
||||
end
|
||||
if nearestplayer then
|
||||
return {"attackplayer", name=nearestplayer}
|
||||
end
|
||||
|
||||
-- Otherwise, wander aimlessly
|
||||
if math.random() < 0.6 then
|
||||
local dist = math.random() * 5 + 5
|
||||
local dir = math.random() * math.pi * 2
|
||||
dbg.v3("ent.name decided to move " .. dist .. "m")
|
||||
move = vector.from_speed_yaw(dist, dir)
|
||||
pos.x = pos.x + move.x
|
||||
pos.z = pos.z + move.z
|
||||
return {"go", pos=pos}
|
||||
end
|
||||
return {"wait", time=5}
|
||||
end,
|
||||
|
||||
on_hit = function(ent, playername)
|
||||
end,
|
||||
|
||||
}
|
||||
|
||||
minetest.register_node("animals:wolfspawner", {
|
||||
description = "Wolf Spawner",
|
||||
drawtype = "normal",
|
||||
tiles = {"default_cobble.png"},
|
||||
groups = {choppy=4, oddly_breakable_by_hand=3},
|
||||
paramtype = "light",
|
||||
})
|
||||
|
||||
minetest.register_abm({
|
||||
nodenames = {"animals:wolfspawner"},
|
||||
neighbors = {"default:air"},
|
||||
interval = 120,
|
||||
chance = 0.5,
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
|
||||
local objects = minetest.get_objects_inside_radius(pos, 48)
|
||||
local count = 0
|
||||
for k, obj in ipairs(objects) do
|
||||
if not obj:is_player() then
|
||||
local ent = obj:get_luaentity()
|
||||
if ent and ent.species == "wolf" then
|
||||
count = count + 1
|
||||
if count >= 4 then return end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local dirs = {{x=1, y=0, z=0},
|
||||
{x=-1, y=0, z=0},
|
||||
{x=0, y=0, z=1},
|
||||
{x=0, y=0, z=-1}}
|
||||
for _, pp in ipairs(dirs) do
|
||||
local ppos = vector.add(pos, pp)
|
||||
if minetest.get_node(ppos).name == "air" then
|
||||
animals.create(ppos, "wolf")
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_craftitem("animals:dead_rat", {
|
||||
description = "Dead rat",
|
||||
inventory_image = "animals_rat_inv.png",
|
||||
})
|
||||
|
||||
minetest.register_craftitem("animals:cooked_rat", {
|
||||
description = "Cooked rat",
|
||||
inventory_image = "animals_cooked_rat.png",
|
||||
on_use = minetest.item_eat(5),
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
type = "cooking",
|
||||
output = "animals:cooked_rat",
|
||||
recipe = "animals:dead_rat",
|
||||
})
|
||||
|
|
@ -8,6 +8,9 @@ animals.species["zombie"] = {
|
|||
mesh = "animals_biped.x",
|
||||
textures = {"animals_zombie.png"},
|
||||
collisionbox = {-0.35,0,-0.35, 0.35,1.75,0.35},
|
||||
|
||||
hp_max = 15,
|
||||
|
||||
yoffset = 0.1,
|
||||
yawoffset = 0,
|
||||
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 360 KiB |
Loading…
Reference in New Issue