yl_speak_up/interface_mobs_api.lua

96 lines
2.5 KiB
Lua

-- Make the NPC talk (mobs_redo interface)
--###
-- Mob functions
--###
function yl_speak_up.on_rightclick(self, clicker)
--local item = clicker:get_wielded_item()
local name = clicker:get_player_name()
-- Take the mob only with net or lasso
if self.owner and self.owner == name then
if mobs:capture_mob(self, clicker, nil, 100, 100, true, nil) then
return
end
end
-- protect npc with mobs:protector
if mobs:protect(self, clicker) then
return
end
-- bring up the dialog options
if clicker then
yl_speak_up.talk(self, clicker)
return
end
end
function yl_speak_up.on_spawn(self)
--Let's assign an ID
local m_talk = yl_speak_up.talk_after_spawn or true
local m_id = yl_speak_up.number_of_npcs + 1
yl_speak_up.number_of_npcs = m_id
yl_speak_up.modstorage:set_int("amount", m_id)
yl_speak_up.mob_table[m_id] = "yl_speak_up:test_npc"
self.yl_speak_up = {
talk = m_talk,
id = m_id,
textures = self.textures
}
--Let's protect it
self.protected = true
self.tamed = true
self.object:set_armor_groups({immortal = 100})
minetest.log(
"action",
"[MOD] yl_speak_up: NPC with ID n_" ..
self.yl_speak_up.id .. " spawned at " .. minetest.pos_to_string(self.object:get_pos(), 0)
)
--Let's do it only once
return true
end
function yl_speak_up.after_activate(self, staticdata, def, dtime)
minetest.log(
"action",
"[MOD] yl_speak_up: NPC with ID n_" ..
self.yl_speak_up.id .. " activated at " .. minetest.pos_to_string(self.object:get_pos(), 0)
)
if yl_speak_up.status == 2 then
self.object:remove()
return true
end
if self.yl_speak_up and self.yl_speak_up.skin then
local tex = self.yl_speak_up.skin
self.object:set_properties({textures = {tex[1], tex[2], tex[3], tex[4]}})
end
if yl_speak_up.infotext then
local i_text = ""
if self.yl_speak_up.npc_name then
i_text = i_text .. self.yl_speak_up.npc_name .. "\n"
end
if self.yl_speak_up.npc_description then
i_text = i_text .. self.yl_speak_up.npc_description .. "\n"
end
i_text = i_text .. yl_speak_up.infotext
self.object:set_properties({infotext = i_text})
end
yl_speak_up.update_nametag(self)
-- create a detached inventory for the npc and load its inventory
yl_speak_up.load_npc_inventory("n_"..tostring(self.yl_speak_up.id))
end