forked from Sokomine/yl_speak_up
do not crash when action leads to d_end in case of success
This commit is contained in:
parent
40a72949eb
commit
e3762b9c4c
@ -7,6 +7,9 @@ yl_speak_up.action_inv_changed = function(inv, listname, index, stack, player, h
|
||||
return
|
||||
end
|
||||
local pname = player:get_player_name()
|
||||
if(not(pname) or not(yl_speak_up.speak_to[pname])) then
|
||||
return
|
||||
end
|
||||
local n_id = yl_speak_up.speak_to[pname].n_id
|
||||
-- if not in edit mode: the player may just be normally interacting with the NPC;
|
||||
-- nothing to do for us here (wait for the player to click on "save")
|
||||
@ -66,7 +69,7 @@ end
|
||||
-- actions - in contrast to preconditions and effects - may take time
|
||||
-- because the player usually gets presented a formspec and needs to
|
||||
-- react to that; thus, we can't just execute all actions simultaneously
|
||||
yl_speak_up.execute_next_action = function(player, a_id, result_of_a_id)
|
||||
yl_speak_up.execute_next_action = function(player, a_id, result_of_a_id, formname)
|
||||
local pname = player:get_player_name()
|
||||
local n_id = yl_speak_up.speak_to[pname].n_id
|
||||
local d_id = yl_speak_up.speak_to[pname].d_id
|
||||
@ -266,6 +269,10 @@ yl_speak_up.execute_next_action = function(player, a_id, result_of_a_id)
|
||||
-- end conversation
|
||||
if(target_dialog and target_dialog == "d_end") then
|
||||
yl_speak_up.stop_talking(pname)
|
||||
-- we are done with this; close any open forms
|
||||
if(formname) then
|
||||
minetest.close_formspec(pname, formname)
|
||||
end
|
||||
return
|
||||
end
|
||||
if(not(target_dialog)
|
||||
@ -526,7 +533,7 @@ yl_speak_up.input_fs_action_npc_gives = function(player, formname, fields)
|
||||
local a_id = yl_speak_up.speak_to[pname].a_id
|
||||
if(fields.npc_does_not_have_item) then
|
||||
-- the NPC can't supply the item - abort the action
|
||||
yl_speak_up.execute_next_action(player, a_id, nil)
|
||||
yl_speak_up.execute_next_action(player, a_id, nil, formname)
|
||||
return
|
||||
end
|
||||
-- is the npc_gives inv empty? then all went as expected.
|
||||
@ -536,7 +543,7 @@ yl_speak_up.input_fs_action_npc_gives = function(player, formname, fields)
|
||||
local n_id = yl_speak_up.speak_to[pname].n_id
|
||||
yl_speak_up.save_npc_inventory(n_id)
|
||||
-- the action was a success; the NPC managed to give the item to the player
|
||||
yl_speak_up.execute_next_action(player, a_id, true)
|
||||
yl_speak_up.execute_next_action(player, a_id, true, formname)
|
||||
return
|
||||
end
|
||||
-- the npc_gives slot does not accept input - so we don't have to check for any misplaced items
|
||||
@ -546,7 +553,7 @@ yl_speak_up.input_fs_action_npc_gives = function(player, formname, fields)
|
||||
-- and give that (hopefully) stackable stack back to the NPC
|
||||
yl_speak_up.action_quest_item_take_back(player)
|
||||
-- the action failed
|
||||
yl_speak_up.execute_next_action(player, a_id, nil)
|
||||
yl_speak_up.execute_next_action(player, a_id, nil, formname)
|
||||
return
|
||||
end
|
||||
-- else show a message to the player that he ought to take the item
|
||||
@ -605,12 +612,15 @@ yl_speak_up.input_fs_action_npc_wants = function(player, formname, fields)
|
||||
return
|
||||
end
|
||||
local pname = player:get_player_name()
|
||||
if(not(pname) or not(yl_speak_up.speak_to[pname])) then
|
||||
return
|
||||
end
|
||||
local trade_inv = minetest.get_inventory({type="detached", name="yl_speak_up_player_"..pname})
|
||||
local a_id = yl_speak_up.speak_to[pname].a_id
|
||||
-- is the npc_wants inv empty and the player pressed the back to talk button? then the action failed.
|
||||
if(trade_inv:is_empty("npc_wants") and fields.back_to_talk) then
|
||||
-- the action was aborted
|
||||
yl_speak_up.execute_next_action(player, a_id, nil)
|
||||
yl_speak_up.execute_next_action(player, a_id, nil, formname)
|
||||
return
|
||||
end
|
||||
-- the player tried to give something; check if it is the right thing
|
||||
@ -619,7 +629,7 @@ yl_speak_up.input_fs_action_npc_wants = function(player, formname, fields)
|
||||
-- check if it really is the item the NPC wanted; let the NPC take it
|
||||
local is_correct_item = yl_speak_up.action_quest_item_take_back(player)
|
||||
-- the action may have been a success or failure
|
||||
yl_speak_up.execute_next_action(player, a_id, is_correct_item)
|
||||
yl_speak_up.execute_next_action(player, a_id, is_correct_item, formname)
|
||||
return
|
||||
end
|
||||
-- else show a message to the player
|
||||
@ -661,11 +671,15 @@ yl_speak_up.input_fs_action_text_input = function(player, formname, fields)
|
||||
return
|
||||
end
|
||||
local pname = player:get_player_name()
|
||||
-- the player is no longer talking to the NPC
|
||||
if(not(pname) or not(yl_speak_up.speak_to[pname])) then
|
||||
return
|
||||
end
|
||||
local a_id = yl_speak_up.speak_to[pname].a_id
|
||||
local a = yl_speak_up.get_action_by_player(player)
|
||||
if(fields.back_to_talk) then
|
||||
-- the action was aborted
|
||||
yl_speak_up.execute_next_action(player, a_id, nil)
|
||||
yl_speak_up.execute_next_action(player, a_id, nil, formname)
|
||||
return
|
||||
end
|
||||
if(fields.finished_action and fields.quest_answer and fields.quest_answer ~= "") then
|
||||
@ -691,7 +705,7 @@ yl_speak_up.input_fs_action_text_input = function(player, formname, fields)
|
||||
-- store what the player entered so that it can be examined by other functions
|
||||
yl_speak_up.last_text_input[pname] = fields.quest_answer:trim()
|
||||
-- the action was a either a success or failure
|
||||
yl_speak_up.execute_next_action(player, a_id, success)
|
||||
yl_speak_up.execute_next_action(player, a_id, success, formname)
|
||||
return
|
||||
end
|
||||
-- no scrolling desired
|
||||
@ -789,17 +803,17 @@ yl_speak_up.input_fs_action_evaluate = function(player, formname, fields)
|
||||
end
|
||||
if(fields.back_to_talk) then
|
||||
-- the action was aborted
|
||||
yl_speak_up.execute_next_action(player, a_id, nil)
|
||||
yl_speak_up.execute_next_action(player, a_id, nil, formame)
|
||||
return
|
||||
end
|
||||
if(fields.failed_action) then
|
||||
-- the action failed
|
||||
yl_speak_up.execute_next_action(player, a_id, false)
|
||||
yl_speak_up.execute_next_action(player, a_id, false, formame)
|
||||
return
|
||||
end
|
||||
if(fields.finished_action) then
|
||||
-- the action was a success
|
||||
yl_speak_up.execute_next_action(player, a_id, true)
|
||||
yl_speak_up.execute_next_action(player, a_id, true, formame)
|
||||
return
|
||||
end
|
||||
if(fields.quit) then
|
||||
|
@ -266,7 +266,7 @@ yl_speak_up.input_talk = function(player, formname, fields)
|
||||
end
|
||||
yl_speak_up.speak_to[pname].o_id = o
|
||||
-- start with executing the first action
|
||||
yl_speak_up.execute_next_action(player, nil, true)
|
||||
yl_speak_up.execute_next_action(player, nil, true, formname)
|
||||
return
|
||||
end
|
||||
|
||||
|
@ -181,7 +181,7 @@ yl_speak_up.input_do_trade_simple = function(player, formname, fields)
|
||||
yl_speak_up.speak_to[pname].target_d_id = nil
|
||||
yl_speak_up.speak_to[pname].trade_id = nil
|
||||
-- execute the next action
|
||||
yl_speak_up.execute_next_action(player, a_id, success)
|
||||
yl_speak_up.execute_next_action(player, a_id, success, formname)
|
||||
return
|
||||
end
|
||||
|
||||
@ -961,7 +961,7 @@ yl_speak_up.trade_inv_on_take = function(inv, listname, index, stack, player)
|
||||
yl_speak_up.speak_to[pname].target_d_id = nil
|
||||
yl_speak_up.speak_to[pname].trade_id = nil
|
||||
-- execute the next action
|
||||
yl_speak_up.execute_next_action(player, trade.a_id, true)
|
||||
yl_speak_up.execute_next_action(player, trade.a_id, true, "yl_speak_up:trade_simple")
|
||||
return
|
||||
end
|
||||
-- information may require an update (NPC might now be out of stock), or
|
||||
|
Loading…
Reference in New Issue
Block a user