-
Notifications
You must be signed in to change notification settings - Fork 2
/
Global.lua
3973 lines (3292 loc) · 127 KB
/
Global.lua
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
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
--------------------------------------------------------------------------------
--[[ MrStump's Blackjack Table ]]--
--------------------------------------------------------------------------------
-- Heavy automation and modification by my_hat_stinks
--[[Table of Contents:
1. Configuration
2. Powerup Detection
3. Powerup effects
4. Card Zone Counting/display
5. Deck Finding/Tracking
6. Card Dealing
7. Functions to find data
8. Button click Functions
9. Button creation
]]
function onload()
--[[The powerupEffectTable allows you to attach an effect to figurines as well as
limit who they can be used on. Combine these factors to make custom powerups.
The name field is the name of your powerup. Powerups can only be figurines
On custom models, that means you need to have it set. right click > custom > figurine
Available Options:
WHO - the 'who' field must have one of the below entries
"Anyone" = usuable on anyone
"Any Player" = usable on any play, but not the dealer
"Other Player" = only usuable on other players, not dealer or self
"Self Only" = only usuable on your own hand zone
"Dealer Only" = only usable on the dealer hand zone
"Colorname" = only usable on that color space, by anyone (ex: "Yellow")
EFFECT - the 'effect' field must have one of the below entries
"Clear" - Removes any cards or powerups in the target zone
"Alt. Clear" - Removes any cards or powerups in the target zone, respawns powerup played
"Redraw" - Removes cards and deals 2 new cards
"Redraw All" - Removes cards and deals 2 new cards to every betting player
"Swap" - Exchanges cards in one zone with those in another
"Clone" - Replaces player's own cards with those from another, leaving the origionals
"Destroy" - Destroys the last dealt card (any player), can only be played mid-round
"Reveal" - Flips over any face-down card
"Stand" - Reveals second card and hides the following cards
"Draw 1" - Forces individual powerup is played on to draw a card. Only works with 1
"Powerup Draw" - Draws 1 random powerup from the powerupTable
"Rupee Pull" - Pulls 1 random rupee from the rupeeWallet
"Reset Timer" - Reduces the bonus round timer to 3 seconds
]]--
powerupEffectTable = {
["Force the dealer to reveal their facedown card"] = {who="Dealer Only", effect="Reveal"},
["Force the dealer to stand on two cards"] = {who="Dealer Only", effect="Stand"},
["Force the dealer to draw an additional card"] = {who="Dealer Only", effect="Draw 1"},
["Copy another player's hand"] = {who="Other Player", effect="Clone"},
["Exit from the round"] = {who="Self Only", effect="Clear"},
["Help another player exit from the round"] = {who="Other Player", effect="Clear"},
["Discard your hand and stand on 19"] = {who="Self Only", effect="Alt. Clear"},
["Swap hands with another player"] = {who="Other Player", effect="Swap"},
["Swap hands with the dealer"] = {who="Dealer Only", effect="Swap"},
["Random powerup draw"] = {who="Self Only", effect="Powerup Draw"},
["Random rupee pull"] = {who="Self Only", effect="Rupee Pull"},
["Reward token"] = {who="Self Only", effect="Reward Token"},
["Royal token"] = {who="Self Only", effect="Royal Token"},
["Prestige token"] = {who="Self Only", effect="Prestige Token"},
-- Card numbers only
["+1 to anyone's hand"] = {who="Anyone", effect="Card Mod"}, ["+1 to any player's hand"] = {who="Any Player", effect="Card Mod"},
["-1 from anyone's hand"] = {who="Anyone", effect="Card Mod"},
["+3 to anyone's hand"] = {who="Anyone", effect="Card Mod"}, ["+3 to any player's hand"] = {who="Any Player", effect="Card Mod"},
["-3 from anyone's hand"] = {who="Anyone", effect="Card Mod"},
["+10 to your own hand"] = {who="Self Only", effect="Card Mod"},
["Force the dealer to bust"] = {who="Dealer Only", effect="Card Mod"},
-- Internal - Do not use
["Fifth Card"] = {who="", effect="FifthCard"},
}
powerupTable = {}
for _,id in pairs({ "2c564b", "432519", "cd6cd1", "a4883c", "7b7031", "4a8de2", "fcaebe", "48ae1d", "3bf915", "b5851f", "81121a", "60a985", "c663e1", "f0150d", "84928d" }) do
local obj = getObjectFromGUID(id)
if obj then
table.insert(powerupTable, {id, obj.getName()})
end
end
prestigeTable = {}
rewards = {
Help = getObjectFromGUID("ef72b4"),
GiveJokers = getObjectFromGUID("4dbf75"),
StealJokers = getObjectFromGUID("395ece"),
CopyJokers = getObjectFromGUID("aad1be"),
FiveCardWin = getObjectFromGUID("890842"),
FiveCardTwentyOne = getObjectFromGUID("37085e"),
SixCardWin = getObjectFromGUID("68a101"),
SixCardTwentyOne = getObjectFromGUID("fe17c6"),
Blackjack = getObjectFromGUID("7c99c4"),
DoubleJoker = getObjectFromGUID("887ef8"),
TripleSeven = getObjectFromGUID("fa1dc7"),
Unused = getObjectFromGUID("9b7f31"),
}
--The names (in quotes) should all match the names on your cards.
--The values should match the value of those cards.
--If you have powerup modifies (ex: +1 to score), it could be added here (again, figurine required)
--0 is reserved for Aces.
cardNameTable = {
["Two"]=2, ["Three"]=3, ["Four"]=4, ["Five"]=5,
["Six"]=6, ["Seven"]=7, ["Eight"]=8, ["Nine"]=9, ["Ten"]=10,
["Jack"]=10, ["Queen"]=10, ["King"]=10, ["Ace"]="Ace", ["Joker"]="Joker",
["+1 to anyone's hand"]=1, ["+1 to any player's hand"]=1, ["-1 from anyone's hand"]=-1,
["+3 to anyone's hand"]=3, ["+3 to any player's hand"]=3, ["-3 from anyone's hand"]=-3,
["+10 to your own hand"]=10, ["Discard your hand and stand on 19"]=19,
["Force the dealer to bust"]=-69
}
--This is what ties a scripting zone to a player/dealer
--color is the player's color, z is the player's scripting zone
--Dealer comes first!
objectSets = {
{color="Dealer", zone=getObjectFromGUID("275a5d"), value=0, count=0, container=getObjectFromGUID("df8d40"), prestige=getObjectFromGUID("885bf4"), btnHandler=getObjectFromGUID("355712"), tbl=getObjectFromGUID("758fe9")},
{color="Pink", zone=getObjectFromGUID("44f05e"), value=0, count=0, container=getObjectFromGUID("7c4eb9"), prestige=getObjectFromGUID("0b4a58"), btnHandler=getObjectFromGUID("4503f9"), tbl=getObjectFromGUID("bb54b1")},
{color="Purple", zone=getObjectFromGUID("63ef4e"), value=0, count=0, container=getObjectFromGUID("54d217"), prestige=getObjectFromGUID("17ddfd"), btnHandler=getObjectFromGUID("2a52f9"), tbl=getObjectFromGUID("b2ab0b")},
{color="Blue", zone=getObjectFromGUID("423ae1"), value=0, count=0, container=getObjectFromGUID("f2e64b"), prestige=getObjectFromGUID("f87e7b"), btnHandler=getObjectFromGUID("5d5e85"), tbl=getObjectFromGUID("7a414f")},
{color="Teal", zone=getObjectFromGUID("5c2692"), value=0, count=0, container=getObjectFromGUID("54cc65"), prestige=getObjectFromGUID("3484cc"), btnHandler=getObjectFromGUID("925380"), tbl=getObjectFromGUID("d21b66")},
{color="Green", zone=getObjectFromGUID("595fa9"), value=0, count=0, container=getObjectFromGUID("579f2e"), prestige=getObjectFromGUID("a7bb1b"), btnHandler=getObjectFromGUID("031d13"), tbl=getObjectFromGUID("2612ed")},
{color="Yellow", zone=getObjectFromGUID("5b82fd"), value=0, count=0, container=getObjectFromGUID("486212"), prestige=getObjectFromGUID("944b87"), btnHandler=getObjectFromGUID("ab82ca"), tbl=getObjectFromGUID("a7596f")},
{color="Orange", zone=getObjectFromGUID("38b2d7"), value=0, count=0, container=getObjectFromGUID("b179e0"), prestige=getObjectFromGUID("844d3d"), btnHandler=getObjectFromGUID("ef0906"), tbl=getObjectFromGUID("efae07")},
{color="Red", zone=getObjectFromGUID("8b37f7"), value=0, count=0, container=getObjectFromGUID("82aca4"), prestige=getObjectFromGUID("d8cd49"), btnHandler=getObjectFromGUID("9fd676"), tbl=getObjectFromGUID("b54e19")},
{color="Brown", zone=getObjectFromGUID("1c13af"), value=0, count=0, container=getObjectFromGUID("cee112"), prestige=getObjectFromGUID("6c29ce"), btnHandler=getObjectFromGUID("5b2fc0"), tbl=getObjectFromGUID("688678")},
{color="White", zone=getObjectFromGUID("a751f4"), value=0, count=0, container=getObjectFromGUID("8144bb"), prestige=getObjectFromGUID("88482c"), btnHandler=getObjectFromGUID("0a3126"), tbl=getObjectFromGUID("33b903")},
-- Split zones - Code cycles through this table backwards, so zone 1 is last
{color="Split6", zone=getObjectFromGUID("43d808"), value=0, count=0, container=getObjectFromGUID("b5effd"), prestige=getObjectFromGUID("43d808"), btnHandler=getObjectFromGUID("1f100d"), tbl=getObjectFromGUID("43d808")},
{color="Split5", zone=getObjectFromGUID("39f2dd"), value=0, count=0, container=getObjectFromGUID("0232e3"), prestige=getObjectFromGUID("39f2dd"), btnHandler=getObjectFromGUID("9a5313"), tbl=getObjectFromGUID("39f2dd")},
{color="Split4", zone=getObjectFromGUID("df3fa1"), value=0, count=0, container=getObjectFromGUID("1c1194"), prestige=getObjectFromGUID("df3fa1"), btnHandler=getObjectFromGUID("0f078a"), tbl=getObjectFromGUID("df3fa1")},
{color="Split3", zone=getObjectFromGUID("391dea"), value=0, count=0, container=getObjectFromGUID("5f8f1e"), prestige=getObjectFromGUID("391dea"), btnHandler=getObjectFromGUID("a356c5"), tbl=getObjectFromGUID("391dea")},
{color="Split2", zone=getObjectFromGUID("e527cb"), value=0, count=0, container=getObjectFromGUID("3e331e"), prestige=getObjectFromGUID("e527cb"), btnHandler=getObjectFromGUID("c84a39"), tbl=getObjectFromGUID("e527cb")},
{color="Split1", zone=getObjectFromGUID("f673d7"), value=0, count=0, container=getObjectFromGUID("b2bf24"), prestige=getObjectFromGUID("f673d7"), btnHandler=getObjectFromGUID("35ea56"), tbl=getObjectFromGUID("f673d7")},
}
--Object on which buttons are placed for things like "deal cards"
cardHandler = getObjectFromGUID("77a0c3")
bonusTimer = getObjectFromGUID("3cce5b")
betBags = getObjectFromGUID("697122")
deckBag = getObjectFromGUID("eaa77b")
minigameBag = getObjectFromGUID("5b38f8")
bonusBag = getObjectFromGUID("91fe78")
bonusObjects = {}
--A zone where the deck is placed. Also used in tagging the deck for identification
deckZone = getObjectFromGUID("885bf4")
bonusZone = getObjectFromGUID("3c31e1")
--A list of objects that we want to disable interaction for
objectLockdown = {
getObjectFromGUID("16f87e"), getObjectFromGUID("8e0429"), -- Dealer area
-- Player tables
getObjectFromGUID("9871fe"), getObjectFromGUID("8eafbb"), -- Pink
getObjectFromGUID("d5d7c5"), getObjectFromGUID("32da09"), -- Purple
getObjectFromGUID("b92ec5"), getObjectFromGUID("51086b"), getObjectFromGUID("981767"), -- Blue
getObjectFromGUID("51aacb"), getObjectFromGUID("60b260"), getObjectFromGUID("5a0955"), -- Teal
getObjectFromGUID("b01343"), getObjectFromGUID("704082"), getObjectFromGUID("653add"), -- Green
getObjectFromGUID("2cc362"), getObjectFromGUID("51690f"), getObjectFromGUID("63c8aa"), -- Yellow
getObjectFromGUID("fddcfc"), getObjectFromGUID("8ea777"), getObjectFromGUID("54895c"), -- Orange
getObjectFromGUID("f12fe3"), getObjectFromGUID("9f466e"), getObjectFromGUID("a3c6db"), -- Red
getObjectFromGUID("ac9b82"), getObjectFromGUID("b2883b"), -- Brown
getObjectFromGUID("a82b72"), getObjectFromGUID("4211a7"), -- White
getObjectFromGUID("9ac0b7"),
-- Button handlers
getObjectFromGUID("4503f9"), -- Pink
getObjectFromGUID("2a52f9"), -- Purple
getObjectFromGUID("5d5e85"), -- Blue
getObjectFromGUID("925380"), -- Teal
getObjectFromGUID("031d13"), -- Green
getObjectFromGUID("ab82ca"), -- Yellow
getObjectFromGUID("ef0906"), -- Orange
getObjectFromGUID("9fd676"), -- Red
getObjectFromGUID("5b2fc0"), -- Brown
getObjectFromGUID("0a3126"), -- White
-- Rupee trophies
getObjectFromGUID("1feed0"), -- Green
getObjectFromGUID("533f81"), -- Blue
getObjectFromGUID("b8bf89"), -- Yellow
getObjectFromGUID("038e19"), -- Red
getObjectFromGUID("02eb77"), -- Purple
getObjectFromGUID("5e2f09"), -- Orange
getObjectFromGUID("df5ce7"), -- Silver
getObjectFromGUID("dc1fe2"), -- Rupoor
getObjectFromGUID("0b6e51"), -- Gold
}
-- Chips list
chipConverter = getObjectFromGUID("ad770c")
chipList = chipConverter and chipConverter.getTable("chipList") or {}
chipListIndex = {}
for i=1,#chipList do
chipListIndex[chipList[i].name or ""] = i
end
-- Round timer
roundStateTable = {"1fe5da","bf6cbd","fd2298","aefae6"} -- Bets, Play, Powerups, Paused
for _,id in ipairs(roundStateTable) do
roundState = getObjectFromGUID(id)
if roundState then break end
end
if roundState and roundState.getGUID()~=roundStateTable[1] then roundState = roundState.setState(1) end
roundTimer = getObjectFromGUID("8f93ac")
if roundTimer then
roundTimer.setValue( 180 )
roundTimer.Clock.paused = false
roundStateID = 1
end
-- Other vars
dealersTurn = false
dealingDealersCards = false
lockout = false
timerTick = 0
lockObjects()
createButtons()
checkForDeck()
findCardsToCount()
clearBonus()
end
function lockObjects()
for i, list in ipairs(objectLockdown) do
list.interactable = false
end
end
function GetSetting( var, default )
if type(var)=="table" then -- Set up var (request from other object)
default = var.default
if default==nil then default = var[2] end
var = var.index or var.id or var.setting or var[1]
end
if not (var and type(var)=="string") then return default end -- No var, return default
if (not BlackjackSettingsObject) or (BlackjackSettingsObject==nil) then
for _,obj in pairs(getAllObjects()) do
if obj.getLock() and obj.getName()=="Blackjack Settings" and obj.getVar("getSetting") and not (obj==nil) then
BlackjackSettingsObject = obj
break
end
end
if (not BlackjackSettingsObject) or (BlackjackSettingsObject==nil) then
return default -- No settings object, return default
end
end
local value = BlackjackSettingsObject.Call("getSetting", {index=var})
if value==nil then return default end -- Unset, return default
return value -- Return value
end
objectHasLeftContainer = {}
objectForceDropped = {}
function onObjectLeaveContainer(bag, obj)
if obj.getPosition()[3] < -16 then
objectHasLeftContainer[obj] = bag
Wait.frames(function()
objectHasLeftContainer[obj] = nil
end, 2)
end
end
function onObjectPickedUp(color, object)
if color ~= "Black" and not (Player[color].admin) then
if object.getPosition()[3] < -16 then
object.translate({0,0.15,0})
print(color .. ' picked up a ' .. object.tag .. ' titled "' .. object.getName() .. '" from the hidden zone!')
if objectHasLeftContainer[object] then
if objectHasLeftContainer[object].tag=="Infinite" then
destroyObject(object)
else
objectHasLeftContainer[object].putObject(object)
end
else
objectForceDropped[object] = true
Wait.frames(function()
objectForceDropped[object] = nil
end, 2)
end
end
for i, set in ipairs(objectSets) do
local objectsInZone = set.zone.getObjects()
for i, found in ipairs(objectsInZone) do
if found.tag == "Deck" or found.tag == "Card" then
if found == object then
object.translate({0,0.15,0})
end
end
end
end
end
end
function giveRewardCallback(obj, data)
if not (obj and data and data.set) then return end
if obj.tag=="Bag" then
obj.reset()
obj.setName("Player save: " .. Player[data.set.color].steam_name)
obj.setDescription(Player[data.set.color].steam_id)
end
local p = {data.pos.x, data.pos.y+0.5, data.pos.z}
obj.setPosition( p )
end
function giveReward( id, zone )
if not rewards[id] then return end
local set = findObjectSetFromZone(zone)
if set.UserColor then
set = findObjectSetFromColor(set.UserColor) or set
zone = set.zone
end
if not Player[set.color].seated then return end
local params = {}
-- params.position = zone.getPosition()
params.position = zone.positionToWorld({0.5,0,-0.5})
params.callback = "giveRewardCallback"
params.callback_owner = Global
params.params = {set=set}
for _,item in pairs( rewards[id].getObjects()) do
params.position.y = params.position.y+0.1
params.params.pos = params.position
local obj
if item.tag=="Infinite" then
obj = item.takeObject(params)
elseif obj.tag=="Bag" then
obj = item.clone(params)
obj.reset()
obj.setName("Player save: " .. Player[set.color].steam_name)
obj.setDescription(Player[set.color].steam_id)
else
obj = item.clone(params)
obj.setDescription( ("%s - %s\n\n%s"):format(Player[set.color].steam_id, Player[set.color].steam_name or "No Name", obj.getDescription()) )
end
if obj then
obj.interactable = true
obj.setLock( false )
end
end
end
--POWERUP DETECTION SECTION
--When an object is dropped by a player, we check if its name is on a powerup list
function onObjectDropped(colorOfDropper, droppedObject)
-- Stacking check
local holding = Player[colorOfDropper].getHoldingObjects()
if #holding>0 then
return
end
-- Dealer zone protections
if objectForceDropped[droppedObject] then
return
elseif droppedObject.getPosition()[3] < -16 and colorOfDropper~="Black" and not Player[colorOfDropper].admin then
local trash = getObjectFromGUID("df8d40")
if trash and not (trash==nil) then
trash.putObject(droppedObject)
if colorOfDropper then
printToColor( "You dropped an item in the dealer zone; it has ben placed in Trash.", colorOfDropper, {0.75,0.45,0.35} )
end
end
return
end
-- Powerup use
local power = powerupEffectTable[droppedObject.getName()]
if power and bonusCanUsePowerup(droppedObject) then
return checkPowerupDropZone(colorOfDropper, droppedObject, power.who, power.effect)
end
-- Chip protections
if droppedObject.tag=="Chip" and droppedObject.getDescription():find(Player[colorOfDropper].steam_id, 0, true) then
local inOwnZone = false
for i=2,#objectSets do
for _,v in pairs({"zone","tbl","prestige"}) do
for _,obj in pairs(objectSets[i][v].getObjects()) do
if obj==droppedObject then
local setCol = objectSets[i].color
if setCol==colorOfDropper then -- If there's an overlap, we prioritise our own zone
inOwnZone = true
obj.setDescription( Player[colorOfDropper].steam_id .." - ".. Player[colorOfDropper].steam_name )
break
end
if setCol:sub(1,5):lower()~="split" and Player[setCol] and Player[setCol].seated then
if GetSetting("Chips.AllowTrading", false) then
obj.setDescription( Player[setCol].steam_id .." - ".. Player[setCol].steam_name )
elseif not Player[colorOfDropper].admin then
local ownSet = findObjectSetFromColor(colorOfDropper)
if ownSet then
obj.setPosition(ownSet.tbl.getPosition())
end
broadcastToColor("You may not trade chips. Chips have been returned to your table.", colorOfDropper, {1,0,0})
return
end
end
end
end
if inOwnZone then break end
end
end
end
end
local preventEnterContainer = {}
function onObjectPickUp(col, obj)
if col~="Black" and obj.getPosition()[3] >= -16 then
local desc = obj.getDescription()
if desc=="" and obj.tag=="Chip" then --obj.getDescription():find("^%$([%d,])+ ?%s*$")
obj.setDescription( ("%s - %s"):format(Player[col].steam_id, Player[col].steam_name) )
elseif desc:find(Player[col].steam_id, 0, true) then
local id, oldDesc = desc:match("^(%d+) %- [^\n]*\n\n(.*)")
if oldDesc then
obj.setDescription( ("%s - %s\n\n%s"):format(Player[col].steam_id, Player[col].steam_name, oldDesc) )
else
obj.setDescription( ("%s - %s"):format(Player[col].steam_id, Player[col].steam_name) )
end
elseif (not Player[col].admin) and desc:find("^(%d+) %- .*") then
local guid = obj.getGUID()
preventEnterContainer[obj.getGUID()] = obj.reload()
Wait.frames(function()
preventEnterContainer[obj.getGUID()] = nil
end, 1)
for k,adminCol in pairs(getSeatedPlayers()) do
if Player[adminCol].admin then
broadcastToColor( tostring(Player[col].steam_name).." attempted to lift another player's \""..tostring(obj.getName()).."\".", adminCol, {1,0,0} )
end
end
end
end
end
function onObjectEnterContainer(bag, obj)
if preventEnterContainer[obj.getGUID()] and preventEnterContainer[obj.getGUID()]==obj then
destroyObject(obj)
end
end
--Triggered by above function, this determines if the powerup was dropped in a card zone (objectSets z fields)
function checkPowerupDropZone(colorOfDropper, droppedObject, who, effect)
for i, set in ipairs(objectSets) do
local objectsInZone = set.zone.getObjects()
for j, zoneObject in ipairs(objectsInZone) do
if zoneObject == droppedObject then
checkPowerupEffect(colorOfDropper, droppedObject, who, effect, set)
break
end
end
end
end
--Checks the logic of who should be able to utilize a powerup and its effect
--This function is what enforces the "who" field, so powerups only trigger in the correct zones
function checkPowerupEffect(colorOfDropper, droppedObject, who, effect, setTarget)
local setUser = findObjectSetFromColor(colorOfDropper)
if not setUser then return end
if inMinigame then
if minigame and (not (minigame==nil)) and minigame.getVar("blackjackCanUsePowerup") and minigame.Call("blackjackCanUsePowerup", {setUser=setUser, setTarget=setTarget, object=droppedObject, who=who, effect=effect}) then
else
printToColor( "You can't use this powerup during this minigame. Try again later.", colorOfDropper, {1,0.25,0.25} )
return
end
end
if (setTarget == objectSets[1]) and dealingDealersCards then
broadcastToColor("You can't use a powerup on the dealer while their cards are being dealt.", setUser.color, {1,0.5,0.5})
return
end
if who == "Anyone" then
activatePowerupEffect(effect, setTarget, droppedObject, setUser)
elseif who == "Any Player" and setTarget ~= objectSets[1] then
activatePowerupEffect(effect, setTarget, droppedObject, setUser)
elseif who == "Other Player" and colorOfDropper ~= setTarget.color and setTarget ~= objectSets[1] and setTarget.UserColor~=colorOfDropper then
activatePowerupEffect(effect, setTarget, droppedObject, setUser)
elseif who == "Self Only" and (colorOfDropper == setTarget.color or setTarget.UserColor==colorOfDropper) then
activatePowerupEffect(effect, setTarget, droppedObject, setUser)
elseif who == "Dealer Only" and setTarget == objectSets[1] then
activatePowerupEffect(effect, setTarget, droppedObject, setUser)
elseif who == setTarget.color or (setTarget.UserColor and who == setTarget.UserColor) then
activatePowerupEffect(effect, setTarget, droppedObject, setUser)
else -- No valid target
activatePowerupFailedCallback( {obj=droppedObject, user=setUser, target=setTarget} )
end
end
function unlockPrestigeDestructionBag(data)
if data and data.bag and not (data.bag and data.bag==nil) then
data.bag.unlock()
if data and data.container and not (data.container and data.container==nil) then
data.container.putObject( data.bag )
elseif data and data.setContainer and not (data.setContainer and data.setContainer==nil) then
data.setContainer.putObject( data.bag )
end
end
end
function doPrestigeDestruction(set)
local destroyChips = GetSetting("Prestige.ClearChips", true)
local destroyPowerups = GetSetting("Prestige.ClearPowerups", true)
return doChipDestruction( set, destroyChips, destroyPowerups, true )
end
function doBankruptDestruction(set)
local destroyChips = GetSetting("Bankruptcy.ClearChips", true)
local destroyPowerups = GetSetting("Bankruptcy.ClearPowerups", true)
local destroyPrestige = GetSetting("Bankruptcy.ClearPrestige", false)
return doChipDestruction( set, destroyChips, destroyPowerups, destroyPrestige )
end
function doChipDestruction( set, destroyChips, destroyPowerups, destroyPrestige )
if not (destroyChips or destroyPowerups or destroyPrestige) then return end
local zoneObjects = set.zone.getObjects()
local tableObjects = set.tbl.getObjects()
local prestigeObjects = set.prestige.getObjects()
local ownedContainers = {}
for _,zone in pairs({zoneObjects, tableObjects, prestigeObjects}) do
for _, obj in ipairs(zone) do
local name = obj.getVar("__trader_ObjectName") or obj.getName()
if obj.getVar("onBlackjackDestroyItems") then
obj.Call("onBlackjackDestroyItems", {destroyChips=destroyChips, destroyPowerups=destroyPowerups, destroyPrestige=destroyPrestige} )
elseif destroyChips and obj.tag == "Chip" then
if destroyPowerups or (not powerupEffectTable[obj.getName()]) then
destroyObject(obj)
end
elseif destroyPowerups and powerupEffectTable[obj.getName()] then
destroyObject(obj)
elseif destroyPrestige and (obj.getVar("PrestigeLevel") or ((string.match(name, "New player") or string.match(name, "Prestige %d+")) and not string.find(name, "Trophy"))) then
destroyObject(obj)
elseif obj.tag=="Bag" then
ownedContainers[obj] = true
end
end
end
local plyID = Player[set.color].seated and Player[set.color].steam_id
for _,obj in pairs(getAllObjects()) do
if obj.tag=="Bag" then
beginRecursiveBagCleanup( obj, plyID, destroyChips, destroyPowerups, destroyPrestige, ownedContainers[obj] )
else
if obj.getVar("onBlackjackDestroyItems") then
if obj.getDescription():match("^(%d+) %- .*")==plyID then
obj.Call("onBlackjackDestroyItems", {destroyChips=destroyChips, destroyPowerups=destroyPowerups, destroyPrestige=destroyPrestige} )
end
elseif destroyChips and obj.tag=="Chip" then
if destroyPowerups or (not powerupEffectTable[obj.getName()]) then
if obj.getDescription():match("^(%d+) %- .*")==plyID then
destroyObject(obj)
end
end
elseif destroyPowerups and powerupEffectTable[obj.getName()] then
if obj.getDescription():match("^(%d+) %- .*")==plyID then
destroyObject(obj)
end
elseif destroyPrestige then
local name = obj.getVar("__trader_ObjectName") or obj.getName()
if (obj.getVar("PrestigeLevel") or ((string.match(name, "New player") or string.match(name, "Prestige %d+")) and not string.find(name, "Trophy"))) then
if obj.getDescription():match("^(%d+) %- .*")==plyID then
destroyObject(obj)
end
end
end
end
end
end
function beginRecursiveBagCleanup( bag, id, destroyChips, destroyPowerups, destroyPrestige, skipIDChecks )
if bag.getName()=="Save storage" and bag.getLock() then -- Save storage bag
if bag.getVar("doPrestige") then
bag.Call("doPrestige", {id=id, destroyChips=destroyChips, destroyPowerups=destroyPowerups, destroyPrestige=destroyPrestige})
end
return bag
end
if bag.getQuantity()<=0 then return bag end -- Empty, skip
-- Yes, this is horrible
-- It's the only way to get the proper data, and with json we can cleanly remove items
-- Definitely causes lag, though
local bagData = JSON.decode(bag.getJSON() or "")
if not bagData then return bag end
local shouldRespawn = doRecursiveBagCleanup( bagData, id, destroyChips, destroyPowerups, destroyPrestige, skipIDChecks ) -- Do cleanup
if shouldRespawn then
local newBag = spawnObjectJSON( {json=JSON.encode(bagData), sound=false} ) -- Respawn with removed data
for i=1,#objectSets do -- Fix objects table
if objectSets[i].container==bag then
objectSets[i].container = newBag
end
end
bag.destruct() -- Remove old container
return newBag
end
return bag
end
function doRecursiveBagCleanup( tbl, id, destroyChips, destroyPowerups, destroyPrestige, skipIDChecks )
if not (tbl and tbl.ContainedObjects) then return false end
local shouldRespawn = false
for i=#tbl.ContainedObjects,1,-1 do
local item = tbl.ContainedObjects[i]
-- local objID = item.Description:match("^(%d+) %- .*")
if item.Name=="Custom_Model_Bag" or item.Name=="Bag" then -- Bag or other container
shouldRespawn = doRecursiveBagCleanup( item, id, destroyChips, destroyPowerups, destroyPrestige, skipIDChecks ) or shouldRespawn
elseif powerupEffectTable[item.Nickname] then -- Powerup
if destroyPowerups and (skipIDChecks or item.Description:match("^(%d+) %- .*")==id) then
table.remove( tbl.ContainedObjects, i )
shouldRespawn = true
end
elseif item.Name=="Custom_Model" or item.Name=="Custom_Model_Stack" then
if item.CustomMesh.TypeIndex==5 then -- Custom chip
if destroyChips and (skipIDChecks or item.Description:match("^(%d+) %- .*")==id) then
table.remove( tbl.ContainedObjects, i )
shouldRespawn = true
end
elseif destroyPrestige then
if ((string.match(item.Nickname, "New player") or string.match(item.Nickname, "Prestige %d+")) and not string.find(item.Nickname, "Trophy")) or -- Prestige (name)
item.LuaScript:match("[^%d%a]PrestigeLevel%s*=%s*%d+") or item.LuaScript:match("%\[nt]PrestigeLevel%s*=%s*(%d+%.?%d*)") then -- Prestige (script)
if skipIDChecks or item.Description:match("^(%d+) %- .*")==id then
table.remove( tbl.ContainedObjects, i )
shouldRespawn = true
end
end
end
end
end
if #tbl.ContainedObjects==0 then
tbl.ContainedObjects = nil
end
return shouldRespawn
end
-- Activates a given effect. setTarget is the objectSets entry for where it was dropped. setUser is the set of the dropper
powerupEffectFunctions = { -- So much cleaner and more efficient than the huge elseif chain
Clear = function( setTarget, powerup, setUser )
if roundStateID~=2 and roundStateID~=3 then return end
local cardsInZone = findCardsInZone(setTarget.zone)
local decksInZone = findDecksInZone(setTarget.zone)
local dlr = objectSets[1].value
if (#cardsInZone>0 or #decksInZone>0) and (setTarget.value<=21 and setTarget.value<dlr and (dlr<=21 or dlr==69)) then
if setTarget.color~=setUser.color and setTarget.UserColor~=setUser.color then
giveReward( "Help", setUser.zone )
end
destroyObject(powerup)
clearCards(setTarget.zone)
-- Unlock Chips
local zoneObjectList = setTarget.zone.getObjects()
for j, bet in ipairs(zoneObjectList) do
if (bet.tag == "Chip" and not powerupEffectTable[bet.getName()]) or (bet.tag == "Bag" and bet.getName():sub(1,11)~="Player save") then
bet.interactable = true
bet.setLock(false)
end
end
if currentPlayerTurn==setTarget.color then
clearPlayerActions(setTarget.zone)
passPlayerActions(setTarget.zone)
end
return true
else
broadcastToColor("Must use powerup on a zone with cards in it, also the targeted player must be losing and not busted.", setUser.color, {1,0.5,0.5})
end
end,
["Alt. Clear"] = function( setTarget, powerup, setUser )
if roundStateID~=2 and roundStateID~=3 then return end
local cardsInZone = findCardsInZone(setTarget.zone)
local decksInZone = findDecksInZone(setTarget.zone)
if (#cardsInZone>0 or #decksInZone>0) and (setTarget.value <= 21 or (setTarget.value>=68 and setTarget.value<=72)) then
if setTarget.color~=setUser.color and setTarget.UserColor~=setUser.color then
local dealerValue = objectSets[1].value
local targetValue = setTarget.value
local v = cardNameTable[powerup.getName()] or 0
if v=="Ace" then v = 11 end
if v~="Joker" and (setTarget.value>dealerValue and v<=dealerValue) or (setTarget.value==dealerValue and v<dealerValue) then
if setUser.value<targetValue and not GetSetting("Powerups.AllowHostile", true) then
broadcastToColor("This powerup cannot be used to make another player lose.", setUser.color, {1,0.5,0.5})
return false
end
elseif (dealerValue<=21 or dealerValue<=68) and (v=="Joker" or (v>=dealerValue and (v<=21 or (v>=68 and v<=72)))) then
if (targetValue<dealerValue) or (targetValue==dealerValue and v>dealerValue) then
giveReward( "Help", setUser.zone )
end
end
end
clearCards(setTarget.zone)
if currentPlayerTurn==setTarget.color then playerStand(setTarget.btnHandler,"Black") end
return true
else
broadcastToColor("Must use powerup on a zone with cards in it, cannot be played on a busted player.", setUser.color, {1,0.5,0.5})
end
end,
Redraw = function( setTarget, powerup, setUser )
if roundStateID~=2 and roundStateID~=3 then return end
local cardsInZone = findCardsInZone(setTarget.zone)
local decksInZone = findDecksInZone(setTarget.zone)
if (#cardsInZone>0 or #decksInZone>0) and (setTarget.value<=21 or (setTarget.value>=68 and setTarget.value<=72)) then
destroyObject(powerup)
clearCards(setTarget.zone)
if setTarget == objectSets[1] then
dealDealer({1,2})
else
dealPlayer(setTarget.color, {1,2})
end
if setTarget.color=="Dealer" and dealersTurn then
startLuaCoroutine( Global, "DoDealersCards" )
end
return true
else
broadcastToColor("Must use powerup on a zone with cards in it, cannot be played on a busted player.", setUser.color, {1,0.5,0.5})
end
end,
["Redraw All"] = function( setTarget, powerup, setUser )
if roundStateID~=2 and roundStateID~=3 then return end
local cardsInZone = findCardsInZone(setUser.zone)
local decksInZone = findDecksInZone(setTarget.zone)
if (#cardsInZone>0 or #decksInZone>0) then
for hand, set in ipairs(objectSets) do
local cardsInZone = findCardsInZone(set.zone)
local decksInZone = findDecksInZone(set.zone)
if (#cardsInZone>0 or #decksInZone>0) then
destroyObject(powerup)
clearCards(set.zone)
if set == objectSets[1] then
dealDealer({1,2})
else
dealPlayer(set.color, {1,2})
end
end
end
if dealersTurn then
startLuaCoroutine( Global, "DoDealersCards" )
end
return true
else
broadcastToColor("Must use powerup on a zone with cards in it.", setUser.color, {1,0.5,0.5})
end
end,
Swap = function( setTarget, powerup, setUser )
if roundStateID~=2 and roundStateID~=3 then return end
local tableZ1 = findCardsInZone(setTarget.zone)
local tableZ2 = findCardsInZone(setUser.zone)
local decksZ1 = findDecksInZone(setTarget.zone) for i=1,#decksZ1 do table.insert(tableZ1, decksZ1[i]) end
local decksZ2 = findDecksInZone(setUser.zone) for i=1,#decksZ2 do table.insert(tableZ2, decksZ2[i]) end
if #tableZ1 ~= 0 and #tableZ2 ~= 0 and (setUser.value<=21 or (setUser.value==68) or (setUser.value==69 and setUser.count==2) or (setUser.value==71 and setUser.count==2) or (setUser.value==70 and setUser.count==3)) then
if setTarget.color~="Dealer" and setTarget.color~=setUser.color and setTarget.UserColor~=setUser.color then
if (setTarget.value==71 and setTarget.count==2) or (setTarget.value==70 and setTarget.count==3) then -- Triple seven/Double joker stolen
giveReward( "StealJokers", setUser.zone )
elseif (setUser.value==71 and setUser.count==2) or (setUser.value==70 and setUser.count==3) then -- Triple seven/Double joker given away
giveReward( "GiveJokers", setUser.zone )
elseif setUser.value>setTarget.value then
local dealerValue = objectSets[1].value
if dealerValue>0 and dealerValue<=21 and (setUser.value>dealerValue and setTarget.value<=dealerValue) or (setUser.value==dealerValue and setTarget.value<dealerValue) then
giveReward( "Help", setUser.zone )
end
elseif setUser.value<setTarget.value and not GetSetting("Powerups.AllowHostile", true) then
broadcastToColor("This powerup cannot be used to make another player lose.", setUser.color, {1,0.5,0.5})
return false
end
end
swapHandZones(setTarget.zone, setUser.zone, tableZ1, tableZ2)
destroyObject(powerup)
if setTarget.color=="Dealer" and dealersTurn then
startLuaCoroutine( Global, "DoDealersCards" )
end
return true
else
broadcastToColor("Must use powerup on a zone with cards in it while you also have cards, cannot be played while busted.", setUser.color, {1,0.5,0.5})
end
end,
Clone = function( setTarget, powerup, setUser )
if roundStateID~=2 and roundStateID~=3 then return end
local tableZ1 = findCardsInZone(setTarget.zone)
local tableZ2 = findCardsInZone(setUser.zone)
local decksZ1 = findDecksInZone(setTarget.zone) for i=1,#decksZ1 do table.insert(tableZ1, decksZ1[i]) end
local decksZ2 = findDecksInZone(setUser.zone) for i=1,#decksZ2 do table.insert(tableZ2, decksZ2[i]) end
if #tableZ1 ~= 0 and #tableZ2 ~= 0 and (setUser.value <= 21 or (setUser.value>=68 and setUser.value<=72)) then
if setTarget.color~="Dealer" then
if (setTarget.value==71 and setTarget.count==2) or (setTarget.value==70 and setTarget.count==3) then -- Triple seven/Double joker cloned
giveReward( "CopyJokers", setUser.zone )
end
end
clearCardsOnly(setUser.zone)
cloneHandZone(setTarget.zone, setUser.zone)
destroyObject(powerup)
return true
else
broadcastToColor("Must use powerup on a zone with cards in it while you also have cards, cannot be played while busted.", setUser.color, {1,0.5,0.5})
end
end,
Destroy = function( setTarget, powerup, setUser )
local cards = findCardsInZone(setTarget.zone)
table.sort( cards, function(a,b)
local aStarter = a.getTable("blackjack_playerSet")
local bStarter = b.getTable("blackjack_playerSet")
if aStarter and not bStarter then
return true
elseif bStarter and not aStarter then
return false
end
local aPos = a.getPosition()
local bPos = b.getPosition()
if math.abs(aPos.z-bPos.z)<0.25 then -- Allow for a small variance in position, if we're too strict cards might re-order
if math.abs(aPos.x-bPos.x)<0.25 then
return aPos.y<bPos.y
end
return aPos.x>bPos.x
end
return aPos.z<bPos.z
end)
if cards[#cards] and not (cards[#cards]==nil) then
cards[#cards].destruct()
destroyObject(powerup)
if dealersTurn and setTarget.color=="Dealer" then
startLuaCoroutine( Global, "DoDealersCards" )
end
return true
end
end,
Reveal = function( setTarget, powerup, setUser )
if roundStateID~=2 and roundStateID~=3 then return end
local cardsInZone = findCardsInZone(setTarget.zone)
if #cardsInZone == 2 then
if setTarget.color=="Dealer" and GetSetting("Powerups.RevealIsHelp", true) then
giveReward( "Help", setUser.zone )
end
revealHandZone(setTarget.zone)
destroyObject(powerup)
return true
end
end,
Stand = function( setTarget, powerup, setUser )
if roundStateID~=2 and roundStateID~=3 then return end
local cardsInZone = findCardsInZone(setTarget.zone)
if #cardsInZone < 2 then
broadcastToColor("This powerup can only be used on a hand with more than two cards.", setUser.color, {1,0.5,0.5})
return
end
local newValue = 0
for i, card in ipairs(findCardsInZone(setTarget.zone) or {}) do
x = card.getPosition().x
if x < 3 then
card.destruct()
else
local cardValue = tonumber((card.getName()=="Ace" and 1) or cardNameTable[card.getName()]) or 0
newValue = newValue + cardValue
end
end
if setTarget.color=="Dealer" and (setTarget.value<=21 or (setTarget.value>=68 and setTarget.value<=72)) then
for i=2,#objectSets do
local s = objectSets[i]
if s~=setUser and s.UserColor~=setUser.color and (s.value>0 or s.count>0) and s.value<=21 and ((s.value<setTarget.value and s.value>=newValue) or (s.value==setTarget.value and s.value>newValue)) then -- Helped someone
giveReward( "Help", setUser.zone )
if not GetSetting("Powerups.MultiHelp", true) then break end
end
end
end
destroyObject(powerup)
return true
end,
["Draw 1"] = function( setTarget, powerup, setUser )
if roundStateID~=2 and roundStateID~=3 then return end
local cardsInZone = findCardsInZone(setTarget.zone)
local decksInZone = findCardsInZone(setTarget.zone)
if #cardsInZone>0 or #decksInZone>0 then
local nextCard = (mainDeck.getObjects()[1] or {}).nickname or ""
local nextCardValue = tonumber((nextCard=="Ace" and 1) or cardNameTable[nextCard]) or 0
if setTarget.color=="Dealer" then
if (setTarget.value<=21 and setTarget.value+nextCardValue>21) or (setTarget.value>=68 and setTarget.value<=72) then
for i=2,#objectSets do
local s = objectSets[i]
if s~=setUser and s.UserColor~=setUser.color and (s.value>0 or s.count>0) and s.value<=21 and s.value<=setTarget.value then -- Helped someone
giveReward( "Help", setUser.zone )
if not GetSetting("Powerups.MultiHelp", true) then break end
end
end
end
forcedCardDraw(setTarget.zone)
while lastCard.getName() == "Joker" do
lastCard.destruct()
forcedCardDraw(setTarget.zone, "Black")
resetTimer(3)
end
else
local dealerValue = objectSets[1].value
if dealerValue<=21 and dealerValue<setTarget.value and (setTarget.value<=21 or setTarget.value>=67 and setTarget.value<=72) then
if not GetSetting("Powerups.AllowHostile", true) then
broadcastToColor("This powerup cannot be used on a winning player.", setUser.color, {1,0.5,0.5})
return false
end
end
local newValue = setTarget.value+nextCardValue
if nextCard=="Joker" or (newValue<=21 and ((setTarget.value<dealerValue and newValue>=dealerValue) or (setTarget.value==dealerValue and newValue>dealerValue))) then
giveReward( "Help", setUser.zone )
end
forcedCardDraw(setTarget.zone)
end
destroyObject(powerup)
return true
end