mirror of
				https://gitea.your-land.de/Sokomine/yl_speak_up.git
				synced 2025-10-31 04:23:03 +01:00 
			
		
		
		
	added yl_speak_up.check_stack_has_meta
This commit is contained in:
		
							parent
							
								
									8f80fd5ade
								
							
						
					
					
						commit
						39632a71f4
					
				| @ -9,6 +9,25 @@ yl_speak_up.get_inventory_save_path = function(n_id) | ||||
| end | ||||
| 
 | ||||
| 
 | ||||
| -- check if stack contains any metadata; return true if it does | ||||
| -- (trade_simple does not allow used items or those with metadata) | ||||
| yl_speak_up.check_stack_has_meta = function(player, stack) | ||||
| 	local meta = stack:get_meta() | ||||
| 	for k, v in pairs(meta:to_table()) do | ||||
| 		-- the name "fields" is allowed - as long as it is empty | ||||
| 		if(k ~= "fields") then | ||||
| 			return true | ||||
| 		end | ||||
| 		for k2, v2 in pairs(v) do | ||||
| 			if(k2) then | ||||
| 				return true | ||||
| 			end | ||||
| 		end | ||||
| 	end | ||||
| 	return false | ||||
| end | ||||
| 
 | ||||
| 
 | ||||
| -- access the inventory of the NPC (only possible for players with the right priv) | ||||
| yl_speak_up.get_fs_inventory = function(player) | ||||
| 	if(not(player)) then | ||||
| @ -95,23 +114,11 @@ yl_speak_up.load_npc_inventory = function(n_id) | ||||
| 				return 0 | ||||
| 			end | ||||
| 			-- items with metadata cannot be traded | ||||
| 			local meta = stack:get_meta() | ||||
| 			for k, v in pairs(meta:to_table()) do | ||||
| 				if(k ~= "fields") then | ||||
| 					minetest.chat_send_player(player:get_player_name(), | ||||
| 								"Your NPC cannot sell items that contain ".. | ||||
| 								"additional (meta-) data.") | ||||
| 					return 0 | ||||
| 				else | ||||
| 					for k2, v2 in pairs(v) do | ||||
| 						if(k2) then | ||||
| 							minetest.chat_send_player(player:get_player_name(), | ||||
| 								"Your NPC cannot sell items that contain ".. | ||||
| 								"additional (meta-) data.") | ||||
| 							return 0 | ||||
| 						end | ||||
| 					end | ||||
| 				end | ||||
| 			if(yl_speak_up.check_stack_has_meta(player, stack)) then | ||||
| 				minetest.chat_send_player(player:get_player_name(), | ||||
| 					"Your NPC cannot sell items that contain ".. | ||||
| 					"additional (meta-) data.") | ||||
| 				return 0 | ||||
| 			end | ||||
| 			return stack:get_count() | ||||
| 		end, | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user