Paste #10570: Edit of P#10568 - Edit of P#10567 - Untitled Paste

Date: 2014/10/19 08:55:37 UTC-07:00
Type: Denizen Script

View Raw Paste Download This Paste
Copy Link


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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431


################################################################################
#
#  Master Waitress Assignment Script
#
# The Waitress will greet players, deliver menus, take orders, and deliver food.
#
MasterWaitressNPC:
  type: assignment
  speed: 1t
  debug: true

  actions:
    on assignment:
      - run locally assignment instantly
    on spawn:
      - run locally spawn instantly delay:2s
    on despawn:
      - run locally despawn instantly delay:1s
    on click:
      - run locally click_<npc.flag[status]||drunk> instantly
    on move proximity:
      - run locally proximity_<npc.flag[status]||drunk> instantly


  assignment:
  # What happens on assignment. We want this as a subscript so we can run it
  # outside the on assignment action if needed.
    - trigger name:chat state:true radius:5 cooldown:5s
    - trigger name:click state:true radius:5 cooldown:5s
    - trigger name:proximity state:true radius:2 cooldown:2s
    - trigger name:damage state:true radius:5 cooldown:5s
    - vulnerable state:false
    - lookclose true range:5 realistic
    - flag npc respawn_location:<npc.location>
    - flag npc Pathfind.FidgetRadius:5
    - flag npc Pathfind.FidgetSpeed:0.7
    - flag npc Pathfind.FidgetWait:1
    - flag npc Pathfind.FidgetLocation:<npc.location>
    - flag npc Pathfind.FidgetHeight:1
    - flag npc Pathfind.FidgetPathMaterial:<npc.location.standing_on.material.name>
    - flag npc dRestaurant_MenuQueue:!
    - flag npc TicketQueue:!
    - inject locally spawn instantly

  spawn:
    - narrate format:GenericNPCFormat "Alright, time to start work..." targets:<npc.location.find.players.within[5]||null>
    - if <queue.exists[fidgetQueue_<npc.id>]> queue queue:fidgetQueue_<npc.id> stop
    - inject locally processTicketQueue

  despawn:
  # Just a code stub
    - if <queue.exists[fidgetQueue_<npc.id>]> queue queue:fidgetQueue_<npc.id> stop
    - narrate format:GenericNPCFormat "Phew... I<&sq>m glad to be done work for the day!" targets:<npc.location.find.players.within[5]||null>

  damage:
  # Just a code stub
    - narrate format:GenericNPCFormat "Why would you do that?" targets:<npc.location.find.players.within[5]||null>

