Highscores

By owl on Mar 07, 2010

This is a highscores system that saves all your values, orders them into a highscores and returns what you want with the rank etc

Everything is commented and how to use it is at the top

Have fun :]

(this one is long for those that wanted it long ;])

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;  Owls Highscore System, hewt o.O  ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;  Using and ini file and @windows

;  To add a nick to the highscores with a set value of 'coins'

;  /highscores -a nick coins
;  To increase the nicks amount of 'coins'
;  /highscores -i nick coins

;  To decrease the nicks amount of 'coins'
;  /highscores -d nick coins

;  To search the highscores use $hs

;  $highscores(nick)  returns their 'rank'
;  $highscores(4)     returns 'nick=coins'
;  $highscores(3-7)   returns 'rank3 rank4 rank5 etc..'
;  $highscores(3,7,8) returns 'rank3 rank7 rank8'

alias highscores {
  ;set the filename
  var %file highscores.ini

  ;set the section that holds all the nicks
  var %section money

  ;if there is no file or section
  if (!$ini(%file,%section)) {

    ;create the file and section
    writeini -n %file %section start 0

    ;delete the entry
    remini %file %section start
  }

  ;if the window '@hs' is not currently open
  if (!$window(@hs)) { 

    ;open it
    window @hs

    ;load the contents of the section in the ini file
    loadbuf -t $+ %section @hs %file

    ;order it into ranks and order :]
    filter -wwctue 2 61 @hs @hs *=*
  }

  ;if the function is called using $hs and not /hs
  if ($isid) {

    ;if $1 is a nick
    if ($left($1,1) !isnum) {

      ;return the line number that nick is on
      return $iif($fline(@hs,$1 $+ =*),$ord($v1),0)
    }

    ;if just a rank is supplied
    else if ($1- isnum) {

      ;return the name=coins and mask it (mask is at the bottom)
      return $hsmask($line(@hs,$1))
    }

    ;if say 2-6 is supplied and there is not a $2
    else if ($regex($1,/[0-9]-[0-9]/)) && (!$2) {

      ;make sure the number of ranks isnt too long
      if ($calc($gettok($1,2,45) - $gettok($1,1,45)) > 7) {
        return Too many nicks, please try a smaller range.
      }
      else {

        ;get either side of the -
        var %x $1, %s $gettok(%x,1,45), %e $gettok(%x,2,45)
        while (%s <= %e) {

          ;add in each rank and mask it
          var %o %o $ord(%s) $hsmask($line(@hs,%s))
          inc %s 
        }

        ;return all the ranks
        return %o 
      }
    }

    ;if multiple ranks are supplied eg, $hs(1,3,7,2,10)
    else if ($2) {

      ;order the ranks and delete repeats
      tokenize 32 $sorttok($regsubex($1-, /(\d)(?=.*\1)/g, $null),32)

      ;make sure that the number of ranks isnt too long
      if ($0 <= 8) {
        var %x 1, %tok

        ;while there are ranks to be done
        while (%x <= $0) {

          ;get the rank number
          var %tok $gettok($1-,%x,32)

          ;add the rank into the message aswell as the nick
          var %o %o $ord(%tok) $hsmask($line(@hs,%tok))
          inc %x
        }

        ;return all the ranks
        return %o
      }
    }
    else {
      return Too many nicks, please try a smaller range.
    }
  }

  ;else if it is trigger by /hs and not $hs
  else {

    ;if $1 is -i
    if ($1 == -i) {

      ;increase the nicks coins
      writeini -n %file %section $2 $calc($readini(%file,%section,$2) + $iif($3,$3,1))

      ;remove the nick from the highscores
      filter -xc @hs @hs $2 $+ =*

      ;add the nick back into the highscores with his new amount of coins
      aline @hs $2 $+ = $+ $readini(%file,%section,$2)

      ;sort the highscores into order and ranks
      filter -wwctue 2 61 @hs @hs *=*
    }

    ;if $1 is -d
    else if ($1 == -d) {

      ;decrease the nicks amount of coins, if it falls below 0 set it to 0
      writeini -n %file %section $2 $iif($calc($readini(%file,%section,$2) - $iif($3,$3,1)) < 0,0,$v1)

      ;take the nick out of the highscores
      filter -xc @hs @hs $2 $+ =*

      ;add the nick back into the highscores with their new amount of coins
      aline @hs $2 $+ = $+ $readini(%file,%section,$2)

      ;sort the highscores in order and ranks
      filter -wwctue 2 61 @hs @hs *=*

    }
    else if ($1 == -a) {

      ;set the nicks amount of coins to $3
      writeini -n %file %section $2 $3

      ;take the nick out of the highscores
      filter -xc @hs @hs $2 $+ =*

      ;add the nick back into the highscores with their new amount of coins
      aline @hs $2 $+ = $+ $readini(%file,%section,$2)

      ;sort the highscores in order and ranks
      filter -wwctue 2 61 @hs @hs *=*

    }

    else {

      ;echo an error if neither -d or -i are present
      echo 2 -sg * /hs: insufficient parameters (need either -d or -i)
    }
  }
}

;The mask so you can colour your output
alias hsmask {
;if there is nick=215
  if (= isin $1-) {
  ;return the input with the $shortgp alias, making the number more readable
  ;You can also colour it here and remove $shortgp to what you want
    return $+($gettok($1,1,61),=,$shortgp($gettok($1,2,61)))
  }
  else {
  ;if it is just a number, return it in shortgp format
    return $shortgp($1)
  }
}

;shortgp alias
alias shortgp { 

;if the input is a number
  if ($remove($$1,$chr(44)) isnum) { 

  ;get the number of commas
    var %a = $numtok($bytes($v1,b),44),%b = $bytes($v1,b) 

    ;return the number in a short gp format eg: 26.07k or 13.32b
    return $+($gettok(%b,1,44),$iif(%a != 1,.),$iif($mid($gettok(%b,2,44),1,2) == 0,0,$v1),$replace(%a,1,$null,2,k,3,m,4,b,5,t)) 
  } 
}

Comments

Sign in to comment.
Snip3KitTy   -  Mar 07, 2010

this will work fine on everywherechat.com but may fail on other servers, as Anspdoijs has already stated :-)

 Respond  
Anspdoijs   -  Mar 07, 2010

On some servers "/hs" is a shortcut for HostServ, so you may want to change that

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.