mIRC Home    About    Download    Register    News    Help

Print Thread
#204683 27/09/08 11:47 PM
Joined: Sep 2007
Posts: 109
K
kwell Offline OP
Vogon poet
OP Offline
Vogon poet
K
Joined: Sep 2007
Posts: 109
I'm trying to create a ranking for a page. The idea is when a user gets a point, he'll receive a silver star. Once he obtains three silver stars, he'll get a bronze one and if he gets three bronze ones, he'll have a golden star. Up to here the code works perfectly but I need new ideas to search for other alternatives, if it's possible without %variables, maybe having the score in a file txt. There are a lot of users, for that reason I'll have lots of %variables. I'm also trying that the users with more golden stars remain above/at the top. I'm looking forward to your replies
Code:
alias ranking {
  inc $+(%,silver,.,$1)
  if $($+(%,silver,.,$1),2) > 3 { set $+(%,silver,.,$1) 1 | inc $+(%,bronze,.,$1) }
  if $($+(%,bronze,.,$1),2) > 3 { set $+(%,bronze,.,$1) 1 | inc $+(%,gold,.,$1) }
  if $read(ranking.html,s,$1) { write -dl $+ $readn ranking.html }
  write -il $+ $readn ranking.html $1 $iif($($+(%,gold,.,$1),2), $str(<img src="C14-027.jpg" width="15" height="12">,$($+(%,gold,.,$1),2))) $iif($($+(%,bronze,.,$1),2), $str(<img src="C14-029.jpg" width="15" height="12">,$($+(%,bronze,.,$1),2))) $str(<img src="C14-028.jpg" width="15" height="12">,$($+(%,silver,.,$1),2)) </br> 
}



Last edited by kwell; 28/09/08 12:11 AM.
kwell #204684 28/09/08 12:00 AM
Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
Silver, bronze then gold?

That's a first crazy

kwell #204713 29/09/08 02:40 AM
Joined: Sep 2007
Posts: 109
K
kwell Offline OP
Vogon poet
OP Offline
Vogon poet
K
Joined: Sep 2007
Posts: 109
is a good alternative?
Code:
alias ranking {
  if $read(ranking.html,s,$1) {
    var %silver = $calc($gettok($read(ranking.html,s,$1),1,32)+1)
    var %bronze = $gettok($read(ranking.html,s,$1),2,32)
    var %gold = $gettok($read(ranking.html,s,$1),3,32)
    if %silver > 3 { var %silver = 0 | var %bronze = $calc(%bronze + 1) }
    if %bronze > 3 { var %bronze = 0 | var %gold = $calc(%gold + 1) }
    write $+(-dl,$readn) ranking.html
    write $+(-il,$readn) ranking.html $1 $str(<img src="C14-027.jpg" width="15" height="12">,%gold) $str(<img src="C14-029.jpg" width="15" height="12">,%bronze) $str(<img src="C14-028.jpg" width="15" height="12">,%silver)
  }
  else { write ranking.html $1 1 0 0 }
  filter -ffcute 3-4 32 ranking.html ranking.html
}

kwell #204714 29/09/08 03:03 AM
Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
Since you're writing to the same line, why delete it, then insert it? Why not just over-write the line?
Also, it might be faster to read the line into a variable, then work with that variable rather than doing multiple reads.
Code:
alias ranking {
  var %rank = $read(ranking.html,s,$1), %silver = $gettok(%rank,1,32), %bronze = $gettok(%rank,2,32), %gold = $gettok(%rank,3,32)
  inc %silver
  if %silver > 3 {    var %silver | inc %bronze  }
  if %bronze > 3 {    var %bronze | inc %gold  }
  if %rank {
    write $+(l,$readn) ranking.html $1 $str(<img src="C14-027.jpg" width="15" height="12">,%gold) $str(<img src="C14-029.jpg" width="15" height="12">,%bronze) $str(<img src="C14-028.jpg" width="15" height="12">,%silver)
  }
  else { write ranking.html $1 1 0 0 }
  filter -ffcute 3-4 32 ranking.html ranking.html
}
 


Link Copied to Clipboard