added yl_speak_up.update_nametag and yl_speak_up.set_muted for colored nametags depending on muted state
This commit is contained in:
parent
4e16cc760a
commit
0c7f4a4db9
@ -1916,7 +1916,7 @@ minetest.register_on_player_receive_fields(
|
||||
|
||||
local i_text = dialog.n_npc .. "\n" .. dialog.n_description .. "\n" .. yl_speak_up.infotext
|
||||
obj:set_properties({infotext = i_text})
|
||||
obj:set_nametag_attributes({color="#00ff00", text=dialog.n_npc})
|
||||
yl_speak_up.update_nametag(ent)
|
||||
end
|
||||
end
|
||||
|
||||
@ -2641,7 +2641,7 @@ minetest.register_on_player_receive_fields(
|
||||
ent.owner = dialog.npc_owner
|
||||
local i_text = dialog.n_npc .. "\n" .. dialog.n_description .. "\n" .. yl_speak_up.infotext
|
||||
obj:set_properties({infotext = i_text})
|
||||
obj:set_nametag_attributes({color="#00ff00", text=dialog.n_npc})
|
||||
yl_speak_up.update_nametag(ent)
|
||||
end
|
||||
end
|
||||
|
||||
@ -3063,10 +3063,7 @@ function yl_speak_up.after_activate(self, staticdata, def, dtime)
|
||||
self.object:set_properties({infotext = i_text})
|
||||
end
|
||||
|
||||
if self.yl_speak_up.npc_name then
|
||||
self.object:set_nametag_attributes({color="#00ff00", text=self.yl_speak_up.npc_name})
|
||||
end
|
||||
|
||||
yl_speak_up.update_nametag(self)
|
||||
end
|
||||
|
||||
function yl_speak_up.talk(self, clicker)
|
||||
@ -3398,3 +3395,54 @@ function yl_speak_up.fashion(player, obj)
|
||||
|
||||
minetest.show_formspec(pname, "yl_speak_up:fashion", get_fs_fashion(pname))
|
||||
end
|
||||
|
||||
|
||||
yl_speak_up.update_nametag = function(self)
|
||||
if self.yl_speak_up.npc_name then
|
||||
-- the nametag is normal (green)
|
||||
if(self.yl_speak_up.talk) then
|
||||
self.object:set_nametag_attributes({color="#00ff00", text=self.yl_speak_up.npc_name})
|
||||
-- the nametag has the addition "[muted]" and is magenta when muted
|
||||
else
|
||||
self.object:set_nametag_attributes({color="#ff00ff", text=self.yl_speak_up.npc_name.." [muted]"})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- mute the npc; either via the appropriate staff or via talking to him
|
||||
yl_speak_up.set_muted = function(p_name, obj, set_muted)
|
||||
if(not(obj)) then
|
||||
return
|
||||
end
|
||||
local luaentity = obj:get_luaentity()
|
||||
if(not(luaentity)) then
|
||||
return
|
||||
end
|
||||
local npc = luaentity.yl_speak_up.id
|
||||
npc_name = luaentity.yl_speak_up.npc_name
|
||||
-- fallback
|
||||
if(not(npc_name)) then
|
||||
npc_name = npc
|
||||
end
|
||||
if(set_muted and luaentity.yl_speak_up.talk) then
|
||||
-- the npc is willing to talk
|
||||
luaentity.yl_speak_up.talk = false
|
||||
yl_speak_up.update_nametag(luaentity)
|
||||
|
||||
minetest.chat_send_player(p_name,"NPC with ID "..npc.." will shut up at pos "..
|
||||
minetest.pos_to_string(obj:get_pos(),0).." on command of "..p_name)
|
||||
minetest.log("action","[MOD] yl_speak_up: NPC with ID n_"..npc..
|
||||
" will shut up at pos "..minetest.pos_to_string(obj:get_pos(),0)..
|
||||
" on command of "..p_name)
|
||||
elseif(not(set_muted) and not(luaentity.yl_speak_up.talk)) then
|
||||
-- mute the npc
|
||||
luaentity.yl_speak_up.talk = true
|
||||
yl_speak_up.update_nametag(luaentity)
|
||||
|
||||
minetest.chat_send_player(p_name,"NPC with ID "..npc.." will resume speech at pos "..
|
||||
minetest.pos_to_string(obj:get_pos(),0).." on command of "..p_name)
|
||||
minetest.log("action","[MOD] yl_speak_up: NPC with ID n_"..npc..
|
||||
" will resume speech at pos "..minetest.pos_to_string(obj:get_pos(),0)..
|
||||
" on command of "..p_name)
|
||||
end
|
||||
end
|
||||
|
18
tools.lua
18
tools.lua
@ -53,15 +53,8 @@ minetest.register_tool("yl_speak_up:staff_of_shut_up", {
|
||||
end
|
||||
|
||||
local p_name = user:get_player_name()
|
||||
local luaentity = obj:get_luaentity()
|
||||
local npc = luaentity.yl_speak_up.id
|
||||
luaentity.yl_speak_up.talk = false
|
||||
yl_speak_up.set_muted(p_name, obj, true)
|
||||
|
||||
minetest.chat_send_player(p_name,"NPC with ID "..npc.." will shut up at pos "..
|
||||
minetest.pos_to_string(obj:get_pos(),0).." on command of "..p_name)
|
||||
minetest.log("action","[MOD] yl_speak_up: NPC with ID n_"..npc..
|
||||
" will shut up at pos "..minetest.pos_to_string(obj:get_pos(),0)..
|
||||
" on command of "..p_name)
|
||||
return itemstack
|
||||
end
|
||||
})
|
||||
@ -77,15 +70,8 @@ minetest.register_tool("yl_speak_up:staff_of_dawai_dawai", {
|
||||
end
|
||||
|
||||
local p_name = user:get_player_name()
|
||||
local luaentity = obj:get_luaentity()
|
||||
local npc = luaentity.yl_speak_up.id
|
||||
luaentity.yl_speak_up.talk = true
|
||||
yl_speak_up.set_muted(p_name, obj, false)
|
||||
|
||||
minetest.chat_send_player(p_name,"NPC with ID "..npc.." will resume speech at pos "..
|
||||
minetest.pos_to_string(obj:get_pos(),0).." on command of "..p_name)
|
||||
minetest.log("action","[MOD] yl_speak_up: NPC with ID n_"..npc..
|
||||
" will resume speech at pos "..minetest.pos_to_string(obj:get_pos(),0)..
|
||||
" on command of "..p_name)
|
||||
return itemstack
|
||||
end
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user