Paste #36519: Edit of P#36513 BlackJackDealer

Date: 2016/09/28 10:36:51 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
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539


###############################################################################################
#                                                                                             #
#       BlackJackDealer GUI Script by: Revdutchie # !! This script requires Vault !!          #
#                                                                                             #
#       Credits to: BlackCoyote for his original blackjack text script                        #
#                   You can find it here http://one.denizenscript.com/denizen/repo/entry/4    #
#                   If you want to have a great text chat based blackjack script              #
#                                                                                             #
#                   The Denizen IRC community who is always there to help                     #
#                   I can name many but mcmonkey and BlackCoyote helped me a lot.             #
#                                                                                             #
###############################################################################################
#                                                                                             #
#                    /npc assign --set BlackJackDealer_assignment                             #
#                                                                                             #
###############################################################################################

BlackJackDealer_assignment:
  type: assignment
  debug: false
  actions:
    on assignment:
      - trigger name:click state:true

    on click:  #### Set payout multiplier options here ####
      - ^flag player TieHandPayout:1.0
      - ^flag player HighHandPayout:2.0
      - ^flag player 21HandPayout:2.1
      - ^flag player BlackJackPayout:2.5

      - if <player.flag[BlackJackStatus]||null> == "InAction" {
        - inventory open d:in@Player_Action_Inventory
        } else {
        - run BlackJack_ResetFlags
        - narrate "<&2>Hi <&e><player.name> <&2>Let's play some <&6>BlackJack!"
        - WAIT 1s
        - narrate "<&2>First you have to place a <&6>bet."
        - wait 1s
        - inventory open d:in@Set_Bet_Inventory
        }

BlackJackDealer_version:
  type: version
  name: BlackJackDealer
  id: 113
  description: NPC blackjack dealer with GUI.
  version: 1.0.2

BlackJackTracker:
  type: world
  debug: false
  events:
    on system time hourly:
    - webget "http://stats.denizenscript.com/tracker?script=113&version=1.0.2"

################################## Set Bet Inventory ##########################################

Set_Bet_Inventory:
  type: inventory
  title: "<&4><&chr[2665]> <&0><&chr[2663]> <&4><&chr[2666]> <&0><&chr[2660]>    <&9>Place your bet    <&4><&chr[2665]> <&0><&chr[2663]> <&4><&chr[2666]> <&0><&chr[2660]>"
  size: 27
  slots:
  - "[] [] [] [] [] [] [] [] []"
  - "[] [i@Bet10] [i@Bet25] [i@Bet50] [i@Bet75] [i@Bet100] [i@Bet150] [i@Bet200] []"
  - "[] [] [] [] [] [] [] [] []"

Bet10:
  type: item
  material: "16"
  display name: "<&6>Bet <&a>$<&2>10"

Bet25:
  type: item
  material: "15"
  display name: "<&6>Bet <&a>$<&2>25"

Bet50:
  type: item
  material: "21"
  display name: "<&6>Bet <&a>$<&2>50"

Bet75:
  type: item
  material: "73"
  display name: "<&6>Bet <&a>$<&2>75"

Bet100:
  type: item
  material: "14"
  display name: "<&6>Bet <&a>$<&2>100"

Bet150:
  type: item
  material: "129"
  display name: "<&6>Bet <&a>$<&2>150"

Bet200:
  type: item
  material: "56"
  display name: "<&6>Bet <&a>$<&2>200"

Set_Bet_Inventory_Handler:
  type: world
  events:
    on player clicks in Set_Bet_Inventory:
    - determine cancelled
    on player drags in Set_Bet_Inventory:
    - determine cancelled
    ############################################

    on player clicks Bet10 in Set_Bet_Inventory:
    - flag <player> Betvalue:10
    - flag <player> BetStartvalue:10
    - run Set_Bet_Handler

    on player clicks Bet25 in Set_Bet_Inventory:
    - flag <player> Betvalue:25
    - flag <player> BetStartvalue:25
    - run Set_Bet_Handler

    on player clicks Bet50 in Set_Bet_Inventory:
    - flag <player> Betvalue:50
    - flag <player> BetStartvalue:50
    - run Set_Bet_Handler

    on player clicks Bet75 in Set_Bet_Inventory:
    - flag <player> Betvalue:75
    - flag <player> BetStartvalue:75
    - run Set_Bet_Handler

    on player clicks Bet100 in Set_Bet_Inventory:
    - flag <player> Betvalue:100
    - flag <player> BetStartvalue:100
    - run Set_Bet_Handler

    on player clicks Bet150 in Set_Bet_Inventory:
    - flag <player> Betvalue:150
    - flag <player> BetStartvalue:150
    - run Set_Bet_Handler

    on player clicks Bet200 in Set_Bet_Inventory:
    - flag <player> Betvalue:200
    - flag <player> BetStartvalue:200
    - run Set_Bet_Handler

