2017-05-16 04:48:28 +02:00
|
|
|
|
2015-09-01 17:15:24 +02:00
|
|
|
-- Npc by TenPlus1
|
2017-07-25 22:28:40 +02:00
|
|
|
-- Modded by KaadmY
|
2019-08-28 17:31:41 +02:00
|
|
|
local S = minetest.get_translator("mobs")
|
2015-09-01 17:15:24 +02:00
|
|
|
|
|
|
|
local npc_types = {
|
2019-08-28 17:31:41 +02:00
|
|
|
{ "farmer", S("Farmer") },
|
|
|
|
{ "tavernkeeper", S("Tavern Keeper") },
|
|
|
|
{ "blacksmith", S("Blacksmith") },
|
|
|
|
{ "butcher", S("Butcher") },
|
2015-09-01 17:15:24 +02:00
|
|
|
}
|
|
|
|
|
2019-08-29 00:20:20 +02:00
|
|
|
local msgs = {
|
|
|
|
npc = {
|
2019-08-29 00:50:13 +02:00
|
|
|
farmer = S("Hi! I'm a farmer. I sell farming goods."),
|
|
|
|
tavernkeeper = S("Hi! I'm a tavernkeeper. I trade with assorted goods."),
|
|
|
|
blacksmith = S("Hi! I'm a blacksmith. I sell metal products."),
|
|
|
|
butcher = S("Hi! I'm a butcher. Want to buy something?"),
|
2019-08-29 00:20:20 +02:00
|
|
|
},
|
|
|
|
trade = {
|
|
|
|
S("If you want to trade, show me a trading book."),
|
|
|
|
},
|
|
|
|
full_already = {
|
|
|
|
S("I don't want to eat anymore!"),
|
|
|
|
S("I'm not hungry!"),
|
|
|
|
S("I'm full already."),
|
|
|
|
S("I don't want food right now."),
|
|
|
|
},
|
|
|
|
eat_full = {
|
2019-08-29 00:50:13 +02:00
|
|
|
S("Ah, now I'm fully energized!"),
|
2019-08-29 00:20:20 +02:00
|
|
|
S("Thanks, now I'm filled up."),
|
|
|
|
S("Thank you, now I feel much better!"),
|
|
|
|
},
|
|
|
|
eat_normal = {
|
|
|
|
S("Munch-munch!"),
|
|
|
|
S("Yummies!"),
|
|
|
|
S("Yum-yum!"),
|
|
|
|
S("Chomp!"),
|
|
|
|
S("Thanks, I liked that!"),
|
|
|
|
},
|
|
|
|
hungry = {
|
|
|
|
S("I could use a snack."),
|
|
|
|
S("I'm a bit hungry."),
|
|
|
|
},
|
|
|
|
happy = {
|
|
|
|
S("Hello!"),
|
|
|
|
S("What's up?"),
|
|
|
|
S("Nice to see you."),
|
|
|
|
},
|
|
|
|
hurt = {
|
|
|
|
S("I don't feel so good."),
|
|
|
|
S("I ... I am hurt."),
|
|
|
|
S("Leave me alone."),
|
|
|
|
S("What do you want from me?"),
|
|
|
|
S("Go away!"),
|
|
|
|
},
|
|
|
|
hostile = {
|
|
|
|
S("Screw you!"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
local function say(text, to_player)
|
2019-08-29 00:31:26 +02:00
|
|
|
minetest.chat_send_player(to_player, S("Villager says: “@1”", text))
|
2019-08-29 00:20:20 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
local function say_random(mtype, to_player)
|
|
|
|
local r = math.random(1, #msgs[mtype])
|
|
|
|
local text = msgs[mtype][r]
|
|
|
|
say(text, to_player)
|
|
|
|
end
|
|
|
|
|
2019-06-23 22:37:51 +02:00
|
|
|
for _, npc_type_table in pairs(npc_types) do
|
|
|
|
local npc_type = npc_type_table[1]
|
|
|
|
local npc_name = npc_type_table[2]
|
2015-09-01 17:15:24 +02:00
|
|
|
mobs:register_mob(
|
|
|
|
"mobs:npc_" .. npc_type,
|
|
|
|
{
|
|
|
|
type = "npc",
|
|
|
|
passive = false,
|
|
|
|
collides_with_objects = false,
|
|
|
|
damage = 3,
|
|
|
|
attack_type = "dogfight",
|
|
|
|
attacks_monsters = true,
|
|
|
|
hp_min = 10,
|
|
|
|
hp_max = 20,
|
|
|
|
armor = 80,
|
|
|
|
collisionbox = {-0.35,-1.0,-0.35, 0.35,0.8,0.35},
|
|
|
|
visual = "mesh",
|
|
|
|
mesh = "mobs_npc.b3d",
|
|
|
|
drawtype = "front",
|
|
|
|
textures = {
|
|
|
|
{"mobs_npc1.png"},
|
|
|
|
{"mobs_npc2.png"},
|
|
|
|
},
|
|
|
|
makes_footstep_sound = true,
|
|
|
|
sounds = {},
|
|
|
|
walk_velocity = 2,
|
|
|
|
run_velocity = 3,
|
|
|
|
jump = true,
|
|
|
|
walk_chance = 50,
|
|
|
|
drops = {
|
|
|
|
{name = "default:planks_oak",
|
|
|
|
chance = 1, min = 1, max = 3},
|
|
|
|
{name = "default:apple",
|
|
|
|
chance = 2, min = 1, max = 2},
|
|
|
|
{name = "default:axe_stone",
|
|
|
|
chance = 5, min = 1, max = 1},
|
|
|
|
},
|
|
|
|
water_damage = 0,
|
|
|
|
lava_damage = 2,
|
|
|
|
light_damage = 0,
|
2017-05-17 17:57:14 +02:00
|
|
|
follow = "gold:ingot_gold",
|
2015-09-01 17:15:24 +02:00
|
|
|
view_range = 15,
|
|
|
|
owner = "",
|
|
|
|
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,
|
|
|
|
},
|
|
|
|
on_spawn = function(self)
|
2017-05-16 04:48:28 +02:00
|
|
|
self.npc_type = npc_type
|
|
|
|
end,
|
2015-09-01 17:15:24 +02:00
|
|
|
on_rightclick = function(self, clicker)
|
2017-05-16 04:48:28 +02:00
|
|
|
local item = clicker:get_wielded_item()
|
|
|
|
local name = clicker:get_player_name()
|
|
|
|
|
2019-08-29 00:20:20 +02:00
|
|
|
-- Reject all interaction when hostile
|
|
|
|
if self.attack and self.attack.player == clicker then
|
|
|
|
say_random("hostile", name)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2017-05-16 04:48:28 +02:00
|
|
|
-- Feed to heal npc
|
|
|
|
|
2019-08-29 00:20:20 +02:00
|
|
|
local hp = self.object:get_hp()
|
|
|
|
local iname = item:get_name()
|
|
|
|
if iname == "mobs:meat" or iname == "mobs:pork"
|
|
|
|
or iname == "farming:bread" or iname == "default:apple"
|
|
|
|
or iname == "default:clam" then
|
2017-05-16 04:48:28 +02:00
|
|
|
|
|
|
|
-- return if full health
|
|
|
|
if hp >= self.hp_max then
|
2019-08-29 00:20:20 +02:00
|
|
|
say_random("full_already", name)
|
2017-05-16 04:48:28 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2019-08-29 00:20:20 +02:00
|
|
|
if iname == "default:apple" then
|
|
|
|
hp = hp + 1
|
|
|
|
elseif iname == "default:clam" then
|
|
|
|
hp = hp + 2
|
|
|
|
else
|
|
|
|
hp = hp + 4
|
|
|
|
end
|
|
|
|
if hp >= self.hp_max then
|
|
|
|
hp = self.hp_max
|
|
|
|
say_random("eat_full", name)
|
|
|
|
else
|
|
|
|
say_random("eat_normal", name)
|
|
|
|
end
|
2017-05-16 04:48:28 +02:00
|
|
|
self.object:set_hp(hp)
|
2015-09-01 17:15:24 +02:00
|
|
|
|
2017-05-16 04:48:28 +02:00
|
|
|
-- take item
|
2017-06-27 21:13:30 +02:00
|
|
|
if not minetest.settings:get_bool("creative_mode") then
|
2017-05-16 04:48:28 +02:00
|
|
|
item:take_item()
|
|
|
|
clicker:set_wielded_item(item)
|
|
|
|
end
|
2015-09-01 17:15:24 +02:00
|
|
|
|
2019-08-29 00:20:20 +02:00
|
|
|
-- Right clicking with trading book trades
|
2017-05-16 04:48:28 +02:00
|
|
|
-- Trading is done in the gold mod
|
|
|
|
else
|
2019-08-29 00:20:20 +02:00
|
|
|
-- No trading if low health
|
|
|
|
if hp < 5 then
|
|
|
|
say_random("hurt", name)
|
|
|
|
return
|
|
|
|
end
|
2015-09-01 17:15:24 +02:00
|
|
|
|
2017-05-16 04:48:28 +02:00
|
|
|
if not self.npc_trade then
|
|
|
|
self.npc_trade = util.choice_element(
|
|
|
|
gold.trades[self.npc_type], gold.pr)
|
|
|
|
end
|
2015-10-03 23:02:14 +02:00
|
|
|
|
2017-05-16 04:48:28 +02:00
|
|
|
if not gold.trade(self.npc_trade, self.npc_type, clicker) then
|
2019-08-29 00:20:20 +02:00
|
|
|
if hp >= self.hp_max-7 then
|
|
|
|
if iname ~= "" then
|
|
|
|
say_random("trade", name)
|
|
|
|
else
|
|
|
|
local r = math.random(1,3)
|
|
|
|
if r == 1 then
|
|
|
|
say_random("trade", name)
|
|
|
|
elseif r == 2 then
|
|
|
|
say(msgs.npc[npc_type], name)
|
|
|
|
else
|
|
|
|
say_random("happy", name)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
elseif hp >= 5 then
|
|
|
|
say_random("hungry", name)
|
|
|
|
else
|
|
|
|
say_random("hurt", name)
|
|
|
|
end
|
2017-05-16 04:48:28 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
})
|
2015-09-01 17:15:24 +02:00
|
|
|
|
2019-06-23 22:51:33 +02:00
|
|
|
mobs:register_egg("mobs:npc_" .. npc_type, npc_name, "mobs_npc_"..npc_type.."_inventory.png")
|
2017-05-16 04:48:28 +02:00
|
|
|
end
|