extracted interface_mobs_api.lua from functions.lua into a seperate file

This commit is contained in:
Sokomine 2022-01-07 21:22:41 +01:00
parent bd2c8bc4cd
commit fc10be7d0e
4 changed files with 97 additions and 149 deletions

View File

@ -271,61 +271,6 @@ yl_speak_up.input_talk = function(player, formname, fields)
end
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
-- recursion_depth is increased each time autoanswer is automaticly selected
yl_speak_up.get_fs_talkdialog = function(player, n_id, d_id, alternate_text, recursion_depth)
local pname = player:get_player_name()

View File

@ -381,100 +381,6 @@ end
-- Make the NPC talk
--###
-- 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
function yl_speak_up.talk(self, clicker)
if not clicker and not clicker:is_player() then

View File

@ -17,6 +17,8 @@ yl_speak_up.speak_to = {}
dofile(modpath .. "config.lua")
dofile(modpath .. "privs.lua")
-- react to right-click etc.
dofile(modpath .. "interface_mobs_api.lua")
-- handle on_player_receive_fields and showing of formspecs
dofile(modpath .. "show_fs.lua")
-- the formspec and input handling for the main dialog

95
interface_mobs_api.lua Normal file
View File

@ -0,0 +1,95 @@
-- 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