forked from Sokomine/yl_speak_up
		
	did preparations for making blocks talk
This commit is contained in:
		
							parent
							
								
									3dfae53782
								
							
						
					
					
						commit
						2ade21640e
					
				@ -96,7 +96,10 @@ yl_speak_up.set_npc_property = function(pname, property_name, property_value, re
 | 
			
		||||
		end
 | 
			
		||||
	end
 | 
			
		||||
	-- store it
 | 
			
		||||
	if(entity) then
 | 
			
		||||
		property_data.entity.yl_speak_up.properties[property_name] = property_value
 | 
			
		||||
	end
 | 
			
		||||
	-- TODO: handle non-npc (blocks etc)
 | 
			
		||||
	return "OK"
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
@ -152,6 +155,9 @@ yl_speak_up.get_fs_properties = function(pname, selected)
 | 
			
		||||
		return
 | 
			
		||||
	end
 | 
			
		||||
	local s = ""
 | 
			
		||||
	if(not(property_data.prop_names)) then
 | 
			
		||||
		property_data.prop_names = {}
 | 
			
		||||
	end
 | 
			
		||||
	local anz_prop = #property_data.prop_names
 | 
			
		||||
	for i, k in ipairs(property_data.prop_names) do
 | 
			
		||||
		local v = property_data.properties[k]
 | 
			
		||||
 | 
			
		||||
@ -384,8 +384,22 @@ function yl_speak_up.talk(self, clicker)
 | 
			
		||||
		return
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	local id_prefix = "n"
 | 
			
		||||
	-- we are not dealing with an NPC but with a position/block on the map
 | 
			
		||||
	if(self.is_block) then
 | 
			
		||||
		id_prefix = "p"
 | 
			
		||||
		self.yl_speak_up = {
 | 
			
		||||
			talk = true,
 | 
			
		||||
			id = minetest.pos_to_string(self.pos, 0),
 | 
			
		||||
			textures = {},
 | 
			
		||||
			owner = "TODO_owner_name", -- TODO
 | 
			
		||||
			npc_name = "TODO_npc_name", -- TODO
 | 
			
		||||
			object = nil, -- blocks don't have an object
 | 
			
		||||
		}
 | 
			
		||||
		-- TODO: remember somewhere that this block is relevant
 | 
			
		||||
 | 
			
		||||
	-- initialize the mob if necessary; this happens at the time of first talk, not at spawn time!
 | 
			
		||||
	if(not(self.yl_speak_up) or not(self.yl_speak_up.id)) then
 | 
			
		||||
	elseif(not(self.yl_speak_up) or not(self.yl_speak_up.id)) then
 | 
			
		||||
		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)
 | 
			
		||||
@ -398,11 +412,11 @@ function yl_speak_up.talk(self, clicker)
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
        -- create a detached inventory for the npc and load its inventory
 | 
			
		||||
        yl_speak_up.load_npc_inventory("n_"..tostring(self.yl_speak_up.id))
 | 
			
		||||
	yl_speak_up.load_npc_inventory(id_prefix.."_"..tostring(self.yl_speak_up.id))
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    local npc_id = self.yl_speak_up.id
 | 
			
		||||
    local n_id = "n_" .. npc_id
 | 
			
		||||
    local n_id = id_prefix.."_" .. npc_id
 | 
			
		||||
 | 
			
		||||
    -- remember whom the npc belongs to (as long as we still have self.owner available for easy access)
 | 
			
		||||
    yl_speak_up.npc_owner[ n_id ] = self.owner
 | 
			
		||||
@ -410,12 +424,16 @@ function yl_speak_up.talk(self, clicker)
 | 
			
		||||
    local pname = clicker:get_player_name()
 | 
			
		||||
    if not self.yl_speak_up or not self.yl_speak_up.talk or self.yl_speak_up.talk~=true then
 | 
			
		||||
 | 
			
		||||
	local was = "This NPC"
 | 
			
		||||
	if(id_prefix ~= "n") then
 | 
			
		||||
		was = "This block"
 | 
			
		||||
	end
 | 
			
		||||
	-- show a formspec to other players that this NPC is busy
 | 
			
		||||
        if(not(yl_speak_up.may_edit_npc(clicker, n_id))) then
 | 
			
		||||
             -- show a formspec so that the player knows that he may come back later
 | 
			
		||||
             yl_speak_up.show_fs(player, "msg", {input_to = "yl_spaek_up:ignore", formspec =
 | 
			
		||||
		"size[6,2]"..
 | 
			
		||||
		"label[1.2,0.0;"..minetest.formspec_escape((self.yl_speak_up.npc_name or "This NPC")..
 | 
			
		||||
		"label[1.2,0.0;"..minetest.formspec_escape((self.yl_speak_up.npc_name or was)..
 | 
			
		||||
			" [muted]").."]"..
 | 
			
		||||
		"label[0.2,0.5;Sorry! I'm currently busy learning new things.]"..
 | 
			
		||||
		"label[0.2,1.0;Please come back later.]"..
 | 
			
		||||
@ -423,7 +441,7 @@ function yl_speak_up.talk(self, clicker)
 | 
			
		||||
             return
 | 
			
		||||
        end
 | 
			
		||||
        -- allow the owner to edit (and subsequently unmute) the npc
 | 
			
		||||
	minetest.chat_send_player(pname, "This NPC is muted. It will only talk to you.")
 | 
			
		||||
	minetest.chat_send_player(pname, was.." is muted. It will only talk to you.")
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    yl_speak_up.speak_to[pname] = {}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user