#
#--------------------------------------
#
#  Logic Utilities
#
#
  collectMenus:
  # Run through a list of players that are waiting to have their menus collected
  # Then go and get them. We aren't going to walk to players that are offline or
  # 30 blocks or more away from the npc. This REALLY should check if the player
  # is in the restaurant cuboid and possibly if the player still has the menu in
  # inventory.
  # Should add nullChecks for this
    - ^if !<npc.is_spawned||false> queue clear
    - if <queue.exists[fidgetQueue_<npc.id>]> queue queue:fidgetQueue_<npc.id> stop
    - inject s@MasterWaitressNPC p:findRestaurant instantly
    - define menuQueue '<npc.flag[dRestaurant_MenuQueue].as_list||null>'
    - if !<def[menuQueue].is_empty||true> {
      - flag npc Status:order
      - foreach %menuQueue% {
        - define player '<def[value].as_player>'
        - if <def[player].is_online||false> && <npc.location.distance[<def[player].location>].is[LESS].than[30]||false> {
          - define loc '<def[player].location.find.surface_blocks[<npc.flag[Pathfind.FidgetPathMaterial].as_list>].within[5].random||<npc.location>>'
          - ~walk %loc% 'speed:<npc.flag[Pathfind.FidgetSpeed].add[0.1].as_money>'
          - look <def[player].eye_location> d:2s
          - wait 10t
          - narrate format:GenericNPCFormat "Your order should be out in just a moment." targets:%player%
          }
        - take '<player.inventory.slot[<player.inventory.find[menu]>].full>' player:%player%
        - flag %player% dRestaurant_Order_Placed:!
        - flag <npc> dRestaurant_MenuQueue:<-:%player%
        - wait 10t
        - if !<npc.flag[TicketQueue].as_list.is_empty||true> {
          - inject processTicketQueue locally
          }
        }
      - if !<npc.flag[dRestaurant_MenuQueue].as_list.is_empty||true> {
        - inject collectMenus locally
        }
      }
    - if !<npc.flag[TicketQueue].as_list.is_empty||true> {
      - inject processTicketQueue locally
      }
    - flag npc Status:available
    - if <queue.exists[fidgetQueue_<npc.id>]> queue queue:fidgetQueue_<npc.id> stop
    - run s@Fidget id:fidgetQueue_<npc.id>
    - queue clear

  processTicketQueue:
  # Run through a list of orders waiting to be delivered. Rinse and repeat until
  # the queue is cleared.
  # Should add nullChecks for this
    - ^if !<npc.is_spawned||false> queue clear
    - inject s@MasterWaitressNPC p:findRestaurant instantly
    - define ticketQueue '<npc.flag[TicketQueue].as_list||null>'
    - narrate format:GenericNPCFormat "<npc.flag[TicketQueue].as_list||null>" targets:<npc.location.find.players.within[5]||null>
    - if !<def[ticketQueue].is_empty||true> {
      - narrate format:GenericNPCFormat "<def[ticketQueue].is_empty||true>" targets:<npc.location.find.players.within[5]||null>
      - flag npc Status:deliver
      - foreach <def[ticketQueue]> {
        - define TicketQueueEntry %value%
        - define ticketNumber '<def[TicketQueueEntry].split_by[/].get[1]>'
        - define displayItems '<def[TicketQueueEntry].split_by[/].get[2].split_by[\].as_list>'
        - define tickets '<server.flag[dRestaurantTickets].as_list>'
        - define ticket '<def[tickets].get[<def[tickets].get_sub_items[1].split_by[/].find[%ticketNumber%]>]>'
        - define player '<def[ticket].split_by[/].get[4].as_player>'
        - define foodItems '<def[ticket].split_by[/].get[5].as_list>'
        - inject s@dRestaurant p:deliverFood_waitress
        - flag npc TicketQueue:<-:%TicketQueueEntry%
        - flag server dRestaurantTickets:<-:%ticket%
        - wait 5t
        - if <npc.has_flag[dRestaurant_MenuQueue]> {
          - inject locally collectMenus
          }
        }
      - if !<npc.flag[TicketQueue].as_list.is_empty||true> {
        - inject processTicketQueue locally
        }
      }
    # Finish up by collecting any menus in queue
    - if <npc.has_flag[dRestaurant_MenuQueue]> {
      - inject locally collectMenus
      }
    - flag npc Status:available
    - if <queue.exists[fidgetQueue_<npc.id>]> queue queue:fidgetQueue_<npc.id> stop
    - run s@Fidget id:fidgetQueue_<npc.id>
    - queue clear

  findRestaurant:
  # This requires an NPC object and should only be run when the player is
  # getting a menu from a waitress in the on click action
    - define restaurants li@
    - foreach <npc.location.cuboids> {
      - if <def[value].notable_name.split[_].get[1].is[==].to[Restaurant]> {
        - define restaurant '<def[value].notable_name.split[_].get[2]>'
        - define owner '<server.flag[dRestaurant.%restaurant%.Owner].as_player>'
        - if <def[owner].is[==].to[<npc.owner>]> {
          - define restaurants '<def[restaurants].include[%restaurant%]>'
          }
        }
      }
    # Because why else would any sane admin have restaurant cuboids overlap?
    - define restaurant '<def[restaurants].random||null>'
    - if <def[restaurant].is[==].to[null]> {
      - narrate format:GenericNPCFormat "Oh dear, I seem to be quite lost..." targets:<npc.location.find.players.within[5]||null>
      - flag npc status:drunk
      - queue stop
      }

  assignWaitress:
  # This assumes we know the restaurant
    - define waitresses li@
    - define owner '<server.flag[dRestaurant.%restaurant%.Owner].as_player>'
    - foreach <el@val[cu@Restaurant_%restaurant%].as_cuboid.list_npcs> {
      - define npc %value%
      - if <def[owner].is[==].to[<def[npc].owner>]>
        && <def[npc].script.name.is[==].to[MasterWaitressNPC]> {
        - define waitresses '<def[waitresses].include[%npc%]>'
        }
      }
    # Now we have a list of waitresses, let's find the least busy
    - foreach %waitresses% {
      - define waitress '<def[waitress]||%value%>'
      - if <def[value].flag[TicketQueue].size.is[LESS].than[<def[waitress].flag[TicketQueue].size>]> {
        - define waitress %value%
        }
      }

  assignChef:
  # This assumes we know the restaurant
    - define chefs li@
    - define owner '<server.flag[dRestaurant.%restaurant%.Owner].as_player>'
    - foreach <el@val[cu@Restaurant_%restaurant%].as_cuboid.list_npcs> {
      - define npc %value%
      - if <def[owner].is[==].to[<def[npc].owner>]>
        && <def[npc].script.name.is[==].to[MasterChefNPC]> {
        - define chefs '<def[chefs].include[%npc%]>'
        }
      }
    # Now we have a list of chefs, let's find the least busy
    - foreach %chefs% {
      - define chef '<def[chef]||%value%>'
      - if <def[value].flag[OrderQueue].size.is[LESS].than[<def[chef].flag[OrderQueue].size>]> {
        - define chef %value%
        }
      }

  assignTicketNumber:
    - repeat 20 {
      - define ticketNumber <util.random.duuid>
      - define ticketList <server.flag[dRestaurantTickets].get_sub_items[1].split_by[/]||null>
      - if !<def[ticketList].contains[%ticketNumber%]> repeat stop
      - if <def[value].is[OR_MORE].than[20]> {
        - define ticketNumber "LastLostTicketDetails"
        - announce "<&b>dRestaurant<&co> <&c>Order Lost - Couldn<&sq>t get a valid ticket number!" to_console
        - announce "<&b>dRestaurant<&co> <&c>%ticketNumber%" to_console
        - announce "<&b>dRestaurant<&co> <&c>Chef<&co> %chef%" to_console
        - announce "<&b>dRestaurant<&co> <&c>Waitress<&co> %waitress%" to_console
        - announce "<&b>dRestaurant<&co> <&c>Player<&co> <player>" to_console
        - announce "<&b>dRestaurant<&co> <&c>foodItems<&co> %foodItems%" to_console
        }
      }

