Ranking and sorting variables - 08/12/14 10:53 PM
Hi, I have a script for looking up a player's decks in a card game. Using the example /modern gainsay, the output looks like this:
gainsay's latest decks: 2014-10-21 < Cuneo UW > 2014-02-27 < Birthing Pod > 2014-01-25 < Birthing Pod > 2014-01-21 < Birthing Pod > 2014-01-08 < Cruel Control > 2014-01-04 < Cruel Control > 2014-01-01 < Cruel Control >
This has all the info I want, but it is a bit messy. I'd like to compile the info and make it look something like this instead:
gainsay's 3 most played decks: Birthing Pod (3/7), Cruel Control (3/7), Cuneo UW (1/7)
Latest deck: 2014-10-21 - Cuneo UW
I'm guessing it involves making dynamic variables for %mtg_deck, counting the number of occurences for each unique deck and then ranking them, but I'm not really sure how to do this. Thanks in advance for any help
This is the script
gainsay's latest decks: 2014-10-21 < Cuneo UW > 2014-02-27 < Birthing Pod > 2014-01-25 < Birthing Pod > 2014-01-21 < Birthing Pod > 2014-01-08 < Cruel Control > 2014-01-04 < Cruel Control > 2014-01-01 < Cruel Control >
This has all the info I want, but it is a bit messy. I'd like to compile the info and make it look something like this instead:
gainsay's 3 most played decks: Birthing Pod (3/7), Cruel Control (3/7), Cuneo UW (1/7)
Latest deck: 2014-10-21 - Cuneo UW
I'm guessing it involves making dynamic variables for %mtg_deck, counting the number of occurences for each unique deck and then ranking them, but I'm not really sure how to do this. Thanks in advance for any help
This is the script
Code:
alias modern { var %sock = modern. $+ $ticks sockopen %sock www.mtggoldfish.com 80 sockmark %sock $1 set %player $1- } on *:SOCKOPEN:modern.*:{ if $sockerr { return } sockwrite -n $sockname GET /player/ $+ %player HTTP/1.1 sockwrite -n $sockname Host: $sock($sockname).addr sockwrite -n $sockname $crlf } on *:SOCKREAD:modern.*:{ if $sockerr { return } var %data | sockread %data while $sockbr { if ($regex(%data,/<td>([0-9]{4}-[0-9]{2}-[0-9]{2})<\/td>/)) { set %mtg_date $regml(1) } else if ($regex(%data,/<a href="\/tournament\/.*?">(Modern .*?)<\/a>/)) { set %mtg_daily $gettok($regml(1),1-2,32) } else if (%mtg_daily && $regex(%data,/<td><a href="\/deck\/[0-9]*">(.*?)</a></td>/)) { set %mtg_deck $regml(1) set %mtg_string $addtok(%mtg_string, %mtg_date < %mtg_deck > ,32) unset %mtg_daily unset %mtg_deck unset %mtg_date } else if (<p class='layout-copyright-notice'> isin %data) { if (%mtg_string = $null) { echo -ag Error / No decks found. sockclose $sockname return } else echo -ag %player $+ 's latest decks: %mtg_string sockclose $sockname unset %mtg_* return } sockread %data } }