Hey everyone, for a while now I've been using a betting script for Twitch where I allow people to place their bets on a Win or a Loss. With all options, my script has a "capacity" of 20 users. Luckily it's a small stream, so I never reach 20, although the script is very repetitive in it's ways. While I am not anywhere close to a good scripter in MIRC, I've written this entire script from scratch(Excluding a couple things to get my method to work) and it's a terrifying 1900 lines of code.

What I'm looking for is a way to minimize the amount of code by using some sort of loop that allows me to retrieve the amount of entries in a file and loop the points per line. So it'll award points to the first entry, automatically use the number of said line and use that +1 for the next line.(Meaning if my script has just finished completing the points for Line 1, it'll go to Line 1 + 1 AKA Line 2, repeat the points routine and go to Line 2 + 1 AKA 3

The current script has 8 different options and they all operate the same. Through text files.

Originally Posted By: The options

Win
Loss
Tie
Top50
Top40
Top30
Top20
Top10


How the current script works:
As soon as a moderator opens the bets for a certain game(I use Win/Loss options for CSGO and Top50-40-30-20-10 for BattleGrounds), the script will create empty files for all options. Once someone enters their bet, their name gets writting into the "Entries" file and the file belonging to their choice. Their name + points entered will be written into an INI file.

By the time a moderator closes the bets, people will not be able to enter their bets anymore(This part is completely irrelevant to this thread, to be honest)

Once the game is done, the moderator enters the result. In this example it'll be !bet result Win. The script will use the following code to process people's points.

If the first line is empty, this could mean 2 things. Nobody entered their bets on a Win, or the first person to do so has removed their bet(Which is also part of the script). In case this happens, the script will skip to Line 2. If Line 2 doesn't contain anything, it'll skip to Line 3 etc. etc. etc. untill it's reached Line 20, writes all names to an announcement file, which gets used in the final announcement.

Code:
        if ($3 == win) {
          :Win1
          if ($read(C:\Users\Administrator\AppData\Roaming\mIRC\BettingFiles\Win.txt, 1) == $null) {
            goto Win2
          }        
          else writeini -n Points.ini $+(#) $read(C:\Users\Administrator\AppData\Roaming\mIRC\BettingFiles\Win.txt, 1) $round($calc($readini(Points.ini,$+(#),$read(C:\Users\Administrator\AppData\Roaming\mIRC\BettingFiles\Win.txt, 1)) + $calc($readini(C:\Users\Administrator\AppData\Roaming\mIRC\BettingFiles\Bets.ini,$+(#),$read(C:\Users\Administrator\AppData\Roaming\mIRC\BettingFiles\Win.txt, 1)) * 1.5)),0)
          /write -a AnnouncementWin.txt $read(C:\Users\Administrator\AppData\Roaming\mIRC\BettingFiles\Win.txt, 1) $+ ( $+ $round($calc($readini(C:\Users\Administrator\AppData\Roaming\mIRC\BettingFiles\Bets.ini,$+(#), $read(C:\Users\Administrator\AppData\Roaming\mIRC\BettingFiles\Win.txt, 1))* 1.5),0) $+ )
          			   
          :Win2
          if ($read(C:\Users\Administrator\AppData\Roaming\mIRC\BettingFiles\Win.txt, 2) == $null) {
            goto Win3
          }
          else writeini -n Points.ini $+(#) $read(C:\Users\Administrator\AppData\Roaming\mIRC\BettingFiles\Win.txt, 2) $round($calc($readini(Points.ini,$+(#),$read(C:\Users\Administrator\AppData\Roaming\mIRC\BettingFiles\Win.txt, 2)) + $calc($readini(C:\Users\Administrator\AppData\Roaming\mIRC\BettingFiles\Bets.ini,$+(#),$read(C:\Users\Administrator\AppData\Roaming\mIRC\BettingFiles\Win.txt, 2)) * 1.5)),0)
          /write -a AnnouncementWin.txt $read(C:\Users\Administrator\AppData\Roaming\mIRC\BettingFiles\Win.txt, 2) $+ ( $+ $round($calc($readini(C:\Users\Administrator\AppData\Roaming\mIRC\BettingFiles\Bets.ini,$+(#), $read(C:\Users\Administrator\AppData\Roaming\mIRC\BettingFiles\Win.txt, 2))* 1.5),0) $+ )


This continues till I've scanned all 20 lines(Even empty ones) and ends with a removal of all the files used for a clean slate. Every time I start the bets, new files get created and every time I set the result, all names and their points get written to an announcement and once that's done and announced, all files get deleted.

Code:
:WinAnnounce
          msg $chan It's a win! Winners are: $read(AnnouncementWin.txt, 1) $read(AnnouncementWin.txt, 2) $read(AnnouncementWin.txt, 3) $read(AnnouncementWin.txt, 4) $read(AnnouncementWin.txt, 5) $read(AnnouncementWin.txt, 6) $read(AnnouncementWin.txt, 7) $read(AnnouncementWin.txt, 8) $read(AnnouncementWin.txt, 9) $read(AnnouncementWin.txt, 10) $read(AnnouncementWin.txt, 11) $read(AnnouncementWin.txt, 12) $read(AnnouncementWin.txt, 13) $read(AnnouncementWin.txt, 14) $read(AnnouncementWin.txt, 15) $read(AnnouncementWin.txt, 16) $read(AnnouncementWin.txt, 17) $read(AnnouncementWin.txt, 18) $read(AnnouncementWin.txt, 19) $read(AnnouncementWin.txt, 20)     
          /echo 4 @Script ( $+ $time $+ ) $nick has set the result to: Win
          /remove C:\Users\Administrator\AppData\Roaming\mIRC\BettingFiles\Win.txt
          /remove C:\Users\Administrator\AppData\Roaming\mIRC\BettingFiles\Loss.txt
          /remove C:\Users\Administrator\AppData\Roaming\mIRC\BettingFiles\Bets.ini
          /remove C:\Users\Administrator\AppData\Roaming\mIRC\BettingFiles\Entries.txt
          /remove AnnouncementWin.txt
          halt


To make a very long story short... How do I turn this method into a less line-consuming and cleaner one? Is there a way to loop through a file once and execute a certain routine for every single line without having to actually define the line in my $read command?