#
#  END Logic Utilities
#
#--------------------------------------
#
#  MasterWaitress Status Actions
#
# We're using an NPC status system for action responses. This is a low latency
# and low load method that allows for very fast NPC reactions since they do not
# have to do ANY comparisons. They just run the correct subscript based on the
# action and their current status.
#
#
#--------------------------------------
#  Click Responses
#
  click_drunk:
  # A catchall if something derps
    - flag npc status:drunk
    - if <queue.exists[fidgetQueue_<npc.id>]> queue queue:fidgetQueue_<npc.id> stop
    - if random {
      - narrate format:GenericNPCFormat "I quit!" targets:<npc.location.find.players.within[5]||null>
      - narrate format:GenericNPCFormat "I<&sq>m done with this place!" targets:<npc.location.find.players.within[5]||null>
      - narrate format:GenericNPCFormat "I should have called out!" targets:<npc.location.find.players.within[5]||null>
      - narrate format:GenericNPCFormat "I had way too much to drink last night..." targets:<npc.location.find.players.within[5]||null>
      - narrate format:GenericNPCFormat "I<&sq>m not feeling well... I have to go." targets:<npc.location.find.players.within[5]||null>
      }
    - wait 2s
    - despawn <npc>

  click_available:
  # When the Waitress is available for whatever
    - flag npc status:order
    - if <player.has_flag[dRestaurant_Order_Placed]> {
      - narrate format:GenericNPCFormat "Someone will collect your menu soon."
      - flag npc status:available
      - queue stop
      }
    - if <player.has_flag[dRestaurant_Order]> {
      - narrate format:GenericNPCFormat "Open up your menu and complete your order."
      - flag npc status:available
      - queue stop
      }
    - if <queue.exists[fidgetQueue_<npc.id>]> queue queue:fidgetQueue_<npc.id> stop
    - inject locally findRestaurant instantly
    - flag <player> dRestaurant_Order:%restaurant%
    - define loc <player.location.find.surface_blocks[<npc.flag[Pathfind.FidgetPathMaterial].as_list>].within[2].get[1]||<npc.location>>
    - ~walk %loc% 'speed:<npc.flag[Pathfind.FidgetSpeed].add[0.1].as_money>'
    - look <player.eye_location> d:2s
    - wait 5t
    - random {
      - narrate format:GenericNPCFormat "Click on the items in the menu." targets:<npc.location.find.players.within[5]||null>
      - narrate format:GenericNPCFormat "Browse through the menu. I<&sq>m sure you<&sq>ll find something you like." targets:<npc.location.find.players.within[5]||null>
      - narrate format:GenericNPCFormat "We serve only the best food prepared by Master Chefs." targets:<npc.location.find.players.within[5]||null>
      - narrate format:GenericNPCFormat "Open the menu and click on the items you want." targets:<npc.location.find.players.within[5]||null>
      - narrate format:GenericNPCFormat "Here you go. Take a look through our menu and choose what you would like."
      }
    - give 'i@menu[display_name=%restaurant% Menu]'
    - wait 15t
    - random {
      - narrate format:GenericNPCFormat "Place your order and I<&sq>ll come get the menu." targets:<npc.location.find.players.within[5]||null>
      - narrate format:GenericNPCFormat "Click the Order Accept button to place your order." targets:<npc.location.find.players.within[5]||null>
      - narrate format:GenericNPCFormat "A waitress will take the menu when you<&sq>re done." targets:<npc.location.find.players.within[5]||null>
      - narrate format:GenericNPCFormat "Click the Order Accept button when you<&sq>re finished." targets:<npc.location.find.players.within[5]||null>
      - narrate format:GenericNPCFormat "Someone will come grab the menu when you are ready."
      }
    - wait 30t
    - inject processTicketQueue locally

  click_order:
  # When the Waitress is taking an order
    - wait 15t
    - random {
      - narrate format:GenericNPCFormat "I<&sq>ll be right with you <player.name>."
      - narrate format:GenericNPCFormat "I<&sq>m with another customer right now." targets:<npc.location.find.players.within[5]||null>
      - narrate format:GenericNPCFormat "One moment please, I<&sq>m taking an order." targets:<npc.location.find.players.within[5]||null>
      - narrate format:GenericNPCFormat "Someone will be with you soon." targets:<npc.location.find.players.within[5]||null>
      - narrate format:GenericNPCFormat "Hold on a sec there dear, I<&sq>m taking another order right now." targets:<npc.location.find.players.within[5]||null>
      }

  click_deliver:
  # When the Waitress is delivering food
    - wait 15t
    - random {
      - narrate format:GenericNPCFormat "We<&sq>re a little busy right now <player.name>."
      - narrate format:GenericNPCFormat "I<&sq>m running food right now <player.name>." targets:<npc.location.find.players.within[5]||null>
      - narrate format:GenericNPCFormat "My hands are a little full <player.name>" targets:<npc.location.find.players.within[5]||null>
      - narrate format:GenericNPCFormat "<player.name> they really don<&sq>t pay me enough for this..." targets:<npc.location.find.players.within[5]||null>
      - narrate format:GenericNPCFormat "I<&sq>m pretty tired <player.name>." targets:<npc.location.find.players.within[5]||null>
      - narrate format:GenericNPCFormat "Please have a seat and a Waitress will be right with you." targets:<npc.location.find.players.within[5]||null>
      }