################################## Action Inventory ###########################################

Player_Action_Inventory:
  type: inventory
  title: "<&4><&chr[2665]> <&0><&chr[2663]> <&4><&chr[2666]> <&0><&chr[2660]>  <&9>Hit / Stay / Double <&4><&chr[2665]> <&0><&chr[2663]> <&4><&chr[2666]> <&0><&chr[2660]>"
  size: 27
  slots:
  - "[] [] [] [] [] [] [] [] []"
  - "[] [] [i@BlackJackHit] [] [i@BlackJackStay] [] [i@BlackJackDouble] [] []"
  - "[] [] [] [] [] [] [] [] []"

BlackJackHit:
  type: item
  material: "129"
  display name: "<green>Hit                <&b>|<&a>$<&6><player.money.as_int||0><&b>|"
  lore:
  - "<&b>Click here for a card"
  - ""
  - "<&e>Your <&2>hand has <&e><player.flag[playerhandvalue].as_int||0><&2> points"
  - "<&e>Your <&2>current bet <&a>$<&6><player.flag[Betvalue]||0>"
  - ""
  - "<&5>Dealer <&2>hand <&e><player.flag[computerhandvalue].as_int||0>"
  - ""

BlackJackStay:
  type: item
  material: "73"
  display name: "<red>Stay          <&b>|<&a>$<&6><player.money.as_int||0><&b>|"
  lore:
  - "<&b>Click here to stand."
  - ""
  - "<&e>Your <&2>hand has <&e><player.flag[playerhandvalue].as_int||0><&2> points"
  - "<&e>Your <&2>current bet <&a>$<&6><player.flag[Betvalue]>"
  - ""
  - "<&5>Dealer <&2>hand <&e><player.flag[computerhandvalue].as_int||0>"
  - ""

BlackJackDouble:
  type: item
  material: "14"
  display name: "<&6>Double Down            <&b>|<&a>$<&6><player.money.as_int||0><&b>|"
  lore:
  - "<&2>Doubles your bet but you get <&b>1<&2> card only"
  - ""
  - "<&e>Your <&2>hand has <&e><player.flag[playerhandvalue].as_int||0><&2> points"
  - "<&e>Your <&2>current bet <&a>$<&6><player.flag[Betvalue]||0>"
  - ""
  - "<&5>Dealer <&2>hand <&e><player.flag[computerhandvalue].as_int||0>"
  - ""

Player_Action_Inventory_Handler:
  type: world
  events:
    on player clicks in Player_Action_Inventory:
    - determine cancelled
    on player drags in Player_Action_Inventory:
    - determine cancelled
    ################################################

    on player clicks BlackJackHit in Player_Action_Inventory:
    - ^inventory close
    - ^wait 1s
    - ^run BlackJack_givecard def:player instantly
    - ^run BlackJackPlayerHandCheck
    - narrate "<&e>You <&2>now have <&e><player.flag[playerhandvalue].as_int||0> points"

    on player clicks BlackJackStay in Player_Action_Inventory:
    - ^inventory close
    - narrate "<&e>You <&2> deceided to <&6>stay, <&2>good luck."
    - ^narrate "<&5>Dealer <&2> will finish his hand"
    - ^wait 1s
    - run BlackJackDealerHandCheck

    on player clicks BlackJackDouble in Player_Action_Inventory:
    - inventory close
    - if <player.money> >= <player.flag[Betvalue]||0> {
      - money take quantity:<player.flag[Betvalue]||0>
      - flag player betvalue:<player.flag[betvalue].mul[2]>
      - playsound <player> sound:BLOCK_ANVIL_USE pitch:2
      - narrate "<&e>You <&2>doubled your bet to <&a>$<&6><player.flag[Betvalue]||0>"
      - wait 1s
      - run BlackJack_givecard def:player instantly
      - flag <player> BlackJackStatus:!
      - narrate "<&e>You <&2>now have <&e><player.flag[playerhandvalue].as_int||0> points"
      - if <player.flag[playerhandvalue].as_int||0> > 21 {
        - narrate "<&e>You <&4>Are BUSTED with <&6><player.flag[playerhandvalue].as_int||0> points!"
        - ^playsound <player> sound:ENTITY_DONKEY_ANGRY pitch:1
        - wait 2s
        - run BlackJack_ResetFlags
        - inventory open d:in@BlackJack_End_Game_Inventory
        } else {
        - narrate "<&e>You <&2> have to <&6>stay <&2>now, good luck."
        - narrate "<&5>Dealer <&2> will finish his hand"
        - wait 1s
        - run BlackJackDealerHandCheck
        }
      } else {
      - narrate "<&e>You <&4>do not have enough money!"
      - wait 1s
      - inventory open d:in@Player_Action_Inventory
      }

