9
3

Blackjack2.lua 28 KB

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