mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Jul 2014
Posts: 4
R
Self-satisified door
OP Offline
Self-satisified door
R
Joined: Jul 2014
Posts: 4
I am trying to write a !top10 count for a twitch stream.

bank.ini looks like
Code:
[scrbr]
bank=165458232

[rage_worthy]
bank=447585310


Current Script:
Code:
alias top10 {
  window -h @all
  var %i 1
  while $ini(bank.ini,%i) {
    aline @all $v1 $readini(bank.ini,$v1,bank)
    inc %i
  }
  filter -cetuwf 2 32 @all bank.txt
  window -c @all
  play -l1 bank.txt 1
  play -l2 bank.txt 1
  play -l3 bank.txt 1
  play -l4 bank.txt 1
  play -l5 bank.txt 1
  play -l6 bank.txt 1
  play -l7 bank.txt 1
  play -l8 bank.txt 1
  play -l9 bank.txt 1
  play -l10 bank.txt 1
}


This is what it outputs
Code:
<@rage_worthy> biebery 534127590
<@rage_worthy> rage_worthy 447585310


This is what I want it to output
Code:
<@rage_worthy> 2 - biebery 534,127,590
<@rage_worthy> 1 - rage_worthy 447,585,310


I don't know where to put the $bytes to get the commas and I don't know how to get the lines numbered.

Last edited by RageWorthy; 31/07/14 05:50 PM.
Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
Change this:

Code:
aline @all $v1 $readini(bank.ini,$v1,bank)


To this:

Code:
aline @all %i - $v1 $readini(bank.ini,$v1,bank)

Joined: Jul 2014
Posts: 4
R
Self-satisified door
OP Offline
Self-satisified door
R
Joined: Jul 2014
Posts: 4
I already tried that. The problem with that is this is happening before the filter, so it outputs the line they are on and not the place they are in.

Also, I need a way to use $bytes on the number.

Last edited by RageWorthy; 31/07/14 08:48 PM.
Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
Apologies, you're right.

Use the -n switch in /filter.

To use $bytes on the number you can use the -k switch in filter, which calls a custom alias. You can then use the custom alias to write to the file and format each line as you see fit.

Let me know if you need help doing this.

Cheers

Joined: Jul 2014
Posts: 4
R
Self-satisified door
OP Offline
Self-satisified door
R
Joined: Jul 2014
Posts: 4
Yes, I very much need help doing that :-D please.

the -n command filters the line number from the IN not the out, so I am getting the wrong line numbers in the txt :-D

Last edited by RageWorthy; 31/07/14 10:02 PM.
Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
Code:
alias top10 {
  if ($isfile(bank.txt)) { .remove bank.txt }
  window -h @all
  inc -u %top10_n
  var %i 1
  while $ini(bank.ini,%i) {
    aline @all $v1 $readini(bank.ini,$v1,bank)
    inc %i
  }
  filter -cetuwk 2 32 @all _top10
  window -c @all
  .play -l1 bank.txt 1
  .play -l2 bank.txt 1
  .play -l3 bank.txt 1
  .play -l4 bank.txt 1
  .play -l5 bank.txt 1
  .play -l6 bank.txt 1
  .play -l7 bank.txt 1
  .play -l8 bank.txt 1
  .play -l9 bank.txt 1
  .play -l10 bank.txt 1
}
alias -l _top10 {
  tokenize 32 $1
  write bank.txt %top10_n $1 $bytes($2,b)
  inc %top10_n
}


Output:

1 b 10,000
2 c 9,000
3 a 8
4 f 7
5 d 6
6 e 5
7 g 4
8 h 3
9 i 2
10 j 1

That was based on this following test file:

[a]
bank=8

[b]
bank=10000

[c]
bank=9000

[d]
bank=6

[e]
bank=5

[f]
bank=7

[g]
bank=4

[h]
bank=3

[i]
bank=2

[j]
bank=1

Joined: Jul 2014
Posts: 4
R
Self-satisified door
OP Offline
Self-satisified door
R
Joined: Jul 2014
Posts: 4
That is exactly what I wanted! Thank you very much for the help. Now, more important than getting it to work for me, is understanding how that works! I'll have to do more research.

Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
I only slightly adapted what you already had so I'll explain my changes.

Code:
if ($isfile(bank.txt)) { .remove bank.txt }


This will check if the file 'bank.txt' already exists and remove it if it does. This is so that the previously sorted top10 list is removed before the script runs.

Code:
inc -u %top10_n


This is a variable that keeps track of what number in the top 10 we're currently on. It is later increased by one each time the _top10 alias runs.

I used /inc -u to set a global variable that unsets itself rather than /var because this effectively creates a local variable, but it does not unset itself until after both the local scope and all of the aliases it calls have finished running. So it's like a wider local variable, if you know what I mean.

Code:
filter -cetuwk 2 32 @all _top10


This is no different to what you had before, except that rather than writing directly to the file, it passes the filtered content onto the /_top10 alias, which you can see below.

Code:
alias -l _top10 {
  tokenize 32 $1
  write bank.txt %top10_n $1 $bytes($2,b)
  inc %top10_n
}


This accepts the filtered content and writes it to the bank.txt file, along with the current top ten number (%top10_n) and it also uses $bytes(,b) to format the numbers from within the top10 list.

Hope that helps smile


Link Copied to Clipboard