################################## End Game Inventory ###########################################

BlackJack_End_Game_Inventory:
  type: inventory
  title: "<&4><&chr[2665]> <&0><&chr[2663]> <&4><&chr[2666]> <&0><&chr[2660]>   <&9>Play a new game?  <&4><&chr[2665]> <&0><&chr[2663]> <&4><&chr[2666]> <&0><&chr[2660]>"
  size: 27
  slots:
  - "[] [] [] [] [] [] [] [] []"
  - "[] [] [i@NewGameNewBet] [] [i@NewGameYes] [] [i@NewGameNO] [] []"
  - "[] [] [] [] [] [] [] [] []"

NewGameNewBet:
  type: item
  material: "22"
  display name: "<green>New Game Yes"
  lore:
  - "Set an other bet value"

NewGameYes:
  type: item
  material: "133"
  display name: "<green>New Game Yes"
  lore:
  - "Start game with same bet value"

NewGameNo:
  type: item
  material: "152"
  display name: "<green>New Game No"
  lore:
  - "No thanks, I am done"

Player_End_Game_Inventory_Handler:
  type: world
  events:
    on player clicks in BlackJack_End_Game_Inventory:
    - determine cancelled
    on player drags in BlackJack_End_Game_Inventory:
    - determine cancelled
  ################################################

    on player clicks NewGameNewBet in BlackJack_End_Game_Inventory:
    - run BlackJack_ResetFlags
    - inventory open d:in@Set_Bet_Inventory

    on player clicks NewGameYes in BlackJack_End_Game_Inventory:
    - run BlackJack_ResetFlags
    - flag player betvalue:<player.flag[BetStartvalue]||0>
    - run Set_Bet_Handler

    on player clicks NewGameNo in BlackJack_End_Game_Inventory:
    - run BlackJack_ResetFlags
    - inventory close
    - Narrate "<&2>Goodbye, <&e><player.name> <&2>hope to see you back soon!"

########################## Handlers and checks #################################

Set_Bet_Handler:
  type: task
  script:
    - if <player.money> >= <player.flag[Betvalue]||0> {
      - ^money take quantity:<player.flag[Betvalue]||0>
      - ^playsound <player> sound:BLOCK_ANVIL_USE pitch:2
      - ^run BlackJack_ResetFlags
      - ^flag player BlackJackStatus:InAction
      - ^inventory close
      - narrate "<&5>-----------------------------------------------------"
      - run BlackJack_startdealing
      } else {
      - ^inventory close
      - narrate "<&e>You <&4>do not have enough money!"
      }

BlackJackPlayerHandCheck:
  type: task
  script:
    - if <player.flag[playerhandvalue].as_int||0> > 21 {
       - ^narrate "<&e>You <&4>Are BUSTED with <&e><player.flag[playerhandvalue].as_int||0> <&2>points!"
       - playsound <player> sound:ENTITY_DONKEY_ANGRY pitch:1
       - ^narrate "<&e>Your <&2>wallet is now <&a>$<&6><player.money.as_int||0>"
       - ^run BlackJack_ResetFlags
       - ^wait 2s
       - inventory open d:in@BlackJack_End_Game_Inventory
       } else if <player.flag[playerhandvalue].as_int||0> == 21 {
       - narrate "<&e>You <&2>have <&e>21 <&2>points, good luck!"
       - wait 1s
       - run BlackJackDealerHandCheck
       } else {
       - inventory open d:in@Player_Action_Inventory
       }

BlackJackDealerHandCheck:
  type: task
  script:
    - if <player.flag[computerhandvalue].as_int||0> < 17 {
      - ^run BlackJack_givecard def:computer instantly
      - ^narrate "<&2>Dealer now has <&e><player.flag[computerhandvalue].as_int||0> points"
      - ^wait 1s
      - run BlackJackDealerHandCheck
      } else if <player.flag[computerhandvalue].as_int||0> > 21 {
      - ^narrate "<&4>Dealer Busted with <&e><player.flag[computerhandvalue].as_int||0> points"
      - run BlackJackHighestHand
      } else {
      - run BlackJackEndResultCheck
      }

