- D1 Meta Docs - Denizen Script -
Home Page / Pi to one million places / Contact mcmonkey / Donate / Paste Scripts / Denizen Help /
You are browsing as a guest.
Login | Register


Click here to create your own public paste ~ ~ click to duplicate and edit this paste


TitleUntitled Paste
TypeDenizen Script
Date2019/08/09 12:48:08 UTC-07:00
ByGuest
Other
Paste
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
12000
player_response_system:
  type: world
  debug: false
  events:
    on player receives message:
    - if <player||none> == none queue clear
    # if the message is a JSON constructor
    - if <context.message.starts_with[@response]> {
        - 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 <player.has_flag[chat_history_cooldown].not> && <context.message.starts_with[--------------------------].not> && <context.message.is[==].to[<player.flag[last_quest_question].unescaped||none>].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 <context.message>
    - inject locally path:listeners_handler
    on questanswer command:
    - determine fulfilled passively
    - define answer <context.args.get[2].after[answer=]>
    - inject locally path:listeners_handler
    on player quits:
    - flag <player> needs_to_answer:!
  listeners_handler:
    - if <player.has_flag[needs_to_answer].not> {
      - queue clear
      }
    - if <player.flag[last_quest_responses].unescaped.contains[<def[answer]>].not||true> queue clear
    - determine cancelled passively
    - flag <player> needs_to_answer:!
    - if <def[answer]> == x queue clear
    - flag <player> npc_interaction_cooldown duration:1m
    - ~run <player.flag[last_quest_return].unescaped> "def:<def[answer]>" player:<player> instantly
    - flag <player> npc_interaction_cooldown:!
  construct_json:
    #Construct JSON
    - define return "<context.message.after[return=].before[/]>"
    - define responses "<context.message.after[responses=].before[/].split[&].include[x]>"
    - define question "<context.message.after[question=].before[/]>"
    - define json "<&lb><&dq>Responses\<&co> <&dq>"
    - foreach "<def[responses]>" {
      - 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=<def[value].escaped><&dq><&rc><&rc>"
      }
    - define json "%json%<&rb>"
    #Keep the JSON and various other data saved
    - flag <player> "last_quest_answer_prompt:<def[json].escaped>"
    - flag <player> "last_quest_question:<def[question].escaped>"
    - flag <player> "last_quest_responses:<def[responses].escaped>"
    - flag <player> "last_quest_return:<def[return].escaped>"
    - flag <player> needs_to_answer
    - flag <player> last_quest_npc:<player.flag[last_interacted_npc]||none>
    #Show the JSON
    - narrate "<&0>---------------------------------------------"
    - narrate "<&e><player.flag[last_quest_question].unescaped>"
    - 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 <player> chat_history_cooldown d:5s
    #keep track of chat history
    - flag <player> "chat_history:->:<context.raw_json.escaped>"
    # if the player needs to provide an answer (if the json construct is shown)
    - if <player.has_flag[needs_to_answer]> {
      #spam history, finish with showing the json again
      - define history "<player.flag[chat_history].as_list>"
      - foreach "%history%" {
        - execute as_op "tellraw @p <def[value].unescaped>"
        }
      - narrate "<&0>---------------------------------------------"
      - narrate "<&e><player.flag[last_quest_question].unescaped>"
      - execute as_op "tellraw @p <player.flag[last_quest_answer_prompt].unescaped>"
      - narrate "<&0>---------------------------------------------"
      - determine cancelled passively
      } else if <player.has_flag[needs_to_answer]> {
      - flag <player> need_to_answer:!
      }
    - flag <player> chat_history_cooldown:!
  manage_chat_history:
    - if <player.flag[chat_history].as_list.size||0> > 25 {
      - define history "<player.flag[chat_history].as_list.reverse.get[1].to[25].reverse>"
      - flag <player> chat_history:!
      - flag <player> "chat_history:|:%history%"
      }
shake_and_nod_listener:
  type: task
  debug: false
  script:
  - while <player.has_flag[needs_to_answer]> {
    - if <player.location.distance[<player.flag[last_quest_npc].as_npc.location||none>]||25> > 9 {
      - queue clear
      }
    - define pitch <player.location.pitch.as_int>
    - define yaw <player.location.yaw.as_int>
    - wait 3t
    - if <player.location.pitch.as_int.sub[%pitch%]> > 40 && <player.location.yaw.as_int.sub[%yaw%]> < 40 {
      - define yes <def[yes].add[1]||1>
      } else if <player.location.pitch.as_int.sub[%pitch%]> < 40 && <player.location.yaw.as_int.sub[%yaw%]> > 40 {
      - define no <def[no].add[1]||1>
      }
    - if <def[yes]||0> > 3 {
      - define answer yes
      - while stop
      } else if <def[no]||0> > 3 {
      - define answer no
      - while stop
      }
    }
  - inject s@player_response_system path:listeners_handler



RawRaw



Pastes made: 70270