- 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
Date2016/02/19 08:41:44 UTC-08: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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
25400
# ======================= #
# Author:  KeangDavid     #
# Version:  1.0.3         #
# Denizen: 0.9.7-SNAPSHOT #
# Build:   277            #
# Core:    1.10           #
# ======================= #

# ----- Trade Command ----- #
Player_Trade_Command:
  # Command Settings #
  use_distance: true
  distance_limit: 6
  description: Used to trade items between players.
  usage: /trade [player]
  permission: dCustom.trade
  permission message<red>Permission needed, <script.yaml_key[permission]>
  
  # Command Script, Change with caution! #
  type: command
  debug: false
  name: trade
  allowed help:
  - determine <player.has_permision[dCustom.trade]>
  help:
  - narrate "<red>/trade [player]"
  - queue clear
  tab complete:
  - determine <server.list_online_players.parse[name].get[<server.list_online_players.parse[name].find_all_partial[<c.args.get[1]>]>]||<server.list_online_players.parse[name]>>
  script:
  - if <c.args.size.is[!=].to[1]> inject locally help
  - if <c.args.get[1].is[==].to[<player.name>]> queue clear
  - if <server.list_online_players.parse[name].contains[<c.args.get[1]>].not> {
    - narrate "<red><c.args.get[1]> is not online."
    - queue clear }
  - if <script.yaml_key[use_distance]> {
    - if <player.location.distance[<c.args.get[1].as_player.location>].is[OR_MORE].to[<script.yaml_key[distance_limit]>]||true> {
      - narrate "<red>You are too far away from <c.args.get[1]>."
      - queue clear }
    }
  - flag player Trading:<c.args.get[1]>
  - if <player.flag[Trading].as_player.flag[Trading].is[==].to[<player.name>]> {
    - inject trade locally
    } else {
    - flag player Trading:<c.args.get[1]> duration:30s
    - narrate "<yellow>Type <gold>/trade <player.name> <yellow>to start trade." targets:<c.args.get[1].as_player>
    - narrate "<aqua>Trade request sent."
    - flag player wait duration:3s
    }
  trade:
  - flag player trading:<c.args.get[1]>
  - flag p@<c.args.get[1]> trading:<player.name>
  - flag p@<c.args.get[1]> wait:!
  - flag player trade:!
  - flag p@<c.args.get[1]> trade:!
  - run Player_Trade_Update def:start
  - run Player_Trade_Update def:start as:<c.args.get[1].as_player>
# =============== Trade Command End =========== #

# =============== Update Trade Inventory =============== #
Player_Trade_Update:
  type: task
  debug: false
  slots:
  # i1=player1 i2=player2 ia=player1StatusButton ib=player2Status is=seperator
  - i1|i1|i1|ia|is|ib|i2|i2|i2
  - i1|i1|i1|i1|is|i2|i2|i2|i2
  - i1|i1|i1|i1|is|i2|i2|i2|i2
  - i1|i1|i1|i1|is|i2|i2|i2|i2
  - i1|i1|i1|i1|is|i2|i2|i2|i2
  - i1|i1|i1|i1|is|i2|i2|i2|i2
  script:
  # Pre script checks
  - ^if <player.has_flag[Trading].not> queue clear
  - ^if <player.has_flag[wait]> queue clear
  - wait 1t
  - ^flag player TradeUpdate
  
  # Changing to appropriate interface
  - ^define slots li@<script.yaml_key[slots].after[li@].replace[i].with[i@Player_Trade_Item_]>
  - ^if <def[1].is[==].to[update]> {
    - if <player.has_flag[TradeWait].not> run Player_Trade_Wait
    - flag player TradeWait duration:5s }
  - ^if <player.has_flag[TradeWait]> define slots <def[slots].replace[regex:\_(a|s|b)].with[_w]>
  - ^if <player.has_flag[TradeReady]> define slots <def[slots].replace[_a].with[_y]>
  - ^if <player.flag[Trading].as_player.has_flag[TradeReady]> define slots <def[slots].replace[_b].with[_z]>
  
  # Adding trade items to interface
  - ^if <player.has_flag[trade]> {
    - foreach <player.flag[trade].as_list> {
      - define slots "<def[slots].replace[firstregex:i@Player_Trade_Item_1].with[%value%]>"
      }
    }
  - ^if <player.has_flag[trading]> && <player.flag[trading].as_player.has_flag[trade]> {
    - foreach <player.flag[trading].as_player.flag[trade].as_list> {
      - define slots "<def[slots].replace[firstregex:i@Player_Trade_Item_2].with[%value%]>"
      }
    }
  - ^note "in@generic[size=54;title=Trading, <player.flag[trading]>;contents=%slots%]" as:Trade
  - ^inventory open d:in@Trade
  - ^inventory update d:<pl.inventory>
  - ^flag player TradeUpdate:!
Player_Trade_Wait:
  type: task
  debug: false
  script:
  - wait 1s
  - while <player.has_flag[TradeWait]> {
    - wait 1s }
  - run Player_Trade_Update
