Guest User

Untitled

a guest
Jun 26th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. --Card zone
  2. Zone = '7e2432'
  3. -- Zone Items
  4. ZoneItems = {}
  5. -- Item Counts
  6. Counts = {
  7. ['Ace'] = 1,
  8. ['Two'] = 2,
  9. ['Three'] = 3,
  10. ['Four'] = 4,
  11. ['Five'] = 5,
  12. ['Six'] = 6,
  13. ['Seven'] = 7,
  14. ['Eight'] = 8,
  15. ['Nine'] = 9,
  16. ['Ten'] = 10,
  17. ['Jack'] = 10,
  18. ['Queen'] = 10,
  19. ['King'] = 10
  20. }
  21. --Init Function
  22. function onLoad(save_state)
  23. --Load zone objects.
  24. Zone = getObjectFromGUID(Zone)
  25. PowerUpZone = getObjectFromGUID(PowerUpZone)
  26. --Update Count Timer
  27. Timer.create({
  28. ['identifier'] = Zone.getGUID(),
  29. ['function_name'] = 'updateCount',
  30. ['delay'] = 0.5,
  31. ['repetitions'] = 0,
  32. })
  33. end
  34. function countTable(table)
  35. local count = 0
  36. for _ in pairs(table) do count = count + 1 end
  37. return count
  38. end
  39. function updateCount()
  40. local count = 0
  41. local aces = 0
  42. local cards = 0
  43. local objects = Zone.getObjects()
  44.  
  45. for key,obj in pairs(objects) do
  46. local z = obj.getRotation().z
  47. if obj.tag == 'Deck' then
  48.  
  49. local deck = obj.getObjects()
  50. cards = countTable(deck) + cards
  51. for key2, deckCard in pairs(deck) do
  52.  
  53. local addValue = Counts[deckCard.nickname]
  54. if addValue == nil then
  55. addValue = 0
  56. end
  57.  
  58. if deckCard.nickname == 'Ace' then
  59. aces = aces + 1
  60. end
  61. count = count + addValue
  62. end
  63.  
  64. else
  65. if Counts[obj.getName()] and (z > 345 or z < 15) then
  66. count = Counts[obj.getName()] + count
  67. if obj.getName() == 'Ace' then
  68. aces = aces + 1
  69. end
  70. end
  71. if obj.tag == 'Card' then
  72. cards = 1 + cards
  73. end
  74. end
  75.  
  76. end
  77.  
  78. if aces ~= 0 then
  79. local testCount = count+10
  80. if testCount == 21 then count = 21 end
  81. end
  82.  
  83. self.setValue(count)
  84. if count == 21 and cards <= 2 and aces == 1 then
  85. self.setColorTint( {0.2, 1, 0.5} ) --Blackjack, turns Yellow
  86. elseif count == 21 and cards > 2 then
  87. self.setColorTint( {1, 1, 0} ) --21 turns green
  88. elseif count > 21 then
  89. self.setColorTint( {1, 0, 0} ) --Bust color red
  90. else
  91. self.setColorTint( {0, 0, 0} ) --regular color
  92. end
  93. end
Add Comment
Please, Sign In to add comment