Difference between revisions of "$comchan"

From Scriptwiki
Jump to: navigation, search
m (wiki link incorrect)
m (Added support for no param to comchans alias)
Line 19: Line 19:
 
This example will return all comchans you have with someone:
 
This example will return all comchans you have with someone:
 
  ; begin a new alias, we want to have something like $comchans(<nick>).
 
  ; begin a new alias, we want to have something like $comchans(<nick>).
 +
; If calling from inside an event, $comchans would return for $nick
 
  [[alias]] comchans {
 
  [[alias]] comchans {
   [[var]] %i = 1, %comchans
+
  ;Check to see if nick was given, if not yet $nick is present, use that.
 +
  [[if]] (!$1) && ([[$nick]]) [[tokenize]] 32 $nick
 +
  ;If no $nick present and no nick given, return false.
 +
  [[elseif]] (!$1) [[return]] [[$false]]
 +
   [[var]] %i = $comchan($1,0), %comchans
 
   ; begin to loop through all comchans
 
   ; begin to loop through all comchans
   [[while]] (%i <= $comchan($1, 0)) {
+
   ; and set %comchans to all common channels, seperated by space (ascii 32)
    ; set %comchans to all common channels, seperated by space (ascii 32)
+
  [[while]] (%i) var %comchans = [[$addtok]](%comchans,$comchan($1,%i),32), %i = %i - 1
    %comchans = [[$addtok]](%comchans, $comchan($1,%i),32)
+
   ; return %comchans if set, if null return $false
    ; increase looping-variable
+
   return [[$iif]](%comchans,%comchans,$false)
    [[inc]] %i
 
  }
 
   ; return %comchans
 
   [[return]] %comchans
 
 
  }
 
  }
  

Revision as of 01:02, 5 November 2006

Returns the names of channels which both you and nick are on.

$comchan(nick,N)


$comchan can have the following properties:

Property Meaning
op returns $true if you're an op on the channel
help returns $true if you have help on the channel
voice returns $true if you have voice on the channel


Example

This example will return all comchans you have with someone:

; begin a new alias, we want to have something like $comchans(<nick>).
; If calling from inside an event, $comchans would return for $nick
alias comchans {
  ;Check to see if nick was given, if not yet $nick is present, use that.
  if (!$1) && ($nick) tokenize 32 $nick
  ;If no $nick present and no nick given, return false.
  elseif (!$1) return $false
  var %i = $comchan($1,0), %comchans
  ; begin to loop through all comchans
  ; and set %comchans to all common channels, seperated by space (ascii 32)
  while (%i) var %comchans = $addtok(%comchans,$comchan($1,%i),32), %i = %i - 1
  ; return %comchans if set, if null return $false
  return $iif(%comchans,%comchans,$false)
}

Note

You should note when using $comchan within the on nick event the IAL has already updated so you must use $newnick not $nick. Here is an example:

; Trigger when someone changes their nick.
on ^*:nick: {
  ; Set %i to the total amount of common channels you and the person changing their nick have in common.
  var %i = $comchan($newnick,0)
  while (%i) {
    ; echo with the color of a nick change to the %i'th common channel the message reguarding the nick change.
    echo $color(nick) -t $comchan($newnick,%i) * $nick changed their nickname to $newnick
    ; Decrease the value of %i so we don't message the same channel twice.
    dec %i
  }
  ; halt the mIRC default action for this event. (must use the ^ prefix with the event for this to work.)
  haltdef
}

See Also

To get all the channels you are in, look at $chan.