mIRC Home    About    Download    Register    News    Help

Print Thread
#64953 23/12/03 05:43 AM
Joined: Jan 2003
Posts: 3,012
Hoopy frood
OP Offline
Hoopy frood
Joined: Jan 2003
Posts: 3,012
Rather than go on about how needed this addition is, or even explain how it should work, im going to paste an alias i've made that does exactly as I want it to do. I'm sorry for the legnth, but its fairly short, just the comments make it extended. Many of the people who know how to script are going to say "you don't nee dcommands for such a simple thing" but Its not as much for me, as for those who read it and trying to learn. I comment not for me, but for those who look at what i've done and try to elarn from it.

Anyways, this (i think) is better shown grin

Code:
; new mode identifier
; by kingtomato
; -
; usage:
;  after using $mode for so long, and trying to match up the letter
;  with the appropriate $mode(N), I got tired of it. So I write a
;  lil snipplet that does just that.  The way it works is just like
;  $mode when no properties are attached. When they are attached, it
;  can return the character of mode N, or its associated parameter.
;  i.e. a ban will return b for its character, and the nick/mask
;  thats being banned for its parameter.  Here's the break down:
;
; syntax:
;  $modes(N)
;    Gets the Nth mode
;  Properties:
;    .chr  - Gets the mode character associated with the mode
;            This will return ONLY the letter (ex: o)
;    .sign - returns the sign of the mode change (ex: +)
;    .mode - returns the mode being set (ex: +o
;
;  syntax 2:
;    /modes <modes>
;    modes - the current mode string being set.  Because this is a
;            custom identifier, I have no means of having it be
;            'auto called' with the mode change. What you have to do
;            is call this before using the variable. Much like a dialog
;            dll such as mdx, you have to 'set' the modes we're going
;            to be parsing before you can use them.
;            
;  So for example, something like a mode change of:
;    +ovp KingTomato KingTomato
;  would return:
;
;  $modes(1)       = KingTomato (Like Normal)
;  $modes(1).chr   = o
;  $modes(1).sign  = +
;  $modes(1).mode  = +o
;
;  $modes(2)       = KingTomato (Again, normal)
;  $modes(1).chr   = v
;  $modes(1).sign  = +
;  $modes(1).mode  = +v
;
;  $modes(3)       = $null
;  $modes(3).chr   = p
;  $modes(1).sign  = +
;  $modes(1).mode  = +p

alias modes {
  ; if it if being used as an identifier ($modes)
  if ($isid) {
    ; set a variable that's easy to work with
    var %modes = %unique_modes_var      | ; variable we are parsing
    var %mode  = $gettok(%modes, 1, 32) | ; just the +this-that part

    ; here we loop through each letter of the mode change. When we find
    ; one that has params that should be associated to it, we put both
    ; the letter, and the parameter together seperated by a colon.  If
    ; a colon should conflict, then please change the variable below to
    ; another char.
    var %param   = 2 | ; Starting gettok value for associations
    var %letter  = 1 | ; letter number we're lookin at in %mode
    var %modeNum = 1 | ; numeric count of the current mode (compared to $1)
    var %delim   = : | ; this is what will seperate the letter from the param

    ; begin to loop through the %mode value
    while ($mid(%modes, %letter, 1)) {
      ; easier to deal with
      var %chr = $ifmatch

      ; check for a mode sign (+/-)
      if (%chr isin +-) var %sign = %chr
      ; not a sign, its a letter
      else {
        ; check for a letter that has a paramter with it
        if ((%chr isincs $gettok($chanmodes, 1-3, 44)) || (%chr isincs qaohv)) {
          ; this has a mode, now we get the parameter that corrisponds to it
          var %curMode = $+(%sign,%chr,$chr(%delim),$gettok(%modes, %param, 32))
          ; add it to the list of modes
          var %modeList = %modeList %curMode

          ; we used a param, increase the coutner
          /inc %param
        }
        ; its jsut a letter mode (like +s, +p, etc)
        else var %modeList = %modeList $+(%sign,%chr)

        ; check if this is a mode the user is requesting
        if ($1 == %modeNum) {
          ; do they want the chr, or its mode
          if ($prop == chr) return %chr
          else if ($prop == sign) return %sign
          else if ($prop == mode) return $+(%sign,%chr)
          else return $mid(%curMode, 3)
        }

        ; moving onto next mode, increase count
        /inc %modeNum
      }

      ; goto next letter
      /inc %letter
    }

    ; 0 as a mode, for total count
    if ($1 == 0) return %curMode

    ; default
    return $null
  }

  ; being used as a command
  else {
    ; I'd use some var like %modes, but i don't want it to interfere
    ; with other's scripts. I'm also using /set because we're not parsing
    ; what's being passed, just setting it into somethign we can deal with
    ; when the time comes
    /set -u0 %unique_modes_var $1-
  }
}


-KingTomato
#64954 23/12/03 05:55 AM
Joined: Jan 2003
Posts: 3,012
Hoopy frood
OP Offline
Hoopy frood
Joined: Jan 2003
Posts: 3,012
Im sorry for another post, but this is just some example code you can see what i mean. Sorry for another alias, and another one by me no less, but it helps with organizing >:D The comments on this alias are again here for tohers, not just to advertise my code >:D

Code:
; -------------------------------------------------------------------------------------------------
; $pad(string, width, align)
; width is assumed left if unspecified, otherwise use left,right,center
;
; exaple:
;  /echo -a $pad(Name, 16, center) $pad(Mail, 32, center) $pad(url, 50, center)
;  /echo -a $pad(KingTomato, 16) $pad(kingtomato@kingtomato.com, 32) $pad(www.kingtomato.com, 50)
; -------------------------------------------------------------------------------------------------
alias pad {
  if ($2 <= $len($1)) return $1
  if ($3 == right) return $+($str($chr(160),$calc($2 - $len($1))), $1)
  else if ($3 == center) {
    var %left = $int($calc(($2 - $len($1)) / 2))
    return $+($str($chr(160),%left), $1, $str($chr(160),$calc(($2 - $len($1)) - %left)))
  }
  return $+($1, $str($chr(160),$calc($2 - $len($1))))
}
; eof
; -------------------------------------------------------------------------------------------------

; demo code
on *:RAWMODE:#: {
  ; give the alias something tow rok with
  /modes $1-

  /echo $chan Modes we're dealing with:
  /echo $chan $pad($chr(35), 5) $pad(chr, 5) $pad(sign, 5) $pad(mode, 5) param
  ; loop through em
  var %m = 1
  while ($modes(%m).chr) {
    /echo $chan $pad(%m, 5) $pad($modes(%m).chr, 5) $pad($modes(%m).sign, 5) $pad($modes(%m).mode, 5) $modes(%m)
    /inc %m
  }
}

output looks kinda like:
Code:
[00:53:10] * ChanServ sets mode: +ntrq KingTomato
Modes we're dealing with:
#     chr   sign  mode  param
1     n     +     +n   
2     t     +     +t   
3     r     +     +r   
4     q     +     +q    KingTomato


-KingTomato

Link Copied to Clipboard