BlackJackEndResultCheck:
  type: task
  script:
    - if <player.flag[computerhandvalue].as_int||0> > <player.flag[playerhandvalue].as_int||0> {
      - run BlackJack_ResetFlags
      - ^narrate "<&5>Dealer <&6>Won! <&2>Better luck next time."
      - ^playsound <player> sound:ENTITY_DONKEY_ANGRY pitch:1
      - ^wait 2s
      - inventory open d:in@BlackJack_End_Game_Inventory
      } else if <player.flag[computerhandvalue].as_int||0> == <player.flag[playerhandvalue].as_int||0> {
      - ^run BlackJack_ResetFlags
      - narrate "<&2>It's a <&6>Tie! <&2>Your bet is returned"
      - narrate "<&e>You <&2>recieve <&a>$<&6><player.flag[betvalue].mul[<player.flag[TieHandPayout]>]>"
      - ^give money quantity:<player.flag[betvalue].mul[<player.flag[TieHandPayout]>]>
      - ^narrate "<&e>Your <&2>wallet is now <&a>$<&6><player.money.as_int||0>"
      - ^wait 2s
      - inventory open d:in@BlackJack_End_Game_Inventory
      } else if <player.flag[computerhandvalue].as_int||0> < <player.flag[playerhandvalue].as_int||0> {
      - run BlackJackHighestHand
      }

BlackJackHighestHand:
  type: task
  script:
    - if <player.flag[playerhandvalue].as_int||0> == 21 {
      - ^run BlackJack_ResetFlags
      - narrate "<&e>You <&6>won <&2>this hand with <&e>21 <&2>points."
      - ^narrate "<&e>You <&2>recieve <&a>$<&6><player.flag[betvalue].as_int.mul[<player.flag[21HandPayout]>]>"
      - ^give money quantity:<player.flag[betvalue].mul[<player.flag[21HandPayout]>]>
      - ^playsound <player> sound:ENTITY_PLAYER_LEVELUP pitch:0.8
      - ^narrate "<&e>Your <&2>wallet is now <&a>$<&6><player.money.as_int||0>"
      - ^wait 2s
      - inventory open d:in@BlackJack_End_Game_Inventory
      } else {
      - ^run BlackJack_ResetFlags
      - ^narrate "<&e>You <&6>won! <&2>You recieve <&a>$<&6><player.flag[betvalue].as_int.mul[<player.flag[HighHandPayout]>]>."
      - ^give money quantity:<player.flag[betvalue].mul[<player.flag[HighHandPayout]>]>
      - ^playsound <player> sound:ENTITY_PLAYER_LEVELUP pitch:0.8
      - ^narrate "<&e>Your <&2>wallet is now <&a>$<&6><player.money.as_int||0>"
      - ^wait 2s
      - inventory open d:in@BlackJack_End_Game_Inventory
      }

BlackJackPayout:
  type: task
  script:
    - run BlackJack_ResetFlags
    - narrate "<&e>You <&2>have <&6>BLACKJACK! <&2>"
    - ^narrate "<&e>You <&2>instantly win <&a>$<&6><player.flag[betvalue].as_int.mul[<player.flag[BlackJackPayout]>]>"
    - ^give money <player.flag[betvalue].mul[<player.flag[BlackJackPayout]>]>
    - ^playsound <player> sound:ENTITY_PLAYER_LEVELUP pitch:0.8
    - wait 1s
    - ^playsound <player> sound:ENTITY_PLAYER_LEVELUP pitch:0.8
    - ^narrate "<&e>Your <&2>wallet is now <&a>$<&6><player.money.as_int||0>"
    - ^wait 2s
    - inventory open d:in@BlackJack_End_Game_Inventory

#################################################################################
######################### BlackJack Mechanics Below #############################
#################################################################################

BlackJack_startdealing:
  type: task
  debug: false
  script:
  - narrate "<&e>Your <&2>bet is <&a>$<&6><player.flag[betvalue]||0>"
  - narrate "<&e>Your <&2>wallet is now <&a>$<&6><player.money.as_int||0>"
  - wait 1s
  - run BlackJack_givecard def:player instantly
  - wait 1s
  - run BlackJack_givecard def:computer instantly
  - wait 1s
  - run BlackJack_givecard def:player instantly
  - wait 1s
  - narrate "<&5>Dealer <&2>recieved <&a>undisclosed <&2>card"
  - playsound <player> sound:ENTITY_BAT_TAKEOFF pitch:1.5
  - wait 1s
  - if <player.flag[playerhandvalue].as_int||0> == 21 {
    - run BlackJackPayout
    } else {
    - narrate "<&e>Your <&2>hand has <&e><player.flag[playerhandvalue].as_int||0> points"
    - wait 1s
    - inventory open d:in@Player_Action_Inventory
    }

