Added Npc, removed barbarian type (was just monster in disguise)

master
tenplus1 2015-03-06 15:23:59 +00:00
parent bbc673622c
commit 1d6776f433
6 changed files with 91 additions and 19 deletions

36
api.lua
View File

@ -1,4 +1,4 @@
-- Mobs Api (5th March 2015)
-- Mobs Api (6th March 2015)
mobs = {}
-- Set global for other mod checks (e.g. Better HUD uses this)
@ -17,7 +17,7 @@ function mobs:register_mob(name, def)
minetest.register_entity(name, {
name = name,
hp_min = def.hp_min or 5,
hp_max = def.hp_max,
hp_max = def.hp_max or 10,
physical = true,
collisionbox = def.collisionbox,
visual = def.visual,
@ -279,7 +279,7 @@ function mobs:register_mob(name, def)
end
-- FIND SOMEONE TO ATTACK
if ( self.type == "monster" or self.type == "barbarian" ) and damage_enabled and self.state ~= "attack" then
if self.type == "monster" and damage_enabled and self.state ~= "attack" then
local s = self.object:getpos()
local inradius = minetest.get_objects_inside_radius(s,self.view_range)
@ -317,22 +317,20 @@ function mobs:register_mob(name, def)
end
-- NPC FIND A MONSTER TO ATTACK
-- if self.type == "npc" and self.attacks_monsters and self.state ~= "attack" then
-- local s = self.object:getpos()
-- local inradius = minetest.get_objects_inside_radius(s,self.view_range)
-- for _, oir in pairs(inradius) do
-- local obj = oir:get_luaentity()
-- if obj then
-- if obj.type == "monster" or obj.type == "barbarian" then
-- -- attack monster
-- local p = obj.object:getpos()
-- local dist = ((p.x-s.x)^2 + (p.y-s.y)^2 + (p.z-s.z)^2)^0.5
-- self.do_attack(self,obj.object,dist)
-- break
-- end
-- end
-- end
-- end
if self.type == "npc" and self.attacks_monsters and self.state ~= "attack" then
local s = self.object:getpos()
local inradius = minetest.get_objects_inside_radius(s,self.view_range)
for _, oir in pairs(inradius) do
local obj = oir:get_luaentity()
if obj and obj.type == "monster" then
-- attack monster
local p = obj.object:getpos()
local dist = ((p.x-s.x)^2 + (p.y-s.y)^2 + (p.z-s.z)^2)^0.5
self.do_attack(self,obj.object,dist)
break
end
end
end
if self.follow ~= "" and not self.following then
for _,player in pairs(minetest.get_connected_players()) do

View File

@ -52,6 +52,7 @@ mobs:register_mob("mobs:chicken", {
follow = "farming:wheat", view_range = 5,
-- right click to pick up chicken
on_rightclick = function(self, clicker)
local item = clicker:get_wielded_item()
if clicker:is_player() and clicker:get_inventory() then
clicker:get_inventory():add_item("main", "mobs:chicken")
self.object:remove()

View File

@ -29,6 +29,9 @@ dofile(minetest.get_modpath("mobs").."/mese_monster.lua")
dofile(minetest.get_modpath("mobs").."/spider.lua")
-- NPC
dofile(minetest.get_modpath("mobs").."/npc.lua")
-- Meat & Cooked Meat
minetest.register_craftitem("mobs:meat_raw", {

BIN
models/character.b3d Normal file

Binary file not shown.

BIN
models/mobs_npc.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 901 B

70
npc.lua Normal file
View File

@ -0,0 +1,70 @@
-- Npc by TenPlus1
mobs:register_mob("mobs:npc", {
-- animal, monster, npc, barbarian
type = "npc",
-- aggressive, deals 1 damage to player/mob when hit
passive = false,
damage = 1,
attack_type = "dogfight",
attacks_monsters = true,
-- health & armor
hp_min = 10, hp_max = 20, armor = 100,
-- textures and model
collisionbox = {-0.35,-1.0,-0.35, 0.35,0.8,0.35},
visual = "mesh",
mesh = "character.b3d",
drawtype = "front",
available_textures = {
total = 1,
texture_1 = {"mobs_npc.png"},
},
visual_size = {x=1, y=1},
-- sounds
makes_footstep_sound = true,
sounds = {},
-- speed and jump
walk_velocity = 1,
run_velocity = 2,
jump = true,
-- drops wood and chance of apples when dead
drops = {
{name = "default:wood",
chance = 1, min = 1, max = 3},
{name = "default:apple",
chance = 2, min = 1, max = 2},
},
-- damaged by
water_damage = 1,
lava_damage = 2,
light_damage = 0,
-- follow diamond
follow = "default:diamond",
view_range = 15,
-- model animation
animation = {
speed_normal = 30, speed_run = 30,
stand_start = 0, stand_end = 79,
walk_start = 168, walk_end = 187,
run_start = 168, run_end = 187,
punch_start = 200, punch_end = 219,
},
-- right clicking with cooked meat will give npc more health
on_rightclick = function(self, clicker)
local item = clicker:get_wielded_item()
if item:get_name() == "mobs:meat" then
if not minetest.setting_getbool("creative_mode") then
item:take_item()
clicker:set_wielded_item(item)
end
local hp = self.object:get_hp() + 4
if hp > self.hp_max then hp = self.hp_max end
self.object:set_hp(hp)
end
end,
})
-- spawning disabled for now
--mobs:register_spawn("mobs:npc", {"default:dirt_with_grass"}, 20, 0, 7000, 1, 31000)
-- register spawn egg
mobs:register_egg("mobs:npc", "Npc", "default_brick.png", 1)