mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Dec 2002
Posts: 271
N
Fjord artisan
OP Offline
Fjord artisan
N
Joined: Dec 2002
Posts: 271
hey, i have made a game, which stores the top 5 players bassed on scores, and the way i did it to set the top 5 works great, BUT, if i have X many players, then it wont set the top 5, because the variable is "set %whatever line too long"
This is the code, and what i am looking for is a better way to sort through the scroes, cause if i have 200 players, then the vars will be too long for sure, here is what i have:

Code:
alias settop5 {
  cplay -r top5
  var %a = $ini(inplay.ini,money,0), %b
  while (%a > 0) {
    %b = %b $cplay(money,$ini(inplay.ini,money,%a)) $+ $chr(44) $+ $ini(inplay.ini,money,%a)
    dec %a
  }
  %b = $gettok($sorttok(%b,32,nr),1-5,32)
  var %c = 0, %d = $numtok(%b,32)
  while (%c < %d) {
   inc %c
    cplay top5 $gettok($gettok(%b,%c,32),2,44) $gettok($gettok(%b,%c,32),1,44) 
  }
}
  


cplay sets in $1 param The $2 param as $3- in an ini file,
$cplay gets the data from the $1 param section, for $2

An example of a few entries in the inifile would be:

nightchillz=250
tim=125
frank=200
etc
.
An example Of What "%b" Would look like is:

250,nightchillz 200,frank 125,tim


those are in the section [money]

thanks in advance smile

Last edited by NightChillz; 23/12/02 08:50 PM.
Joined: Dec 2002
Posts: 1,922
O
Hoopy frood
Offline
Hoopy frood
O
Joined: Dec 2002
Posts: 1,922
I haven't had time to figure what exactly does $cplay do, but this code may help you anyway
Code:
alias top5 {
  ; Open a hidden sorted window. 
  window -hs @i
  var %i = 1, %a = 1, %top5

  ; Add this info to the window
  ; Each line looks like: <score> <name>
  while $ini(inplay.ini,money,%i) {
    aline @i $readini(inplay.ini,money,$ifmatch) $ifmatch
    inc %i
  }

  ; And retrieve the top 5 lines...
  while %a <=  5 && $line(@i,%a) {
    echo * Place %a - $gettok($ifmatch,2,32) with $gettok($ifmatch,1,32) points.
    inc %a
  }

  window -c @i
}

Joined: Dec 2002
Posts: 271
N
Fjord artisan
OP Offline
Fjord artisan
N
Joined: Dec 2002
Posts: 271
ok, lets say a person named Online sais "1points" in the room, so i wanna find out how many points you have:

//echo -a $nick has --> $cplay(money,$nick) Points

$cplay returns, in $1 parameter Section, In This Case It Would Read From The Ini File, In The [money] Section, For The Persons Nick, And Return What It Finds

Joined: Dec 2002
Posts: 271
N
Fjord artisan
OP Offline
Fjord artisan
N
Joined: Dec 2002
Posts: 271
hmm, iot doesnt seem to be sorting the window at all :S

i get what you mean by sorting it like that, i was thinking of something similar to that aswell, but now that i try it, it doest seem to sort the window, seems to just place them in the window the way they are read from the file smirk

Joined: Dec 2002
Posts: 271
N
Fjord artisan
OP Offline
Fjord artisan
N
Joined: Dec 2002
Posts: 271
ok, i see it is sorting it, but not the way i need it to, its sorting like this:

132
150
175
179
199
20
200
67
95

I need it to be sorted like:

200
199
175
132
99
65
13
5
etc

Last edited by NightChillz; 23/12/02 09:39 PM.
Joined: Dec 2002
Posts: 1,922
O
Hoopy frood
Offline
Hoopy frood
O
Joined: Dec 2002
Posts: 1,922
Oh, I see what you mean. -s treats numeric values as text, thus sorting them at first-letter basis.

A correct list of:

1
500
1000

Appears like:

1
1000
500

it first lists all 1's, then 5's.

I used the /filter command instead, using the -a switch that lets you call an external sorting alias (/sort).
Code:
alias top5 {
  window -h @i
  var %i = 1, %a = 1, %top5

  while $ini(inplay.ini,money,%i) {
    aline @i $readini(inplay.ini,money,$ifmatch) $ifmatch
    inc %i
  }

  ; Sorting the window by calling the /filter command
  filter -awwc @i @i sort

  while %a <=  5 && $line(@i,%a) {
    echo * Place %a - $gettok($ifmatch,2,32) with $gettok($ifmatch,1,32) points.
    inc %a
  }

  window -c @i
}
alias sort if $sorttok($1 $+ . $+ $2,46,nr) == $1 $+ . $+ $2 { return -1 } | else { return 1 }

Last edited by Online; 23/12/02 10:07 PM.
Joined: Dec 2002
Posts: 271
N
Fjord artisan
OP Offline
Fjord artisan
N
Joined: Dec 2002
Posts: 271
ok great thanks, that works, guess i'll have to take a closer look at /filter in the help file :P

Joined: Dec 2002
Posts: 1,922
O
Hoopy frood
Offline
Hoopy frood
O
Joined: Dec 2002
Posts: 1,922
Yes, probably. it's a rather complicated command. By the way, maybe you can figure out why didn't the -u (numeric sort) switch work for me (no idea, gotta check it one day) smirk


Link Copied to Clipboard