# =============== Update Trade Inventory End =============== #

# =============== Trade Interface Listener ============== #
Player_Trade_Listener:
  type: world
  debug: false
  update:
  - flag player TradeReady:!
  - flag <player.flag[trading].as_player> TradeReady:!
  - run Player_Trade_Update def:update
  - run Player_Trade_Update def:update as:<player.flag[trading].as_player>
  events:
    on player clicks in inventory:
    - if <c.inventory.title.contains[Trading,].not> queue clear
    - if <c.raw_slot.is[OR_MORE].to[55]> && <c.action.is[!=].to[COLLECT_TO_CURSOR]> {
      - if <c.item.is[!=].to[i@air]> && <c.action.is[==].to[MOVE_TO_OTHER_INVENTORY]> {
        - if <player.flag[trade].as_list.size.is[OR_MORE].to[<s@Player_Trade_Update.yaml_key[slots].as_list.count[i1]>]> {
          - narrate "<red>Trade full."
          - determine CANCELLED
          }
        - flag player trade:->:<c.item>
        - take slot:<c.slot>
        - inject locally update
        }
      - queue clear
      }
    - if <player.flag[Trade].as_list.contains[<c.item>]> && <c.raw_slot.is[OR_LESS].to[54]> {
      - flag player trade:<-:<c.item>
      - give <player> <c.item>
      - inject locally update
      }
    #- narrate "slot=<c.slot> raw=<c.raw_slot> click=<c.click> type=<c.slot_type> item=<c.item>"
    - determine CANCELLED
    
    on player clicks Player_Trade_ITEM_A in TRADE:
    - flag player TradeReady
    - if <player.flag[Trading].as_player.has_flag[TradeReady]> {
      - run Player_Trade_Accept
      } else {
      - flag player TradeReady
      - run Player_Trade_Update def:ready
      - run Player_Trade_Update def:ready as:<player.flag[Trading].as_player> }
      
    on player closes inventory:
    - if <c.inventory.is[!=].to[in@trade]> queue clear
    - if <player.has_flag[TradeUpdate]> {
      - flag player TradeUpdate:!
      } else { - run Player_Trade_Decline }
    
    on player drops item:
    - if <player.open_inventory.title.contains[Trading,]> determine CANCELLED
# =============== Trade Interface Listener End ============== #

# =========== Trade Finish ============ #
Player_Trade_Decline:
  type: task
  debug: false
  close:
  - inventory close
  script:
  - flag player wait duration:1s
  - ^if <player.flag[Trading].as_player.has_flag[Trading]> run locally close as:<player.flag[Trading].as_player>
  - ^flag player trading:!
  - ^foreach <player.flag[Trade].as_list> { - give <def[value]> }
  - ^flag player trade:!
  - ^flag player tradeready:!
  - narrate "<red>The trade was cancelled."

Player_Trade_Accept:
  type: task
  debug: false
  accept:
  - ^foreach <player.flag[Trade].as_list> { - give <def[value]> to:<player.flag[Trading].as_player.inventory> }
  - ^flag player trade:!
  - ^flag player trading:!
  - ^flag player tradeready:!
  - ^flag player TradeUpdate
  - ^inventory close
  - narrate "<green>Trade accepted."
  script:
  - flag player wait duration:1s
  - ^if <player.flag[Trading].as_player.has_flag[Trading]> run locally accept as:<player.flag[Trading].as_player>
  - ^run locally accept
# =========== Trade Finish End ============ #

# =========== Trade Interface Items ========== #
Player_Trade_Item_1:
  type: item
  material: light_gray_stained_glass_pane
  display name<&sp>
Player_Trade_Item_2:
  type: item
  material: light_gray_stained_glass_pane
  display name<&sp>
Player_Trade_Item_r:
  type: item
  material: red_stained_glass_pane
  display name<&sp>
Player_Trade_Item_s:
  type: item
  material: black_stained_glass_pane
  display name<&sp>
Player_Trade_Item_w:
  type: item
  material: yellow_stained_glass_pane
  display name<&sp>
Player_Trade_Item_a:
  type: item
  material: lime_stained_glass_pane
  display name<green>Accept
  lore:
  - "Click here to"
  - "accept the trade."
Player_Trade_Item_y:
  type: item
  material: yellow_stained_glass_pane
  display name<yellow>Ready
  lore:
  - "Waiting for"
  - "other player."
Player_Trade_Item_b:
  type: item
  material: yellow_stained_glass_pane
  display name<yellow>Waiting
  lore:
  - "Other player"
  - "is not ready."
Player_Trade_Item_z:
  type: item
  material: lime_stained_glass_pane
  display name<green>Ready
  lore:
  - "Other player"
  - "has accepted."
# =========== Trade Interface Items End ========== #

Player_Trading_Version:
  type: version
  author: KeangDavid
  name: Player Trading
  version: 1.0.3
  description: Player to player trading
  id: 42



RawRaw



Pastes made: 59170