allow to take parts of a stack in d_got_item if take_as_wanted is set
This commit is contained in:
parent
9d2fb157d0
commit
3855a9b393
@ -197,7 +197,7 @@ yl_speak_up.execute_all_relevant_effects = function(player, effects, o_id, actio
|
||||
end
|
||||
if(r and r.r_type and r.r_type == "deal_with_offered_item") then
|
||||
refuse_items = true
|
||||
if(not(r.r_value) or r.r_value == "do_nothing") then
|
||||
if(not(r.r_value) or r.r_value == "do_nothing" or r.r_value == "take_as_wanted") then
|
||||
refuse_items = false
|
||||
end
|
||||
end
|
||||
@ -456,7 +456,7 @@ yl_speak_up.execute_effect = function(player, n_id, o_id, r)
|
||||
local amount = 0
|
||||
if(r.r_value == "take_all") then
|
||||
amount = stack_got:get_count()
|
||||
elseif(r.r_value == "takeas_wanted") then
|
||||
elseif(r.r_value == "take_as_wanted") then
|
||||
amount = stack_wanted:get_count()
|
||||
-- the NPC didn't get enough
|
||||
if(amount > stack_got:get_count()) then
|
||||
@ -465,6 +465,16 @@ yl_speak_up.execute_effect = function(player, n_id, o_id, r)
|
||||
"is smaller than what the NPC wanted: \""..
|
||||
tostring(stack_wanted).."\".")
|
||||
return false
|
||||
elseif(amount < stack_got:get_count()) then
|
||||
local rest = stack_got:get_count() - amount
|
||||
player_inv = player:get_inventory()
|
||||
if(player_inv) then
|
||||
rest_stack = ItemStack(stack_got:to_table())
|
||||
rest_stack:set_count(rest)
|
||||
player_inv:add_item("main", rest_stack)
|
||||
stack_got:set_count(amount)
|
||||
inv:set_stack("npc_wants", 1, stack_got)
|
||||
end
|
||||
end
|
||||
end
|
||||
local take_stack = stack_got:get_name().." "..tostring(amount)
|
||||
|
Loading…
Reference in New Issue
Block a user