#
#--------------------------------------
#  Order Up Responses
#
  orderup_drunk:
  # A catchall if something derps
    - flag npc status:drunk
    - if <queue.exists[fidgetQueue_<npc.id>]> queue queue:fidgetQueue_<npc.id> stop
    - random {
      - narrate format:GenericNPCFormat "I quit!" targets:<npc.location.find.players.within[5]||null>
      - narrate format:GenericNPCFormat "I<&sq>m done with this place!" targets:<npc.location.find.players.within[5]||null>
      - narrate format:GenericNPCFormat "I should have called out!" targets:<npc.location.find.players.within[5]||null>
      - narrate format:GenericNPCFormat "I had way too much to drink last night..." targets:<npc.location.find.players.within[5]||null>
      - narrate format:GenericNPCFormat "I<&sq>m not feeling well... I have to go." targets:<npc.location.find.players.within[5]||null>
      }
    - wait 2s
    - despawn <npc>

  orderup_available:
  # When the Waitress is available for whatever
    - flag npc status:deliver
    - if <queue.exists[fidgetQueue_<npc.id>]> queue queue:fidgetQueue_<npc.id> stop
    - if <util.random.int[1].to[10].is[OR_MORE].than[7]> {
      - random {
        - narrate format:GenericNPCFormat "Ticket %ticketNumber% heard!" targets:<npc.location.find.players.within[5]||null>
        - narrate format:GenericNPCFormat "Oh, another order is ready." targets:<npc.location.find.players.within[5]||null>
        - narrate format:GenericNPCFormat "Yay! Food to run!" targets:<npc.location.find.players.within[5]||null>
        - narrate format:GenericNPCFormat "I<&sq>m a happy little worker bee." targets:<npc.location.find.players.within[5]||null>
        - narrate format:GenericNPCFormat "Time to get working." targets:<npc.location.find.players.within[5]||null>
        }
      }
    - inject locally processTicketQueue

  orderup_order:
  # When the Waitress is taking an order
    - if <util.random.int[1].to[10].is[OR_MORE].than[7]> {
      - random {
        - narrate format:GenericNPCFormat "Heard ticket %ticketNumber%! I<&sq>m taking an order right now." targets:<npc.location.find.players.within[5]||null>
        - narrate format:GenericNPCFormat "Buzz buzz." targets:<npc.location.find.players.within[5]||null>
        - narrate format:GenericNPCFormat "The kitchen sure is busy!" targets:<npc.location.find.players.within[5]||null>
        - narrate format:GenericNPCFormat "They are working hard back there." targets:<npc.location.find.players.within[5]||null>
        - narrate format:GenericNPCFormat "The guy on the grill is by bf." targets:<npc.location.find.players.within[5]||null>
        }
      }

  orderup_deliver:
  # When the Waitress is delivering food
    - if <util.random.int[1].to[10].is[OR_MORE].than[7]> {
      - random {
        - narrate format:GenericNPCFormat "Heard ticket %ticketNumber%! I<&sq>m running food right now." targets:<npc.location.find.players.within[5]||null>
        - narrate format:GenericNPCFormat "My goodness, the food just keeps on coming!" targets:<npc.location.find.players.within[5]||null>
        - narrate format:GenericNPCFormat "I<&sq>m in the weeds!" targets:<npc.location.find.players.within[5]||null>
        - narrate format:GenericNPCFormat "I<&sq>m going as fast as I can!" targets:<npc.location.find.players.within[5]||null>
        - narrate format:GenericNPCFormat "This is a rough night!" targets:<npc.location.find.players.within[5]||null>
        }
      }
