display and evaluate preconditions of type block_inv
This commit is contained in:
parent
a39d308ebc
commit
f5ceb9b04c
@ -205,18 +205,31 @@ yl_speak_up.show_precondition = function(p, pname)
|
|||||||
if(nr and check_trade[ nr ]) then
|
if(nr and check_trade[ nr ]) then
|
||||||
return check_trade[ nr ]
|
return check_trade[ nr ]
|
||||||
end
|
end
|
||||||
elseif(p.p_type == "player_inv" or p.p_type == "npc_inv") then
|
elseif(p.p_type == "player_inv" or p.p_type == "npc_inv" or p.p_type == "block_inv") then
|
||||||
local who = "The player"
|
local who = "The player"
|
||||||
|
local what = "\""..tostring(p.p_itemstack).."\" in his inventory."
|
||||||
if(p.p_type == "npc_inv") then
|
if(p.p_type == "npc_inv") then
|
||||||
who = "The NPC"
|
who = "The NPC"
|
||||||
|
elseif(p.p_type == "block_inv") then
|
||||||
|
if(not(p.p_pos) or type(p.p_pos) ~= "table"
|
||||||
|
or not(p.p_pos.x) or not(p.p_pos.y) or not(p.p_pos.z)) then
|
||||||
|
return "ERROR: p.p_pos is "..minetest.serialize(p.p_pos)
|
||||||
|
end
|
||||||
|
who = "The block at "..minetest.pos_to_string(p.p_pos)
|
||||||
|
what = "\""..tostring(p.p_itemstack).."\" in inventory list \""..
|
||||||
|
tostring(p.p_inv_list_name).."\"."
|
||||||
end
|
end
|
||||||
if(p.p_value == "inv_contains") then
|
if(p.p_value == "inv_contains") then
|
||||||
return who.." has \""..tostring(p.p_itemstack).."\" in his inventory."
|
return who.." has "..what
|
||||||
elseif(p.p_value == "inv_does_not_contain") then
|
elseif(p.p_value == "inv_does_not_contain") then
|
||||||
return who.." does not have \""..tostring(p.p_itemstack).."\" in his inventory."
|
return who.." does not have "..what
|
||||||
elseif(p.p_value == "has_room_for") then
|
elseif(p.p_value == "has_room_for") then
|
||||||
return who.." has room for \""..tostring(p.p_itemstack).."\" in his inventory."
|
return who.." has room for "..what
|
||||||
elseif(p.p_value == "inv_is_empty") then
|
elseif(p.p_value == "inv_is_empty") then
|
||||||
|
if(p.p_type == "block_inv") then
|
||||||
|
return who.." has an empty inventory list \""..
|
||||||
|
tostring(p.p_inv_list_name).."\"."
|
||||||
|
end
|
||||||
return who.." has an empty inventory."
|
return who.." has an empty inventory."
|
||||||
end
|
end
|
||||||
elseif(p.p_type == "custom") then
|
elseif(p.p_type == "custom") then
|
||||||
@ -478,16 +491,30 @@ yl_speak_up.eval_precondition = function(player, n_id, p, other_options_true_or_
|
|||||||
return not(player_inv:contains_item("main", trade.pay[1]))
|
return not(player_inv:contains_item("main", trade.pay[1]))
|
||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
elseif(p.p_type == "player_inv" or p.p_type == "npc_inv") then
|
elseif(p.p_type == "player_inv" or p.p_type == "npc_inv" or p.p_type == "block_inv") then
|
||||||
local inv = nil
|
local inv = nil
|
||||||
local inv_name = "main"
|
local inv_name = "main"
|
||||||
-- determine the right inventory
|
-- determine the right inventory
|
||||||
if(p.p_type == "player_inv") then
|
if(p.p_type == "player_inv") then
|
||||||
inv = player:get_inventory()
|
inv = player:get_inventory()
|
||||||
else
|
elseif(p.p_type == "npc_inv") then
|
||||||
inv = minetest.get_inventory({type="detached",
|
inv = minetest.get_inventory({type="detached",
|
||||||
name="yl_speak_up_npc_"..tostring(n_id)})
|
name="yl_speak_up_npc_"..tostring(n_id)})
|
||||||
inv_name = "npc_main"
|
inv_name = "npc_main"
|
||||||
|
elseif(p.p_type == "block_inv") then
|
||||||
|
if(not(p.p_pos) or type(p.p_pos) ~= "table"
|
||||||
|
or not(p.p_pos.x) or not(p.p_pos.y) or not(p.p_pos.z)) then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
local meta = minetest.get_meta(p.p_pos)
|
||||||
|
if(not(meta)) then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
inv = meta:get_inventory()
|
||||||
|
if(not(inv)) then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
inv_name = p.p_inv_list_name
|
||||||
end
|
end
|
||||||
if( p.p_itemstack and p.p_value == "inv_contains") then
|
if( p.p_itemstack and p.p_value == "inv_contains") then
|
||||||
return inv:contains_item(inv_name, p.p_itemstack)
|
return inv:contains_item(inv_name, p.p_itemstack)
|
||||||
|
Loading…
Reference in New Issue
Block a user