mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Dec 2002
Posts: 174
P
Vogon poet
OP Offline
Vogon poet
P
Joined: Dec 2002
Posts: 174
how would i make a remote to pull the top 3 results from a text file from this format

OuTsIdErS 3
Joshey 2
Mamamia 3
Jonboi 15

how would i do a remote to have it read and list the top 3 of these to tell you who and what the top 3 scores where?

any ideas?

Joined: Dec 2002
Posts: 580
N
Fjord artisan
Offline
Fjord artisan
N
Joined: Dec 2002
Posts: 580
He is how I would do it with hash tables...

Code:
alias top3 {
  var %N1 | var %N2 | var %N3
  var %Index 1 | var %Nick | var %Data

  ; Make hashtable
  hadd -m hashfind OuTsIdErS 3
  hadd hashfind Joshey 8
  hadd hashfind Bo 2
  hadd hashfind Moe 12
  hadd hashfind Hoe 11
  hadd hashfind Pimp 9
  hadd hashfind Mamamia 3
  hadd hashfind Jonboi 15

  ; Find Top 3
  set %Nick $hfind(hashfind, *, %Index, w)
  while (%Nick != $null) || (%Index == 1) {
    set %Data $hget(hashfind, %Nick)
    if (%N1 == $null) { set %N1 %Nick %Data }
    else {
      if (%N2 == $null) {
        if ($num(%N1) < %Data) { set %N2 %N1 | set %N1 %Nick %Data }
        else { set %N2 %Nick %Data }
      }
      else {
        if (%N3 == $null) {
          if ($num(%N1) < %Data) { set %N3 %N2 | set %N2 %N1 | set %N1 %Nick %Data }
          else if ($num(%N2) < %Data) { set %N3 %N2 | set %N2 %Nick %Data }
          else { set %N3 %Nick %Data }
        }
        else {
          if ($num(%N1) < %Data) { set %N3 %N2 | set %N2 %N1 | set %N1 %Nick %Data }
          else if ($num(%N2) < %Data) { set %N3 %N2 | set %N2 %Nick %Data }
          else if ($num(%N3) < %Data) { set %N3 %Nick %Data }
        }
      }
    }
    inc %Index | set %Nick $hfind(hashfind, *, %Index, w)
  }
  ; Display Results
  echo -a 1st Place went to $gettok(%N1, 1, 32) with a score of $gettok(%N1, 2, 32)
  echo -a 2nd Place went to $gettok(%N2, 1, 32) with a score of $gettok(%N2, 2, 32)
  echo -a 3rd Place went to $gettok(%N3, 1, 32) with a score of $gettok(%N3, 2, 32)
  .hfree hashfind
}
alias num { return $gettok($1, 2, 32) }

Last edited by NaquadaServ; 26/12/02 05:37 PM.

NaquadaBomb
www.mirc-dll.com
Joined: Dec 2002
Posts: 144
D
Vogon poet
Offline
Vogon poet
D
Joined: Dec 2002
Posts: 144
Something along the lines of ...

Code:
On *:TEXT:!topresults:#:{
  if ($lines(results.txt) >= 3) {
    var %i = 1
    while (%i <= 3) {
      msg # Number %i $+ : $gettok($read(results.txt,%i),1,32) with a score of $gettok($read(results.txt,%i),2,32)
      inc %i
    }
  }
}


"Any sufficiently advanced technology is indistinguishable from magic." - Arthur C. Clarke
Joined: Dec 2002
Posts: 174
P
Vogon poet
OP Offline
Vogon poet
P
Joined: Dec 2002
Posts: 174
thats how i got the code to start for the game,
how would i get what you put in to work for that?

thanks for your ehlp

on *:text:Ms_7-11 guess*:#Praise-Him: {
if ($3 == %guessnum1) {
msg $chan 1,8 $nick Got The Right Number It Was %guessnum1 $+ !!!!! ( $+ $nick has won, $read(text.txt, s, $nick) times!
set %variables $read(text.txt, s, $nick)
write -ds $+ $nick text.txt
write text.txt $nick $calc(%variables + 1)
}
if ($3 < %guessnum1) {
msg $chan 2,13Sorry $nick The Number Is Higher Than $3
halt
}
if ($3 > %guessnum1) {
msg $chan 6,15Sorry $nick The Number Is Lower Than $3
halt
}
}
on 100:text:Ms_7-11 Stop Guess Game:#Praise-Him:/unset %guessnum1 | /msg #Praise-Him 3,11The Guess Game Is Over!

}

Joined: Dec 2002
Posts: 699
N
Fjord artisan
Offline
Fjord artisan
N
Joined: Dec 2002
Posts: 699
Here's two ways to go about it

Will result in the top 3 scores being sent...
Code:
alias top3 {
  filter -cfftue 2 32 file.txt file.txt *
  msg #Praise-Him The top three are
  var %i = 1
  while (%i &lt;= 3) {
    if ($read(file.txt,%i)) {
      tokenize 32 $ifmatch
      msg #Praise-Him * $+($ord(%i),:)  $1 with $2 wins
      inc %i
    }
  }
}

Or you could use this to 'grab' the top <any-number> scores...
Code:
; Usage /top N
alias top {
  if ($1 !isnum) echo -a * Usage /top Number
  var %i = 1,%a = $$1
  window -c @top@ | window -h @top@
  filter -cfwtue 2 32 text.txt @top@ *
  msg #Praise-Him The top %a are
  while (%i &lt;= %a) &amp;&amp; ($line(@top@,%i)) {
    tokenize 32 $ifmatch
    msg #Praise-Him * $+($ord(%i),:) $1 with $2 wins
   inc %i
  }
  window -c @top@
}

Joined: Dec 2002
Posts: 174
P
Vogon poet
OP Offline
Vogon poet
P
Joined: Dec 2002
Posts: 174
* /filter: unable to open 'C:\MS711\file.txt' (line 2, script.mrc)

i did your first suggestion
alias top3 {
filter -cfftue 2 32 file.txt file.txt *
msg #Praise-Him The top three are
var %i = 1
while (%i <= 3) {
if ($read(file.txt,%i)) {
tokenize 32 $ifmatch
msg #Praise-Him * $+($ord(%i),:) $1 with $2 wins
inc %i
}
}
}

and that was the error msg
ive never worked with filter, and apreciate any help you could give


Joined: Dec 2002
Posts: 699
N
Fjord artisan
Offline
Fjord artisan
N
Joined: Dec 2002
Posts: 699
Change all the occurences of [color:blue]"file.txt"[color:black] to the filename you're writing the scores to smile

--edit--
I had assumed "text.txt" was not the actual filename laugh
Code:
alias top3 {
  filter -cfftue 2 32 text.txt text.txt *
  msg #Praise-Him The top three are
  var %i = 1
  while (%i &lt;= 3) {
    if ($read(text.txt,%i)) {
      tokenize 32 $ifmatch
      msg #Praise-Him * $+($ord(%i),:) $1 with $2 wins
      inc %i
    }
  }
}

Last edited by Nimue; 27/12/02 01:30 AM.
Joined: Dec 2002
Posts: 174
P
Vogon poet
OP Offline
Vogon poet
P
Joined: Dec 2002
Posts: 174
works perfect,
sorry fbout that i should have figured that out

God bless


Link Copied to Clipboard