Advertisement
Guest User

BAB script Games Since N

a guest
Oct 29th, 2020
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. var config = {
  2. n: { value: '1', type: 'text', label: 'Rounds since last game >= multiplier (n)'},
  3. t: { value: 2, type: 'multiplier', label: 'Multiplier (t)'},
  4. wager: { value: 0, type: 'balance', label: 'Wager'}
  5. };
  6.  
  7. // Globals
  8. const n = parseInt(config.n.value);
  9. const t = config.t.value;
  10. const wager = config.wager.value;
  11. let m = 0;
  12.  
  13. // Ensure user input makes sense
  14. if(isNaN(n)) {
  15. stop('n must be an integer');
  16. } else if(n < 0) {
  17. stop('n cannot be less than 0');
  18. } else if(n === 0) {
  19. log('Warning: n is 0, the script will be betting on every game');
  20. } else if(t > 1000) {
  21. log('Warning: You are using a very high multiplier');
  22. log('Using large values can cause the script to freeze temporarily');
  23. }
  24.  
  25. // Recursive function to find the number of games since a multiplier
  26. function findM(m, hash) {
  27. return new Promise((resolve, reject) => {
  28. gameResultFromHash(hash).then((result) => {
  29. if(result >= t) {
  30. resolve(m);
  31. } else {
  32. SHA256(hash).then((newHash) => {
  33. findM(m + 1, newHash).then((m) => {
  34. resolve(m);
  35. });
  36. });
  37. }
  38. });
  39. });
  40. }
  41.  
  42. // Place a bet with the specified options
  43. function placeBet() {
  44. log('Placing bet');
  45. checkBalance();
  46. engine.bet(wager, t);
  47. }
  48.  
  49. // Pre-check before betting
  50. function checkBalance() {
  51. if(userInfo.balance < config.wager.value) {
  52. stop('Insufficient balance');
  53. }
  54. }
  55.  
  56. // Happens after the initial "sync", and after every game ending
  57. function checkParams(initial) {
  58. if(engine.history.first().bust >= t && !initial) {
  59. log(`Multiplier for finished game was >= ${t}x, resetting count. `);
  60. m = 0;
  61. log(`${n-m} round(s) of multipliers < ${t}x before betting remaining`);
  62. } else {
  63. if(!initial) m++;
  64. if(m >= n) {
  65. placeBet();
  66. m = 0;
  67. } else {
  68. log(`${n-m} round(s) of multipliers < ${t}x before betting remaining`);
  69. }
  70. }
  71. }
  72.  
  73. findM(0, engine.history.first().hash).then((value) => {
  74. // m is global here
  75. m = value;
  76. log(`${m} game(s) since multiplier of or at least ${t}x`);
  77. checkParams(true);
  78. // Set up event listeners to continue the script after the initial stage
  79. engine.on('GAME_ENDED', () => {
  80. checkParams();
  81. });
  82. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement