Guest User

Untitled

a guest
Oct 21st, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 45.85 KB | None | 0 0
  1. ;########################################################
  2. ;########################################################
  3. ; SETTINGS (for YOU.... yes YOU!!!)
  4. ;########################################################
  5. ;########################################################
  6.  
  7. ;# THE DEALER HAS AN EDGE. If you win as much as you lose, all player balances will gradually decrease making the 'finish' impossible to reach.
  8. ;# to compensate, you can award points for draws, and reward more money for a win than you take away for a loss. The same applies for doubles.
  9. ;# for faster games: 200 40 20 30 0 -10 5 10 -3
  10. ;# more realistic game values: 150 40 20 30 -10 -25 0 0 -5
  11.  
  12. alias -l finish return 150
  13. alias -l winDouble return 40
  14. alias -l winSingle return 20
  15. alias -l winBlackjack return 30
  16. alias -l loseSingle return -10
  17. alias -l loseDouble return -25
  18. alias -l drawSingle return 0
  19. alias -l drawDouble return 0
  20. alias -l surrender return -5
  21.  
  22. ;# theEdge - Set to 0 to disable. Kicks players from the game after falling below -N
  23.  
  24. alias -l theEdge return -100
  25.  
  26. ;# Bonus payouts. N card tricks represent an auto-payout if a player's hand consists of N cards. set to 0 to disable, otherwise set to the amount which should be paid out.
  27.  
  28. alias -l var5CardTrickPayout return 5
  29. alias -l var6CardTrickPayout return 10
  30. alias -l var7CardTrickPayout return 15
  31. alias -l var5Card21Payout return 20
  32. alias -l var6Card21Payout return 40
  33. alias -l var7Card21Payout return 100
  34.  
  35. ;# House rules. 'decks' can be from 2-8. The other lines respresent rules which can be used in the game. To "activate" a rule, change the 0 to a 1.
  36.  
  37. alias -l decks return 2
  38. alias -l dealerHitsOnSoft17 return 0
  39. alias -l doubleWith3orMoreCards return 0
  40. alias -l noResplitWithAces return 0
  41. alias -l splitAcesOneCardOnly return 0
  42.  
  43. ;# Colors. 3 are used, each represented below. Use 2 digits, from 00-15
  44.  
  45. alias -l color1 return 07
  46. alias -l color2 return 03
  47. alias -l color3 return 06
  48.  
  49. ;# AI opponents. Just seperate the names by spaces, if you want to add more.
  50. ;# the intelligence levels correlate to the names, so Jess matches 6 and Kyle matches the last 1.
  51.  
  52. alias -l ai return Jess Trump DeathKnight AIMaster Jerry Lacey Jonorama Degausser NotTheSun Kyle
  53. alias -l aiIntel return 6 9 8 10 3 5 4 7 2 1
  54.  
  55. ;# 'statEnable' signifies whether the statistics will be recorded. 1 represents on, and 0 off
  56. ;# 'statDirectory' is your path to stats. there should be no slashes at the beginning or end of the path. use \ if you want to go deeper into folders
  57. ;# the other two aliases represent the minimum needed hands/games for a user to be displayed in the top5 lists
  58.  
  59. alias -l statEnable return 1
  60. alias -l statDirectory return stats\blackjack
  61. alias -l statMinHands return 10
  62. alias -l statMinGames return 2
  63.  
  64. ;########################################################
  65. ;########################################################
  66. ; TEXT EVENTS
  67. ;########################################################
  68. ;########################################################
  69.  
  70. on *:TEXT:*:#:{
  71. if ($hget($g($chan,1))) {
  72. if ($hget($g($chan,1), $nick)) && ($hget($g($chan,1), $nick) != check) && (!$isAI($chan, $nick)) {
  73. if ($timer($+(BlackJack,$chan,DrawTimer))) {
  74. if ($1 == !hit) || ($1 == !card) drawCardAction $chan $nick
  75. elseif ($1 == !double) drawCardAction $chan $nick -d
  76. elseif ($1 == !stand) standAction $chan $nick
  77. elseif ($1 == !split) splitAction $chan $nick
  78. elseif ($1 == !surrender) surrenderAction $chan $nick
  79. }
  80. if ($1 == !replace) || ($1 == !drop) replaceAction $chan $nick
  81. }
  82. elseif ($istok(!join.join,$1,46)) && ($timer($+(BlackJack,$chan,JoinTimer))) addPlayer $chan $nick
  83. if ($1-2 == !blackjack stop) || ($1 == !stop) triggerBlackjackStop $chan -m $nick
  84. elseif ($1 == !abort) && ($hget($s($chan), stop)) triggerAbort $1-
  85. elseif ($1 == !repair) && ($nick isop $chan) triggerRepair $chan
  86. }
  87. elseif ($1 == !blackjack) triggerBlackjack $1-
  88. if ($1 == !stat) triggerStats stat $1-
  89. elseif ($1 == !coins) triggerStats coins $1-
  90. elseif ($1 == !commands) triggerCommands $1-
  91. elseif ($1 == !top5) triggerTop5 $1-
  92. elseif ($1 == !compare) triggerCompare $1-
  93. elseif ($1 == !ai) .notice $nick List of computer opponents: $listAI
  94. }
  95.  
  96. ;########################################################
  97. ;########################################################
  98. ; LITTLE ALIASES
  99. ;########################################################
  100. ;########################################################
  101.  
  102. alias -l suits return ♣♠♥♦
  103. alias -l cardify return $replace($1-,10,E,11,J,12,Q,13,K,1,A,E,10)
  104. alias -l bracks return $+($chr(40),$1-,$chr(41))
  105. alias -l cb1 return $+(,$color1,,$1-,)
  106. alias -l cb2 return $+(,$color2,,$1-,)
  107. alias -l cb3 return $+(,$color3,,$1-,)
  108. alias -l c1 return $+(,$color1,$1-,,)
  109. alias -l c2 return $+(,$color2,$1-,,)
  110. alias -l c3 return $+(,$color3,$1-,,)
  111. alias -l f { verif | return $+(",$mircdir,$statDirectory,\,$1,.ini,") }
  112. alias -l l { verif | return $+(",$mircdir,$statDirectory,\,$1,.txt,") }
  113. alias -l getStat return $iif($readini($1,$2,$3),$ifmatch,0)
  114. alias -l fs filter -ffctue 1 32 $1- $1-
  115. alias -l top5 return cph.wr.cpg.gr.h2h
  116. alias -l g return $+(bj_game,_,$1,_,$2)
  117. alias -l a return $+(bj_action,_,$1,_,$2)
  118. alias -l d return $+(bj_deck,_,$1)
  119. alias -l w return $+(bj_score,_,$1)
  120. alias -l s return $+(bj_settings,_,$1)
  121.  
  122. alias -l hfreedom {
  123. if ($hget($g($1,1))) hfree $g($1,1)
  124. if ($hget($a($1,1))) hfree $a($1,1)
  125. if ($hget($d($1))) hfree $d($1)
  126. if ($hget($w($1))) hfree $w($1)
  127. if ($hget($s($1))) hfree $s($1)
  128. hfreedomMirror $1
  129. }
  130.  
  131. alias -l hfreedomMirror {
  132. var %x = 2
  133. while ($hget($g($1,%x))) {
  134. hfree $hget($g($1,%x))
  135. hfree $hget($a($1,%x))
  136. inc %x
  137. }
  138. }
  139.  
  140. alias -l verif {
  141. if (!isdir($+(",$mircdir,$statDirectory,\,"))) {
  142. var %x = 1
  143. while (%x <= $numtok($statDirectory,92)) {
  144. if (!isdir($+(",$mircdir,$gettok($statDirectory,$+(1-,%x),92),\,"))) .mkdir $+(",$mircdir,$gettok($statDirectory,$+(1-,%x),92),\,")
  145. inc %x
  146. }
  147. }
  148. }
  149.  
  150. ;########################################################
  151. ;########################################################
  152. ; GAME TRIGGERS
  153. ;########################################################
  154. ;########################################################
  155.  
  156. alias triggerBlackjack {
  157. if (!$2) blackjackStart $chan $nick
  158. elseif ($istok(1.2.3.4.5.6.7,$2,46)) blackjackStart $chan $nick $2
  159. elseif ($filterAI($2-)) blackjackStart $chan $nick $ifmatch
  160. else {
  161. .notice $nick Invalid parameter. To start a game with AI opponents ready to join, type !blackjack N. N can be a number from 1-7
  162. .notice $nick You can also specify certain AI opponents you want in the game, for example: !blackjack AIMaster Degausser Trump
  163. }
  164. }
  165.  
  166. alias triggerBlackjackStop {
  167. if ($3 !isop $1) .notice $3 You must be an operator to stop a game!
  168. else {
  169. if ($cardsRemaining($1)) {
  170. if (!$hget($s($1), stop)) stopAction $1 $3
  171. else .notice $3 The game will end after the current round!
  172. }
  173. elseif ($timer($+(BlackJack,$1,JoinTimer))) {
  174. $+(.timerBlackJack,$chan,*) off
  175. if ($2 == -m) msg $chan $cb3(Blackjack Race) has been stopped by $c3($3)
  176. hfreedom $1
  177. }
  178. else .notice $3 You can't perform this action now!
  179. }
  180. }
  181.  
  182. alias -l triggerAbort {
  183. if ($timer($+(BlackJack,$chan,DrawTimer))) && ($nick isop $chan) abortAction $chan $nick
  184. elseif ($nick !isop $chan) .notice $nick You must be an operator to abort the games termination!
  185. else .notice $nick You can't perform that action now
  186. }
  187.  
  188. alias -l triggerStats {
  189. if (!$3) .notice $nick Invalid parameters. Specify a name. The -a flag can be used to specify an AI character like: $+(!,$1) -a Degausser
  190. elseif (((!$4) && (!$userStats($3))) || (($4) && (!$userStats($4)))) || (($1 == coins) && ((!$userStats($4).user) && (!$userStats($3).user))) .notice $nick Sorry, I haven't heard that name before
  191. else {
  192. var %s
  193. if (!$4) %s = $chan -u $3
  194. elseif ($3 == -a) && ($userStats($4).ai) && ($1 != coins) %s = $chan -a $4
  195. else %s = $chan -u $4
  196. if ($1 == stat) displayStats %s
  197. elseif ($1 == coins) displayCoins %s
  198. }
  199. }
  200.  
  201. alias -l triggerCommands {
  202. if ($istok(!ai.ai,$2,46)) .notice $nick This will send you a notice with a list of AI opponents you're able to play against
  203. elseif ($istok(!stat.stat,$2,46)) .notice $nick These will send a message with user statistics for the specified name. You can specify the -a flag to define AI opponents, such as: !stat -a Degausser
  204. elseif ($istok(!coins.coins,$2,46)) .notice $nick These will send a message with total user coins. Define a user (not AI) by simply specifying a username.
  205. elseif ($istok(!commands.commands,$2,46)) .notice $nick This will notice you a list of commands.... silly!
  206. elseif ($istok(!compare.compare,$2,46)) {
  207. .notice $nick Compare two players based on their stats in comparison to all other players. You can specify two names, and optionally a -a or -u before the names to specify AI or user
  208. .notice $nick For example, !compare Anne -a Degausser. Example 2: !compare -a Kyle -u Sarah
  209. }
  210. elseif ($istok(!blackjack.blackjack,$2,46)) {
  211. .notice $nick This command will start a game. You can specify the number of AI opponents ready to join by typing !blackjack N, where N is a number from 1-7
  212. .notice $nick You can also specify specific players by using their names (type !ai for a list) like so: !blackjack Degausser NotTheSun
  213. .notice $nick If a game is active, channel operators can end the game by typing: !blackjack stop
  214. }
  215. elseif ($istok(!replace.replace,$2,46)) .notice $nick Specifically an in-game command to be used if you don't want to play anymore. The game will be counted as a loss
  216. elseif ($istok(!top5.top5,$2,46)) {
  217. .notice $nick Displays lists of top 5 players. You can specify a -a or -u flag to view distinct AI or user lists. You can also specify the type of list from: $replace($top5,$chr(46),$chr(32))
  218. .notice $nick Example 1: !top5 -u wr :: Example 2: !top5 cph
  219. }
  220. elseif ($istok(!abort.abort,$2,46)) {
  221. .notice $nick Allows you to abort the !blackjack stop operation, before a hand finishes
  222. }
  223. elseif ($istok(!stop.stop,$2,46)) {
  224. .notice $nick Stops the entire round. Does not apply game based statistics
  225. }
  226. elseif ($istok(!repair.repair,$2,46)) {
  227. .notice $nick Repairs the game if you're having trouble starting a new game
  228. }
  229. else {
  230. .notice $nick Helpful commands - IN GAME: !hit !stand !double !split !surrender !replace !stop !abort !repair - OUTSIDE: !blackjack !commands !ai !stat !coins !top5 !compare
  231. .notice $nick Type !commands command for more information on some commands, for example: !commands ai
  232. }
  233. }
  234.  
  235. alias -l triggerTop5 {
  236. var %t = $gettok($top5,1,46)
  237. if (!$3) {
  238. if ($istok(-a.-u,$2,46)) displayTop5 $chan $2 %t
  239. else displayTop5 $chan -n $iif($istok($top5,$2,46),$2,%t)
  240. }
  241. elseif ($left($2,1) == $chr(45) && $len($2) == 2) displayTop5 $chan $iif($istok(-a.-u,$2,46),$2,-n) $iif($istok($top5,$3,46),$3,%t)
  242. elseif ($2) displayTop5 $chan -n $iif($istok($top5,$2,46),$2,%t)
  243. else displayTop5 $chan -n %t
  244. }
  245.  
  246. alias -l triggerCompare {
  247. if ($0 == 3) {
  248. if ($userStats($2)) && ($userStats($3)) displayCompare -u $2 -u $3 $chan
  249. else .notice $nick One of more of the specified users could not be found
  250. }
  251. elseif ($0 == 5) {
  252. if ($userStats($3)) && ($userStats($5)) displayCompare $iif($2 == -a,-a,-u) $3 $iif($4 == -a,-a,-u) $5 $chan
  253. else .notice $nick One of more of the specified users could not be found
  254. }
  255. elseif ($0 < 3) .notice $nick You have to specify two users to compare them. Type !compare player1 player2
  256. elseif ($0 > 5) .notice $nick You've specified to many parameters! To specify users or AI, type: !compare -u user -a AIname
  257. else {
  258. if ($userStats($3)) {
  259. if ($userStats($4)) displayCompare $iif($2 == -a,-a,-u) $3 -u $4 $chan
  260. elseif ($userStats($2)) displayCompare -u $2 $iif($4` == -a,-a,-u) $3 $chan
  261. }
  262. elseif ($userStats($2)) && ($userStats($4)) displayCompare -u $2 $iif($3 == -a,-a,-u) $4 $chan
  263. else .notice $nick One or more of the specified users are not recognized
  264. }
  265. }
  266.  
  267. alias -l triggerRepair {
  268. if (!$timerCheck($1)) {
  269. msg $1 $cb3(Blackjack Race) was found in a $c2(broken state) $+ , and has been $c3(repaired)
  270. hfreedom $1
  271. }
  272. }
  273.  
  274. alias -l timerCheck {
  275. if ($timer($+(blackjack,$1,DrawTimer)).secs isnum) return $true
  276. if ($timer($+(blackjack,$1,JoinTimer)).secs isnum) return $true
  277. if ($timer($+(blackjack,$1,AutoTimer)).secs isnum) return $true
  278. if ($timer($+(blackjack,$1,RepeatGame)).secs isnum) return $true
  279. if ($timer($+(blackjack,$1,NextRound)).secs isnum) return $true
  280. if ($timer($+(blackjack,$1,AnnounceWinner)).secs isnum) return $true
  281. if ($timer($+(blackjack,$1,EndGame)).secs isnum) return $true
  282. return $false
  283. }
  284.  
  285. ;########################################################
  286. ;########################################################
  287. ; ACTIONS
  288. ;########################################################
  289. ;########################################################
  290.  
  291. alias -l drawCardAction {
  292. if ($numerifyTotal($cardTotal($1,-u,$2).hard) < 21) && (!$istok(double.stand, $hget($a($1,1), $2), 46)) {
  293. var %d = $iif(d isin $3,$true,$false)
  294. if ((%d) && ($numtok($hget($g($1,1), $2), 32) > 2)) && (!$doubleWith3orMoreCards) .notice $nick You can only double with the first two cards!
  295. else {
  296. var %card = $drawCard($1), %z
  297. hadd $g($1,1) $2 $hget($g($1,1), $2) %card
  298. %z = $numerifyTotal($cardTotal($1,-u,$2).hard)
  299. if (%z > 20) && (!%d) hadd $a($1,1) $2 stand
  300. else hadd $a($1,1) $2 $iif(%d,double,hit)
  301. msg $1 $c2($2) $iif(%d,doubled,hit) and drew: $cardflair(%card) :: Current hand: $cardflair($hget($g($1,1), $2)) $bracks($cardTotal($1,-u,$2))
  302. if (%z == 21) && ($($+($chr(36),var,$numtok($hget($g($1,1),$2),32),Card21Payout),2)) {
  303. hinc $w($1) $2 $ifmatch
  304. msg $1 $c1($2) has hit a $cb3($numtok($hget($g($1,1),$2),32) Card 21) and is rewarded $c2($ifmatch coins)
  305. }
  306. elseif (%z < 21) && ($($+($chr(36),var,$numtok($hget($g($1,1),$2),32),CardTrickPayout),2)) {
  307. hinc $w($1) $2 $ifmatch
  308. msg $1 $c1($2) has hit a $cb3($numtok($hget($g($1,1),$2),32) Card Trick) and is rewarded $c2($ifmatch coins)
  309. }
  310. if ((%d) || (%z > 20)) {
  311. hinc $s($1) completed 1
  312. if ($splitHand($1,$2)) createSplits $1 $2 $ifmatch
  313. elseif ($actionsComplete($1)) checkWinner $1 -f
  314. }
  315. }
  316. }
  317. else .notice $2 You can't draw anymore cards!
  318. }
  319.  
  320. alias -l standAction {
  321. if ($numerifyTotal($cardTotal($1,-u,$2).hard) < 21) && (!$istok(double.stand, $hget($a($1,1), $2), 46)) {
  322. hadd $a($1,1) $2 stand
  323. hinc $s($1) completed 1
  324. msg $1 $c2($2) stands with the hand: $cardflair($hget($g($1,1), $2)) $bracks($cardTotal($1,-u,$2))
  325. if ($splitHand($1,$2)) createSplits $1 $2 $ifmatch
  326. elseif ($actionsComplete($1)) checkWinner $1 -f
  327. }
  328. else .notice $2 You can't perform this action!
  329. }
  330.  
  331. alias -l splitAction {
  332. var %hand = $hget($g($1,1),$2)
  333. if ($cardPair(%hand)) && (!$istok(double.stand,$hget($a($1,1),$2),46)) {
  334. if ($noResplitWithAces) && ($gettok($gettok(%hand,1,32),2,95) == A) && ($hget($g($1,2),$2)) .notice $2 You can't split Aces more than once!
  335. else {
  336. msg $1 $c2($2) splits the hand: $cardflair($hget($g($1,1),$2)) $bracks($cardTotal($1,-u,$2))
  337. hadd $newSplitTable($1,$2) $2 $gettok($hget($g($1,1),$2),2,32)
  338. hadd $g($1,1) $2 $gettok($hget($g($1,1), $2),1,32)
  339. hinc $s($1) actions 1
  340. createSplits $1 $2
  341. }
  342. }
  343. else .notice $2 You can't perform this action!
  344. }
  345.  
  346. alias -l surrenderAction {
  347. if ($numtok($hget($g($1,1), $2), 32) == 2) && ($numerifyTotal($cardTotal($1,-u,$2).hard) < 21) && (!$hget($m($1,1),$2)) && (!$istok(double.stand, $hget($a($1,1), $2), 46)) {
  348. msg $1 $c2($2) surrenders their hand: $cardflair($hget($g($1,1), $2)) $bracks($cardTotal($1,-u,$2)) and $c1($iif($surrender > 0,wins,loses) $abs($surrender) $iif($abs($surrender) == 1,coin,coins))
  349. hdel $a($1,1) $2
  350. hadd $g($1,1) $2 check
  351. hinc $w($1) $2 $surrender
  352. hinc $s($1) completed 1
  353. processHandStats $1 $2 total 1
  354. processHandStats $1 $2 lose 1
  355. processHandStats $1 $2 coins $surrender
  356. if ($actionsComplete($1)) checkWinner $1 -f
  357. }
  358. else .notice $2 You can't perform this action!
  359. }
  360.  
  361. alias -l replaceAction {
  362. if (!$istok($hget($s($1),replace),$nick,32)) {
  363. hadd $s($1) replace $hget($s($1), replace) $2
  364. msg $1 $cb3($2) $c3(will be replaced after the next round!)
  365. }
  366. }
  367.  
  368. alias -l stopAction {
  369. hadd $s($1) stop $2
  370. msg $1 $cb3(Blackjack Race) $c3(will be stopped after the next round!)
  371. }
  372.  
  373. alias -l abortAction {
  374. if ($hget($s($1),stop)) hdel $s($1) stop
  375. msg $1 $cb3(Blackjack Race) $c3(will no longer be stopped after this round!)
  376. }
  377.  
  378. alias -l actionsComplete {
  379. if ($hget($s($1), completed) == $hget($s($1), actions)) return $true
  380. return $false
  381. }
  382.  
  383. ;########################################################
  384. ;########################################################
  385. ; SPLIT TABLES
  386. ;########################################################
  387. ;########################################################
  388.  
  389. alias -l newSplitTable {
  390. var %x = 2
  391. while (%x) {
  392. if (!$hget($g($1, %x))) {
  393. hmake $g($1, %x) 1
  394. hmake $a($1, %x) 1
  395. $+(.timerBlackJack,$1,DrawTimer) -o 1 $calc($timer($+(BlackJack,$1,DrawTimer)).secs + 10) checkWinner $1
  396. }
  397. if (!$hget($g($1, %x), $2)) return $g($1,%x)
  398. inc %x
  399. }
  400. }
  401.  
  402. alias -l splitHand {
  403. var %x = 2
  404. while ($hget($g($1,%x),$2)) {
  405. if ($numtok($ifmatch,32) == 1) return %x
  406. inc %x
  407. }
  408. return $false
  409. }
  410.  
  411. ;########################################################
  412. ;########################################################
  413. ; THE EDGE
  414. ;########################################################
  415. ;########################################################
  416.  
  417. alias -l offTheEdge {
  418. if ($theEdge < 0) {
  419. var %x = 1, %n = $hget($w($1),0).item, %p, %s, %e = $v1, %count = 1, %countvar, %minimum, %a
  420. while (%x <= %n) {
  421. %s = $hget($w($1),%x).data
  422. if (!$len(%countvar)) %countvar = %s
  423. elseif (%countvar == %s) inc %count
  424. if (%s > %minimum) || (!$len(%minimum)) %minimum = %s
  425. inc %x
  426. }
  427. if (%count != %n) {
  428. if (%minimum > %e) %minimum = %e
  429. %x = 1
  430. while ($len($hget($w($1),%x).item)) {
  431. %p = $hget($w($1),%x).item
  432. %s = $hget($w($1),%p)
  433. if (%s < %minimum) {
  434. %a = $iif($isAI($1,%p),-a,-u)
  435. msg $1 $cb2(%p) has tipped over $c3(The Edge) and fallen into obscurity! $cb3(Goodbye %p $+ !)
  436. preProcessHandStats $1 %p %a lose
  437. if (%a == -u) coinSave $1 %p
  438. hdel $g($1,1) %p
  439. hdel $w($1) %p
  440. top5PreWrite $1 %p %a
  441. }
  442. else {
  443. if (%s == %minimum) msg $1 $c2(%p) is on $cb3(The Edge) with $+(04,%s,) coins!
  444. inc %x
  445. }
  446. }
  447. }
  448. }
  449. }
  450.  
  451. ;########################################################
  452. ;########################################################
  453. ; ARTIFICIAL INTELLIGENCE
  454. ;########################################################
  455. ;########################################################
  456.  
  457. alias -l getIntel return $iif($findtok($ai,$1,1,32) <= $numtok($aiIntel,32),$iif($gettok($aiIntel,$findtok($ai,$1,1,32),32) isnum 1-10, $v1, 5),5)
  458. alias -l isAI return $istok($hget($s($1), ai),$2,32)
  459.  
  460. alias -l listAI {
  461. var %x = 1, %y = $numtok($ai,32), %r, %u
  462. while (%x <= %y) {
  463. %u = $gettok($ai,%x,32)
  464. %r = %r $c2(%u) $c1($bracks($getIntel(%u))) /
  465. inc %x
  466. }
  467. return $left(%r,-1)
  468. }
  469.  
  470. alias -l filterAI {
  471. var %x = 1, %y = $numtok($1-,32), %return, %a
  472. while (%x <= %y) {
  473. %a = $gettok($1-,%x,32)
  474. if ($istok($ai,%a,32)) && (!$istok(%return,%a,32)) %return = $addtok(%return,%a,32)
  475. inc %x
  476. }
  477. return %return
  478. }
  479.  
  480. alias -l generateAI {
  481. var %x = 1, %y = $numtok($ai,32), %s, %u, %n = $iif($2- isnum 1-7,$iif($2- <= $numtok($ai,32),$2-,$numtok($ai,32)),$numtok($2-,32))
  482. while (%x <= %n) {
  483. if ($2- isnum 1-7) {
  484. while ($istok(%s,%u,32) || !%u) {
  485. %u = $gettok($ai,$rand(1,$numtok($ai,32)),32)
  486. }
  487. %s = %s %u
  488. }
  489. elseif ($istok($ai,$gettok($2-,%x,32),32)) %u = $gettok($2-,%x,32)
  490. else %u = $null
  491. if (%u) $+(.timerBlackJack,$1,JoinTimer,%u) -o 1 $rand(2,28) addPlayer $1 %u -a
  492. inc %x
  493. }
  494. }
  495.  
  496. alias -l rollAI {
  497. var %x = 1, %ai = $hget($s($1), ai), %y = $numtok(%ai, 32), %player
  498. while (%x <= %y) {
  499. %player = $gettok(%ai,%x,32)
  500. if (!$istok(double.stand, $hget($a($1,1), %player), 46)) timeAI $1 %player
  501. inc %x
  502. }
  503. }
  504.  
  505. alias -l performAIAction {
  506. if ($timer($+(BlackJack,$1,DrawTimer))) {
  507. var %action = stand, %intel = $getIntel($2), %dealer = $cardTotal($1, -d).hard, %hard = $cardTotal($1,-u,$2).hard, %soft = $cardTotal($1,-u,$2).soft, %d = $iif($numtok($hget($g($1,1), $2), 32) == 2 || $doubleWith3orMoreCards,1,0), %s = $iif($cardPair($hget($g($1,1),$2)),$ifmatch,0)
  508. if (%s == A) && ($hget($g($1,2),$2)) && ($noResplitWithAces) %s = 0
  509. if (%hard < 12) || (%soft < 8) %action = hit
  510. if (%intel > 1) && (%hard < 17) %action = hit
  511. if (%intel > 1) && (%s) && (%soft == 2) %action = split
  512. if (%intel > 2) && (%dealer < 11) && (%hard isnum 10-11) %action = double
  513. if (%intel > 2) && (%dealer > 6) && ((%soft > 7) && (%hard > 13)) %action = stand
  514. if (%intel > 3) && (%dealer isnum 2-6) && (%hard > 11) && (%soft > 7) %action = stand
  515. if (%intel > 3) && (%s) && (%hard == 16) && (%dealer < 11) %action = split
  516. if (%intel > 4) && (%dealer isnum 2-3) && (%hard < 14) && (!$istok(double.split,%action,46)) %action = hit
  517. if (%intel > 4) && (%dealer > 6) && ((%hard < 15) || (%soft < 8) && (!$istok(double.split,%action,46))) %action = hit
  518. if (%intel > 5) && (%dealer == 9) && (%soft < 9) && (%action != %split) %action = hit
  519. if (%intel > 5) && (%dealer isnum 10-11) && (%soft == 8) %action = hit
  520. if (%intel > 5) && (%s) && (%dealer isnum 3-6) && ($istok(4.6.12.14.18,%hard,46)) %action = split
  521. if (%intel > 6) && (%dealer == 10) && (%hard isnum 10-11) %action = hit
  522. if (%intel > 6) && (%dealer == 9) && (%hard isnum 10-11) %action = double
  523. if (%intel > 6) && (%dealer == 11) && (%hard < 17) && (%soft > 2) %action = hit
  524. if (%intel > 7) && (%dealer == 3) && (%hard == 13) && (%soft == 13) %action = stand
  525. if (%intel > 7) && (%dealer > 7) && (%hard isnum 12-16) && (!$istok(double.split,%action,46)) %action = hit
  526. if (%intel > 7) && (%s) && (%dealer == 2) && (%hard isnum 4-6) %action = split
  527. if (%intel > 7) && (%s) && (%dealer == 7) && ($istok(4.6.14.16,%hard,46)) %action = split
  528. if (%intel > 8) && (%dealer isnum 3-6) && (%hard == 9) %action = double
  529. if (%intel > 8) && (%dealer isnum 5-6) && (%soft isnum 2-8) && (%hard > 11) %action = $iif(!%d && %soft == 8,stand,double)
  530. if (%intel > 8) && (%dealer == 7) && (%hard isnum 15-16) && (%action != %split) %action = hit
  531. if (%intel > 8) && (%s) && (%hard == 18) && ($istok(4.5.6.8.9,%dealer,46)) %action = split
  532. if (%intel > 9) && (%dealer == 4) && (%soft isnum 5-8) && (%hard > 11) && (%action != split) %action = $iif(!%d && %soft == 8,stand,double)
  533. if (%intel > 9) && (%dealer == 3) && (%soft isnum 7-8) && (%hard > 11) && (%action != split) %action = $iif(!%d && %soft == 8,stand,double)
  534. if (%action == hit) || ((%action == double) && (!%d)) drawCardAction $1 $2
  535. elseif (%action == double) drawCardAction $1 $2 -d
  536. elseif (%action == split) splitAction $1 $2
  537. else standAction $1 $2
  538. if (!$istok(double.stand, $hget($a($1,1), $2), 46)) timeAI $1 $2
  539. }
  540. }
  541.  
  542. alias -l timeAI {
  543. $+(.timerBlackJack,$1,DrawTimer,$2) -o 1 $rand(2,7) performAIAction $1 $2
  544. }
  545.  
  546. ;########################################################
  547. ;########################################################
  548. ; SHOE MANAGEMENT
  549. ;########################################################
  550. ;########################################################
  551.  
  552. alias -l createDeck {
  553. var %i = 1, %d = $calc($hget($s($1), decks) * 52)
  554. while (%i <= %d) {
  555. hadd $d($1) %i 1
  556. inc %i
  557. }
  558. }
  559.  
  560. alias -l cardsRemaining return $hget($d($1), 0).item
  561.  
  562. alias -l drawCard {
  563. if (!$cardsRemaining($1)) checkShuffle $1
  564. var %r = $rand(1,$cardsremaining($1)), %t = $hget($d($1), %r).item
  565. hdel $d($1) %t
  566. return $+($mid($suits,$calc((%t % 4) + 1),1),_,$cardify($calc((%t % 13) + 1)))
  567. }
  568.  
  569. ;########################################################
  570. ;########################################################
  571. ; GAME FLOW
  572. ;########################################################
  573. ;########################################################
  574.  
  575. alias -l blackjackStart {
  576. hfreedom $1
  577. hmake $g($1,1) 1
  578. hmake $a($1,1) 1
  579. hmake $d($1) $floor($calc(($iif($decks isnum 1-8,$v1,2) * 52) / 10))
  580. hmake $w($1) 1
  581. hmake $s($1) 1
  582. hadd $s($1) decks $iif($decks isnum 1-8,$v1,2)
  583. hadd $s($1) stats $iif($statEnable,1,0)
  584. msg $1 $c2($2) has started a game of $cb3(Blackjack Race!) Type $c2(!join) to join the game, you have $c1(30 seconds!)
  585. $+(.timerBlackJack,$1,JoinTimer) -o 1 30 startGame $1
  586. if ($3) generateAI $1 $3-
  587. }
  588.  
  589. alias -l addPlayer {
  590. if (!$hget($g($1,1), $2)) {
  591. hadd $g($1,1) $2 check
  592. hadd $w($1) $2 0
  593. if ($3) && (a isin $3) hadd $s($1) ai $iif($hget($s($1), ai),$ifmatch $2,$2)
  594. msg $1 $c2($2) $+ $iif(($3) && (a isin $3),$+($chr(32),$bracks(AI level $getIntel($2)))) has joined the game! $c1($players($1)) players joined! $iif($hget($g($1,1), 0).item < 7 && $timer($+(BlackJack,$1,JoinTimer)).secs > 1,You've $c1($timer($+(BlackJack,$1,JoinTimer)).secs) seconds left to join!)
  595. if ($hget($g($1,1), 0).item > 6) startGame $1 -f
  596. }
  597. }
  598.  
  599. alias -l startGame {
  600. $+(.timerBlackJack,$1,JoinTimer*) off
  601. if (!$players($1)) {
  602. msg $1 Nobody has joined the game. $c2(1 player) is required! Turning off.
  603. blackjackStop $1 -f
  604. }
  605. else {
  606. if ($players($1) == 1) {
  607. while ($players($1) < 2) {
  608. if (($isAI($1, $hget($g($1,1), 1).item)) && ($numtok($ai,32) < 2)) || (!$ai) addPlayer $1 $+(Agent,$rand(11111,99999)) -a
  609. else addPlayer $1 $gettok($ai,$rand(1,$numtok($ai,32)),32) -a
  610. }
  611. }
  612. hadd $s($1) original_players $players($1)
  613. createDeck $1
  614. var %text = The aim is to win $cb1($finish coins) from the $c2(Dealer) before everyone else. Bet amounts are in units of $winSingle $+ , $cb3($iif($hget($s($1), decks) > 1,$v1 decks,1 deck)) in use. Get ready...
  615. if ($2) && (f isin $2) msg $1 There are a maximum of $c1($players($1) players!) %text
  616. else msg $1 $c1(Time is up!) There are $c1($players($1) players!) %text
  617. $+(.timerBlackJack,$1,RepeatGame) -o 1 10 startRound $1
  618. }
  619. }
  620.  
  621. alias -l startRound {
  622. createDefaults $1
  623. if ($actionsComplete($1)) $+(.timerBlackJack,$1,AutoTimer) -o 1 2 checkWinner $1 -f
  624. else {
  625. $+(.timerBlackJack,$1,DrawTimer) -o 1 30 checkWinner $1
  626. if ($hget($s($1), ai)) rollAI $1
  627. }
  628. }
  629.  
  630. alias -l createDefaults {
  631. var %x = 1, %p = $players($1), %player, %actions
  632. hadd $s($1) dealer $drawCard($1)
  633. hadd $s($1) actions $hget($g($1,1),0).item
  634. hadd $s($1) completed 0
  635. while (%x <= %p) {
  636. %player = $hget($g($1,1), %x).item
  637. hadd $g($1,1) %player $drawCard($1) $drawCard($1)
  638. %actions = $iif($numerifyTotal($cardTotal($1,-u,%player).hard) < 21,hit,stand)
  639. hadd $a($1,1) %player %actions
  640. if (%actions == stand) hinc $s($1) completed 1
  641. msg $1 $c2($+(%player,:)) Your cards are: $cardflair($hget($g($1,1), %player)) :: Total: $bracks($cardTotal($1,-u,%player)) $iif(%actions == hit,:: You can: !hit !stand !double $+ $iif($cardPair($hget($g($1,1), %player)),$+($chr(32),!split))) $+ $iif(%actions == hit,$+($chr(32),!surrender)))
  642. inc %x
  643. }
  644. msg $1 The $cb2(Dealer) is showing: $cardflair($hget($s($1), dealer))
  645. }
  646.  
  647. alias -l createSplits {
  648. if ($3) {
  649. var %temp = $hget($g($1,1),$2)
  650. hadd $g($1,1) $2 $hget($g($1,$3),$2)
  651. hadd $g($1,$3) $2 %temp
  652. hadd $a($1,$3) $2 $hget($a($1,1),$2)
  653. }
  654. hadd $g($1,1) $2 $hget($g($1,1),$2) $drawCard($1)
  655. var %one = $iif(($splitAcesOneCardOnly) && ($gettok($gettok($hget($g($1,1),$2),1,32),2,95) == A),1,0), %actions = $iif($numerifyTotal($cardTotal($1,-u,$2).hard) < 21 && !%one,hit,stand)
  656. hadd $a($1,1) $2 %actions
  657. msg $1 $c2($+($2,:)) Your cards are: $cardflair($hget($g($1,1), $2)) :: Total: $bracks($cardTotal($1,-u,$2)) $iif(%actions == hit && !%one,:: You can: !hit !stand !double $+ $iif($cardPair($hget($g($1,1), $2)) && (($cardPair($hget($g($1,1), $2)) != A) || (!$noResplitWithAces)),$+($chr(32),!split)))
  658. if (%actions == stand) {
  659. hinc $s($1) completed 1
  660. if ($splitHand($1,$2)) forwardSplitter $1 $2 $splitHand($1,$2)
  661. elseif ($actionsComplete($1)) checkWinner $1 -f
  662. }
  663. }
  664.  
  665. alias -l forwardSplitter {
  666. createSplits $1-
  667. }
  668.  
  669. alias -l blackjackStop {
  670. if ($hget($s($1),stats)) {
  671. var %x = 1, %f, %u, %p = $players($1), %w, %winner = $3
  672. while ($hget($g($1,1), %x).item) {
  673. %u = $ifmatch
  674. %f = $iif($isAI($1,%u),-a,-u)
  675. %w = $iif(%winner && ($2 != -f),$iif(%winner == %u,win,lose),draw)
  676. preProcessHandStats $1 %u %f %w
  677. top5PreWrite $1 %u %f
  678. if (%f == -u) coinSave $1 %u
  679. inc %x
  680. }
  681. top5Sort
  682. }
  683. hfreedom $1
  684. }
  685.  
  686. ;########################################################
  687. ;########################################################
  688. ; POST HAND
  689. ;########################################################
  690. ;########################################################
  691.  
  692. alias -l checkWinner {
  693. $+(.timerBlackJack,$1,DrawTimer,*) off
  694. var %dealer = $dealerOption($1)
  695. dealerDraw $1 %dealer
  696. roundDisplay $1 %dealer $iif($2,$2)
  697. }
  698.  
  699. alias -l roundDisplay {
  700. var %t = $hget($s($1), dealer), %win = $getWinner($1).win, %draw = $getWinner($1).draw, %lose = $getWinner($1).lose, %finished = $cb1($iif(f isin $3,All hands are finished!,Time is up!))
  701. var %displaywin = $formatPlayers($1, %win).win, %displaylose = $formatPlayers($1, %lose).lose, %displaydraw = $formatPlayers($1, %draw).draw
  702. if ($istok(1.2,$2,46)) msg $1 %finished The $cb2(Dealer) shows $cardflair($gettok(%t,1,32)) and $iif($2 = 2,draws the following cards:,drew the card:) $cardflair($gettok(%t,2-,32)) :: Total: $cb2($cardTotal($1, -d).hard)
  703. elseif ($2 == 0) msg $1 %finished Everyone went $c1(bust) so the $cb2(Dealer) wins
  704. elseif ($2 == 4) msg $1 %finished Everyone $c1(surrendered) so the $cb2(Dealer) doesn't draw cards
  705. else msg $1 %finished The $cb2(Dealer) can't make $c1(Blackjack) so doesn't draw cards
  706. if (%win) msg $1 $c1($iif($numtok(%win, 32) != 1,$v1 players,%win)) beat the dealer $+ $iif($numtok(%win, 32) != 1,: %displaywin,: $gettok(%displaywin,2-,32))
  707. if (%draw) msg $1 $c1($iif($numtok(%draw, 32) != 1,$v1 players,%draw)) managed to draw $+ $iif($numtok(%draw, 32) != 1,: %displaydraw,: $gettok(%displaydraw,2-,32))
  708. if (!%win) && (!%draw) && (%lose) && ($istok(1.2,$2,46)) msg $1 The $cb2(Dealer) beat everyone with: $cardflair(%t) :: Total: $cb2($cardTotal($1,-d).hard)
  709. $+(.timerBlackJack,$1,nextRound) -o 1 2 nextRound $1
  710. }
  711.  
  712. alias -l checkShuffle {
  713. var %r = $cardsRemaining($1)
  714. if (%r < $calc(($players($1) + 1) * 7)) {
  715. msg $1 $cb3(The cards are getting shuffled and reloaded) $bracks($+($round($calc((%r / ($hget($s($1), decks) * 52)) * 100),2),$chr(37)) density)
  716. createDeck $1
  717. }
  718. else msg $1 $cb3(%r cards) remain in the shoe $bracks($+($round($calc((%r / ($hget($s($1), decks) * 52)) * 100),2),$chr(37)) density)
  719. }
  720.  
  721. alias -l nextRound {
  722. msg $1 Current scores: $allScores($1)
  723. offTheEdge $1
  724. if ($overallWinner($1)) {
  725. var %winner = $ifmatch, %coins = $hget($w($1), %winner)
  726. $+(.timerBlackJack,$1,announceWinner) -o 1 2 msg $1 Okay we have an $cb3(overall winner.) $cb2(%winner) wins the game, finishing with $c1(%coins coins!)
  727. $+(.timerBlackJack,$1,endGame) -o 1 4 blackjackStop $1 -m %winner
  728. }
  729. elseif ($hget($s($1), stop)) {
  730. $+(.timerBlackJack,$1,announceStop) -o 1 2 msg $1 $cb3(Blackjack Race) was set to be stopped by $c2($hget($s($1), stop)) and has been terminated
  731. $+(.timerBlackJack,$1,endGame) -o 1 4 blackjackStop $1 -f
  732. }
  733. else {
  734. hdel -w $a($1,1) *
  735. hfreedomMirror $1
  736. $+(.timerBlackJack,$1,ShuffleTimer) -o 1 5 checkShuffle $1
  737. if ($hget($s($1),replace)) $+(.timerBlackJack,$1,ReplaceUser) -o 1 10 replaceUser $1
  738. $+(.timerBlackJack,$1,RepeatGame) -o 1 12 startRound $1
  739. }
  740. }
  741.  
  742. alias -l replaceUser {
  743. var %x = 1, %u = $hget($s($1),replace), %y = $numtok(%u,32), %user, %a
  744. hdel $s($1) replace
  745. while (%x <= %y) {
  746. %user = $gettok(%u,%x,32)
  747. if ($hget($g($1,1), %user)) {
  748. while (!%a) || ($hget($g($1,1), %a)) {
  749. %a = $iif($rand(1,20) == 1,$+($chr(74),$chr(109),m,$chr(105),$chr($+(10,1))),$+(Agent,$rand(10000,99999)))
  750. }
  751. preProcessHandStats $1 %user -u lose
  752. top5PreWrite $1 %user -u
  753. coinSave $1 %user
  754. hadd $g($1,1) %a $hget($g($1,1),%user)
  755. hadd $w($1) %a $hget($w($1),%user)
  756. hdel $g($1,1) %user
  757. hdel $w($1) %user
  758. hadd $s($1) ai $iif($hget($s($1), ai),$ifmatch %a,%a)
  759. msg $1 $cb3(%a) replaces $c2(%user) and joins the game!
  760. }
  761. inc %x
  762. }
  763. }
  764.  
  765. ;########################################################
  766. ;########################################################
  767. ; CARD FUNCTIONS
  768. ;########################################################
  769. ;########################################################
  770.  
  771. alias -l numerifyTotal {
  772. if ($1- == TOO MANY) return 30
  773. if ($1- == BLACKJACK) return 22
  774. return $1-
  775. }
  776.  
  777. alias -l cardflair {
  778. tokenize 32 $1-
  779. var %x = 1 ,%s ,%d
  780. while ($eval($+($,%x),2)) {
  781. %d = $remove($ifmatch,_)
  782. %s = %s $iif($left(%d,1) isin $left($suits,2),%d,$+(04,%d,))
  783. inc %x
  784. }
  785. return %s
  786. }
  787.  
  788. alias -l cardPair {
  789. if ($gettok($gettok($1-,1,32),2,95) == $gettok($gettok($1-,2-,32),2-,95)) return $v1
  790. return $false
  791. }
  792.  
  793. alias -l cardTotal {
  794. var %s = $iif($2 == -u,$hget($g($1,1), $3),$iif($2 == -d,$hget($s($1), dealer),$2-)), %x = 1, %c = $numtok(%s, 32), %return = 0, %n, %soft = 0
  795. while (%x <= %c) {
  796. %n = $replace($gettok($gettok(%s,%x,32),2,95),A,1,J,10,Q,10,K,10)
  797. inc %return %n
  798. if (%n == 1) && (!%soft) && (%return < 12) inc %soft
  799. elseif (%soft) && (%return > 11) dec %soft
  800. if (%return > 21) return TOO MANY
  801. inc %x
  802. }
  803. if (%soft) {
  804. if (%return == 11) return $iif(%x == 3,BLACKJACK,21)
  805. if (!$prop) return $+(%return,/,$calc(%return + 10))
  806. if ($prop == hard) return $calc(%return + 10)
  807. }
  808. return %return
  809. }
  810.  
  811. alias -l formatPlayers {
  812. var %x = 1, %y = $numtok($2-,32), %u, %return, %split = 1, %hand, %i, %c, %d
  813. while (%x <= %y) {
  814. %u = $gettok($2-,%x,32)
  815. %hand = $hget($g($1,%split), %u)
  816. if ($dealerVS($1, %hand) == $prop) {
  817. if (!%i) { %return = %return %u $+ : $bracks($cardflair(%hand)) / | %i = 1 }
  818. else %return = $left(%return,-1) $bracks($cardflair(%hand)) /
  819. processHandStats $1 %u total 1 $iif($isAI($1, %u),-a)
  820. processHandStats $1 %u $prop 1 $iif($isAI($1, %u),-a)
  821. if ($prop == win) && ($numerifyTotal($cardTotal($1, %hand).hard) == 22) {
  822. hinc $w($1) %u $winBlackjack
  823. processHandStats $1 %u coins $winBlackjack $iif($isAI($1, %u),-a)
  824. }
  825. else {
  826. %d = $iif($hget($a($1,%split),%u) == Double,$v2,Single)
  827. %c = $eval($+($,$prop,%d),2)
  828. hinc $w($1) %u %c
  829. if (%d == Double) processHandStats $1 %u double 1 $iif($isAI($1, %u),-a)
  830. processHandStats $1 %u coins %c $iif($isAI($1, %u),-a)
  831. }
  832. }
  833. inc %split
  834. if ($hget($g($1,%split), %u)) continue
  835. %split = 1
  836. %i = 0
  837. inc %x
  838. }
  839. return $left(%return,-1)
  840. }
  841.  
  842. ;########################################################
  843. ;########################################################
  844. ; DEALER FUNCTIONS
  845. ;########################################################
  846. ;########################################################
  847.  
  848. alias -l dealerOption {
  849. var %x = 1, %y = $hget($g($1,1),0).item, %return = 0, %t, %m = 1, %p, %q = 1
  850. while (%x <= %y) {
  851. %p = $hget($g($1,1),%x).item
  852. if ($hget($g($1,%m),%p) == check) inc %q
  853. else {
  854. %t = $numerifyTotal($cardTotal($1, $hget($g($1,%m), %p)).hard)
  855. if (%t < 22) return 2
  856. elseif (%t == 22) %return = 1
  857. inc %m
  858. if ($hget($g($1,%m),%p)) continue
  859. }
  860. %m = 1
  861. inc %x
  862. }
  863. if (%return == 1) && (!$istok(10.11,$cardTotal($1,-d).hard,46)) return 3
  864. if (%q < %x) return %return
  865. return 4
  866. }
  867.  
  868. alias -l dealerDraw {
  869. while ($cardTotal($1,-d).hard < 17) || (($dealerHitsOnSoft17) && ($cardTotal($1,-d).soft < 8)) {
  870. if ($istok(0.3.4,$2,46)) break
  871. hadd $s($1) dealer $hget($s($1), dealer) $drawCard($1)
  872. if ($2 == 1) break
  873. }
  874. }
  875.  
  876. alias -l dealerVS {
  877. var %cards = $numerifyTotal($cardTotal($1,$2-).hard), %dealer = $numerifyTotal($cardTotal($1,-d).hard)
  878. if ((%cards < %dealer) && (%dealer < 30)) || (%cards == 30) return lose
  879. if (%cards == %dealer) return draw
  880. return win
  881. }
  882.  
  883. ;########################################################
  884. ;########################################################
  885. ; OTHER FUNCTIONS
  886. ;########################################################
  887. ;########################################################
  888.  
  889. alias -l players return $iif($hget($g($1,1), 0).item, $ifmatch, 0)
  890.  
  891. alias -l getWinner {
  892. var %return , %x = 1, %p = $players($1), %player, %split = 1, %h
  893. while (%x <= %p) {
  894. %player = $hget($g($1,1), %x).item
  895. if ($hget($g($1,1),%player) != check) {
  896. %h = $hget($g($1, %split), %player)
  897. inc %split
  898. if ($prop == $dealerVS($1,%h)) %return = $addtok(%return,%player,32)
  899. elseif ($hget($g($1,%split), %player)) continue
  900. %split = 1
  901. }
  902. inc %x
  903. }
  904. return %return
  905. }
  906.  
  907. alias -l allScores {
  908. var %return, %x = 1, %y = $hget($w($1), 0).item, %s
  909. while (%x <= %y) {
  910. %s = $hget($w($1), %x).data
  911. %return = %return $hget($w($1), %x).item $+ : $iif(%s == 0,0,$+(,$iif(%s < 0,04,$iif(%s >= 100,06,03)),%s,)) ::
  912. inc %x
  913. }
  914. return $left(%return, -2)
  915. }
  916.  
  917. alias -l overallWinner {
  918. var %return, %x = 1, %y = $hget($w($1), 0).item, %score = $finish - 1, %data
  919. while (%x <= %y) {
  920. %data = $hget($w($1), %x).data
  921. if (%data >= %score) {
  922. if (%data > %score) %return = $hget($w($1), %x).item
  923. else %return = %return $hget($w($1), %x).item
  924. %score = %data
  925. }
  926. inc %x
  927. }
  928. if (%x == 2) return $hget($w($1), 1).item
  929. if ($numtok(%return, 32) == 1) return %return
  930. return $false
  931. }
  932.  
  933. ;########################################################
  934. ;########################################################
  935. ; STATISTICS WRITE
  936. ;########################################################
  937. ;########################################################
  938.  
  939. alias -l preProcessHandStats {
  940. if ($hget($s($1),stats)) {
  941. var %p = $hget($s($1),original_players)
  942. processHandStats $1 $2 total 1 $3 games
  943. processHandStats $1 $2 players %p $3 games
  944. processHandStats $1 $2 $4 1 $3 games
  945. processHandStats $1 $2 $+($4,_,single) $iif($4 == win,$calc(%p - 1),1) $3 games
  946. processHandStats $1 $2 coins $iif($hget($w($1),$2),$ifmatch,0) $3 games
  947. }
  948. }
  949.  
  950. alias -l processHandStats {
  951. if ($hget($s($1),stats)) {
  952. var %a = $iif($5 && a isin $5,$true), %z = $iif($6,$6,hands), %f = $iif(%a,$+(%z,_ai),%z)
  953. if (!%a) || ($istok($ai,$2,32)) writeini -n $f(%f) $2 $3 $calc($getStat($f(%f),$2,$3) + $4)
  954. }
  955. }
  956.  
  957. alias -l userStats {
  958. if (!$prop) {
  959. if ($getStat($f($iif($2,$2,hands)),$1,total)) return $true
  960. if ($getStat($f($iif($2,$2,hands_ai)),$1,total)) return $true
  961. return $false
  962. }
  963. if ($prop == ai) return $iif($getStat($f($+($iif($2,$2,hands),_ai)),$1,total),$true,$false)
  964. if ($prop == user) return $iif($getStat($f($+($iif($2,$2,hands))),$1,total),$true,$false)
  965. }
  966.  
  967. alias -l coinSave {
  968. if ($hget($s($1),stats)) {
  969. var %new = $iif($hget($w($1),$2),$ifmatch,0)
  970. writeini -n $f(coins) $2 coins $calc($getStat($f(coins),$2,coins) + %new)
  971. blackjackCoinListener $2 %new $getStat($f(coins),$2,coins)
  972. }
  973. }
  974.  
  975. alias -l top5Write {
  976. var %a = $iif(a isin $2,$true), %f = $iif($istok(cph.wr,$3,46),$f($iif(%a,hands_ai,hands)),$f($iif(%a,games_ai,games))), %data = $top5Data($1,%f,$3), %l
  977. if ($len(%data)) {
  978. %l = $read($l($3),w,$+(*,$chr(32),$1,$iif(%a,$+($chr(32),-a),$null)))
  979. %l = $iif($readn,$ifmatch,0)
  980. write $iif(%l,$+(-l,%l)) $l($3) %data $1 $iif(%a,-a,$null)
  981. writeini -n %f $1 $3 %data
  982. }
  983. }
  984.  
  985. alias -l top5Data {
  986. if ($istok(cpg.cph,$3,46)) return $round($calc($getStat($2,$1,coins) / $getStat($2,$1,total)),2)
  987. if ($3 == h2h) return $+($round($calc(($getStat($2,$1,win_single) / ($getStat($2,$1,win_single) + $getStat($2,$1,lose_single))) * 100),2),$chr(37))
  988. if ($3 == wr) return $round($calc(($getStat($2,$1,win) / ($getStat($2,$1,win) + $getStat($2,$1,lose) + $getStat($2,$1,draw))) * 100),2)
  989. var %t = $getStat($2,$1,total)
  990. return $round($calc(((($getStat($2,$1,win) * ((%t * ($getStat($2,$1,players) / %t)) / %t)) / %t) / ($getStat($2,$1,players) / %t)) * 100),2)
  991. }
  992.  
  993. alias -l top5PreWrite {
  994. var %x = 1
  995. if ($hget($s($1),stats)) {
  996. if ($istok($ai,$2,32) || (a !isin $3)) {
  997. while ($gettok($top5,%x,46)) {
  998. top5Write $2 $3 $ifmatch
  999. inc %x
  1000. }
  1001. }
  1002. }
  1003. }
  1004.  
  1005. alias -l top5Sort {
  1006. var %x = 1, %l
  1007. while ($gettok($top5,%x,46)) {
  1008. %l = $l($ifmatch)
  1009. if ($exists(%l)) fs %l
  1010. inc %x
  1011. }
  1012. }
  1013.  
  1014. ;########################################################
  1015. ;########################################################
  1016. ; STATISTICS DISPLAY
  1017. ;########################################################
  1018. ;########################################################
  1019.  
  1020. alias -l displayStats {
  1021. var %a = $iif((($2 == -a) && $getStat($f(hands_ai),$3,total)) || !$getStat($f(hands),$3,total),$true), %f = $f($+(hands,$iif(%a,_ai))), %f2 = $f($+(games,$iif(%a,_ai))), %x = 1, %c, %g, %h
  1022. var %t = $getStat(%f,$3,total), %w = $getStat(%f,$3,win), %d = $getStat(%f,$3,draw), %o = $round($calc(($getStat(%f,$3,double) / (%w + $getStat(%f,$3,lose) + %d)) * 100),2) $+ $chr(37)
  1023. while ($gettok($top5,%x,46)) {
  1024. %g = $ifmatch
  1025. %h = $read($l(%g),w,$+(*,$chr(32),$3,$iif(%a,$+($chr(32),-a),$null)))
  1026. %c = %c $+($upper(%g),:) $c3($ord($iif($readn,$ifmatch,$lines($l(%g))))) $c2(/)
  1027. inc %x
  1028. }
  1029. msg $1 Play stats for $cb1($3 $+ :) Hands: $c3(%t) $c2(/) Wins: $c3(%w) $c2(/) Draws: $c3(%d) $c2(/) CPH: $c3($top5Data($3,%f,cph)) $c2(/) Win Rate: $c3($top5Data($3,%f,wr)) $c2(/) Double Rate: $c3(%o)
  1030. msg $1 Game stats for $cb1($3 $+ :) Games: $c3($getStat(%f2,$3,total)) $c2(/) Wins: $c3($getStat(%f2,$3,win)) $c2(/) CPG: $c3($top5Data($3,%f2,cpg)) $c2(/) Game Rating: $c3($top5Data($3,%f2,gr)) $c2(/) H2H Tier: $c3($top5Data($3,%f2,h2h))
  1031. msg $1 List stats for $cb1($3 $+ :) $gettok(%c,$+(1-,$calc($numtok(%c,32) - 1)),32)
  1032. }
  1033.  
  1034. alias -l displayCoins {
  1035. %f = $f(coins)
  1036. if ($ini(%f,$3)) msg $1 Total coins for $cb1($3 $+ :) $c3($getStat(%f,$3,coins))
  1037. }
  1038.  
  1039. alias -l displayTop5 {
  1040. var %x = 1, %f = $l($3), %l = $lines(%f), %c = 0, %r, %f2, %a, %game = $iif($istok(cpg.gr.h2h,$3,46),games,hands), %y = $iif(%game == games,$statMinGames,$statMinHands), %p
  1041. msg $1 $cb3(Top 5) $c3($iif(a isin $2,robots,$iif(u isin $2,users,players)) for:) $c2($iif($3 == cph,Coins Per Hand,$iif($3 == wr,Win Rate,$iif($3 == cpg,Coins Per Game,$iif($3 == gr,Game Rating,Head to Head Tier))))) $bracks(min %y %game)
  1042. while (%x <= %l) && (%c < 5) {
  1043. %r = $read(%f,%x)
  1044. %p = $gettok(%r,2,32)
  1045. %a = $iif($gettok(%r,3,32) == -a,$true,$false)
  1046. %f2 = $f($iif(%a,$+(%game,_,ai),%game))
  1047. if ($getStat(%f2,%p,total) >= %y) && ((($2 == -a) && (%a)) || (($2 == -u) && (!%a)) || ($2 == -n)) {
  1048. inc %c
  1049. msg $1 $cb1($+(%c,$chr(46))) $c2(%p) $iif(%a,$+($chr(32),$bracks(AI level $getIntel(%p)))) $cb3($bracks($gettok(%r,1,32)))
  1050. }
  1051. inc %x
  1052. }
  1053. }
  1054.  
  1055. alias -l displayCompare {
  1056. var %x = 1, %a1 = $iif((($1 == -a) && ($getStat($f(hands_ai),$2,total))) || (!$getStat($f(hands),$2,total)),$true,$false), %a2 = $iif((($3 == -a) && ($getStat($f(hands_ai),$4,total))) || (!$getStat($f(hands),$4,total)),$true,$false)
  1057. var %f, %r1, %r2, %t1, %t2
  1058. while (%x <= $numtok($top5,46)) {
  1059. %f = $l($gettok($top5,%x,46))
  1060. %r1 = $read(%f,w,$+(*,$chr(32),$2,$iif(%a1,$+($chr(32),-a),$null)))
  1061. inc %t1 $iif($readn,$ifmatch,$lines(%f))
  1062. %r2 = $read(%f,w,$+(*,$chr(32),$4,$iif(%a2,$+($chr(32),-a),$null)))
  1063. inc %t2 $iif($readn,$ifmatch,$lines(%f))
  1064. inc %x
  1065. }
  1066. %r2 = $round($calc((%t1 / (%t1 + %t2)) * 100),2)
  1067. %r1 = $calc(100 - %r2)
  1068. if (%r1 > %r2) msg $5 $cb1(>>>) $cb2($2) $cb1(<<<) $cb3($+(%r1,$chr(37))) $c1(vs) $+(%r2,$chr(37)) $c2($4)
  1069. elseif (%r2 > %r1) msg $5 $c2($2) $+(%r1,$chr(37)) $c1(vs) $cb3($+(%r2,$chr(37))) $cb1(>>>) $cb2($4) $cb1(<<<)
  1070. else msg $5 $cb2($2) $cb3($+(%r1,$chr(37))) $c1(vs) $cb3($+(%r2,$chr(37))) $cb2($4)
  1071. }
  1072.  
  1073. ;########################################################
  1074. ;########################################################
  1075. ; HELPER FUNCTIONS (use outside script)
  1076. ;########################################################
  1077. ;########################################################
  1078.  
  1079. ; return coins in coins.ini
  1080. alias blackjackGetCoins {
  1081. return $getStat($f(coins),$1,coins)
  1082. }
  1083.  
  1084. ; remove coins from coins.ini
  1085. alias blackjackDelCoins {
  1086. var %u = $1, %f = $f(coins)
  1087. writeini -n %f %u coins $calc($getStat(%f,%u,coins) - $iif($2 isnum,$ifmatch,0))
  1088. if ($isid) return $getStat(%f,$1,coins)
  1089. }
  1090.  
  1091. ;########################################################
  1092. ;########################################################
  1093. ; ACCUMULATED COINS LISTENER
  1094. ;########################################################
  1095. ;########################################################
  1096.  
  1097. ; listener, each time the user accumulates more coins (runs once per user per game played)
  1098. ; you can 'transport' the coins accumulated to a separate script/file, and/or delete them
  1099. ; these coins are displayed by the !coins command, removing them will be reflected.
  1100. ; you can copy new points ($2) to a global/master file which works with your other scripts, if you want
  1101. ; take note that $2 and $3 can both be negatives, make proper checks to keep things in accordance with the rest of your script
  1102.  
  1103. alias -l blackjackCoinListener {
  1104. ; $1 = the username
  1105. ; $2 = coins added for user after current game
  1106. ; $3 = new total coins for user
  1107. ; your commands here:
  1108.  
  1109. ; example echo after each time coins are added (uncomment to try)
  1110. ; echo -a $1 finished the game, $iif($2 >= 0,winning,losing) $2 coins, and now has $3 total coins!
  1111.  
  1112. ; example removing coins just earnt:
  1113. ; blackjackDelCoins $1 $2
  1114.  
  1115. ; example write to a separate file which holds stars collected by users. Each star is worth 20 coins
  1116. ; also remove N stars worth of coins from the coin bank.
  1117. ; if ($3 > 0) {
  1118. ; var %file = stars.ini, %coinsPerStar = 20, %stars = $floor($calc($3 / %coinsPerStar))
  1119. ; writeini %file $1 stars $calc($iif($readini(%file,$1,stars),$v1,0) + %stars)
  1120. ; blackjackDelCoins $1 $calc($3 - ($3 % %coinsPerStar))
  1121. ; }
  1122.  
  1123. ; hint: removing the if statement surrounding the previous 3 commands will hold it's current functionality,
  1124. ; but will also remove stars from the stars file if the user falls to -20 or less
  1125. }
Add Comment
Please, Sign In to add comment