BlackJack_givecard:
  type: task
  debug: false
  speed: 1
  script:
  - define card <player.flag[cardpack].random[1].as_list.get[1]>
  - flag <player> cardpack:<-:%card%
  - flag <player> %1%hand:->:%card%
  - flag <player> %1%handvalue:+:<proc[BlackJack_cardvalueprocedure].context[%card%|%1%]>
  - playsound <player> sound:ENTITY_BAT_TAKEOFF pitch:1.5
  - if %1% == player narrate "<&e>You <&2>recieved <proc[BlackJack_cardnameprocedure].context[%card%]>"
  - if %1% == computer narrate "<&5>Dealer <&2>recieved <proc[BlackJack_cardnameprocedure].context[%card%]>"

BlackJack_cardvalueprocedure:
  type: procedure
  definitions: card|type
  debug: false
  speed: 1
  script: 
  - if <el@val[%card%].starts_with[a]> {
    - define value <el@val[%card%].after[a]>
    - if %value% > 10 define value 10
    - if %value% == 1 {
      - if <player.flag[%type%handvalue]||0> < 11 define value 11
      } 
    }
  - if <el@val[%card%].starts_with[b]> {
    - define value <el@val[%card%].after[b]>
    - if %value% > 10 define value 10
    - if %value% == 1 {
      - if <player.flag[%type%handvalue]||0> < 11 define value 11
      } 
    }
  - if <el@val[%card%].starts_with[c]> {
    - define value <el@val[%card%].after[c]>
    - if %value% > 10 define value 10
    - if %value% == 1 {
      - if <player.flag[%type%handvalue]||0> < 11 define value 11
      } 
    }
  - if <el@val[%card%].starts_with[d]> {
    - define value <el@val[%card%].after[d]>
    - if %value% > 10 define value 10
    - if %value% == 1 {
      - if <player.flag[%type%handvalue]||0> < 11 define value 11
      }
    }
  - determine %value%

BlackJack_cardnameprocedure:
  type: procedure
  definitions: card
  debug: false
  speed: 1
  script: 
  - if <el@val[%card%].starts_with[a]> {
    - define type <&4><&chr[2665]><&a>
    - define value <el@val[%card%].after[a]>
    - if %value% == 1 define value Ace
    - if %value% == 13 define value King
    - if %value% == 12 define value Queen
    - if %value% == 11 define value Jack
    }
  - if <el@val[%card%].starts_with[b]> {
    - define type <&4><&chr[2666]><&a>
    - define value <el@val[%card%].after[b]>
    - if %value% == 1 define value Ace
    - if %value% == 13 define value King
    - if %value% == 12 define value Queen
    - if %value% == 11 define value Jack
    }
  - if <el@val[%card%].starts_with[c]> {
    - define type <&7><&chr[2663]><&a>
    - define value <el@val[%card%].after[c]>
    - if %value% == 1 define value Ace
    - if %value% == 13 define value King
    - if %value% == 12 define value Queen
    - if %value% == 11 define value Jack
    }
  - if <el@val[%card%].starts_with[d]> {
    - define type <&7><&chr[2660]><&a>
    - define value <el@val[%card%].after[d]>
    - if %value% == 1 define value Ace
    - if %value% == 13 define value King
    - if %value% == 12 define value Queen
    - if %value% == 11 define value Jack
    }
  - determine '<el@val[%type%]||no><&a> <el@val[%value%]||cards>'

BlackJack_ResetFlags:
  type: task
  debug: false
  script:
  - flag <player> BlackJackStatus:!
  - flag <player> computerstay:!
  - flag <player> playerhandvalue:!
  - flag <player> computerhandvalue:!
  - flag <player> playerhand:!
  - flag <player> computerhand:!
  - flag <player> cardpack:!
  - flag <player> cardpack:|:a1|a2|a3|a4|a5|a6|a7|a8|a9|a10|a12|a13|b1|b2|b3|b4|b5|b6|b7|b8|b9|b10|b12|b13|c1|c2|c3|c4|c5|c6|c7|c8|c9|c10|c12|c13|d1|d2|d3|d4|d5|d6|d7|d8|d9|d10|d12|d13|