9
3

Blackjack.lua 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714
  1. -- Blackjack script
  2. --[[
  3. Phil NPCID: 2490682 (on live)
  4. Script Name: SpawnScripts/ThunderingSteppes/Blackjack.lua
  5. Script Purpose: a Blackjack game with bets, payouts, and real shuffling
  6. Script Author: Patrikpatrik
  7. Script Date: August 22 2016
  8. Script Notes: seems bulletproof but needs more testing. 7th revision
  9. --]]
  10. --52 cards in a deck
  11. local cardtable = {
  12. 'A♠', '2♠', '3♠','4♠','5♠','6♠','7♠',
  13. '8♠','9♠','10♠','Jack♠','Queen♠','King♠',
  14. 'A♥', '2♥', '3♥','4♥','5♥','6♥','7♥',
  15. '8♥','9♥','10♥','Jack♥','Queen♥','King♥',
  16. 'A♣', '2♣', '3♣','4♣','5♣','6♣','7♣',
  17. '8♣','9♣','10♣','Jack♣','Queen♣','King♣',
  18. 'A♦', '2♦', '3♦','4♦','5♦','6♦','7♦',
  19. '8♦','9♦','10♦','Jack♦','Queen♦','King♦',
  20. }
  21. --This shuffles the deck of cards randomly each pass
  22. function shuffle(NPC, Spawn)
  23. new = {}
  24. for i=1, #cardtable do
  25. table.insert(new, math.random(i), cardtable[i])
  26. end
  27. end
  28. --Assign values to firstcard
  29. function CardValues1(NPC, Spawn)
  30. if firstcard == 'A♠' or firstcard == 'A♥' or firstcard == 'A♣' or firstcard == 'A♦' then
  31. first = 1
  32. myace = 10
  33. elseif firstcard == '2♠' or firstcard == '2♥' or firstcard == '2♣' or firstcard == '2♦' then
  34. first = 2
  35. elseif firstcard == '3♠' or firstcard == '3♥' or firstcard == '3♣' or firstcard == '3♦' then
  36. first = 3
  37. elseif firstcard == '4♠' or firstcard == '4♥' or firstcard == '4♣' or firstcard == '4♦' then
  38. first = 4
  39. elseif firstcard == '5♠' or firstcard == '5♥' or firstcard == '5♣' or firstcard == '5♦' then
  40. first = 5
  41. elseif firstcard == '6♠' or firstcard == '6♥' or firstcard == '6♣' or firstcard == '6♦' then
  42. first = 6
  43. elseif firstcard == '7♠' or firstcard == '7♥' or firstcard == '7♣' or firstcard == '7♦' then
  44. first = 7
  45. elseif firstcard == '8♠' or firstcard == '8♥' or firstcard == '8♣' or firstcard == '8♦' then
  46. first = 8
  47. elseif firstcard == '9♠' or firstcard == '9♥' or firstcard == '9♣' or firstcard == '9♦' then
  48. first = 9
  49. elseif firstcard == '10♠' or firstcard == '10♥' or firstcard == '10♣' or firstcard == '10♦' then
  50. first = 10
  51. elseif firstcard == 'Jack♠' or firstcard == 'Jack♥' or firstcard == 'Jack♣' or firstcard == 'Jack♦' then
  52. first = 10
  53. elseif firstcard == 'Queen♠' or firstcard == 'Queen♥' or firstcard == 'Queen♣' or firstcard == 'Queen♦' then
  54. first = 10
  55. elseif firstcard == 'King♠' or firstcard == 'King♥' or firstcard == 'King♣' or firstcard == 'King♦' then
  56. first = 10
  57. else
  58. end
  59. end
  60. --Assign values to secondcard
  61. function CardValues2(NPC, Spawn)
  62. if secondcard == 'A♠' or secondcard == 'A♥' or secondcard == 'A♣' or secondcard == 'A♦' then
  63. second = 1
  64. dealerace = 10
  65. elseif secondcard == '2♠' or secondcard == '2♥' or secondcard == '2♣' or secondcard == '2♦' then
  66. second = 2
  67. elseif secondcard == '3♠' or secondcard == '3♥' or secondcard == '3♣' or secondcard == '3♦' then
  68. second = 3
  69. elseif secondcard == '4♠' or secondcard == '4♥' or secondcard == '4♣' or secondcard == '4♦' then
  70. second = 4
  71. elseif secondcard == '5♠' or secondcard == '5♥' or secondcard == '5♣' or secondcard == '5♦' then
  72. second = 5
  73. elseif secondcard == '6♠' or secondcard == '6♥' or secondcard == '6♣' or secondcard == '6♦' then
  74. second = 6
  75. elseif secondcard == '7♠' or secondcard == '7♥' or secondcard == '7♣' or secondcard == '7♦' then
  76. second = 7
  77. elseif secondcard == '8♠' or secondcard == '8♥' or secondcard == '8♣' or secondcard == '8♦' then
  78. second = 8
  79. elseif secondcard == '9♠' or secondcard == '9♥' or secondcard == '9♣' or secondcard == '9♦' then
  80. second = 9
  81. elseif secondcard == '10♠' or secondcard == '10♥' or secondcard == '10♣' or secondcard == '10♦' then
  82. second = 10
  83. elseif secondcard == 'Jack♠' or secondcard == 'Jack♥' or secondcard == 'Jack♣' or secondcard == 'Jack♦' then
  84. second = 10
  85. elseif secondcard == 'Queen♠' or secondcard == 'Queen♥' or secondcard == 'Queen♣' or secondcard == 'Queen♦' then
  86. second = 10
  87. elseif secondcard == 'King♠' or secondcard == 'King♥' or secondcard == 'King♣' or secondcard == 'King♦' then
  88. second = 10
  89. else
  90. end
  91. end
  92. --Assign values to thirdcard
  93. function CardValues3(NPC, Spawn)
  94. if thirdcard == 'A♠' or thirdcard == 'A♥' or thirdcard == 'A♣' or thirdcard == 'A♦' then
  95. third = 1
  96. myace = 10
  97. elseif thirdcard == '2♠' or thirdcard == '2♥' or thirdcard == '2♣' or thirdcard == '2♦' then
  98. third = 2
  99. elseif thirdcard == '3♠' or thirdcard == '3♥' or thirdcard == '3♣' or thirdcard == '3♦' then
  100. third = 3
  101. elseif thirdcard == '4♠' or thirdcard == '4♥' or thirdcard == '4♣' or thirdcard == '4♦' then
  102. third = 4
  103. elseif thirdcard == '5♠' or thirdcard == '5♥' or thirdcard == '5♣' or thirdcard == '5♦' then
  104. third = 5
  105. elseif thirdcard == '6♠' or thirdcard == '6♥' or thirdcard == '6♣' or thirdcard == '6♦' then
  106. third = 6
  107. elseif thirdcard == '7♠' or thirdcard == '7♥' or thirdcard == '7♣' or thirdcard == '7♦' then
  108. third = 7
  109. elseif thirdcard == '8♠' or thirdcard == '8♥' or thirdcard == '8♣' or thirdcard == '8♦' then
  110. third = 8
  111. elseif thirdcard == '9♠' or thirdcard == '9♥' or thirdcard == '9♣' or thirdcard == '9♦' then
  112. third = 9
  113. elseif thirdcard == '10♠' or thirdcard == '10♥' or thirdcard == '10♣' or thirdcard == '10♦' then
  114. third = 10
  115. elseif thirdcard == 'Jack♠' or thirdcard == 'Jack♥' or thirdcard == 'Jack♣' or thirdcard == 'Jack♦' then
  116. third = 10
  117. elseif thirdcard == 'Queen♠' or thirdcard == 'Queen♥' or thirdcard == 'Queen♣' or thirdcard == 'Queen♦' then
  118. third = 10
  119. elseif thirdcard == 'King♠' or thirdcard == 'King♥' or thirdcard == 'King♣' or thirdcard == 'King♦' then
  120. third = 10
  121. else
  122. end
  123. end
  124. --Assign values to fourthcard
  125. function CardValues4(NPC, Spawn)
  126. if fourthcard == 'A♠' or fourthcard == 'A♥' or fourthcard == 'A♣' or fourthcard == 'A♦' then
  127. fourth = 1
  128. dealerace = 10
  129. elseif fourthcard == '2♠' or fourthcard == '2♥' or fourthcard == '2♣' or fourthcard == '2♦' then
  130. fourth = 2
  131. elseif fourthcard == '3♠' or fourthcard == '3♥' or fourthcard == '3♣' or fourthcard == '3♦' then
  132. fourth = 3
  133. elseif fourthcard == '4♠' or fourthcard == '4♥' or fourthcard == '4♣' or fourthcard == '4♦' then
  134. fourth = 4
  135. elseif fourthcard == '5♠' or fourthcard == '5♥' or fourthcard == '5♣' or fourthcard == '5♦' then
  136. fourth = 5
  137. elseif fourthcard == '6♠' or fourthcard == '6♥' or fourthcard == '6♣' or fourthcard == '6♦' then
  138. fourth = 6
  139. elseif fourthcard == '7♠' or fourthcard == '7♥' or fourthcard == '7♣' or fourthcard == '7♦' then
  140. fourth = 7
  141. elseif fourthcard == '8♠' or fourthcard == '8♥' or fourthcard == '8♣' or fourthcard == '8♦' then
  142. fourth = 8
  143. elseif fourthcard == '9♠' or fourthcard == '9♥' or fourthcard == '9♣' or fourthcard == '9♦' then
  144. fourth = 9
  145. elseif fourthcard == '10♠' or fourthcard == '10♥' or fourthcard == '10♣' or fourthcard == '10♦' then
  146. fourth = 10
  147. elseif fourthcard == 'Jack♠' or fourthcard == 'Jack♥' or fourthcard == 'Jack♣' or fourthcard == 'Jack♦' then
  148. fourth = 10
  149. elseif fourthcard == 'Queen♠' or fourthcard == 'Queen♥' or fourthcard == 'Queen♣' or fourthcard == 'Queen♦' then
  150. fourth = 10
  151. elseif fourthcard == 'King♠' or fourthcard == 'King♥' or fourthcard == 'King♣' or fourthcard == 'King♦' then
  152. fourth = 10
  153. else
  154. end
  155. end
  156. --Assign values to nextcard
  157. function CardValues5(NPC, Spawn)
  158. if extracard == 'A♠' or extracard == 'A♥' or extracard == 'A♣' or extracard == 'A♦' then
  159. extra = 1
  160. nextace = 10
  161. elseif extracard == '2♠' or extracard == '2♥' or extracard == '2♣' or extracard == '2♦' then
  162. extra = 2
  163. elseif extracard == '3♠' or extracard == '3♥' or extracard == '3♣' or extracard == '3♦' then
  164. extra = 3
  165. elseif extracard == '4♠' or extracard == '4♥' or extracard == '4♣' or extracard == '4♦' then
  166. extra = 4
  167. elseif extracard == '5♠' or extracard == '5♥' or extracard == '5♣' or extracard == '5♦' then
  168. extra = 5
  169. elseif extracard == '6♠' or extracard == '6♥' or extracard == '6♣' or extracard == '6♦' then
  170. extra = 6
  171. elseif extracard == '7♠' or extracard == '7♥' or extracard == '7♣' or extracard == '7♦' then
  172. extra = 7
  173. elseif extracard == '8♠' or extracard == '8♥' or extracard == '8♣' or extracard == '8♦' then
  174. extra = 8
  175. elseif extracard == '9♠' or extracard == '9♥' or extracard == '9♣' or extracard == '9♦' then
  176. extra = 9
  177. elseif extracard == '10♠' or extracard == '10♥' or extracard == '10♣' or extracard == '10♦' then
  178. extra = 10
  179. elseif extracard == 'Jack♠' or extracard == 'Jack♥' or extracard == 'Jack♣' or extracard == 'Jack♦' then
  180. extra = 10
  181. elseif extracard == 'Queen♠' or extracard == 'Queen♥' or extracard == 'Queen♣' or extracard == 'Queen♦' then
  182. extra = 10
  183. elseif extracard == 'King♠' or extracard == 'King♥' or extracard == 'King♣' or extracard == 'King♦' then
  184. extra = 10
  185. else
  186. end
  187. end
  188. --Deals the cards
  189. function Deal(NPC, Spawn)
  190. shuffle(NPC, Spawn)
  191. shuffle(NPC, Spawn)
  192. burncard = table.remove(new, 1) --burns a card off the top
  193. firstcard = table.remove(new, 1) --1st card goes to player
  194. secondcard = table.remove(new, 1) --2nd card goes to dealer
  195. thirdcard = table.remove(new, 1) --3rd card goes to player
  196. fourthcard = table.remove(new, 1) --4th card goes to dealer
  197. CardValues1()
  198. CardValues2()
  199. CardValues3()
  200. CardValues4() --assigns values
  201. --peeking at what goes on at this junction
  202. --Say(NPC, "In deal function firstcard is [" .. firstcard .. "] value of " .. first .. ". Secondcard is [" .. secondcard .. "] value of " .. second .. ".")
  203. --Say(NPC, "In deal function thirdcard is [" .. thirdcard .. "] value of " .. third .. ". Fourthcard is [" .. fourthcard .. "] value of " .. fourth .. ".")
  204. end
  205. --This function combines total, checks for aces logic, and determines if blackjack occured
  206. function Calculates(NPC, Spawn)
  207. playertotal = first + third
  208. dealertotal = second + fourth
  209. if myace == 10 and dealerace == 10 and playertotal == 11 and dealertotal == 11 then
  210. Bothbj(NPC, Spawn)
  211. elseif dealerace == 10 and dealertotal == 11 then
  212. dealertotal = 21
  213. Dealerbj(NPC, Spawn)
  214. elseif myace == 10 and playertotal == 11 then
  215. playertotal = 21
  216. Playerbj(NPC, Spawn)
  217. elseif myace == 10 and dealerace == 10 then
  218. alt = " or "
  219. alt2 = " or "
  220. myaces = first + third + 10
  221. dealeraces = second + fourth + 10
  222. HitStand1(NPC, Spawn)
  223. elseif myace == 10 then
  224. alt = " or "
  225. alt2 = ""
  226. dealeraces = ""
  227. myaces = first + third + 10
  228. HitStand1(NPC, Spawn)
  229. elseif dealerace == 10 then
  230. alt = ""
  231. alt2 = " or "
  232. myaces = ""
  233. dealeraces = second + fourth + 10
  234. HitStand1(NPC, Spawn)
  235. else
  236. alt = ""
  237. alt2 = ""
  238. myaces = ""
  239. dealeraces = ""
  240. HitStand1(NPC, Spawn)
  241. end
  242. end
  243. --calculates the next card etc..
  244. function CalcMore(NPC, Spawn)
  245. playertotal = playertotal + extra
  246. if myace == 10 then
  247. alt = " or "
  248. myaces = playertotal + 10
  249. elseif nextace == 10 then
  250. alt = " or "
  251. myaces = playertotal + 10
  252. else
  253. alt = ""
  254. myaces = ""
  255. end
  256. end
  257. --Text results
  258. function Bothbj(NPC, Spawn)
  259. Emote(NPC, "reveals [" .. secondcard .. "][" .. fourthcard .. "]")
  260. Emote(Spawn, "peeks at [" .. firstcard .. "][" .. thirdcard .. "]")
  261. Say(NPC, "You both get blackjack, it's a push!")
  262. SendPopUpMessage(Spawn, "You both get blackjack, it's a push!", 255, 255, 0)
  263. PushLose1(NPC, Spawn)
  264. AddCoin(Spawn, coins) -- Get your money back
  265. Dumbdoh1(NPC, Spawn)
  266. Clearvars()
  267. end
  268. function Dealerbj(NPC, Spawn)
  269. Emote(Spawn, "peeks at [" .. firstcard .. "][" .. thirdcard .. "] for a total of " .. playertotal .. ".")
  270. Emote(NPC, "reveals [" .. secondcard .. "][" .. fourthcard .. "]")
  271. Say(NPC, "I'm sorry but dealer hits blackjack!")
  272. SendPopUpMessage(Spawn, "Dealer hits blackjack! You lose" .. GetCoinMessage(coins) .. "!", 255, 0, 0)
  273. ApplySpellVisual(Spawn, 874)
  274. Sorry1(NPC, Spawn)
  275. Clearvars()
  276. end
  277. function Playerbj(NPC, Spawn)
  278. Emote(Spawn, "peeks at [" .. firstcard .. "][" .. thirdcard .. "]")
  279. Say(NPC, "Congratulations, you got blackjack!")
  280. Winning1(NPC, Spawn)
  281. PlaySound(NPC, "sounds/test/endquest.wav", GetX(NPC), GetY(NPC), GetZ(NPC)) --Ding!
  282. ApplySpellVisual(Spawn, 872) --Jackpot style!
  283. AddCoin(Spawn, coins/2*3)
  284. SendPopUpMessage(Spawn, "Congratulations " .. GetName(Spawn) .. " you got blackjack! You win" .. GetCoinMessage(coins/2*3) .. "!" , 0, 255, 0)
  285. Emote(NPC, "reveals [" .. secondcard .. "][" .. fourthcard .. "]")
  286. Clearvars()
  287. end
  288. -- Agree sounds
  289. function Agree(NPC, Spawn)
  290. agree1 = math.random(3)
  291. if agree1 == 1 then
  292. --PlayFlavor(NPC, "voiceover/english/voice_emotes/agree/agree_1_1006.mp3", "", "agree", 0, 0, Spawn)
  293. PlaySound(NPC, "voiceover/english/voice_emotes/agree/agree_1_1006.mp3", GetX(NPC), GetY(NPC), GetZ(NPC))
  294. elseif agree1 == 2 then
  295. --PlayFlavor(NPC, "voiceover/english/voice_emotes/agree/agree_2_1006.mp3", "", "agree", 0, 0, Spawn)
  296. PlaySound(NPC, "voiceover/english/voice_emotes/agree/agree_2_1006.mp3", GetX(NPC), GetY(NPC), GetZ(NPC))
  297. elseif agree1 == 3 then
  298. --PlayFlavor(NPC, "voiceover/english/voice_emotes/agree/agree_3_1006.mp3", "", "agree", 0, 0, Spawn)
  299. PlaySound(NPC, "voiceover/english/voice_emotes/agree/agree_3_1006.mp3", GetX(NPC), GetY(NPC), GetZ(NPC))
  300. end
  301. end
  302. -- dumb doh sounds
  303. function Dumbdoh1(NPC, Spawn)
  304. randpickv = math.random(3)
  305. if randpickv == 1 then
  306. PlayFlavor(NPC, "voiceover/english/voice_emotes/doh/doh_1006.mp3", "", "doh", 0, 0, Spawn)
  307. elseif randpickv == 2 then
  308. PlayFlavor(NPC, "voiceover/english/voice_emotes/doh/doh_1022.mp3", "", "doh", 0, 0, Spawn)
  309. else
  310. PlayFlavor(NPC, "voiceover/english/voice_emotes/doh/doh_1050.mp3", "", "doh", 0, 0, Spawn)
  311. end
  312. end
  313. -- Sorry sounds
  314. function Sorry1(NPC, Spawn)
  315. sorrypick = math.random(3)
  316. if sorrypick == 1 then
  317. PlayFlavor(NPC, "voiceover/english/voice_emotes/apologies/apologies_1_1006.mp3", "", "apologize", 0, 0, Spawn)
  318. elseif sorrypick == 2 then
  319. PlayFlavor(NPC, "voiceover/english/voice_emotes/apologies/apologies_2_1006.mp3", "", "apologize", 0, 0, Spawn)
  320. elseif sorrypick == 3 then
  321. PlayFlavor(NPC, "voiceover/english/voice_emotes/apologies/apologies_3_1006.mp3", "", "apologize", 0, 0, Spawn)
  322. end
  323. end
  324. -- Levels of coin falling function
  325. function CoinFalling1(NPC, Spawn)
  326. -- if coins == 100 then
  327. if coins == 10000 then
  328. --Too cheap for falling coins!
  329. elseif coins == 100000 then
  330. ApplySpellVisual(Spawn, 869)
  331. elseif coins == 500000 then
  332. ApplySpellVisual(Spawn, 870)
  333. elseif coins == 10000000 then
  334. ApplySpellVisual(Spawn, 871)
  335. end
  336. end
  337. -- Winning emotes function
  338. function Winning1(NPC, Spawn)
  339. winning = math.random(12)
  340. if winning == 1 then
  341. PlayFlavor(Spawn, "", "", "agree", 0, 0, NPC)
  342. elseif winning == 2 then
  343. PlayFlavor(Spawn, "", "", "bow", 0, 0, NPC)
  344. elseif winning == 3 then
  345. PlayFlavor(Spawn, "", "", "cackle", 0, 0, NPC)
  346. elseif winning == 4 then
  347. PlayFlavor(Spawn, "", "", "cheer", 0, 0, NPC)
  348. elseif winning == 5 then
  349. PlayFlavor(Spawn, "", "", "chuckle", 0, 0, NPC)
  350. elseif winning == 6 then
  351. PlayFlavor(Spawn, "", "", "cutthroat", 0, 0, NPC)
  352. elseif winning == 7 then
  353. PlayFlavor(Spawn, "", "", "flex", 0, 0, NPC)
  354. elseif winning == 8 then
  355. PlayFlavor(Spawn, "", "", "happy", 0, 0, NPC)
  356. elseif winning == 9 then
  357. PlayFlavor(Spawn, "", "", "heartattack", 0, 0, NPC)
  358. elseif winning == 10 then
  359. PlayFlavor(Spawn, "", "", "heelclick", 0, 0, NPC)
  360. elseif winning == 11 then
  361. PlayFlavor(Spawn, "", "", "howl", 0, 0, NPC)
  362. elseif winning == 12 then
  363. PlayFlavor(Spawn, "", "", "laugh", 0, 0, NPC)
  364. end
  365. end
  366. -- Losing /pushing emotes function
  367. function PushLose1(NPC, Spawn)
  368. PushLose = math.random(11)
  369. if PushLose == 1 then
  370. PlayFlavor(Spawn, "", "", "shrug", 0, 0, NPC)
  371. elseif PushLose == 2 then
  372. PlayFlavor(Spawn, "", "", "violin", 0, 0, NPC)
  373. elseif PushLose == 3 then
  374. PlayFlavor(Spawn, "", "", "boggle", 0, 0, NPC)
  375. elseif PushLose == 4 then
  376. PlayFlavor(Spawn, "", "", "confused", 0, 0, NPC)
  377. elseif PushLose == 5 then
  378. PlayFlavor(Spawn, "", "", "cringe", 0, 0, NPC)
  379. elseif PushLose == 6 then
  380. PlayFlavor(Spawn, "", "", "doh", 0, 0, NPC)
  381. elseif PushLose == 7 then
  382. PlayFlavor(Spawn, "", "", "doubletake", 0, 0, NPC)
  383. elseif PushLose == 8 then
  384. PlayFlavor(Spawn, "", "", "hearnoevil", 0, 0, NPC)
  385. elseif PushLose == 9 then
  386. PlayFlavor(Spawn, "", "", "speaknoevil", 0, 0, NPC)
  387. elseif PushLose == 10 then
  388. PlayFlavor(Spawn, "", "", "lookaway", 0, 0, NPC)
  389. elseif PushLose == 11 then
  390. PlayFlavor(Spawn, "", "", "sigh", 0, 0, NPC)
  391. end
  392. end
  393. -- Busting emotes function
  394. function Busting1(NPC, Spawn)
  395. Busting = math.random(11)
  396. if Busting == 1 then
  397. PlayFlavor(Spawn, "", "", "rude", 0, 0, NPC)
  398. elseif Busting == 2 then
  399. PlayFlavor(Spawn, "", "", "heartattack", 0, 0, NPC)
  400. elseif Busting == 3 then
  401. PlayFlavor(Spawn, "", "", "curse", 0, 0, NPC)
  402. elseif Busting == 4 then
  403. PlayFlavor(Spawn, "", "", "frustrated", 0, 0, NPC)
  404. elseif Busting == 5 then
  405. PlayFlavor(Spawn, "", "", "swear", 0, 0, NPC)
  406. elseif Busting == 6 then
  407. PlayFlavor(Spawn, "", "", "tantrum", 0, 0, NPC)
  408. elseif Busting == 7 then
  409. PlayFlavor(Spawn, "", "", "threaten", 0, 0, NPC)
  410. elseif Busting == 8 then
  411. PlayFlavor(Spawn, "", "", "brandish", 0, 0, NPC)
  412. elseif Busting == 9 then
  413. PlayFlavor(Spawn, "", "", "crazy", 0, 0, NPC)
  414. elseif Busting == 10 then
  415. PlayFlavor(Spawn, "", "", "cry", 0, 0, NPC)
  416. elseif Busting == 11 then
  417. PlayFlavor(Spawn, "", "", "sulk", 0, 0, NPC)
  418. end
  419. end
  420. --This function iterates player hit
  421. function Hit1(NPC, Spawn)
  422. extracard = table.remove(new, 1)
  423. CardValues5()
  424. CalcMore(NPC, Spawn)
  425. if playertotal > 21 then
  426. Emote(Spawn, "receives a [" .. extracard .. "] for a total of " .. playertotal .. ".")
  427. Say(NPC, "I'm sorry but you bust!")
  428. Busting1(NPC, Spawn)
  429. Sorry1(NPC, Spawn)
  430. Emote(NPC, "reveals [" .. secondcard .. "][" .. fourthcard .. "]")
  431. SendPopUpMessage(Spawn, "Player busts! You lose " .. GetCoinMessage(coins) .. "!", 255, 0, 0)
  432. Clearvars()
  433. elseif myaces~= "" and myaces < 22 then
  434. conversation = CreateConversation()
  435. AddConversationOption(conversation, "Hit!", "Hit1")
  436. AddConversationOption(conversation, "Stand!", "Stand1")
  437. StartConversation(conversation, NPC, Spawn, "You HIT!")
  438. Emote(Spawn, "receives a [" .. extracard .. "] for a total of " .. playertotal .. alt .. myaces .. ".")
  439. elseif playertotal <= 21 then
  440. conversation = CreateConversation()
  441. AddConversationOption(conversation, "Hit!", "Hit1")
  442. AddConversationOption(conversation, "Stand!", "Stand1")
  443. StartConversation(conversation, NPC, Spawn, "You HIT!")
  444. Emote(Spawn, "receives a [" .. extracard .. "] for a total of " .. playertotal .. ".")
  445. end
  446. end
  447. --Function for dealer's hit iteration and lower/higher value logic
  448. function DealerHit(NPC, Spawn)
  449. if dealeraces ~= "" and dealeraces > 16 then
  450. dealertotal = dealeraces
  451. Say(NPC, dealertotal .. "!")
  452. elseif dealeraces~= "" and dealeraces < 17 then
  453. while dealeraces < 17 do
  454. extracard = table.remove(new, 1)
  455. CardValues5()
  456. Emote(NPC, "next card is [" .. extracard .. "]")
  457. dealeraces = dealeraces + extra
  458. dealertotal = dealertotal + extra
  459. if dealeraces > 21 then
  460. dealeraces = dealertotal
  461. Say(NPC, dealeraces .. "!")
  462. else
  463. dealertotal = dealeraces
  464. Say(NPC, dealertotal .. "!")
  465. end
  466. end
  467. elseif dealertotal < 17 then
  468. while dealertotal < 17 do
  469. extracard = table.remove(new, 1)
  470. CardValues5()
  471. Emote(NPC, "next card is [" .. extracard .. "]")
  472. dealertotal = dealertotal + extra
  473. if nextace == 10 then
  474. dealeraces = dealertotal + 10
  475. if dealeraces > 21 then
  476. dealeraces = dealertotal
  477. Say(NPC, dealeraces .. "!")
  478. else
  479. dealertotal = dealeraces
  480. Say(NPC, dealertotal .. "!")
  481. end
  482. else
  483. Say(NPC, dealertotal .. "!")
  484. end
  485. end
  486. end
  487. ComparingFinal(NPC, Spawn)
  488. end
  489. --Comparing final values and ending the game
  490. function ComparingFinal(NPC, Spawn)
  491. if dealertotal > 21 then
  492. Say(NPC, "Dealer busts and player wins" .. GetCoinMessage(coins) .. "!")
  493. Winning1(NPC, Spawn)
  494. CoinFalling1(NPC, Spawn)
  495. AddCoin(Spawn, coins*2)
  496. SendPopUpMessage(Spawn, "Dealer busts! You win" .. GetCoinMessage(coins) .. "!", 255, 255, 0)
  497. elseif myaces~= "" and dealertotal > myaces then
  498. Say(NPC, "Dealer must stand and Dealer wins!")
  499. PushLose1(NPC, Spawn)
  500. SendPopUpMessage(Spawn, "Dealer wins! You lose" .. GetCoinMessage(coins) .. "!", 213, 89, 0)
  501. Sorry1(NPC, Spawn)
  502. elseif myaces~= "" and dealertotal < myaces then
  503. Say(NPC, "Dealer must stand and Player wins!")
  504. Winning1(NPC, Spawn)
  505. CoinFalling1(NPC, Spawn)
  506. AddCoin(Spawn, coins*2)
  507. SendPopUpMessage(Spawn, "Player wins! You win" .. GetCoinMessage(coins) .. "!", 255, 255, 0)
  508. elseif myaces~= "" and dealertotal == myaces then
  509. Say(NPC, "Dealer stands. It's a push, nobody wins!")
  510. AddCoin(Spawn, coins) -- Get your money back
  511. SendPopUpMessage(Spawn, "It's a push. You get your money back!", 255, 255, 0)
  512. PushLose1(NPC, Spawn)
  513. Dumbdoh1(NPC, Spawn)
  514. elseif dealertotal > playertotal then
  515. Say(NPC, "Dealer must stand and Dealer wins!")
  516. PushLose1(NPC, Spawn)
  517. SendPopUpMessage(Spawn, "Dealer wins! You lose" .. GetCoinMessage(coins) .. "!", 213, 89, 0)
  518. Sorry1(NPC, Spawn)
  519. elseif playertotal > dealertotal then
  520. Say(NPC, "Dealer must stand and Player wins!")
  521. Winning1(NPC, Spawn)
  522. CoinFalling1(NPC, Spawn)
  523. AddCoin(Spawn, coins*2)
  524. SendPopUpMessage(Spawn, "Player wins! You win" .. GetCoinMessage(coins) .. "!", 255, 255, 0)
  525. else
  526. Say(NPC, "Dealer stands. It's a push, nobody wins!")
  527. AddCoin(Spawn, coins) -- Get your money back
  528. SendPopUpMessage(Spawn, "It's a push. You get your money back!", 255, 255, 0)
  529. PushLose1(NPC, Spawn)
  530. Dumbdoh1(NPC, Spawn)
  531. end
  532. Clearvars()
  533. end
  534. --Function on STAND now dealer needs to iterate value, determine aces, and compare players total
  535. function Stand1(NPC, Spawn)
  536. if myaces == "" then
  537. myaces = ""
  538. elseif myaces > 21 then
  539. alt = ""
  540. myaces = ""
  541. elseif myaces < 22 then
  542. alt = ""
  543. playertotal = ""
  544. end
  545. Emote(NPC, "reveals [" .. secondcard .. "][" .. fourthcard .. "]")
  546. DealerHit(NPC, Spawn)
  547. end
  548. --Function for hit or stand option with cards revealed.
  549. function HitStand1(NPC, Spawn)
  550. conversation = CreateConversation()
  551. AddConversationOption(conversation, "Hit!", "Hit1")
  552. AddConversationOption(conversation, "Stand!", "Stand1")
  553. StartConversation(conversation, NPC, Spawn, "Dealer's top card is [" .. fourthcard .. "]")
  554. Emote(Spawn, "peeks at [" .. firstcard .. "][" .. thirdcard .. "] for a total of " .. playertotal .. alt .. myaces .. ".")
  555. end
  556. --Resets variables for the next playthrough
  557. function Clearvars(NPC, Spawn)
  558. alt = ""
  559. alt2 = ""
  560. myaces = ""
  561. dealeraces = ""
  562. myace = 0
  563. dealerace = 0
  564. playertotal = 0
  565. dealertotal = 0
  566. nextace = ""
  567. end
  568. --Start of usual functions
  569. function spawn(NPC)
  570. SetPlayerProximityFunction(NPC, 4, "InRange", "LeaveRange")
  571. end
  572. function respawn(NPC)
  573. spawn(NPC)
  574. Clearvars()
  575. end
  576. function InRange(NPC, Spawn)
  577. Emote(NPC, "shuffles a crisp deck of cards.")
  578. Say(NPC, "Test your luck mate?")
  579. Clearvars()
  580. end
  581. function LeaveRange(NPC, Spawn)
  582. Say(NPC, "See you next time!")
  583. PlayFlavor(NPC, "", "", "bye", 0, 0, Spawn)
  584. Clearvars() --Just in case
  585. end
  586. function hailed(NPC, Spawn)
  587. Clearvars() --Just in case
  588. conversation = CreateConversation()
  589. AddConversationOption(conversation, "Let's play.", "Play1")
  590. AddConversationOption(conversation, "Rules please.", "Rules1")
  591. StartConversation(conversation, NPC, Spawn, "Ready to play?")
  592. end
  593. function Play1(NPC, Spawn)
  594. conversation = CreateConversation()
  595. AddConversationOption(conversation, "I'll bet 10 platinum!", "Plat1")
  596. AddConversationOption(conversation, "I'll bet 50 gold!", "Gold2")
  597. AddConversationOption(conversation, "I'll bet 10 gold.", "Gold1")
  598. AddConversationOption(conversation, "I'll bet 1 gold.", "Silver1")
  599. -- AddConversationOption(conversation, "I'll bet 100 copper.", "Copper1") -- Too cheap!!
  600. AddConversationOption(conversation, "I changed my mind, sorry.", "Bye1")
  601. StartConversation(conversation, NPC, Spawn, "Let's begin! Place your bets please.")
  602. end
  603. --Start of blackjack script
  604. function Plat1(NPC, Spawn)
  605. conversation = CreateConversation()
  606. coins = 10000000 -- 10 platinum
  607. local poolCoins = RemoveCoin(Spawn, coins)
  608. if(poolCoins) then
  609. Agree(NPC, Spawn)
  610. Emote(NPC, "shuffles twice and then begins to deal.")
  611. --Deal the cards
  612. Deal(NPC, Spawn) --adding parameters for troubleshooting
  613. --Do calculations
  614. Calculates(NPC, Spawn)
  615. else
  616. Say(NPC, "I'm sorry but you don't have enough money.")
  617. PlaySound(NPC, "sounds/combat/impact/leather/impact_metal_to_leather04.wav", GetX(NPC), GetY(NPC), GetZ(NPC))
  618. PlayFlavor(NPC, "voiceover/english/voice_emotes/apologies/apologies_3_1006.mp3", "", "apologize", 0, 0, Spawn)
  619. Clearvars()
  620. end
  621. end
  622. function Gold2(NPC, Spawn)
  623. conversation = CreateConversation()
  624. coins = 500000 -- 50 gold
  625. local poolCoins = RemoveCoin(Spawn, coins)
  626. if(poolCoins) then
  627. Agree(NPC, Spawn)
  628. Emote(NPC, "shuffles twice and then begins to deal.")
  629. --Deal the cards
  630. Deal(NPC, Spawn) --adding parameters for troubleshooting
  631. --Do calculations
  632. Calculates(NPC, Spawn)
  633. else
  634. Say(NPC, "I'm sorry but you don't have enough money.")
  635. PlaySound(NPC, "sounds/combat/impact/leather/impact_metal_to_leather04.wav", GetX(NPC), GetY(NPC), GetZ(NPC))
  636. PlayFlavor(NPC, "voiceover/english/voice_emotes/apologies/apologies_3_1006.mp3", "", "apologize", 0, 0, Spawn)
  637. Clearvars()
  638. end
  639. end
  640. function Gold1(NPC, Spawn)
  641. conversation = CreateConversation()
  642. coins = 100000 -- 10 gold
  643. local poolCoins = RemoveCoin(Spawn, coins)
  644. if(poolCoins) then
  645. Agree(NPC, Spawn)
  646. Emote(NPC, "shuffles twice and then begins to deal.")
  647. --Deal the cards
  648. Deal(NPC, Spawn) --adding parameters for troubleshooting
  649. --Do calculations
  650. Calculates(NPC, Spawn)
  651. else
  652. Say(NPC, "I'm sorry but you don't have enough money.")
  653. PlaySound(NPC, "sounds/combat/impact/leather/impact_metal_to_leather04.wav", GetX(NPC), GetY(NPC), GetZ(NPC))
  654. PlayFlavor(NPC, "voiceover/english/voice_emotes/apologies/apologies_3_1006.mp3", "", "apologize", 0, 0, Spawn)
  655. Clearvars()
  656. end
  657. end
  658. function Silver1(NPC, Spawn)
  659. conversation = CreateConversation()
  660. coins = 10000 -- 1 gold
  661. local poolCoins = RemoveCoin(Spawn, coins)
  662. if(poolCoins) then
  663. Agree(NPC, Spawn)
  664. Emote(NPC, "shuffles twice and then begins to deal.")
  665. --Deal the cards
  666. Deal(NPC, Spawn) --adding parameters for troubleshooting
  667. --Do calculations
  668. Calculates(NPC, Spawn)
  669. else
  670. Say(NPC, "I'm sorry but you don't have enough money.")
  671. PlaySound(NPC, "sounds/combat/impact/leather/impact_metal_to_leather04.wav", GetX(NPC), GetY(NPC), GetZ(NPC))
  672. PlayFlavor(NPC, "voiceover/english/voice_emotes/apologies/apologies_3_1006.mp3", "", "apologize", 0, 0, Spawn)
  673. Clearvars()
  674. end
  675. end
  676. function Copper1(NPC, Spawn) --Omitted for now
  677. -- conversation = CreateConversation()
  678. -- coins = 100 -- 1 silver
  679. -- local poolCoins = RemoveCoin(Spawn, coins)
  680. -- if(poolCoins) then
  681. -- Agree(NPC, Spawn)
  682. -- Emote(NPC, "shuffles twice and then begins to deal.")
  683. -- --Deal the cards
  684. -- Deal(NPC, Spawn) --adding parameters for troubleshooting
  685. -- --Do calculations
  686. -- Calculates(NPC, Spawn)
  687. -- else
  688. -- Say(NPC, "I'm sorry but you don't have enough money.")
  689. -- PlaySound(NPC, "sounds/combat/impact/leather/impact_metal_to_leather04.wav", GetX(NPC), GetY(NPC), GetZ(NPC))
  690. -- PlayFlavor(NPC, "voiceover/english/voice_emotes/apologies/apologies_3_1006.mp3", "", "apologize", 0, 0, Spawn)
  691. -- Clearvars()
  692. -- end
  693. end
  694. --Rules of blackjack
  695. function Rules1(NPC, Spawn)
  696. conversation = CreateConversation()
  697. AddConversationOption(conversation, "I understand.", "Play1")
  698. AddConversationOption(conversation, "Maybe next time.", "Bye1")
  699. StartConversation(conversation, NPC, Spawn, "The object of Blackjack is to achieve a hand greater than the dealer to 21 without going over. If you go over 21, it is called a 'bust' and the dealer wins. Winning hands are paid out 1 to 1 and a tie results in a 'push'. Card values are scored from 2 to 9 respectively with 10 and face cards worth 10 points and Ace being worth 1 or 11 points. If you have a 10 point card and an Ace in your starting hand, it is called a natural 21 or 'Blackjack' and it pays 3 to 2. Lastly, dealers must draw to 17.")
  700. end
  701. function Bye1(NPC, Spawn)
  702. Say(NPC, "Goodbye!")
  703. PlayFlavor(NPC, "voiceover/english/voice_emotes/goodbye/goodbye_3_1006.mp3", "", "bye", 0, 0, Spawn)
  704. Clearvars()
  705. end
  706. --END Blackjack.lua