player_response_system: type: world debug: false events: on player receives message: - if == none queue clear # if the message is a JSON constructor - if { - inject locally path:construct_json # if the message is not a JSON constructor, or any of the other messages around the JSON constructor to help it look pretty, and the player is not on cooldown for this script (the cooldown prevents the player from getting flooded too much, and avoids a worst case scenario of infinite loop) } else if && && ].not> { - inject locally path:keep_json_visible } - inject locally path:manage_chat_history on yes command: - determine fulfilled passively - define answer yes - inject locally path:listeners_handler on no command: - determine fulfilled passively - define answer no - inject locally path:listeners_handler on player chats: - define answer - inject locally path:listeners_handler on questanswer command: - determine fulfilled passively - define answer - inject locally path:listeners_handler on player quits: - flag needs_to_answer:! listeners_handler: - if { - queue clear } - if ].not||true> queue clear - determine cancelled passively - flag needs_to_answer:! - if == x queue clear - flag npc_interaction_cooldown duration:1m - ~run "def:" player: instantly - flag npc_interaction_cooldown:! construct_json: #Construct JSON - define return "" - define responses "" - define question "" - define json "<&lb><&dq>Responses\<&co> <&dq>" - foreach "" { - define json "%json%,<&lc><&dq>text<&dq><&co><&dq>\<&lb>%value%\<&rb><&sp><&dq>,<&dq>clickEvent<&dq><&co><&lc><&dq>action<&dq><&co><&dq>run_command<&dq>,<&dq>value<&dq><&co><&dq>/questanswer %return% answer=<&dq><&rc><&rc>" } - define json "%json%<&rb>" #Keep the JSON and various other data saved - flag "last_quest_answer_prompt:" - flag "last_quest_question:" - flag "last_quest_responses:" - flag "last_quest_return:" - flag needs_to_answer - flag last_quest_npc: #Show the JSON - narrate "<&0>---------------------------------------------" - narrate "<&e>" - determine "raw_json:%json%" passively - wait 1t - narrate "<&0>---------------------------------------------" #initiate shake and nod listener - run shake_and_nod_listener instantly keep_json_visible: # generic cooldown - flag chat_history_cooldown d:5s #keep track of chat history - flag "chat_history:->:" # if the player needs to provide an answer (if the json construct is shown) - if { #spam history, finish with showing the json again - define history "" - foreach "%history%" { - execute as_op "tellraw @p " } - narrate "<&0>---------------------------------------------" - narrate "<&e>" - execute as_op "tellraw @p " - narrate "<&0>---------------------------------------------" - determine cancelled passively } else if { - flag need_to_answer:! } - flag chat_history_cooldown:! manage_chat_history: - if > 25 { - define history "" - flag chat_history:! - flag "chat_history:|:%history%" } shake_and_nod_listener: type: task debug: false script: - while { - if ]||25> > 9 { - queue clear } - define pitch - define yaw - wait 3t - if > 40 && < 40 { - define yes } else if < 40 && > 40 { - define no } - if > 3 { - define answer yes - while stop } else if > 3 { - define answer no - while stop } } - inject s@player_response_system path:listeners_handler