diff --git a/fs_edit_preconditions.lua b/fs_edit_preconditions.lua index 16c7dec..a9ed50f 100644 --- a/fs_edit_preconditions.lua +++ b/fs_edit_preconditions.lua @@ -565,6 +565,53 @@ yl_speak_up.eval_precondition = function(player, n_id, p, other_options_true_or_ return inv:is_empty(inv_name) end return false + elseif(p.p_type == "player_offered_item") then + local pname = player:get_player_name() + local inv = minetest.get_inventory({type="detached", name="yl_speak_up_player_"..pname}) + local stack_got = inv:get_stack("npc_wants",1) + if(stack_got:is_empty()) then + return false -- empty stack + end + local stack_wanted = ItemStack(p.p_value) + -- check group + if(p.p_item_group and p.p_item_group ~= "") then + local g = minetest.get_item_group(stack_got:get_name(), p.p_item_group) + if(not(g) or g == 0) then + return false -- wrong group + end + -- or: check item name + elseif(stack_got:get_name() ~= stack_wanted:get_name()) then + return false -- wrong item + end + -- independent of that: check stack size + if(p.p_match_stack_size and p.p_match_stack_size ~= "") then + local c_got = stack_got:get_count() + local c_wanted = stack_wanted:get_count() + if( p.p_match_stack_size == "exactly" and c_got ~= c_wanted) then + return false -- not exactly the same amount as the wanted one + elseif(p.p_match_stack_size == "less" and c_got >= c_wanted) then + return false -- didn't get less than the given number + elseif(p.p_match_stack_size == "more" and c_got <= c_wanted) then + return false -- didn't get more than the given number + elseif(p.p_match_stack_size == "another" and c_got == c_wanted) then + return false -- got the same than the given number + end + end + -- check quest_id + if(p.p_item_quest_id and p.p_item_quest_id ~= "") then + local meta = stack_got:get_meta() + -- we don't check here if the item was given by the right NPC; + -- only the quest id has to fit + if(meta:get_string("yl_speak_up:quest_id") ~= p.p_item_quest_id) then + return false -- wrong quest_id + end + -- was this quest item given to another player? + if(meta:get_string("yl_speak_up:quest_item_for") ~= pname) then + return false -- wrong player + end + end + -- all ok + return true elseif(p.p_type == "custom") then -- execute the custom function return yl_speak_up.precondition_custom(player, p.p_value)