When replacing default text like this (which is often done by crypto scripts and skinning scripts, among others):

Code:
on *:TEXT:*:*:echo $target $myfilter($1-) | haltdef

One of the most challenging tasks is writing all the code necessary to 100% honor mIRC's numerous text "routing" and "decoration" options:

* Events in Channel|Status|Both|Hide (global)
* Events in Channel|Status|Both|Hide (window-specific)
* Show in active CTCPs|Invites|Notices|Queries
* Use single message window
* Use query for notify nicks
* Prefix own messages
* Show mode prefix
* Short joins and parts
* User addresses
* etc.

It is especially difficult to write that code because you must figure out how each of those options overrule (or are overruled by) the rest.

To illustrate what I mean by "difficult," here is what I had to write just to have an ACTION event that does $myfilter($1-) but which doesn't simultaneously break all of mIRC's user settings:

Code:
    alias -l morestuff {
      var %c = $iif($cnick($2) != 0 && $cnick($2).method < 2,$&
        $base($cnick($2).color,10,10,2))
      return $iif(!$1,* $+ $chr(32)) $+ $iif(($1) && (%c) && ($3 == < >),$chr(3) $&
        $+ %c) $+ $iif($1,$gettok($3,1,32)) $+ $iif((%c) && (((!$1) && (!$4)) || $&
        (($1) && ($3 == * *))),$chr(3) $+ %c) $+ $2 $+ $iif((%c) && $&
        (((!$1) && (!$4)) || (($1) && ($3 == * *))),$chr(15)) $+ $&
        $iif($1,$gettok($3,2,32)) $+ $iif(($1) && (%c) && ($3 == < >),$chr(15))
    }
    on ^*:ACTION:*:*:{
      if ($left($gettok($rawmsg,3,32),1) != $) && (!$halted) {
        var %t = $iif(!$chan,$nick,$chan)
        var %s = $myfilter($left($gettok($rawmsg,5,32),-1))
        var %b = < >
        if (!$chan) {
          saveini
          var %d = $iif($gettok($readini($mircini,n,options,n0),22,44) == 1,$true)
          var %q = $iif($gettok($readini($mircini,n,options,n4),5,44) == 1,$true)
          if (%d) && (!$query($nick)) && (!$window(Message Window)) dqwindow show
          if ((%d) && (!$query($nick))) || $&
            ((%q) && ($active ischan) && (!$query($nick))) var %b = * *
        }
        var %g = $iif(%d && !$query($nick),$true)
        var %n = $iif(($gettok($readini($mircini,n,options,n7),11,44) == 1) && $&
          ($notify($nick)) && (($notify($nick).network == $network) || $&
          ($notify($nick).network == $server) || $&
          ($notify($nick).network == $null)),$true)
        echo $+(-bcfilmrt,$iif(!$query($nick),$iif(%d && !%n,d,$iif(%q && $active ischan,a)))) $&
          $iif((!%d || %n) && %q && $active ischan && !$query($nick),notice,action) $&
          $iif((!%d || $query($nick)) && (!%q || $active !ischan || $query($nick)),%t) $&
          $morestuff($iif(!%d && %q && $active ischan && !$query($nick),$true,$false),$&
          $iif($chan && $gettok($readini($mircini,n,options,n2),30,44) == 1,$&
          $nick($chan,$nick).pnick,$nick),%b,%g) %s
        haltdef
      }
    }

Headache inducing! And bear in mind I forgot to code support for window-specific "Events in Channel|Status|Both|Hide", so the above code should actually be even more complex.

Anyway: in light of this situation I'd like to propose two ideas for simplifying things for anybody doing default text replacement:

1) $deftext and /deftext to give DLL hook-like read/replace access to mIRC's default text. With these, the above action event could be as simple as this (note the absence of haltdef):

Code:
on ^*:ACTION:*:*:/deftext $myIncomingActionFilter($deftext)

Note that $deftext would return the full line to be printed. So in the case of ON ACTION, it wouldn't contain just the user message (the equivalent of $1-), but rather, it would contain "[01:34] * Nick user message" ... or if timestamps were disabled, "* Nick user message".

2) For more advanced scripting, where people still want to do their own /echos followed by haltdef, a new identifier that returns the window which mIRC normally would have written its default text to (were it not for haltdef). This would at least eliminate all of the work of parsing multiple mirc.ini options in order to figure out the actual target for yourself (code which may need to be completely revised if future mIRC versions change the rules):

Code:
$targetwin(N)
   $targetwin(0) returns number of target windows
   $targetwin(1) returns 1st target window name (e.g. "Bob" or "=Bob" or "#channel" or
                 "Message Window" or "Status Window" or "Notify List" or "Urls List" or
                 "Channels List" or "Links List"... or any others I'm forgetting)
Properties to allow constructing an /echo command line:
   .wid       - Returns "@WID" of target window
   .color     - Returns default line color mIRC would've used (e.g., "Notice")
   .switches  - Except for echo's -c switch, returns fully-constructed /echo -switchset
                for all other parameters mIRC would've used.  E.g., "-adsbefghi#lmnrt"
                Specifically:
                    a  - included if mIRC would've printed to active window
                    d  - included if mIRC would've printed to dqwindow
                    s  - included if mIRC would've printed to status window
                    b  - included if mIRC would've applied beep settings
                    e  - included if mIRC would've used line separators
                    f  - included if mIRC would've applied flash settings
                    g  - included if mIRC would've exempted line from logfile
                    h  - included if mIRC would've hard-wrapped line
                    i# - included if mIRC would've indented
                    l  - included if mIRC would've applied highlight settings
                    m  - included if mIRC would've treated as user message
                    n  - included if mIRC would've highlighted switchbar icon
                    r  - included if mIRC would've applied strip settings
                    t  - included if mIRC would've applied timestamp settings

$targetwin would be useful for situations where you would otherwise use /deftext $deftext, except that you want to make a few changes to mIRC's behavior. For instance, the following code would give me almost the same convenience as /deftext $deftext, except I now have conditional control over whether mIRC applies its flash settings -- while leaving all other behaviors at their defaults:

Code:
on ^*:TEXT:*:*:{
  var %n = 1
  while (%n <= $targetwin(0)) {
    echo $+($iif($no_flashing,$remove($targetwin(%n).switches,f),$targetwin(%n).switches),c) $targetwin(%n).color $targetwin(%n).wid $+(<,$nick,>) $1-
    inc %n
  }
  haltdef
}