Advertisement
Guest User

!guess script

a guest
Mar 16th, 2018
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
mIRC 15.93 KB | None | 0 0
  1.  
  2.  
  3.  
  4.  
  5. on *:TEXT:!guess*:#: {
  6.   if ($1 != !guess) halt
  7.  
  8.   ; ||-----|| This section is for mods only ||-----||
  9.  
  10.   ; Checks if user is operator (mod) on channel.
  11.  
  12.   if ($ismod()) {
  13.     if ($2 == timer) {
  14.       if ($3 == set) {
  15.         if ($4 isnum) {
  16.           if (($4 < 60) || ($4 > 3600)) {
  17.             msg # Please select a time between 50 and 3600 seconds.
  18.             halt
  19.           }
  20.           writeini $get_filename() Info Timer $4
  21.           msg # New Timer set.
  22.           if ($readini($get_filename(), n, Info, Running)) {
  23.             timerHuntGuess off
  24.             timerHuntGuess 0 $readini($get_filename(), n, Info, Timer) print_guess_message
  25.             halt
  26.           }
  27.           halt
  28.         }
  29.         halt
  30.       }
  31.       halt
  32.     }
  33.     if ($2 == new) {
  34.       if ($is_running) {
  35.         msg # Guessing is already running. To stop it, use !guess stop.
  36.         halt
  37.       }
  38.       var %old_winners 1
  39.       var %old_prize €50 Cash
  40.       var %old_timer 300
  41.       var %text Couldn't find the previous guess-file. Creating a new with default settings.
  42.       if ($isfile($get_filename())) {
  43.         var %old_winners $readini($get_filename(), n, Info, Winners)
  44.         var %old_prize $readini($get_filename(), n, Info, Prize)
  45.         var %old_timer $readini($get_filename(), n, Info, Timer)
  46.         var %text Archived the last Guess, copied the settings and created a new one. SeemsGood
  47.         archive
  48.       }
  49.  
  50.       writeini $get_filename() Info Winners %old_winners
  51.       writeini $get_filename() Info Prize %old_prize
  52.       writeini $get_filename() Info Timer %old_timer
  53.       writeini $get_filename() Info Channel $chan
  54.  
  55.  
  56.       msg # %text
  57.       halt
  58.     }
  59.     if ($2 == avg) {
  60.       msg # Average betsize: € $+ $round($get_avg_betsize(), 2)
  61.       halt
  62.     }
  63.     if ($2 == rb) {
  64.       if ($3 != $null) {
  65.         var %restbalance $replace($3, $chr(44), $chr(46))
  66.         if (%restbalance isnum) {
  67.           writeini $get_filename() Info RestBalance %restbalance
  68.           msg # Restbalance is now set to %restbalance $+ . It will be subtracted from the amount used in !guess pick.
  69.           halt
  70.         }
  71.         msg # @ $+ $nick That's not a valid number.
  72.         halt
  73.       }
  74.       var %restbalance $readini($get_filename(), n, Info, RestBalance)
  75.       if (%restbalance == $null) var %restbalance 0
  76.       msg # Restbalance is currently set to € $+ %restbalance $+ .
  77.       halt
  78.     }
  79.     if ($2 == start) {
  80.       if ($is_running) {
  81.         msg # Guessing is already running. To stop it, use !guess stop.
  82.         halt
  83.       }
  84.       if (!$readini(stats\channel_variables.ini, n, Bullet, Hunt)) {
  85.         msg # Bonushunt bullet not set, aborting script. (!sethuntbullet <amount>)
  86.         halt
  87.       }
  88.       if ($readini($get_filename(), n, Info, Start) != $null) {
  89.         msg # This Guess is already tagged as "completed". If you want to start a new one, use "!guess new" first.
  90.         halt
  91.       }
  92.  
  93.  
  94.       var %total_bonuses $ini(bonushunt.ini, Collected, 0)
  95.       var %hunt_bullet $readini(stats\channel_variables.ini, n, Bullet, Hunt)
  96.       var %avg_betsize $round($get_avg_betsize(), 2)
  97.  
  98.       var %topic Guess the outcome of the bonushunt! € $+ %hunt_bullet was invested with %total_bonuses bonuses in total. (€ $+ %avg_betsize average betsize)
  99.  
  100.       ; writing guess-info to file
  101.       writeini $get_filename() Info Bullet %hunt_bullet
  102.       writeini $get_filename() Info Topic %topic
  103.  
  104.       start_guess
  105.  
  106.       msg # /me What will the balance be after all the bonuses have been completed? Type "!guess <your guess>" to join. (Example: !guess $calc($get_hunt_bullet() - 500 + $rand(0, 2000)) $+ )
  107.       timerHuntGuess 0 $readini($get_filename(), n, Info, Timer) print_guess_message $get_filename() $chan
  108.       halt
  109.     }
  110.     ; stopping the guessing, denying more entries and writing an end time to file
  111.     if ($2 == stop) {
  112.       if (!$is_running) {
  113.         msg # @ $+ $nick Stop what? The guessing isn't running at the moment. FailFish
  114.         halt
  115.       }
  116.       stop_guess
  117.       timerHuntGuess off
  118.       writeini $get_filename() Info End $ctime
  119.       var %entries $ini($get_filename(), Guess, 0)
  120.       if (%entries == $null) var %entries 0
  121.       msg # /me Guessing stopped! No more entries accepted. Total entries: %entries
  122.       halt
  123.     }
  124.     ; Removing user from the list
  125.     if ($2 == remove) {
  126.       if ($3 == $null) {
  127.         msg # @ $+ $nick $+ , To remove a user from the guessing list, type "!guess remove <user>"
  128.         halt
  129.       }
  130.       var %user $readini($get_filename(), n, Guess, $3)
  131.       if (%user != $null) {
  132.         remini $get_filename() Guess $3
  133.         remini $get_filename() Winners $3
  134.         msg # $3 removed from list.
  135.         halt
  136.       }
  137.       msg # Could not find $3 in the list.
  138.       halt
  139.     }
  140.     if ($2 == pick) {
  141.       if ($is_running) {
  142.         msg # @ $+ $nick Guessing is currently running. To pick a winner, you need to stop it first. "!guess stop".
  143.         halt
  144.       }
  145.      
  146.       var %result $replace($3, $chr(44), $chr(46))
  147.       if ($3 !isnum) {
  148.         msg # @ $+ $nick That's not a valid number.
  149.         halt
  150.       }
  151.       var %restbalance $readini($get_filename(), n, Info, RestBalance)
  152.       if (%restbalance) {
  153.         var %result $calc(%result - %restbalance)
  154.       }
  155.       writeini $get_filename() Info Result %result
  156.       var %amount_winners $readini($get_filename(), n, Info, Winners)
  157.  
  158.       if ($ini($get_filename(), Winners, 0) == %amount_winners) {
  159.         msg # Winners were already picked!
  160.         halt
  161.       }
  162.      
  163.       remini $get_filename Winners
  164.      
  165.       var %x 1
  166.       while ((%x <= %amount_winners) && ($ini($get_filename(), Guess, 0) != 0)) {
  167.         var %winner $find_winner(%result)  
  168.         var %guess $readini($get_filename(), n, Guess, %winner)
  169.         writeini $get_filename() Winners %winner %guess
  170.         inc %x
  171.       }
  172.  
  173.       print_winners
  174.       halt
  175.     }
  176.     if ($2 == setwinners) {
  177.       if (($3 isnum) && ($3 > 0)) {
  178.         var %winners $round($3, 0)
  179.         msg # Total number of winners set to %winners
  180.         writeini $get_filename Info Winners %winners
  181.       }
  182.       else msg # @ $+ $nick Please provide the number of winners to be picked for when the hunt is completed.
  183.       halt
  184.     }
  185.     if ($2 == setprize) {
  186.       msg # Setting prize to $3-
  187.       writeini $get_filename Info Prize $3-
  188.       halt
  189.     }
  190.   }
  191.  
  192.   ; ||-----|| This section is for everyone ||-----||
  193.  
  194.   if ($2 == help) {
  195.     msg # If guessing is open, you can join by typing '!guess <your guess>' (Ex: !guess 7777). Use '!guess prize' to see what you can win. '!guess rules' to read the rules. '!guess check' to check your entry.
  196.     halt
  197.   }
  198.  
  199.   if ($2 == prize) {
  200.     if ($readini($get_filename(), Info, Prize) == $null) writeini $get_filename Info Prize €50 Cash
  201.     msg # The prize(s) of this contest: => $readini($get_filename(), Info, Prize) <= PogChamp
  202.     halt
  203.   }
  204.   if ($2 == rules) {
  205.     var %winners $readini($get_filename, n, Info, Winners)
  206.     if (%winners > 1) {
  207.       msg # /me The funds left in the account after all bonuses are played (minus the starting balance) will be the 'result' used to pick the winners. $chr(9679) YOU NEED TO BE A FOLLOWER of this channel to be able to win. $chr(9679) The %winners closest guesses will be the winners. $chr(9679) We reserve the rights to redistribute any prize at our own discretion.
  208.     }
  209.     else msg # /me The funds left in the account after all bonuses are played (minus the starting balance) will be the 'result' used to pick a winner. $chr(9679) YOU NEED TO BE A FOLLOWER of this channel to be able to win. $chr(9679) The closest guess will be the winner. $chr(9679) We reserve the rights to redistribute any prize at our own discretion.
  210.     halt
  211.   }
  212.   if ($2 == check) {
  213.     var %input $3
  214.     var %input $remove(%input, @)
  215.     if (%input == $null) var %input $nick
  216.     if (%input !isnum) {
  217.       var %value $readini($get_filename(), n, Guess, %input)
  218.       if (%value != $null) {
  219.         if (%input == $nick) {
  220.           msg # @ $+ $nick $+ , You're in the list with the guess € $+ %value
  221.           halt
  222.         }
  223.         msg # @ $+ $nick $+ , %input guessed € $+ %value for today.
  224.         halt
  225.       }
  226.       if (%input == $nick) {
  227.         msg # @ $+ $nick $+ , You didn't make a guess today.
  228.         halt
  229.       }
  230.       msg # @ $+ $nick $+ , Couldn't find %input in todays list.
  231.       halt
  232.     }
  233.  
  234.  
  235.     var %list $get_guess_list(%input)
  236.     var %text $numtok(%list, 32)
  237.     if (%text == $null) var %text 0
  238.     msg # There are %text entries with the guess € $+ %input
  239.  
  240.     halt
  241.   }
  242.  
  243.  
  244.  
  245.  
  246.  
  247.   if (!$is_running()) {
  248.     if ($ini($get_filename(), Winners, 0)) print_winners
  249.     elseif ($ini($get_filename(), Guess, 0)) msg # @ $+ $nick $+ , Guessing is currently closed. It ended $asctime($readini($get_filename(), Info, End), HH:nn) with $ini($get_filename(), Guess, 0) entries. The winners have not yet been revealed!
  250.     else msg # Guessing is not open yet. It will start as soon as a moderator writes "!guess start".
  251.     halt
  252.   }
  253.   ; Guess is running, but the user didn't add a guess. Same as above, if it was more than 5 second since the last displayed text, it will print this message.
  254.   if ($2 == $null) {
  255.     print_guess_message
  256.     halt
  257.   }
  258.  
  259.   var %guess $replace($2, $chr(44), $chr(46))
  260.   var %guess $remove(%guess, €)
  261.   if (%guess isnum) var %guess $round(%guess, 2)
  262.  
  263.  
  264.  
  265.  
  266.   if ((%guess !isnum) || (%guess < 0)) {
  267.     if ((%guess !isnum) && (@ isin %guess)) {
  268.       halt
  269.     }
  270.     msg # @ $+ $nick Invalid guess. Only numbers above 0 accepted. You wrote $2 $+ .
  271.     halt
  272.   }
  273.   if ((%guess !isnum) || (%guess > 99999)) {
  274.     msg # @ $+ $nick Come on. Get real! It's just not going to happen. Guess denied! FailFish
  275.     halt
  276.   }
  277.  
  278.   var %is_guesser $false
  279.   if ($readini($get_filename(), n, Guess, $nick) != $null) {
  280.     var %is_guesser $true
  281.     remini $get_filename() Guess $nick
  282.   }
  283.  
  284.  
  285.   writeini $get_filename() Guess $nick %guess
  286.   if (%is_guesser) msg # Changing guess for $nick $+ . The new one is € $+ %guess $+ .
  287.   else msg # Guess placed for $nick (€ $+ %guess $+ )
  288.   halt
  289. }
  290.  
  291. alias -l get_avg_betsize {
  292.   var %totalbetsize 0
  293.   var %x 1
  294.   var %collected $ini(bonushunt.ini, Collected, 0)
  295.   while (%x <= %collected) {
  296.     var %item $ini(bonushunt.ini, Collected, %x)
  297.     var %totalbetsize $calc( %totalbetsize + $readini(bonushunt.ini, n, Collected, %item) )
  298.     inc %x
  299.   }
  300.  
  301.   return $calc(%totalbetsize / %collected)
  302. }
  303.  
  304. alias -l print_winners {
  305.   var %result $readini($get_filename(), n, Info, Result)
  306.   var %x 1
  307.   var %text There were no winners. FeelsBadMan
  308.   while (%x <= $ini($get_filename(), Winners, 0)) {
  309.     var %user $ini($get_filename(), Winners, %x)
  310.     var %guess $readini($get_filename(), n, Winners, %user)
  311.     var %diff $calc($calc(%result - %guess) * -1)
  312.     if (%diff > 0) var %diff + $+ %diff
  313.  
  314.     if (%x == 1) {
  315.       if ($ini($get_filename(), Winners, 0) == 1) var %text %user (€ $+ %guess / %diff $+ )
  316.       else var %text %x $+ . %user (€ $+ %guess / %diff $+ )
  317.     }
  318.     else {
  319.       var %text %text $chr(9679) %x $+ . %user (€ $+ %guess / %diff $+ )
  320.     }
  321.     inc %x
  322.   }
  323.  
  324.   var %time $asctime($readini($get_filename(), Info, End), dd.mm.yy HH:nn)
  325.   if ($readini($get_filename(), n, Info, Announced)) {
  326.     if ($ini($get_filename(), Winners, 0) == 1) msg # Final balance: € $+ %result $+ . The winner was: %text $+ . This contest ended %time $+ .
  327.     else msg # Final balance: € $+ %result $+ . The winners: %text $+ . This contest ended %time $+ .
  328.   }
  329.   else {
  330.     if ($ini($get_filename(), Winners, 0) == 1) msg # Final balance: € $+ %result $+ . The winner is: %text $+ . Congratulations! The prize: $readini($get_filename(), Info, Prize) FeelsAmazingMan
  331.     else msg # Final balance: € $+ %result $+ . The winners: %text $+ . Congratulations! Here are the prizes: $readini($get_filename(), Info, Prize) FeelsAmazingMan
  332.     writeini $get_filename() Info Announced $true
  333.   }
  334. }
  335.  
  336. alias -l get_filename {
  337.   return bonushunt_guess.ini
  338. }
  339.  
  340. alias -l start_guess {
  341.   writeini $get_filename() Info Start $ctime
  342.   writeini $get_filename() Info Running $true
  343. }
  344.  
  345. alias -l stop_guess {
  346.   writeini $get_filename() Info Running $false
  347. }
  348.  
  349. alias -l is_running {
  350.   if ($isfile($get_filename())) {
  351.     if ($readini($get_filename(), n, Info, Running)) return $true
  352.   }
  353.   return $false
  354. }
  355.  
  356. alias -l get_hunt_bullet {
  357.   return $readini(stats\channel_variables.ini, n, Bullet, Hunt)
  358. }
  359.  
  360. alias -l print_guess_message {
  361.   var %chan $readini($get_filename(), n, Info, Channel)
  362.   var %time $calc($ctime - $readini($get_filename(), Info, Start))
  363.   var %minute $floor($calc(%time / 60))
  364.   var %sec $calc(%time % 60)
  365.   var %entries $ini($get_filename(), Guess, 0)
  366.   if (%entries == $null) var %entries 0
  367.   msg %chan /me $readini($get_filename(), Info, Topic) Type "!guess" followed by your number to join. (Example: !guess $calc($get_hunt_bullet() - 500 + $rand(0, 2000)) $+ ). Runtime: %minute $+ m %sec $+ s. %entries entries so far. Only followers can win. Type "!guess rules" to see the rules.
  368. }
  369.  
  370.  
  371. alias -l archive {
  372.   if (!$isfile($get_filename())) return 0
  373.   var %date $asctime($ctime, ddmmyyyy)
  374.   var %new_file archive\bonushunt_guess $+ %date $+ .ini
  375.   if ($exists(%new_file)) {
  376.     var %x 2
  377.     while ($exists(%new_file)) {
  378.       var %new_file archive\bonushunt_guess $+ %date $+ _ $+ %x $+ .ini
  379.       inc %x
  380.     }
  381.   }
  382.   copy $get_filename() %new_file
  383.   if ($exists(%new_file)) {  
  384.     remove $get_filename()
  385.     return 1
  386.   }
  387.   else {
  388.     return 0
  389.   }
  390. }
  391.  
  392.  
  393. alias -l get_guess_list {
  394.   var %x 1
  395.   var %result
  396.   var %length $ini($get_filename(), Guess, 0)
  397.   while (%x <= %length) {
  398.     var %item $ini($get_filename(), Guess, %x)
  399.     if ($1 == all) {
  400.       var %result $addtok(%result, $ini($get_filename(), Guess, %x), 32)
  401.     }
  402.     elseif ($readini($get_filename(), n, Guess, %item) == $1) {
  403.       var %result $addtok(%result, $ini($get_filename(), Guess, %x), 32)
  404.     }
  405.     inc %x
  406.   }
  407.   return %result
  408. }
  409.  
  410. alias -l is_winner {
  411.   var %user $1
  412.   var %result $readini($get_filename(), n, Winners, %user)
  413.   if (%result != $null) return $true
  414.   else return $ralse
  415. }
  416.  
  417.  
  418. alias -l find_winner {
  419.   var %result $1
  420.   var %x 1
  421.   var %total $ini($get_filename(), Guess, 0)
  422.   var %under 0
  423.   var %over 1000000
  424.   var %under_user
  425.   var %over_user
  426.   while (%x <= %total) {
  427.     var %user $ini($get_filename(), Guess, %x)
  428.     var %guess $readini($get_filename(), n, Guess, %user)
  429.     if ($is_winner(%user)) {
  430.       inc %x
  431.       continue
  432.     }
  433.     if (%guess == %result) return %user
  434.     if ((%guess >= %under) && (%guess <= %result)) {
  435.       var %under %guess
  436.       var %under_user %user
  437.     }
  438.     elseif ((%guess <= %over) && (%guess >= %result)) {
  439.       var %over %guess
  440.       var %over_user %user
  441.     }
  442.     inc %x
  443.   }
  444.   var %under_diff $calc(%result - %under)
  445.   var %over_diff $calc(%over - %result)
  446.   if (%under_diff < %over_diff) return %under_user
  447.   else return %over_user
  448.  
  449. }
  450.  
  451.  
  452. alias -l find_lowest_guess {
  453.   var %x 1
  454.   var %total $ini($get_filename(), Guess, 0)
  455.   var %lowest
  456.   var %lowest_user
  457.   while (%x <= %total) {
  458.     var %user $ini($get_filename(), Guess, %x)
  459.     var %guess $readini($get_filename(), n, Guess, %user)
  460.     if (%x == 1) {
  461.       var %lowest %guess
  462.       var %lowest_user %user
  463.     }
  464.     else {
  465.       if (%guess < %lowest) {
  466.         var %lowest %guess
  467.         var %lowest_user %user
  468.       }
  469.     }
  470.     inc %x
  471.   }
  472.   return %lowest
  473. }
  474.  
  475. alias -l find_highest_guess {
  476.   var %x 1
  477.   var %total $ini($get_filename(), Guess, 0)
  478.   var %highest 0
  479.   var %highest_user
  480.   while (%x <= %total) {
  481.     var %user $ini($get_filename(), Guess, %x)
  482.     var %guess $readini($get_filename(), n, Guess, %user)
  483.     if (%x == 1) {
  484.       var %highest %guess
  485.       var %highest_user %user
  486.     }
  487.     else {
  488.       if (%guess > %highest) {
  489.         var %highest %guess
  490.         var %highest_user %user
  491.       }
  492.     }
  493.     inc %x
  494.   }
  495.   return %highest
  496. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement