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") },
|
2019-09-21 14:44:30 +02:00
|
|
|
{ "carpenter", S("Carpenter") },
|
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-09-22 02:08:02 +02:00
|
|
|
carpenter = S("Hi! I'm a carpenter. Making things out of wood is my job."),
|
2019-08-29 00:20:20 +02:00
|
|
|
},
|
|
|
|
trade = {
|
|
|
|
S("If you want to trade, show me a trading book."),
|
|
|
|
},
|
|
|
|
happy = {
|
|
|
|
S("Hello!"),
|
|
|
|
S("Nice to see you."),
|
2019-08-29 06:53:22 +02:00
|
|
|
S("Life is beautiful."),
|
|
|
|
S("I feel good."),
|
|
|
|
S("Have a nice day!"),
|
2019-08-29 00:20:20 +02:00
|
|
|
},
|
2021-08-08 02:07:08 +02:00
|
|
|
exhausted = {
|
|
|
|
S("I'm not in a good mood."),
|
|
|
|
S("I'm tired."),
|
|
|
|
S("I need to rest."),
|
|
|
|
S("Life could be better."),
|
|
|
|
},
|
2019-08-29 00:20:20 +02:00
|
|
|
hurt = {
|
|
|
|
S("I don't feel so good."),
|
|
|
|
S("I ... I am hurt."),
|
2019-08-29 06:53:22 +02:00
|
|
|
S("I feel weak."),
|
|
|
|
S("My head hurts."),
|
|
|
|
S("I have a bad day today."),
|
2019-08-29 00:20:20 +02:00
|
|
|
},
|
|
|
|
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,
|
2019-09-25 13:43:57 +02:00
|
|
|
breath_max = 11,
|
2015-09-01 17:15:24 +02:00
|
|
|
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"},
|
2021-08-08 00:12:59 +02:00
|
|
|
{"mobs_npc3.png"},
|
|
|
|
{"mobs_npc4.png"},
|
|
|
|
{"mobs_npc5.png"},
|
|
|
|
{"mobs_npc6.png"},
|
2015-09-01 17:15:24 +02:00
|
|
|
},
|
|
|
|
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,
|
2019-09-22 02:12:40 +02:00
|
|
|
group_attack = true,
|
2017-05-17 17:57:14 +02:00
|
|
|
follow = "gold:ingot_gold",
|
2019-09-22 02:12:40 +02:00
|
|
|
view_range = 16,
|
2015-09-01 17:15:24 +02:00
|
|
|
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,
|
|
|
|
},
|
2021-08-08 02:21:21 +02:00
|
|
|
do_custom = function(self)
|
|
|
|
-- Slowly heal NPC over time
|
|
|
|
self.healing_counter = self.healing_counter + 1
|
2021-08-08 02:38:15 +02:00
|
|
|
if self.healing_counter >= 7 then
|
2021-08-08 02:21:21 +02:00
|
|
|
local hp = self.object:get_hp()
|
|
|
|
hp = math.min(20, hp + 1)
|
|
|
|
self.object:set_hp(hp)
|
|
|
|
local hp = self.object:get_hp()
|
|
|
|
self.healing_counter = 0
|
|
|
|
end
|
|
|
|
end,
|
2015-09-01 17:15:24 +02:00
|
|
|
on_spawn = function(self)
|
2017-05-16 04:48:28 +02:00
|
|
|
self.npc_type = npc_type
|
2021-08-08 02:21:21 +02:00
|
|
|
self.healing_counter = 0
|
2017-05-16 04:48:28 +02:00
|
|
|
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
|
|
|
|
|
2019-09-22 02:08:02 +02:00
|
|
|
local iname = item:get_name()
|
|
|
|
if minetest.get_item_group(iname, "sword") > 0 or minetest.get_item_group(iname, "spear") > 0 or iname == "default:thistle" then
|
|
|
|
say(S("Get this thing out of my face!"), name)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2019-09-22 03:37:22 +02:00
|
|
|
achievements.trigger_achievement(clicker, "smalltalk")
|
|
|
|
|
2019-08-29 00:20:20 +02:00
|
|
|
local hp = self.object:get_hp()
|
2021-08-08 02:07:08 +02:00
|
|
|
do
|
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
|
2019-08-29 17:04:51 +02:00
|
|
|
if iname == "gold:ingot_gold" then
|
2019-08-29 00:20:20 +02:00
|
|
|
say_random("trade", name)
|
2019-09-22 02:08:02 +02:00
|
|
|
elseif iname == "default:fertilizer" then
|
|
|
|
if npc_type == "farmer" then
|
|
|
|
say(S("This makes seeds grow faster. Place the fertilizer on soil, then plant the seed on top of it."), name)
|
|
|
|
else
|
|
|
|
say(S("Sorry, I don't know how to use this. Maybe ask a farmer."), name)
|
|
|
|
end
|
|
|
|
elseif minetest.get_item_group(iname, "bucket") > 0 then
|
|
|
|
if npc_type == "farmer" then
|
|
|
|
say(S("Remember to put water near to your seeds."), name)
|
|
|
|
else
|
|
|
|
say_random("happy", name)
|
|
|
|
end
|
|
|
|
elseif iname == "mobs:lasso" then
|
|
|
|
say(S("It's used to capture large animals."), name)
|
|
|
|
elseif iname == "locks:pick" then
|
|
|
|
say(S("Why are you carrying this around? Do you want crack open our locked chests?"), name)
|
|
|
|
elseif iname == "mobs:net" then
|
|
|
|
say(S("It's used to capture small animals."), name)
|
|
|
|
elseif iname == "farming:wheat_1" then
|
|
|
|
say(S("Every kid knows seeds need soil, water and sunlight."), name)
|
2021-08-08 02:07:08 +02:00
|
|
|
elseif iname == "farming:wheat" then
|
|
|
|
if npc_type == "farmer" then
|
|
|
|
say(S("Sheep love to eat wheat. Give them enough wheat and they'll multiply!"), name)
|
|
|
|
else
|
|
|
|
say(S("We use wheat to make flour and bake bread."), name)
|
|
|
|
end
|
|
|
|
elseif iname == "farming:flour" then
|
|
|
|
say(S("Put it in a furnace to bake tasty bread."), name)
|
2019-09-22 02:08:02 +02:00
|
|
|
elseif iname == "farming:cotton_1" then
|
|
|
|
if npc_type == "farmer" then
|
|
|
|
say(S("Did you know cotton seed not only grow on dirt, but also on sand? But it still needs water."), name)
|
|
|
|
else
|
|
|
|
say(S("Every kid knows seeds need soil, water and sunlight."), name)
|
|
|
|
end
|
|
|
|
elseif iname == "default:book" then
|
|
|
|
say(S("A truly epic story!"), name)
|
|
|
|
elseif iname == "default:pearl" then
|
|
|
|
say(S("Ooh, a shiny pearl! Unfortunately, I don't know what it's good for."), name)
|
|
|
|
elseif minetest.get_item_group(iname, "sapling") > 0 then
|
|
|
|
say(S("Place it on the ground in sunlight and it will grow to a tree."), name)
|
|
|
|
elseif minetest.get_item_group(iname, "shears") > 0 then
|
2019-09-24 03:04:46 +02:00
|
|
|
say(S("Use this to trim plants and get wool from sheep."), name)
|
2019-09-22 02:08:02 +02:00
|
|
|
elseif iname == "default:papyrus" then
|
|
|
|
if npc_type == "farmer" then
|
|
|
|
say(S("Papyrus likes to grow next to water."), name)
|
|
|
|
else
|
|
|
|
say(S("When I was I kid, I always liked to climb on the papyrus."), name)
|
|
|
|
end
|
|
|
|
elseif iname == "default:cactus" then
|
|
|
|
if npc_type == "farmer" then
|
|
|
|
say(S("Cacti like to grow on sand. They are also a food source, if you're really desperate."), name)
|
|
|
|
elseif npc_type == "blacksmith" then
|
|
|
|
say(S("Ah, a cactus. You'd be surprised how well they burn in a furnace."), name)
|
|
|
|
else
|
|
|
|
say(S("Now what can you possibly do with a cactus? I don't know!"), name)
|
|
|
|
end
|
|
|
|
elseif iname == "jewels:jewel" then
|
|
|
|
if npc_type == "blacksmith" then
|
|
|
|
say(S("Jewels are great! If you have a jeweller's workbench, you can enhance your tools."), name)
|
|
|
|
else
|
|
|
|
say(S("Did you know we sometimes sell jewels?"), name)
|
|
|
|
end
|
|
|
|
elseif iname == "lumien:crystal_off" then
|
|
|
|
say(S("This looks like it could be a good wall decoration."), name)
|
|
|
|
elseif iname == "default:flower" then
|
|
|
|
say(S("A flower? I love flowers! Let's make the world bloom!"), name)
|
|
|
|
elseif iname == "default:flint_and_steel" then
|
2019-09-24 04:34:37 +02:00
|
|
|
if minetest.settings:get_bool("tnt_enable", true) then
|
|
|
|
say(S("You can use this to light up torches and ignite TNT."), name)
|
|
|
|
else
|
|
|
|
say(S("You can use this to light up torches."), name)
|
|
|
|
end
|
2019-09-22 02:08:02 +02:00
|
|
|
elseif iname == "tnt:tnt" then
|
2019-09-24 04:34:37 +02:00
|
|
|
if minetest.settings:get_bool("tnt_enable", true) then
|
|
|
|
say(S("TNT needs to be ignited by a flint and steel."), name)
|
|
|
|
else
|
|
|
|
say(S("For some reason, TNT can't be ignited. Strange."), name)
|
|
|
|
end
|
2019-09-22 02:08:02 +02:00
|
|
|
elseif iname == "bed:bed_foot" then
|
|
|
|
if npc_type == "carpenter" then
|
|
|
|
say(S("Isn't it stressful to carry this heavy bed around?"), name)
|
|
|
|
else
|
|
|
|
say(S("Sleeping makes the night go past in the blink of an eye."), name)
|
|
|
|
end
|
2021-08-08 02:07:08 +02:00
|
|
|
elseif iname == "default:apple" then
|
|
|
|
if npc_type == "farmer" then
|
|
|
|
say(S("Boars love to eat apples, too! If you feed enough of these to them, they will multiply."), name)
|
|
|
|
else
|
|
|
|
say(S("Apples are so tasty!"), name)
|
|
|
|
end
|
|
|
|
elseif minetest.get_item_group(iname, "food") > 0 then
|
|
|
|
say(S("Stay healthy!"), name)
|
2019-08-29 00:20:20 +02:00
|
|
|
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
|
2021-08-08 02:07:08 +02:00
|
|
|
say_random("exhausted", name)
|
2019-08-29 00:20:20 +02:00
|
|
|
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
|