Misc Functions

Contributed by dohcan
I know this isn't a tutorial where I teach about a certain thing, but this is a little too big to be a code snippet, so I decided to make it a tutorial. Most of these functions are just shortcuts to other functions, but they are grouped in a way that they are easy to remember, and their function is more apparent than the function(s) they wrap to. A few do add functionality, so enjoy. These functions have been tested and used on mIRC v5.71.
Math Functions
Here are a few extra math functions that aren't currently in mIRC

$math.floor(N)
Returns the next lowest integer of N, where N is a floating point number
$math.floor(3) = 3
$math.floor(3.5) = 3
$math.floor(3.9) = 3
$math.ceil(N)
Returns the next highest integer of N, where N is a floating point number
$math.ceil(3) = 3
$math.ceil(3.5) = 4
$math.ceil(3.9) = 4
$math.round(N, [P])
Rounds N with optional P precision. If P is 0, it will round all halves (0.5) up, unlike $round
$math.round(3.5) = 4
$math.round(3.5, 0) = 4
$math.round(2.5, 0) = 3
$math.round(2.131, 2) = 2.13
$math.pi
Returns PI to 11 decimal places; NOTE: You can use more than 5 decimal places inside of $calc() to get more precision, but mIRC will only make a result with 5 decimal places.


$math.max(N1, N2)
Returns the higher number of the pair
$math.max(10, 13) = 13
$math.max(13, 8) = 13
$math.min(N1, N2)
Returns the lower number of the pair
$math.min(10, 13) = 10
$math.min(13, 8) = 8
$math.avg(N1, N2, N3, ..., N)
Returns the average of the sum of the numbers, with any number of parameters allowed
$math.avg(3, 3, 6) = 4
$math.avg(5, 25) = 15
$math.percent(N, D, [P])
Returns the percentage of N from D, with optional P precision; NOTE: requires $math.round
$math.percent(50, 100) = 50
$math.percent(50, 100, 1) = 50.0
$math.percent(50, 105, 1) = 47.6
math.floor return $iif($int($1) == $1, $1, $int($1))
math.ceil return $iif($int($1) == $1, $1, $calc($int($1) + 1))
math.round return $iif(($calc($1 % 1) == 0.5) && ($iif($2, $2, 0) == 0), $calc($int($1) + 1), $round($1, $iif($2, $2, 0)))
math.pi return 3.14159265358
math.max return $iif($1 > $2, $1, $2)
math.min return $iif($1 < $2, $1, $2)
math.avg {
  var %i = 1
  var %t = 0
  while (%i <= $0) {
    inc %t $ [ $+ [ %i ] ]
    inc %i
  }
  return $calc(%t / $0)
}
math.percent return $math.round($calc($1 / $2 * 100), $iif($3, $3, 0))
String Functions
All of these functions handle strings broken up with spaces, or "words", with the only exception being $str.concat, which takes all types of strings.

$str.index(S, N)
Returns the Nth word in the string S; 0 for N returns the number of words
$str.index(this is a sentence, 2) = is
$str.count(S)
Returns the number of words in the string S
$str.count(this is a sentence) = 4
$str.range(S, offset, [count])
Returns count words starting from offset; If count is left out, it returns the rest of the string
$str.range(this is a sentence, 2) = is a sentence
$str.range(this is a sentence, 2, 2) = is a
$str.delete(S, offset, [count])
Deletes count words start from offset; If count is left out, it only deletes one word
$str.delete(this is a sentence, 2) = this a sentence
$str.delete(this is a sentence, 2, 2) = this sentence
$str.insert(S, W, P)
Inserts word W into string S at position P
$str.insert(this a sentence, is, 2) = this is a sentence
$str.over(S, W, P)
Overwrites the Pth word in string S with word W
$str.over(this at a sentence, is, 2) = this is a sentence
$str.concat(glue, S1, S2, S3, ..., S)
Concatenates all S paramenters with phrase glue; NOTE: this does not have to be words, it can work with anything
$str.concat($chr(32), this, is, a, sentence) = this is a sentence
$str.concat(!, one, two, three) = one!two!three
$str.concat(., one two, three) = one two.three
str.index return $gettok($1, $2, 32)
str.count return $numtok($1-, 32)
str.range {
  var %s = $2 $+ - $+ $calc($2 + $3 - 1)
  return $gettok($1, %s, 32)
}
str.delete {
  var %s = $2 $+ - $+ $calc($2 + $3 - 1) $+ -
  return $deltok($1, %s, 32)
}
str.insert return $instok($1, $2, $3, 32)
str.over return $puttok($1, $2, $3, 32)
str.concat {
  var %i = 2
  var %result
  while (%i <= $0) {
    if (%i == 2) %result = $2
    else %result = %result $+ $1 $+ $ [ $+ [ %i ] ]
    inc %i
  }
  return %result
}
Mass Popup Commands
These commands allow you to select any number of people and op, deop, etc.. to them. It uses a central command (/mass.modes) with parameters.

/mass.modes <sign> <mode>
Performs a mass mode on the selected nicknames in a channel; Sign must be positive or negative and mode can be o, h, v or any other modes that are added later
/mass.modes + o = ops everyone you have selected
/mass.modes - v = devoices every you have selected
mass.op mass.modes + o
mass.deop mass.modes - o
mass.voice mass.modes + v
mass.devoice mass.modes - v
mass.help mass.modes + h
mass.dehelp mass.modes - h
mass.modes {
  var %sign = $1, %mode = $2 
  var %n, %i, %num, %mod, %nicks = $numtok($snicks, 44)
  %num = $int($calc(%nicks / 6))
  %mod = $int($calc(%nicks % 6))
  %i = 1
  while (%i <= %num) {
    %n = $calc(((%i - 1) * 6) + 1)
    %n = %n $+ - $+ $calc(%n + 5)
    mode # %sign $+ $str(%mode, 6) $replace($gettok($snicks, %n, 44), $chr(44), $chr(32))
    inc %i
  }
  if (%mod) {
    %n = $calc(%num * 6 + 1) 
    %n = %n $+ - $+ $calc(%n + %mod - 1)
    mode # %sign $+ $str(%mode, %mod) $replace($gettok($snicks, %n, 44), $chr(44), $chr(32))
  }
}
All content is copyright by mircscripts.org and cannot be used without permission. For more details, click here.