#
#--------------------------------------
#  Proximity Responses
#
  proximity_drunk:
  # A catchall if something derps
    - flag npc status:drunk
    - if <queue.exists[fidgetQueue_<npc.id>]> queue queue:fidgetQueue_<npc.id> stop
    - random {
      - narrate format:GenericNPCFormat "I quit!" targets:<npc.location.find.players.within[5]||null>
      - narrate format:GenericNPCFormat "I<&sq>m done with this place!" targets:<npc.location.find.players.within[5]||null>
      - narrate format:GenericNPCFormat "I should have called out!" targets:<npc.location.find.players.within[5]||null>
      - narrate format:GenericNPCFormat "I had way too much to drink last night..." targets:<npc.location.find.players.within[5]||null>
      - narrate format:GenericNPCFormat "I<&sq>m not feeling well... I have to go." targets:<npc.location.find.players.within[5]||null>
      }
    - wait 2s
    - despawn <npc>

  proximity_available:
  # When the Waitress is available for whatever
    - if <util.random.int[1].to[10].is[OR_MORE].than[7]> {
      - random {
        - narrate format:GenericNPCFormat "Ticket %ticketNumber% heard!" targets:<npc.location.find.players.within[5]||null>
        - narrate format:GenericNPCFormat "Oh, another order is ready." targets:<npc.location.find.players.within[5]||null>
        - narrate format:GenericNPCFormat "Yay! Food to run!" targets:<npc.location.find.players.within[5]||null>
        - narrate format:GenericNPCFormat "I<&sq>m a happy little worker bee." targets:<npc.location.find.players.within[5]||null>
        - narrate format:GenericNPCFormat "Time to get working." targets:<npc.location.find.players.within[5]||null>
        }
      }

  proximity_order:
  # When the Waitress is taking an order
    - if <util.random.int[1].to[10].is[OR_MORE].than[7]> {
      - random {
        - narrate format:GenericNPCFormat "Heard ticket %ticketNumber%! I<&sq>m taking an order right now." targets:<npc.location.find.players.within[5]||null>
        - narrate format:GenericNPCFormat "Buzz buzz." targets:<npc.location.find.players.within[5]||null>
        - narrate format:GenericNPCFormat "The kitchen sure is busy!" targets:<npc.location.find.players.within[5]||null>
        - narrate format:GenericNPCFormat "They are working hard back there." targets:<npc.location.find.players.within[5]||null>
        - narrate format:GenericNPCFormat "The guy on the grill is by bf." targets:<npc.location.find.players.within[5]||null>
        }
      }

  proximity_deliver:
  # When the Waitress is delivering food
    - define player '<npc.flag[dRestaurant_MenuQueue].as_list.get[1].as_player||null>'
    - if <util.random.int[1].to[10].is[OR_MORE].than[7]> {
      - random {
        - narrate format:GenericNPCFormat "Heard ticket %ticketNumber%! I<&sq>m running food right now." targets:<npc.location.find.players.within[5]||null>
        - narrate format:GenericNPCFormat "My goodness, the food just keeps on coming!" targets:<npc.location.find.players.within[5]||null>
        - narrate format:GenericNPCFormat "I<&sq>m in the weeds!" targets:<npc.location.find.players.within[5]||null>
        - narrate format:GenericNPCFormat "I<&sq>m going as fast as I can!" targets:<npc.location.find.players.within[5]||null>
        - narrate format:GenericNPCFormat "This is a rough night!" targets:<npc.location.find.players.within[5]||null>
        }
      }

#
#  END MasterWaitress Status Actions
#--------------------------------------
#
#
#  END MASTERWAITRESS ASSIGNMENT SCRIPT CONTAINER
#