npc_talk/talk_tool.lua
2023-09-04 02:36:33 +02:00

30 lines
994 B
Lua

-- we need to initiate talk to a mob somehow
npc_talk.talk_tool = function(itemstack, player, pointed_thing)
if(not(player) or not(pointed_thing) or pointed_thing.type ~= 'object') then
return nil
end
local pname = player:get_player_name()
local ref = pointed_thing.ref
if(not(ref)) then
return
elseif(ref:is_player()) then
minetest.chat_send_player(pname, "You can talk to other players via /msg <playername> <text>")
return
end
local luaob = ref:get_luaentity();
if(not(luaob)
or not(luaob.name)
-- we can only talk to NPC for which we have information for skin configuration
or not(yl_speak_up.mob_skins[luaob.name])) then
minetest.chat_send_player(pname, "Sorry. This entity hasn't been taught how to talk ("..
tostring(luaob.name)..").")
return
end
-- actually talk
minetest.chat_send_player(pname, "Talking to entity of type "..tostring(luaob.name)..".")
yl_speak_up.talk(luaob, player)
return nil -- no item shall be removed from inventory
end