; MTS Theme Engine. 
; By Eric^^ <EricN@accesswave.ca>
; http://ericswebpage.org (may not be up yet)
;
; Feel free to include this engine in your scripts.
; You may edit it as you like, but keep credits alive :P
;
;
; Thanks to Kamek, fubar and the rest of #mircscripts.org on undernet helping me find bugs.

alias theme {
  var %theme = $$sfile(*.mts,Select a theme:,OK)
  mtsload mts %theme
}
alias themes {
  dialog - $+ $iif($dialog(theme),v,m) theme theme
}

alias mtsecho {
  if ($1 != !script) && (%:echo) %:echo $1-
  else return
}

on *:start:mtsreload
on *:active:*:setfont $active

alias ctcp {
  if (!$2) return
  var %ctcp = $iif($2 == PING,PING $ctime,$upper($2) $3-)
  .raw privmsg $1 : $+ $chr(1) $+ %ctcp $+ $chr(1)
  set -un %::nick $1
  set -un %::chan $1
  set -un %::ctcp $gettok(%ctcp,1,32)
  set -un %::text $gettok(%ctcp,2-,32)
  set -un %:echo echo $colour(ctcp) -at
  if ($show) mtsecho $mtsget($iif($1 ischan,ctcpchanself,ctcpself))
}
alias ctcpreply {
  if (!$2) return
  var %ctcp = $upper($2) $3-
  .raw notice $1 : $+ $chr(1) $+ %ctcp $+ $chr(1)
  set -un %::nick $1
  set -un %::ctcp $gettok(%ctcp,1,32)
  set -un %::text $gettok(%ctcp,2-,32)
  set -un %:echo echo $colour(ctcp) -at
  if ($show) mtsecho $mtsget(ctcpreplyself)
}
alias notice {
  if (!$2) return
  set -un %::nick $1
  set -un %::me $me 
  set -un %::chan $1
  set -un %:echo echo $colour(notice) -ati3
  set -un %::text $2- 
  set -un %::cmode $remove($nick($1,$me).pnick,$me)
  .notice $1 %::text
  if ($show) mtsecho $mtsget($iif($1 ischan,NoticeSelfChan,NoticeSelf)).null
}
alias me {
  if ($isid) { return $me } 
  else { 
    describe $active $1-
  }
}
alias describe {
  if ($2 == $null) return
  if ($show) {
    set -un %::nick $1 
    set -un %::me $me 
    set -un %::chan $1
    set -un %:echo echo $colour(own) -ati3
    set -un %::text $2- 
    set -un %::cmode $remove($nick($1,$me).pnick,$me)
    var %mts = $iif($1 ischan,ActionChanSelf,ActionQuerySelf)
    if (#* iswm $1) && (!$chan($1)) var %mts = TextMsgSelf
    if ($chr(61) $+ = iswm $1) && (!$chat($1)) (!$query($1)) var %mts = TextMsgSelf
    if (#* !iswm $1) && ($chr(61) $+ * !iswm $1) && (!$query($1)) var %mts = TextMsgSelf
    if (%mts != TextMsgSelf) set -un %:echo echo $colour(own) -ti3 $1
    mtsecho $mtsget(%mts)
  }
  .msg $1 $chr(1) $+ ACTION %::text $+ $chr(1) 
}
alias say {
  if ($isid) { return } 
  else { 
    msg $active $1-
  }
}
alias msg {
  if ($2 == $null) return
  if ($show) {
    set -un %::nick $1 
    set -un %::me $me 
    set -un %::chan $1
    set -un %:echo echo $colour(own) -ati3
    set -un %::text $2- 
    set -un %::cmode $remove($nick($1,$me).pnick,$me)
    var %mts = $iif($1 ischan,TextChanSelf,TextQuerySelf)
    if (#* iswm $1) && (!$chan($1)) var %mts = TextMsgSelf
    if ($chr(61) $+ = iswm $1) && (!$chat($1)) (!$query($1)) var %mts = TextMsgSelf
    if (#* !iswm $1) && ($chr(61) $+ * !iswm $1) && (!$query($1)) var %mts = TextMsgSelf
    if (%mts != TextMsgSelf) set -un %:echo echo $colour(own) -ti3 $1
    mtsecho $mtsget(%mts)
  }
  .msg $1 $2-
}
alias ame {
  var %c = 1
  while ($chan(%c)) {
    if ($show) describe $chan(%c) $$1-
    else .describe $chan(%c) $$1-
    inc %c
  }
}
alias amsg {
  var %c = 1
  while ($chan(%c)) {
    if ($show) msg $chan(%c) $$1-
    else .msg $chan(%c) $$1-
    inc %c
  }
}
;;

alias mtsdll return $dll(sistema\dlls\mtsgen.dll,MTSPrecompile,$1-)
alias mtsget {
  var %cs = $hget(theme,BASECOLORS)
  set -un %::c1 $gettok(%cs,1,44)
  set -un %::c2 $gettok(%cs,2,44)
  set -un %::c3 $gettok(%cs,3,44)
  set -un %::c4 $gettok(%cs,4,44)
  set -un %::timestamp $timestamp
  set -un %::pre [ [ $hget(theme,prefix) ] ] | set %prefisso %::pre
  set -un %::parentext [ [ $iif(%::text,$hget(theme,parentext)) ] ]
  var %return = [ [ $hget(theme,$$1) ] ]
  if (%return == $null) && ($prop != null) halt
  if (!script* iswm %return) {
    if ($gettok(%return,2-,32)) [ [ $ifmatch ] ] 
    else if ($prop != null) halt
    return !script
  }
  if (!script* !iswm %return) return %return
  if ($prop != null) halt
}
alias mtsreload {
  var %command = $iif(%theme,%theme)
  if (%command) $ifmatch
  else mtsload
}
alias mtsload {

  ; mtsload [[schemeN or MTS] [filename]]

  if ($1 == -s) { tokenize 32 $2- | var %silent = 1 }

  var %s = $1,%f = $2-,%d = sistema\default.mts,%w = @loadtheme

  if ($script($mtsget(script).null)) .unload -rs $nopath($ifmatch)
  if ($hget(theme)) { 
    set -un %:echo echo $colour(normal) -at 
    if ($hget(theme,unload)) && (!%silent) { 
      mtsecho $mtsget(unload)
    }
    hdel -w theme * 
  }
  if (!$hget(theme)) hmake theme 10
  set %theme mtsload $1-
  window -h %w
  if ($isfile(%d)) {
    loadbuf %w " $+ %d $+ "
    var %l = 1
    while (%l <= $line(%w,0)) {
      var %line = $line(%w,%l) 
      if ($gettok(%line,2,32)) && ($left(%line,1) != $chr(59)) hadd theme $mtsdll(%line)
      inc %l
    }
  }
  clear %w
  if ($isfile(%f)) {
    loadbuf -tMTS %w " $+ %f $+ "
    var %l = 1
    while (%l <= $line(%w,0)) {
      var %line = $line(%w,%l) 
      if ($gettok(%line,2,32)) && ($left(%line,1) != $chr(59)) hadd theme $mtsdll(%line)
      inc %l
    }
    if (%s != MTS) {
      clear %w
      loadbuf -t $+ %s %w " $+ %f $+ "
      var %l = 1
      while (%l <= $line(%w,0)) {
        var %line = $line(%w,%l) 
        if ($gettok(%line,2,32)) && ($left(%line,1) != $chr(59)) hadd theme $mtsdll(%line)
        inc %l
      }
    }
  }
  clear %w
  if ($mtsget(SCRIPT).null) && (!$script($mtsget(SCRIPT).null)) .load -rs " $+ $+($nofile(%f),$mtsget(SCRIPT)) $+ "
  var %cs = $hget(theme,BASECOLORS),%::c1 = $gettok(%cs,1,44),%::c2 = $gettok(%cs,2,44),%::c3 = $gettok(%cs,3,44),%::c4 = $gettok(%cs,4,44)
  .timestamp $iif($mtsget(TIMESTAMP).null == ON,ON,OFF) 
  if ($mtsget(TIMESTAMPFORMAT).null) .timestamp -f [ [ $ifmatch ] ]
  if (!%silent) {
    mtscolor | mtsnicklist | setfonts | bg | set -un %:echo echo $colour(normal) -at 
    if ($hget(theme,load)) mtsecho $mtsget(load)
  }
}

alias colorset {
  if ($chr(44) isin $1-) { tokenize 44 $1- } 
  colour background $1 | colour action $2 | colour ctcp $3 | colour highlight $4 | colour info $5 | colour info2 $6 | colour invite $7 | colour join $8 | colour kick $9 | colour mode $10 | colour nick $11 | colour normal $12 | colour notice $13 | colour notify $14 
  colour other $15 | colour own $16 | colour part $17 | colour  quit $18 | colour topic $19 | colour wallops $20 | colour whois $21 | colour editbox $22 | colour editbox text $23 | colour listbox $24 | colour listbox text $25 | color grayed text $iif($26,$26,$25) | colour inactive $iif($27 isnum,$27,$22)
}
alias colorreset var %a = 0 | while (%a < 15) { colour -r %a | inc %a }
alias mtsnicklist {
  var %c = $cnick(0) 
  while (%c) {
    if ($cnick(%c)) { .cnick -r $cnick(%c) } 
    else { .cnick -r * } 
    dec %c 
  } 
  if ($hget(theme,CLINEME) isnum) && ($me) { .cnick $me $fixcol($hget(theme,CLINEME)) } 
  if ($hget(theme,CLINEENEMY) isnum) { .cnick -i * $fixcol($hget(theme,CLINEENEMY)) } 
  if ($hget(theme,CLINEFRIEND) isnum) { .cnick -ovpn * $fixcol($hget(theme,CLINEFRIEND)) } 
  if ($hget(theme,CLINEOP) isnum) { .cnick * $fixcol($hget(theme,CLINEOP)) @ } 
  if ($hget(theme,CLINEHOP) isnum) { .cnick * $fixcol($hget(theme,CLINEHOP)) % } 
  if ($hget(theme,CLINEVOICE) isnum) { .cnick * $fixcol($hget(theme,CLINEVOICE)) + } 
  if ($hget(theme,CLINEREGULAR) isnum) { .cnick -n * $fixcol($hget(theme,CLINEREGULAR)) } 
}

alias fixcol return $right($+(0,$calc($1 % 16)),2)
alias mtscolor {
  var %rgbc = $mtsget(rgbcolors)
  if (!%rgbc) var %rgbc = 255,255,255 0,0,0 0,0,128 0,144,0 255,0,0 128,0,0 160,0,160 255,128,0 255,255,0 0,255,0 0,144,144 0,255,255 0,0,255 255,0,255 128,128,128 208,208,208
  var %colors = $mtsget(colors)
  if (!%colors) var %colors = 0,6,4,5,2,3,3,3,2,2,3,1,5,7,12,1,3,2,2,5,1,0,1,0,1,7
  var %a = 1 | while %a < 17 { colour $calc(%a -1) [ $rgb( [ $gettok(%rgbc,%a,32) ] ) ] | inc %a } 
  colorset %colors
}

on *:input:*:{
  if ($left($1,1) == /) && (!$ctrlenter) || ($1 == $null) || (!$server) { return }
  if ($target == Status Window) || (@* iswm $target) { return }
  .signal mts.input $target $nick $reppptext($1-) | haltdef
}
alias reppptext { return %grassetto $+ %sottolineato $+ %textcoloring $+ $wordreplacer($1-) }
on ^*:join:*:.signal mts.join $target $nick $address | haltdef
on ^*:part:*:.signal mts.part $target $nick $address $1- | haltdef
on ^*:quit:{
  var %q = 1
  while $comchan($nick,%q) {
    .signal mts.quit $nick $address $comchan($nick,%q) $1-
    inc %q
  }
  haltdef
}
on ^*:nick:.signal mts.nick $nick $newnick | haltdef
on ^*:chat:*:.signal mts.text $+(=,$target) $nick $address $1- | haltdef
on ^*:text:*:*:.signal mts.text $target $nick $address $1- | haltdef
on ^*:action:*:*:.signal mts.action $target $nick $address $1- | haltdef
on ^*:notice:*:*:.signal mts.notice $target $nick $address $1- | haltdef
on ^*:snotice:*:.signal mts.snotice $nick $1- | haltdef
on ^*:rawmode:*:.signal mts.mode $target $nick $address $1- | haltdef
on ^*:usermode:.signal mts.umode $1- | haltdef
on ^*:error:*:.signal mts.error $1- | haltdef
on ^*:kick:*:.signal mts.kick $target $nick $address $knick $1- | haltdef
on ^*:notify:if (%notifyecho) { .signal mts.notify $nick } | if (%popupnotify) { notifylist | dialog -t notifylist $nick è online } | haltdef
on ^*:unotify:if (%notifyecho) { .signal mts.unotify $nick } | if (%popupnotify) { notifylist | dialog -t notifylist $nick è online } | haltdef
on *:ctcpreply:*:{
  .signal mts.ctcpreply $nick $address $1- | haltdef
}
on ^*:topic:*:.signal mts.topic $target $nick $address $1- | haltdef
on ^*:invite:*:.signal mts.invite $nick $address $chan | haltdef
on ^*:wallops:*:.signal mts.wallop $nick $1- | haltdef
ctcp *:*:*:{
  if ($1 == dcc) return
  if ($1 == PING) && ($2) .ctcpreply $nick PING $2
  if ($1 == TIME) .ctcpreply $nick TIME $asctime
  if ($1 == MOTFV) tokenize 32 VERSION $2-
  .signal mts.ctcp $target $nick $address $1- | haltdef
}
raw *:*:.signal mts.raw $numeric $1- | halt
on *:DNS:{
  set -un %:echo echo $colour(info2) -at
  if (!$raddress) { mtsecho $mtsget(DNSerror) }
  if ($raddress) { set -un %::raddress $raddress | set -un %::iaddress $iaddress | set -un %::naddress $naddress | mtsecho $mtsget(DNSresolve) }
  unset %::address
  haltdef
}

on *:signal:mts.*:{
  scid $cid

  var %event = $right($signal,-4)
  set -un %::target $iif($1,$1,$active)
  set -un %::chan $1
  set -un %::nick $2
  set -un %::address $3
  set -un %::text $4-
  set -un %::me $me
  set -un %:echo echo $colour(info) -st

  if (%event == input) {
    set -un %:echo echo $colour(own) -ti3 $1
    set -un %::cmode $remove($nick($1,$2).pnick,$2)
    set -un %::text $3-
    set -un %::address $right($address($me,5),$calc($len($address($me,5)) - $pos($address($me,5),!)))
    set -un %::cnick $nick($1,$2).color
    if (#* iswm $1) var %mts = TextChanSelf
    elseif (#* !iswm $1) var %mts = TextQuerySelf
    mtsecho $mtsget(%mts)
    .msg $1 $3-
  }

  if (%event == text) {
    var %target = $iif(#* iswm $1,$1,$2)
    if (=* iswm $1) var %target = $1
    set -un %:echo echo $colour(normal) -mtli3 %target
    set -un %::cmode $left($remove($nick($1,$2).pnick,$2),1)
    set -un %::cnick $nick($1, $2).color
    if (#* iswm $1) var %mts = TextChan
    elseif (#* !iswm $1) var %mts = TextQuery
    mtsecho $mtsget(%mts)
  }

  if (%event == action) {
    set -un %:echo echo $colour(action) -mtli3 $iif(#* iswm $1,$1,$2)
    set -un %::cmode $left($remove($nick($1,$2).pnick,$2),1)
    set -un %::cnick $nick($1, $2).color
    if (#* iswm $1) var %mts = ActionChan
    elseif (#* !iswm $1) var %mts = ActionQuery
    mtsecho $mtsget(%mts)
  }

  if (%event == notice) {
    set -un %:echo echo $colour(notice) -ati3
    set -un %::cmode $left($remove($nick($1,$2).pnick,$2),1)
    set -un %::cnick $nick($1, $2).color
    if (#* iswm $1) var %mts = NoticeChan
    elseif (#* !iswm $1) var %mts = Notice
    mtsecho $mtsget(%mts)
  }

  if (%event == snotice) {
    set -un %::address $address 
    set -un %::nick $1
    set -un %::server $1
    set -un %::text $2-
    set -un %:echo echo $colour(notice) -smt
    mtsecho $mtsget(noticeserver)
  }

  if (%event == umode) {
    set -un %::nick $me
    set -un %::address $right($address($me,5),$calc($len($address($me,5)) - $pos($address($me,5),!)))
    set -un %::modes $1-
    set -un %::text $1-
    set -un %:echo echo $colour(mode) -smt
    mtsecho $mtsget(modeuser)
  }

  if (%event == error) {
    set -un %:echo echo $colour(info2) -smt
    set -un %::text $1-
    mtsecho $mtsget(servererror)
  }

  if (%event == mode) {
    ;.timerredonicklist -m 1 500 mtsnicklist
    set -un %::cmode $left($remove($nick($1,$2).pnick,$2),1)
    set -un %::modes $4-
    set -un %:echo echo $colour(mode) -tm $1
    mtsecho $mtsget(mode)
  }

  if (%event == topic) {
    set -un %:echo echo $colour(topic) -mt $1
    mtsecho $mtsget(topic)
  }

  if (%event == invite) {
    set -un %::nick $1
    set -un %::address $2
    set -un %::chan $3
    set -un %:echo echo $colour(invite) -at
    mtsecho $mtsget(invite)
  }

  if (%event == ctcp) {
    set -un %::ctcp $4 
    set -un %::text $5- 
    if (#* iswm $1) { set -un %:echo echo $colour(ctcp) -mt $1 | var %mts = ctcpchan }
    else { set -un %:echo echo $colour(ctcp) -at | var %mts = ctcp }
    mtsecho $mtsget(%mts)
  }

  if (%event == ctcpreply) {
    if ($3 == PING) { 
      set -un %::ctcp PING 
      set -un %::text $iif($4 isnum,$duration($calc($ctime - $4)),$4-) 
      goto echo 
    }
    set -un %::ctcp $3
    set -un %::text $4-
    :echo 
    set -un %::nick $1
    set -un %::address $2
    set -un %:echo echo $colour(ctcp) -at 
    mtsecho $mtsget(ctcpreply) 
    halt
  }

  if (%event == join) {
    var %mts = join
    if ($2 == $me) { var %mts = joinself | bg | setfonts }
    ;.timerredonicklist -m 1 500 mtsnicklist
    set -un %:echo echo $colour(join) -mt $1
    mtsecho $mtsget(%mts)
  }  

  if (%event == part) {
    if ($2 == $me) halt
    set -un %:echo echo $colour(part) -mt $1
    mtsecho $mtsget(part)
  }

  if (%event == kick) {
    set -un %::knick $4
    set -un %::kaddress $right($address($knick,0),$calc($len($address($knick,0)) -2))
    set -un %::text $5-
    set -un %:echo echo $colour(kick) -mt $1
    if ($knick == $me) { set -un %:echo echo -st }
    mtsecho $mtsget($iif($knick == $me,KICKSELF,KICK))
  }

  if (%event == quit) {
    set -un %:echo echo $colour(quit) -mt $3
    set -un %::nick $1
    set -un %::address $2
    set -un %::text $4-
    set -un %::chan $3
    mtsecho $mtsget(quit)
  }

  if (%event == wallops) {
    set -un %::nick $1 
    set -un %::text $2- 
    set -un %:echo echo $colour(wallop) -st 
    mtsecho $mtsget(wallop)
  }

  if (%event == notify) {
    ;  var %ignore = insert,nicks,that,you,don't,want,to,notify,here
    if ($findtok(%ignore,$1,44)) halt
    set -un %::nick $1
    set -un %::text $notify($1).note
    set -un %:echo echo $colour(notify) -at 
    mtsecho $mtsget(notify)
  }

  if (%event == unotify) {
    ;  var %ignore = insert,nicks,that,you,don't,want,to,notify,here
    if ($findtok(%ignore,$1,44)) halt
    set -un %::nick $1
    set -un %::text $notify($1).note
    set -un %:echo echo $colour(notify) -at 
    mtsecho $mtsget(unotify)
  }

  if (%event == nick) {
    var %mts = Nick
    if ($2 == $me) || ($1 == $me) { var %mts = NickSelf | ;.timerredonicklist -m 1 500 mtsnicklist }
    set -un %::nick $1
    set -un %::newnick $2
    var %q = 1
    while $comchan($2,%q) {
      set -un %::chan $comchan($2,%q) 
      set -un %:echo echo $colour(nick) -mt %::chan
      %:echo $mtsget(%mts)
      inc %q
    }
  }

  if (%event == raw) {
    var %raw = $right(00 $+ $1,3) | tokenize 32 $2-
    ; /list
    if (%raw == 322) halt

    ; /invite
    if (%raw == 341) { set -un %::nick $2 | set -un %::chan $3 | set -un %:echo echo $colour(info) -tm $3 }

    ; /server
    if (%RAW == 001) { set -un %:echo echo $colour(info) -st }
    if (%RAW == 002) { set -un %::address $5 | set -un %::value $8 | set -un %:echo echo $colour(info) -st }
    if (%RAW == 003) { set -un %::value $6- | set -un %:echo echo $colour(info) -ts }
    if (%RAW == 005) { set -un %::text $2- | set -un %:echo echo $colour(info) -ts }

    ; /map
    if (%RAW == 015) { echo $colour(info) -ts $2- | halt }

    ; /links
    if (%RAW == 364) { echo $colour(info) -ts $2- | halt }

    ; /motd
    if (%RAW == 372) { set -un %::text $2- | set -un %:echo echo $colour(info) -ts }
    if (%RAW == 374) { set -un %:echo echo $colour(info) -st }
    if (%RAW == 376) { set -un %:echo echo $colour(info) -st }

    ; /Topic
    if (%RAW == 328) { set -un %::chan $2 | set -un %::text $3- | set -un %:echo echo $colour(topic) -mt $2 }
    if (%RAW == 332) { set -un %::chan $2 | set -un %::text $3- | set -un %:echo echo $colour(topic) -mt $2 }
    if (%RAW == 333) { set -un %::chan $2 | set -un %::nick $3 | set -un %::text $asctime($4) | set -un %:echo echo $colour(topic) -tm $2 }

    ; /Mode
    if (%RAW == 324) { if ($me ison $2) { set -un %::chan $2 | set -un %::modes $3- | set -un %:echo echo $colour(info) -tm $2 } }
    if (%RAW == 329) { if ($me ison $2) { set -un %::chan $2 | set -un %::text $asctime($3) | set -un %:echo echo $colour(info) -tm $2 }  }

    ; /Names
    if (%RAW == 353) { set -un %::chan $3 | set -un %::text $4- | set -un %:echo echo $colour(info2) -ts } 
    if (%RAW == 366) { set -un %::chan $2 | set -un %:echo echo $colour(info2) -st } 

    ; /Whois
    if (%RAW == 307) { set -un %::nick $2 | set -un %::isreg is | set -un %:echo echo $colour(whois) -at | set -n %mu.nick $2 | set -n %mu.isreg is }

    if (%RAW == 311) { 
      set -un %::nick $2 | set -un %::address $+($3,@,$4) | set -un %::realname $6- | set -n %mu.address $+($3,@,$4) | set -n %mu.realname $6- | set -un %:echo echo $colour(whois) -at | if (!%mu.whois) { inc %mu.whois | goto skip }
      if (%mu.whois) { set -un %::isreg $iif(%mu.isreg,%mu.isreg,is not) | set -un %::wserver %mu.wserver | set -un %::ircop $iif(%mu.ircop,%mu.ircop,is not) | set -un %::signontime %mu.signontime | set -un %::idletime %mu.idletime | set -un %::text %mu.text | set -un %::serverinfo %mu.serverinfo | set -un %::chan %mu.chan | unset %mu.* | unset %mu.text | mtsecho $mtsget(whois) }
      :skip
    }
    if (%RAW == 319) { set -un %::nick $2 | set -un %::chan $3- | set -un %:echo echo $colour(whois) -at | set -n %mu.chan $3- }
    if (%RAW == 312) { set -un %::nick $2 | set -un %::wserver $3 | set -un %::serverinfo $4- | set -n %mu.wserver $3 | set -n %mu.serverinfo $4- | set -un %:echo echo $colour(whois) -at }
    if (%RAW == 301) { set -un %::nick $2 | set -un %::text $3- | set -n %mu.text $3- | set -un %:echo echo $colour(whois) -at }
    if (%RAW == 317) { set -un %::nick $2 | set -un %::idletime $3 | set -un %::signontime $asctime($4) | set -un %:echo echo $colour(whois) -at | set -n %mu.idletime $3 | set -n %mu.signontime $asctime($4) }
    if (%RAW == 318) { 
      set -un %::nick $2 | set -un %:echo echo $colour(whois) -at 
      if (%mu.whois) { set -un %::isreg $iif(%mu.isreg,%mu.isreg,is not) | set -un %::address %mu.address | set -un %::realname %mu.realname  | set -un %::wserver %mu.wserver | set -un %::ircop $iif(%mu.ircop,%mu.ircop,is not) | set -un %::signontime %mu.signontime | set -un %::idletime %mu.idletime | set -un %::text %mu.text | set -un %::serverinfo %mu.serverinfo | set -un %::chan %mu.chan | unset %mu.* | unset %mu.text | mtsecho $mtsget(whois) }
    }
    if (%RAW == 313) { set -un %::nick $2 | set -un %::ircop is | set -n %mu.ircop is | set -un %:echo echo $colour(whois) -at }

    ; /Who
    if (%RAW == 352) { set -un %::nick $6 | set -un %::chan $2 | set -un %::address $+($3,@,$4) | set -un %::wserver $5 | set -un %::away $7 | set -un %::value $8 | set -un %::realname $9- | set -un %:echo echo $colour(whois) -at }
    if (%RAW == 315) { set -un %::value $2 | set -un %:echo echo $colour(whois) -st }

    ; /Whowas
    if (%RAW == 314) { 
      set -un %::nick $2 | set -un %::address $+($3,@,$4) | set -un %::realname $6- | set -n %mu.nick $2 | set -n %mu.address $+($3,@,$4) | set -n %mu.realname $6- | set -un %:echo echo $colour(whois) -st 
      if (!%mu.whowas) { inc %mu.whowas | goto skip }
      if (%mu.whowas) { set -un %::wserver %mu.wserver | unset %mu.* | mtsecho $mtsget(whowas) } | :skip
    }
    if (%RAW == 369) { set -un %::nick $2 | set -un %:echo echo $colour(whois) -st | if (%mu.whowas) { set -un %::wserver %mu.wserver | set -un %::nick %mu.nick | set -un %::address %mu.address | set -un %::realname %mu.realname | unset %mu.* | mtsecho $mtsget(WHOWAS) } }

    ; /lusers
    if (%RAW == 251) { set -un %::users $4 | set -un %::text $7 | set -un %::value $10 | set -un %:echo echo $colour(info) -st }
    if (%RAW == 252) { set -un %::value $2 | set -un %:echo echo $colour(info) -st }
    if (%RAW == 253) { set -un %::value $2 | set -un %:echo echo $colour(info) -st }
    if (%RAW == 254) { set -un %::value $2 | set -un %:echo echo $colour(info) -st }
    if (%RAW == 255) { set -un %::users $4 | set -un %::value $7 | set -un %:echo echo $colour(info) -st }

    ; /userhost
    if (%RAW == 302) { set -un %::nick $gettok($2,1,62) | set -un %::address $remove($gettok($2,1,62),+,-,*) |  set -un %::value $remove($gettok($2,1,62),%%::address) | set -un %:echo echo $colour(whois) -at }

    ; /away
    if (%RAW == 305) { set -un %:echo echo $colour(info) -st }
    if (%RAW == 306) { set -un %:echo echo $colour(info) -st }

    ; Errors
    if (%RAW == 401) { set -un %::nick $2 | set -un %:echo echo $colour(info2) -at }
    if (%RAW == 402) { set -un %::server $2 | set -un %:echo echo $colour(info2) -st }
    if (%RAW == 403) { set -un %::chan $2 | set -un %:echo echo $colour(info2) -st }
    if (%RAW == 404) { set -un %::chan $2 | set -un %:echo echo $colour(info2) -at }
    if (%RAW == 405) { set -un %::chan $2 | set -un %:echo echo $colour(info2) -st }
    if (%RAW == 406) { set -un %::nick $2 | set -un %:echo echo $colour(info2) -st }
    if (%RAW == 407) { set -un %::nick $2 | set -un %::chan $2 | set -un %:echo echo $colour(info2) -st }
    if (%RAW == 408) { set -un %:echo echo $colour(info2) -st }
    if (%RAW == 411) { set -un %::text $5- | set -un %:echo echo $colour(info2) -st }
    if (%RAW == 412) { set -un %::text $1- | set -un %:echo echo $colour(info2) -st }
    if (%RAW == 421) { set -un %::text $2 | set -un %::value $2 | set -un %:echo echo $colour(info2) -st }
    if (%RAW == 422) { set -un %::text $2- | set -un %:echo echo $colour(info2) -st }
    if (%RAW == 411) { set -un %::server $2 | set -un %:echo echo $colour(info2) -st }
    if (%RAW == 431) { set -un %:echo echo $colour(info2) -st }
    if (%RAW == 432) { set -un %::nick $2 | set -un %:echo echo $colour(info2) -st }
    if (%RAW == 433) { set -un %::nick $2 | set -un %:echo echo $colour(info2) -at }
    if (%RAW == 406) { set -un %::nick $2 | set -un %:echo echo $colour(info2) -st }
    if (%RAW == 436) { set -un %::nick $2 | set -un %:echo echo $colour(info2) -st }
    if (%RAW == 437) { set -un %:echo echo $colour(info2) -st }
    if (%RAW == 438) { set -un %:echo echo $colour(info2) -st }
    if (%RAW == 439) { set -un %:echo echo $colour(info2) -st }
    if (%RAW == 441) { set -un %::nick $2 | set -un %::chan $3 | set -un %:echo echo $colour(info2) -st }
    if (%RAW == 442) { set -un %::chan $2 | set -un %:echo echo $colour(info2) -st }
    if (%RAW == 443) { set -un %::nick $2 | set -un %::chan $3 | set -un %:echo echo $colour(info2) -st }
    if (%RAW == 461) { set -un %::text $2 | set -un %:echo echo $colour(info2) -st }
    if (%RAW == 465) { set -un %:echo echo $colour(info2) -st }
    if (%RAW == 467) { set -un %::chan $2 | set -un %:echo echo $colour(info2) -at }
    if (%RAW == 471) { set -un %::chan $2 | set -un %:echo echo $colour(info2) -at }
    if (%RAW == 473) { set -un %::chan $2 | set -un %:echo echo $colour(info2) -at }
    if (%RAW == 474) { set -un %::chan $2 | set -un %:echo echo $colour(info2) -at }
    if (%RAW == 475) { set -un %::chan $2 | set -un %:echo echo $colour(info2) -at }
    if (%RAW == 482) { set -un %::chan $2 | set -un %:echo echo $colour(info2) -at }
    mtsecho $mtsget($+(raw,.,%raw))
  }
}

alias setfonts {
  var %i = $scon(0)
  while (%i) {
    scon %i
    var %a = $chan(0),%b = $query(0),%c = $chat(0)
    var %d = $gettok($hget(theme,fontdefault),2,44) $gettok($hget(theme,fontdefault),1,44),%e = $gettok($hget(theme,fontchan),2,44) $gettok($hget(theme,fontchan),1,44),%f = $gettok($hget(theme,fontquery),2,44) $gettok($hget(theme,fontquery),1,44),%d = $iif(%d,%d,12 tahoma),%e = $iif(%e,%e,%d),%f = $iif(%f,%f,%d)
    while (%a) { font $+(-d,$iif($gettok($mtsget(fontchan),3,44) == B,b)) $chan(%a) %e | dec %a }
    while (%b) { font $+(-d,$iif($gettok($mtsget(fontquery),3,44) == B,b)) $query(%b) %f | dec %b } 
    while (%c) { font $+(-d,$iif($gettok($mtsget(fontquery),3,44) == B,b)) $chat(%c) %f | dec %c } 
    if (%d) { 
      font $+(-ds,$iif($gettok($mtsget(fontdefault),3,44) == B,b)) %d 
      var %a = $window(0) | while %a { font -d $window(%a) %d | dec %a } 
    }
    dec %i
  }
} 
alias setfont {
  var %d = $gettok($hget(theme,fontdefault),2,44) $gettok($hget(theme,fontdefault),1,44),%e = $gettok($hget(theme,fontchan),2,44) $gettok($hget(theme,fontchan),1,44),%f = $gettok($hget(theme,fontquery),2,44) $gettok($hget(theme,fontquery),1,44),%d = $iif(%d,%d,12 tahoma),%e = $iif(%e,%e,%d),%f = $iif(%f,%f,%d)
  if ($1 ischan) { font $+(-d,$iif($gettok($mtsget(fontchan),3,44) == B,b)) $1 %e | dec %a }
  if ($query($1)) { font $+(-d,$iif($gettok($mtsget(fontquery),3,44) == B,b)) $1 %f | dec %b } 
  if ($chat($1)) { font $+(-d,$iif($gettok($mtsget(fontquery),3,44) == B,b)) $1 %f | dec %c } 
  if (%d) { font $+(-ds,$iif($gettok($mtsget(fontdefault),3,44) == B,b)) %d }
} 
alias bgrep {
  return $iif($1,$replace($1,fill,f,center,c,stretch,r,tile,t,photo,p),x)
}
alias bg {  
  var %i = 1,%td = $nofile($gettok(%theme,3-,32))
  while $scon(%i) {
    scon %i
    var %ch = $chan(0),%qu = $query(0),%cha = $chat(0)
    while (%ch) { background -e $+ $bgrep($gettok($hget(theme,IMAGECHAN),1,32)) $chan(%ch) $+(%td,$gettok($hget(theme,IMAGECHAN),2-,32)) | dec %ch }  
    while (%qu) { background -e $+ $bgrep($gettok($hget(theme,IMAGEQUERY),1,32)) $query(%qu) $+(%td,$gettok($hget(theme,IMAGEQUERY),2-,32)) | dec %qu }
    while (%cha) { background -e $+ $bgrep($gettok($hget(theme,IMAGEQUERY).null,1,32)) $chat(%cha) $+(%td,$gettok($hget(theme,IMAGEQUERY),2-,32)) | dec %cha }
    background -s $+ $bgrep($gettok($hget(theme,IMAGESTATUS),1,32)) $+(%td,$gettok($hget(theme,IMAGESTATUS),2-,32))
    inc %i
  }
  background -m $+ $bgrep($gettok($mtsget(IMAGEMIRC).null,1,32)) $+(%td,$gettok($mtsget(IMAGEMIRC).null,2-,32))
  if ($isfile($+(%td,$mtsget(imageswitchbar).null))) background -h $+(%td,$mtsget(imageswitchbar).null)
  if (!$isfile($+(%td,$mtsget(imageswitchbar).null))) background -hx
  if ($isfile($+(%td,$mtsget(imagetoolbar).null))) background -l $+(%td,$mtsget(imagetoolbar).null)
  if (!$isfile($+(%td,$mtsget(imagetoolbar).null))) background -lx
  if ($isfile($+(%td,$mtsget(imagebuttons).null))) background -u $+(%td,$mtsget(imagebuttons).null)
  if (!$isfile($+(%td,$mtsget(imagebuttons).null))) background -ux
}

dialog theme {
  title Themes Manager - Ms3
  size -1 -1 440 284
  box "Temi", 1, 2 4 238 46
  combo 2, 10 20 222 150, size drop sort
  box "Schemi", 3, 242 4 196 46
  button "Applica", 6, 280 254 74 24
  button "Chiudi", 7, 200 254 74 24, cancel
  button "OK", 8, 120 254 74 24, ok
  combo 10, 250 22 180 150, size drop
  box "Informazioni", 11, 242 50 196 196
  text "Nome:", 12, 248 64 42 16
  text "Autore:", 13, 248 84 44 16
  text "E-mail:", 14, 248 104 46 16
  text "Website:", 15, 248 124 50 16
  text "Descrizione:", 16, 248 168 88 16
  edit "", 17, 246 182 188 58,multi,autovs,vsbar,return,read
  edit "", 18, 310 64 124 20,read,autohs
  edit "", 19, 310 84 124 20,read,autohs
  edit "", 20, 310 104 124 20,read,autohs
  edit "", 21, 310 122 124 20,read,autohs
  text "Versione:", 22, 248 144 50 16
  edit "", 23, 310 140 124 20,read,autohs
  box "Anteprima", 24, 2 50 238 196
  icon 25, 9 67 223 171
  menu &File,26
  item "",27
  item &Chiudi,29
  menu &About,30
  item altri temi...,31
  item break,32
  item about,33
  button Genera Anteprima,34, 70 125 100 25,flat hide
  button "&Guida >>", 35, 360 254 74 24
  list 36, 445 10 140 250,size
  text "www.mIRCscript.it", 37, 470 265 85 21
  icon 38, 10 250 32 32, images\icone\theme.ico
}
alias -l themepreview {
  if ($isfile($2-)) {
    did -g $1 25 " $+ $2- $+ "
    did -v $1 25
    did -h $1 34
  }
  else {
    did -h $1 25
    did -v $1 34
  }
}
alias -l addschemes did -r $dname 10 | did -a $dname 10 ::Default:: | var %a = 1 | while $read(" $+ $1- $+ ",w,scheme $+ %a *) { did -a $dname 10 $gettok($read($1-,w,scheme $+ %a *),2-,32) | inc %a } | did -c $dname 10 1
alias -l resel var %a = $did($dname,2).sel,%b = $did($dname,10).sel | did -u $dname 2,10 | .timerresel -m 1 100 if ($dialog(theme)) did -c $dname 2 %a | .timerresel2 -m 1 100 if ($dialog(theme)) did -c $dname 10 %b
alias -l mtspreview {
  if (!$2) { if ($show) echo -at /mtspreview: insuficient parameters | halt }
  if (!$isfile($2-)) { if ($show) echo -at Cannot find $2- | halt }
  var %bmp = $+($scriptdir,temp\,$left($nopath($2-),-4),$1,.bmp)
  write -c " $+ %bmp $+ "
  if ($window(@preview)) window -c @preview
  window -fopk0h +fl @preview -1 -1 223 171
  hsave -o theme temp-theme.erc
  if ($hget(theme)) { hdel -w theme * }
  if (!$hget(theme)) hmake theme 20 
  window -h @theme 
  loadbuf -t $+ MTS @theme " $+ $2- $+ "
  var %a = $line(@theme,0) 
  while %a { 
    if ($left($line(@theme,%a),1) != $chr(59)) && ($gettok($line(@theme,%a),2,32)) { 
      hadd theme $mtsdll($line(@theme,%a)) 
    } 
    dec %a 
  } 
  window -c @theme
  if ($1 != mts) {
    window -h @theme
    loadbuf -t $+ $1 @theme " $+ $2- $+ "
    var %a = $line(@theme,0) 
    while %a { 
      if ($left($line(@theme,%a),1) != $chr(59)) && ($gettok($line(@theme,%a),2,32)) { 
        hadd theme $mtsdll($line(@theme,%a)) 
      } 
      dec %a 
    } 
    window -c @theme
  }
  if ($hget(theme,SCRIPT)) && (!$script($hget(theme,SCRIPT))) .load -rs " $+ $+($nofile($2-),$hget(theme,SCRIPT)) $+ "
  var %cs = $hget(theme,BASECOLORS),%::c1 = $gettok(%cs,1,44),%::c2 = $gettok(%cs,2,44),%::c3 = $gettok(%cs,3,44),%::c4 = $gettok(%cs,4,44)
  .timestamp $iif($hget(theme,TIMESTAMP) == ON,ON,OFF) 
  if ($hget(theme,TIMESTAMPFORMAT)) .timestamp -f [ [ $ifmatch ] ] 
  window -fopk0h +fl @preview -1 -1 223 171
  var %color = $hget(theme,colors),%rgbs = $hget(theme,RGBColors)
  set -un %f.name " $+ $gettok($hget(theme,fontdefault),1,44) $+ " | set -un %f.size $gettok($hget(theme,fontdefault),2,44) | set -un %f.pos 0
  drawdot @preview $gettok(%color,1,44) 1000 0 0
  set -un %:echo mtsprview $gettok(%color,8,44) $gettok(%color,1,44) | set -un %::nick preview | set -un %::chan #eIRC | set -un %::address theme@preview.com | mtsecho $mtsget(JOIN).null
  set -un %:echo mtsprview $gettok(%color,16,44) $gettok(%color,1,44) | set -un %::nick Eric^^ | set -un %::me Eric^^ | set -un %::address Eric^^@owns.you.com | set -un %::cmode @ | set -un %::text Hi preview! | mtsecho $mtsget(TextChanSelf).null
  set -un %:echo mtsprview $gettok(%color,10,44) $gettok(%color,1,44) | set -un %::address Eric^^@owns.you.com | set -un %::nick Eric^^ | set -un %::modes +v preview | mtsecho $mtsget(Mode).null
  set -un %:echo mtsprview $gettok(%color,12,44) $gettok(%color,1,44) | set -un %::nick preview | set -un %::address theme@preview.com | set -un %::cmode + | set -un %::text Hey Eric^^ $+ ! What's up? | mtsecho $mtsget(TextChan).null
  set -un %:echo mtsprview $gettok(%color,21,44) $gettok(%color,1,44) | set -un %::nick preview | set -un %::address theme@preview.com | set -un %::realname eIRC $ver | set -un %::wserver *.Undernet.org | set -un %::idletime 21 | set -un %::signontime Jan 4th 1987 at 5:00pm
  mtsecho $mtsget(WHOIS).null | mtsecho $mtsget(raw.311).null | mtsecho $mtsget(raw.319).null | mtsecho $mtsget(raw.312).null | mtsecho $mtsget(raw.317).null | mtsecho $mtsget(raw.318).null
  set -un %:echo mtsprview $gettok(%color,16,44) $gettok(%color,1,44) | set -un %::nick Eric^^ | set -un %::address Eric^^@owns.you.com | set -un %::cmode @ | set -un %::me Eric^^ | set -un %::text Nothing, you? | mtsecho $mtsget(TextChanSelf).null
  set -un %:echo mtsprview $gettok(%color,2,44) $gettok(%color,1,44) | set -un %::nick preview | set -un %::address theme@preview.com | set -un %::cmode + | set -un %::text gtg | mtsecho $mtsget(ActionChan).null
  set -un %:echo mtsprview $gettok(%color,16,44) $gettok(%color,1,44) | set -un %::nick Eric^^ | set -un %::address Eric^^@owns.you.com | set -un %::cmode @ | set -un %::nick Eric^^ | set -un %::text See ya! :) | set -un %::me Eric^^ | mtsecho $mtsget(TextChanSelf).null
  set -un %:echo mtsprview $gettok(%color,12,44) $gettok(%color,1,44) | set -un %::nick preview | set -un %::address theme@preview.com | set -un %::cmode + | set -un %::text I'll be back later, bye. | mtsecho $mtsget(TextChan).null
  set -un %:echo mtsprview $gettok(%color,18,44) $gettok(%color,1,44) | set -un %::nick preview | set -un %::address theme@preview.com | set -un %::cmode + | set -un %::text http://eircweb.com | mtsecho $mtsget(quit).null
  set -un %:echo mtsprview $gettok(%color,8,44) $gettok(%color,1,44) | set -un %::nick you-suck | set -un %::address I@am.du.mb | set -un %::chan #eirc | mtsecho $mtsget(join).null
  set -un %:echo mtsprview $gettok(%color,9,44) $gettok(%color,1,44) | set -un %::nick Eric^^ | set -un %::address Eric^^@owns.you.com | set -un %::text Don't come back. | set -un %::knick you-suck | set -un %::kaddress I@am.du.mb | set -un %::chan #eIRC | mtsecho $mtsget(Kick).null
  set -un %:echo mtsprview $gettok(%color,6,44) $gettok(%color,1,44) $colour(info) :: End of $nopath($2-) preview
  set -un %:echo mtsprview $gettok(%color,6,44) $gettok(%color,1,44) $colour(info) :: MTS Theme engine by Eric^^
  var %c = 1
  while (%c != 16) {
    var %r = [ $rgb( [ $gettok(%rgbs,%c,32) ] ) ]
    if ($gettok(%r,2,44)) var %r = [ $rgb( [ %r ] ) ]
    if (%r) drawreplace -r @preview $colour($calc(%c -1)).rgb [ %r ]
    inc %c
  }
  drawsave @preview " $+ %bmp $+ "
  window -c @preview
  if ($hget(theme,SCRIPT)) && ($script($hget(theme,SCRIPT))) { .unload -rs $hget(theme,SCRIPT) }
  hdel -w theme * | hload theme temp-theme.erc | .remove temp-theme.erc
  .timestamp $iif($hget(theme,TIMESTAMP) == ON,ON,OFF) 
  if ($hget(theme,TIMESTAMPFORMAT)) .timestamp -f [ [ $ifmatch ] ]
  return %bmp
}
alias mtsprview if ($3) { drawtext -pb @preview $1 $2 %f.name %f.size 2 %f.pos $3-    | inc %f.pos $height($3-,%f.name,%f.size)  }
on *:dialog:theme:*:*:{
  if (!$isdir($+($scriptdir,temp))) mkdir " $+ $+($scriptdir,temp) $+ "
  var %dir = $did($dname,27)
  if (($devent == sclick) && ($did == 34)) || (($devent == dclick) && ($did == 25)) {
    if (%theme.halt) halt
    mtspreview $iif($did($dname,10).sel != 1,scheme $+ $calc($ifmatch -1),MTS) $findfile(%dir,$did($dname,2),1)
    themepreview $dname $result
    set -u1 %theme.halt 1
    halt
  }
  if ($devent == menu) {
    if ($did == 27) { 
      var %dir = $$sdir(Select a new themes directory:)
      %themedir = %dir
      did -o $dname 27 %dir
      did -r $dname 2
      var %addthemes = $findfile(%dir,*.mts,0,did -a $dname 2 $nopath($1-))
      did -c $dname 2 1
      var %a = $findfile(%dir,$did($dname,2).seltext,1)
      if ($isfile(%a)) {
        addschemes %a
        themepreview $dname
      }
      halt
    }
    if ($did == 29) dialog -c $dname
    if ($did == 31) url http://www.mircscript.it
    if ($did == 33) {
      echo $colour(info) -a *** MTS Theme engine by Eric^^
      echo $colour(info) -a *** ericn@accesswave.ca / http://ericswebpage.org
    }
  }
  if ($devent == init) {
    unset %guidaMTS
    mdxbegin 
    mdx SetFont 2,6,7,8,10,12,13,14,15,16,17,18,19,20,21,22,23,34,35,36,37 12 400 Tahoma
    mdx SetFont 1,3,11,24 12 700 Tahoma
    mdx SetBorderStyle 6,7,8,11,24,34,35 staticedge
    mdx SetControlMDX 36 ListView report rowselect showsel single labeltip headerdrag > sistema\dlls\ $+ views.mdx
    did -i theme 36 1 headerdims 120:1 | did -i theme 36 1 headertext + 0 Guida all'uso:
    var %rigo = 1 | while $lines(dati\guide\mts.txt) >= %rigo { did -az theme 36 $read -l $+ %rigo dati\guide\mts.txt | inc %rigo } 
    if (!$hget(theme)) hmake theme 20
    var %dir = $iif(($isdir(%themedir)) && (%themedir),%themedir,$scriptdirthemes\)
    did -o $dname 27 %dir
    var %addthemes = $findfile(%dir,*.mts,0,did -a $dname 2 $nopath($1-))
    did -c $dname 2 1
    var %a = $findfile(%dir,$did($dname,2).seltext,1)
    if ($isfile(%a)) {
      addschemes %a
      goto init
    }
  }
  var %a = $findfile(%dir,$did($dname,2).seltext,1)
  if ($devent == sclick) && (%a) { 
    if ($did == 2) || ($did == 10) {
      if ($did != 10) addschemes %a
      :init
      var %scheme = $iif($did($dname,10).sel == 1,MTS,scheme $+ $calc($did($dname,10).sel -1))
      var %bmp = $+($scriptdir,temp\,$left($nopath(%a),-4),%scheme,.bmp)
      did -ra $dname 18 $gettok($read(%a,w,NAME *),2-,32)
      did -ra $dname 19 $gettok($read(%a,w,AUTHOR *),2-,32)
      did -ra $dname 20 $gettok($read(%a,w,EMAIL *),2-,32)
      did -ra $dname 21 $gettok($read(%a,w,WEBSITE *),2-,32)
      did -ra $dname 23 $gettok($read(%a,w,VERSION *),2-,32)
      did -ra $dname 17 $gettok($read(%a,w,DESCRIPTION *),2-,32)
      :skip
      themepreview $dname %bmp
      resel
    }
    if ($did == 35) { if (%guidaMTS) { did -ra $dname 35 &Guida >> | guidainMTS } | else { did -ra $dname 35 &Guida << | guidaoutMTS } }
    var %s = $iif($did($dname,10).sel == 1,MTS,scheme $+ $calc($did($dname,10).sel -1))
    if ($did == 6) { mtsload %s %a | resel | halt }
    if ($did == 8) { var %th = mtsload %s %a | if (%theme == %th) goto noload | %th | :noload | dialog -x $dname | halt }
  }
}
alias guidainMTS { 
  unset %guidaMTS | set %guidainMTSX 590 | :diminuisci 
  if (%guidainMTSX > 440) { dialog -s theme -1 -1 %guidainMTSX 303 | dec %guidainMTSX | goto diminuisci
  }
  else { halt }
}

alias guidaoutMTS { 
  set %guidaMTS on | set %guidaoutMTSX 440 | :incrementa 
  if (%guidaoutMTSX < 590) { dialog -s theme -1 -1 %guidaoutMTSX 303 | inc %guidaoutMTSX | goto incrementa
  }
  else { halt }
}
alias themereload mtsreload

[script]
n0=; MTS Theme Engine. 
n1=; By Eric^^ <EricN@accesswave.ca>
n2=; http://ericswebpage.org (may not be up yet)
n3=;
n4=; Feel free to include this engine in your scripts.
n5=; You may edit it as you like, but keep credits alive :P
n6=;
n7=;
n8=; Thanks to Kamek, fubar and the rest of #mircscripts.org on undernet helping me find bugs.
n9=
n10=alias theme {
n11=  var %theme = $$sfile(*.mts,Select a theme:,OK)
n12=  mtsload mts %theme
n13=}
n14=alias themes {
n15=  dialog - $+ $iif($dialog(theme),v,m) theme theme
n16=}
n17=
n18=alias mtsecho {
n19=  if ($1 != !script) && (%:echo) && ($1- != $null) %:echo $1-
n20=  else return
n21=}
n22=
n23=on *:start:mtsreload
n24=on *:active:*:setfont $active
n25=
n26=alias ctcp {
n27=  if (!$2) return
n28=  var %ctcp = $iif($2 == PING,PING $ctime,$upper($2) $3-)
n29=  .raw privmsg $1 : $+ $chr(1) $+ %ctcp $+ $chr(1)
n30=  set -un %::nick $1
n31=  set -un %::chan $1
n32=  set -un %::ctcp $gettok(%ctcp,1,32)
n33=  set -un %::text $gettok(%ctcp,2-,32)
n34=  set -un %:echo echo $colour(ctcp) -at
n35=  if ($show) mtsecho $mtsget($iif($1 ischan,ctcpchanself,ctcpself))
n36=}
n37=alias ctcpreply {
n38=  if (!$2) return
n39=  var %ctcp = $upper($2) $3-
n40=  .raw notice $1 : $+ $chr(1) $+ %ctcp $+ $chr(1)
n41=  set -un %::nick $1
n42=  set -un %::ctcp $gettok(%ctcp,1,32)
n43=  set -un %::text $gettok(%ctcp,2-,32)
n44=  set -un %:echo echo $colour(ctcp) -at
n45=  if ($show) mtsecho $mtsget(ctcpreplyself)
n46=}
n47=alias notice {
n48=  if (!$2) return
n49=  set -un %::nick $1
n50=  set -un %::me $me 
n51=  set -un %::chan $1
n52=  set -un %:echo echo $colour(notice) -ati3
n53=  set -un %::text $2- 
n54=  set -un %::cmode $remove($nick($1,$me).pnick,$me)
n55=  .notice $1 %::text
n56=  if ($show) mtsecho $mtsget($iif($1 ischan,NoticeSelfChan,NoticeSelf)).null
n57=}
n58=alias me {
n59=  if ($isid) { return $me } 
n60=  else { 
n61=    describe $active $1-
n62=  }
n63=}
n64=alias describe {
n65=  if ($2 == $null) return
n66=  if ($show) {
n67=    set -un %::nick $1 
n68=    set -un %::me $me 
n69=    set -un %::chan $1
n70=    set -un %:echo echo $colour(own) -ati3
n71=    set -un %::text $2- 
n72=    set -un %::cmode $remove($nick($1,$me).pnick,$me)
n73=    var %mts = $iif($1 ischan,ActionChanSelf,ActionQuerySelf)
n74=    if (#* iswm $1) && (!$chan($1)) var %mts = TextMsgSelf
n75=    if ($chr(61) $+ = iswm $1) && (!$chat($1)) (!$query($1)) var %mts = TextMsgSelf
n76=    if (#* !iswm $1) && ($chr(61) $+ * !iswm $1) && (!$query($1)) var %mts = TextMsgSelf
n77=    if (%mts != TextMsgSelf) set -un %:echo echo $colour(own) -ti3 $1
n78=    mtsecho $mtsget(%mts)
n79=  }
n80=  .msg $1 $chr(1) $+ ACTION %::text $+ $chr(1) 
n81=}
n82=alias say {
n83=  if ($isid) { return } 
n84=  else { 
n85=    msg $active $1-
n86=  }
n87=}
n88=alias ame {
n89=  var %c = 1
n90=  while ($chan(%c)) {
n91=    if ($show) describe $chan(%c) $$1-
n92=    else .describe $chan(%c) $$1-
n93=    inc %c
n94=  }
n95=}
n96=alias amsg {
n97=  var %c = 1
n98=  while ($chan(%c)) {
n99=    if ($show) msg $chan(%c) $$1-
n100=    else .msg $chan(%c) $$1-
n101=    inc %c
n102=  }
n103=}
n104=;;
n105=
n106=alias mtsdll return $dll(sistema\dlls\mtsgen.dll,MTSPrecompile,$1-)
n107=alias mtsget {
n108=  var %cs = $hget(theme,BASECOLORS)
n109=  set -un %::c1 $gettok(%cs,1,44)
n110=  set -un %::c2 $gettok(%cs,2,44)
n111=  set -un %::c3 $gettok(%cs,3,44)
n112=  set -un %::c4 $gettok(%cs,4,44)
n113=  set -un %::timestamp $timestamp
n114=  set -un %::pre [ [ $hget(theme,prefix) ] ] | set %prefisso %::pre
n115=  set -un %::parentext [ [ $iif(%::text,$hget(theme,parentext)) ] ]
n116=  var %return = [ [ $hget(theme,$$1) ] ]
n117=  if (%return == $null) && ($prop != null) halt
n118=  if (!script* iswm %return) {
n119=    if ($gettok(%return,2-,32)) [ [ $ifmatch ] ] 
n120=    else if ($prop != null) halt
n121=    return !script
n122=  }
n123=  if (!script* !iswm %return) return %return
n124=  if ($prop != null) halt
n125=}
n126=alias mtsreload {
n127=  var %command = $iif(%theme,%theme)
n128=  if (%command) $ifmatch
n129=  else mtsload
n130=}
n131=alias mtsload {
n132=
n133=  ; mtsload [[schemeN or MTS] [filename]]
n134=
n135=  if ($1 == -s) { tokenize 32 $2- | var %silent = 1 }
n136=
n137=  var %s = $1,%f = $2-,%d = sistema\default.mts,%w = @loadtheme
n138=
n139=  if ($script($mtsget(script).null)) .unload -rs $nopath($ifmatch)
n140=  if ($hget(theme)) { 
n141=    set -un %:echo echo $colour(normal) -at 
n142=    if ($hget(theme,unload)) && (!%silent) { 
n143=      mtsecho $mtsget(unload)
n144=    }
n145=    hdel -w theme * 
n146=  }
n147=  if (!$hget(theme)) hmake theme 10
n148=  set %theme mtsload $1-
n149=  window -h %w
n150=  if ($isfile(%d)) {
n151=    loadbuf %w " $+ %d $+ "
n152=    var %l = 1
n153=    while (%l <= $line(%w,0)) {
n154=      var %line = $line(%w,%l) 
n155=      if ($gettok(%line,2,32)) && ($left(%line,1) != $chr(59)) hadd theme $mtsdll(%line)
n156=      inc %l
n157=    }
n158=  }
n159=  clear %w
n160=  if ($isfile(%f)) {
n161=    loadbuf -tMTS %w " $+ %f $+ "
n162=    var %l = 1
n163=    while (%l <= $line(%w,0)) {
n164=      var %line = $line(%w,%l) 
n165=      if ($gettok(%line,2,32)) && ($left(%line,1) != $chr(59)) hadd theme $mtsdll(%line)
n166=      inc %l
n167=    }
n168=    if (%s != MTS) {
n169=      clear %w
n170=      loadbuf -t $+ %s %w " $+ %f $+ "
n171=      var %l = 1
n172=      while (%l <= $line(%w,0)) {
n173=        var %line = $line(%w,%l) 
n174=        if ($gettok(%line,2,32)) && ($left(%line,1) != $chr(59)) hadd theme $mtsdll(%line)
n175=        inc %l
n176=      }
n177=    }
n178=  }
n179=  clear %w
n180=  if ($mtsget(SCRIPT).null) && (!$script($mtsget(SCRIPT).null)) .load -rs " $+ $+($nofile(%f),$mtsget(SCRIPT)) $+ "
n181=  var %cs = $hget(theme,BASECOLORS),%::c1 = $gettok(%cs,1,44),%::c2 = $gettok(%cs,2,44),%::c3 = $gettok(%cs,3,44),%::c4 = $gettok(%cs,4,44)
n182=  .timestamp $iif($mtsget(TIMESTAMP).null == ON,ON,OFF) 
n183=  if ($mtsget(TIMESTAMPFORMAT).null) .timestamp -f [ [ $ifmatch ] ]
n184=  if (!%silent) {
n185=    mtscolor | mtsnicklist | setfonts | bg | set -un %:echo echo $colour(normal) -at 
n186=    if ($hget(theme,load)) mtsecho $mtsget(load)
n187=  }
n188=}
n189=
n190=alias colorset {
n191=  if ($chr(44) isin $1-) { tokenize 44 $1- } 
n192=  colour background $1 | colour action $2 | colour ctcp $3 | colour highlight $4 | colour info $5 | colour info2 $6 | colour invite $7 | colour join $8 | colour kick $9 | colour mode $10 | colour nick $11 | colour normal $12 | colour notice $13 | colour notify $14 
n193=  colour other $15 | colour own $16 | colour part $17 | colour  quit $18 | colour topic $19 | colour wallops $20 | colour whois $21 | colour editbox $22 | colour editbox text $23 | colour listbox $24 | colour listbox text $25 | color grayed text $iif($26,$26,$25) | colour inactive $iif($27 isnum,$27,$22)
n194=}
n195=alias colorreset var %a = 0 | while (%a < 15) { colour -r %a | inc %a }
n196=alias mtsnicklist {
n197=  var %c = $cnick(0) 
n198=  while (%c) {
n199=    if ($cnick(%c)) { .cnick -r $cnick(%c) } 
n200=    else { .cnick -r * } 
n201=    dec %c 
n202=  } 
n203=  if ($hget(theme,CLINEME) isnum) && ($me) { .cnick $me $fixcol($hget(theme,CLINEME)) } 
n204=  if ($hget(theme,CLINEENEMY) isnum) { .cnick -i * $fixcol($hget(theme,CLINEENEMY)) } 
n205=  if ($hget(theme,CLINEFRIEND) isnum) { .cnick -ovpn * $fixcol($hget(theme,CLINEFRIEND)) } 
n206=  if ($hget(theme,CLINEOP) isnum) { .cnick * $fixcol($hget(theme,CLINEOP)) @ } 
n207=  if ($hget(theme,CLINEHOP) isnum) { .cnick * $fixcol($hget(theme,CLINEHOP)) % } 
n208=  if ($hget(theme,CLINEVOICE) isnum) { .cnick * $fixcol($hget(theme,CLINEVOICE)) + } 
n209=  if ($hget(theme,CLINEREGULAR) isnum) { .cnick -n * $fixcol($hget(theme,CLINEREGULAR)) } 
n210=}
n211=
n212=
n213=alias fixcol return $right($+(0,$calc($1 % 16)),2)
n214=alias mtscolor {
n215=  var %rgbc = $mtsget(rgbcolors)
n216=  if (!%rgbc) var %rgbc = 255,255,255 0,0,0 0,0,128 0,144,0 255,0,0 128,0,0 160,0,160 255,128,0 255,255,0 0,255,0 0,144,144 0,255,255 0,0,255 255,0,255 128,128,128 208,208,208
n217=  var %colors = $mtsget(colors)
n218=  if (!%colors) var %colors = 0,6,4,5,2,3,3,3,2,2,3,1,5,7,12,1,3,2,2,5,1,0,1,0,1,7
n219=  var %a = 1 | while %a < 17 { colour $calc(%a -1) [ $rgb( [ $gettok(%rgbc,%a,32) ] ) ] | inc %a } 
n220=  colorset %colors
n221=}
n222=
n223=on *:input:*:{
n224=  if ($left($1,1) == /) && (!$ctrlenter) || ($1 == $null) || (!$server) { return }
n225=  if ($target == Status Window) || (@* iswm $target) { return }
n226=  .signal mts.input $target $nick $reppptext($1-) | haltdef
n227=}
n228=alias reppptext { return %grassetto $+ %sottolineato $+ %textcoloring $+ $wordreplacer($1-) }
n229=on ^*:join:*:.signal mts.join $target $nick $address | haltdef
n230=on ^*:part:*:.signal mts.part $target $nick $address $1- | haltdef
n231=on ^*:quit:{
n232=  var %q = 1
n233=  while $comchan($nick,%q) {
n234=    .signal mts.quit $nick $address $comchan($nick,%q) $1-
n235=    inc %q
n236=  }
n237=  haltdef
n238=}
n239=on ^*:nick:.signal mts.nick $nick $newnick | haltdef
n240=on ^*:chat:*:.signal mts.text $+(=,$target) $nick $address $1- | haltdef
n241=on ^*:text:*:#:.signal mts.text $target $nick $address $bword($1-) | if (%caps.prot) && ($len($1-) > 20) && ($caps($1-) > 80) && ($me isop $chan) { kick # $nick No caps %pic } | haltdef
n242=on ^*:text:*:?:.signal mts.text $target $nick $address $1- | haltdef 
n243=on ^*:action:*:*:.signal mts.action $target $nick $address $1- | haltdef
n244=on ^*:notice:*:*:.signal mts.notice $target $nick $address $1- | haltdef
n245=on ^*:snotice:*:.signal mts.snotice $nick $1- | haltdef
n246=on ^*:rawmode:*:.signal mts.mode $target $nick $address $1- | haltdef
n247=on ^*:usermode:.signal mts.umode $1- | haltdef
n248=on ^*:error:*:.signal mts.error $1- | haltdef
n249=on ^*:kick:*:.signal mts.kick $target $nick $address $knick $1- | haltdef
n250=on ^*:notify:if (%notifyecho) { .signal mts.notify $nick } | if (%popupnotify) { notifylist | dialog -t notifylist $nick è online } | haltdef
n251=on ^*:unotify:if (%notifyecho) { .signal mts.unotify $nick } | if (%popupnotify) { notifylist | dialog -t notifylist $nick è online } | haltdef
n252=on *:ctcpreply:*:{
n253=  .signal mts.ctcpreply $nick $address $1- | haltdef
n254=}
n255=on ^*:topic:*:.signal mts.topic $target $nick $address $1- | haltdef
n256=on ^*:invite:*:.signal mts.invite $nick $address $chan | haltdef
n257=on ^*:wallops:*:.signal mts.wallop $nick $1- | haltdef
n258=ctcp *:*:*:{
n259=  if ($1 == dcc) return
n260=  if ($1 == PING) && ($2) .ctcpreply $nick PING $2
n261=  if ($1 == TIME) .ctcpreply $nick TIME $asctime
n262=  if ($1 == MOTFV) tokenize 32 VERSION $2-
n263=  .signal mts.ctcp $target $nick $address $1- | haltdef
n264=}
n265=raw *:*:.signal mts.raw $numeric $1- | halt
n266=;on *:DNS:{
n267=;  set -un %:echo echo $colour(info2) -at
n268=;  if (!$raddress) { mtsecho $mtsget(DNSerror) }
n269=;  if ($raddress) { set -un %::raddress $raddress | set -un %::iaddress $iaddress | set -un %::naddress $naddress | mtsecho $mtsget(DNSresolve) }
n270=;  unset %::address | haltdef
n271=;}
n272=on *:DNS:{
n273=  if ($iaddress == $null) { echo $colour(info) -a %prefisso Impossibile risolvere l'indirizzo ip per $nick }
n274=  if ($iaddress != $null) { echo $colour(info) -a %prefisso Indirizzo ip per  $nick : $iaddress }
n275=  haltdef
n276=}
n277=on *:signal:mts.*:{
n278=  scid $cid
n279=
n280=  var %event = $right($signal,-4)
n281=  set -un %::target $iif($1,$1,$active)
n282=  set -un %::chan $1
n283=  set -un %::nick $2
n284=  set -un %::address $3
n285=  set -un %::text $4-
n286=  set -un %::me $me
n287=  set -un %:echo echo $colour(info) -st
n288=
n289=  if (%event == input) {
n290=    set -un %:echo echo $colour(own) -ti3 $1
n291=    set -un %::cmode $remove($nick($1,$2).pnick,$2)
n292=    set -un %::text $3-
n293=    set -un %::address $right($address($me,5),$calc($len($address($me,5)) - $pos($address($me,5),!)))
n294=    set -un %::cnick $nick($1,$2).color
n295=    if (#* iswm $1) var %mts = TextChanSelf
n296=    elseif (#* !iswm $1) var %mts = TextQuerySelf
n297=    mtsecho $mtsget(%mts)
n298=    .msg $1 $3-
n299=  }
n300=
n301=  if (%event == text) {
n302=    var %target = $iif(#* iswm $1,$1,$2)
n303=    if (=* iswm $1) var %target = $1
n304=    set -un %:echo echo $colour(normal) -mtli3 %target
n305=    set -un %::cmode $left($remove($nick($1,$2).pnick,$2),1)
n306=    set -un %::cnick $nick($1, $2).color
n307=    if (#* iswm $1) var %mts = TextChan
n308=    elseif (#* !iswm $1) var %mts = TextQuery
n309=    mtsecho $mtsget(%mts)
n310=  }
n311=
n312=  if (%event == action) {
n313=    set -un %:echo echo $colour(action) -mtli3 $iif(#* iswm $1,$1,$2)
n314=    set -un %::cmode $left($remove($nick($1,$2).pnick,$2),1)
n315=    set -un %::cnick $nick($1, $2).color
n316=    if (#* iswm $1) var %mts = ActionChan
n317=    elseif (#* !iswm $1) var %mts = ActionQuery
n318=    mtsecho $mtsget(%mts)
n319=  }
n320=
n321=  if (%event == notice) {
n322=    set -un %:echo echo $colour(notice) -ati3
n323=    set -un %::cmode $left($remove($nick($1,$2).pnick,$2),1)
n324=    set -un %::cnick $nick($1, $2).color
n325=    if (#* iswm $1) var %mts = NoticeChan
n326=    elseif (#* !iswm $1) var %mts = Notice
n327=    mtsecho $mtsget(%mts)
n328=  }
n329=
n330=  if (%event == snotice) {
n331=    set -un %::address $address 
n332=    set -un %::nick $1
n333=    set -un %::server $1
n334=    set -un %::text $2-
n335=    set -un %:echo echo $colour(notice) -smt
n336=    mtsecho $mtsget(noticeserver)
n337=  }
n338=
n339=  if (%event == umode) {
n340=    set -un %::nick $me
n341=    set -un %::address $right($address($me,5),$calc($len($address($me,5)) - $pos($address($me,5),!)))
n342=    set -un %::modes $1-
n343=    set -un %::text $1-
n344=    set -un %:echo echo $colour(mode) -smt
n345=    mtsecho $mtsget(modeuser)
n346=  }
n347=
n348=  if (%event == error) {
n349=    set -un %:echo echo $colour(info2) -smt
n350=    set -un %::text $1-
n351=    mtsecho $mtsget(servererror)
n352=  }
n353=
n354=  if (%event == mode) {
n355=    ;.timerredonicklist -m 1 500 mtsnicklist
n356=    set -un %::cmode $left($remove($nick($1,$2).pnick,$2),1)
n357=    set -un %::modes $4-
n358=    set -un %:echo echo $colour(mode) -tm $1
n359=    mtsecho $mtsget(mode)
n360=  }
n361=
n362=  if (%event == topic) {
n363=    set -un %:echo echo $colour(topic) -mt $1
n364=    mtsecho $mtsget(topic)
n365=  }
n366=
n367=  if (%event == invite) {
n368=    set -un %::nick $1
n369=    set -un %::address $2
n370=    set -un %::chan $3
n371=    set -un %:echo echo $colour(invite) -at
n372=    mtsecho $mtsget(invite)
n373=  }
n374=
n375=  if (%event == ctcp) {
n376=    set -un %::ctcp $4 
n377=    set -un %::text $5- 
n378=    if (#* iswm $1) { set -un %:echo echo $colour(ctcp) -mt $1 | var %mts = ctcpchan }
n379=    else { set -un %:echo echo $colour(ctcp) -at | var %mts = ctcp }
n380=    mtsecho $mtsget(%mts)
n381=  }
n382=
n383=  if (%event == ctcpreply) {
n384=    if ($3 == PING) { 
n385=      set -un %::ctcp PING 
n386=      set -un %::text $iif($4 isnum,$duration($calc($ctime - $4)),$4-) 
n387=      goto echo 
n388=    }
n389=    set -un %::ctcp $3
n390=    set -un %::text $4-
n391=    :echo 
n392=    set -un %::nick $1
n393=    set -un %::address $2
n394=    set -un %:echo echo $colour(ctcp) -at 
n395=    mtsecho $mtsget(ctcpreply) 
n396=    halt
n397=  }
n398=
n399=  if (%event == join) {
n400=    var %mts = join
n401=    if ($2 == $me) { var %mts = joinself | bg | setfonts }
n402=    ;.timerredonicklist -m 1 500 mtsnicklist
n403=    set -un %:echo echo $colour(join) -mt $1
n404=    mtsecho $mtsget(%mts)
n405=  }  
n406=
n407=  if (%event == part) {
n408=    if ($2 == $me) halt
n409=    set -un %:echo echo $colour(part) -mt $1    
n410=    mtsecho $mtsget(part)
n411=  }
n412=
n413=  if (%event == kick) {
n414=    set -un %::knick $4
n415=    set -un %::kaddress $right($address($knick,0),$calc($len($address($knick,0)) -2))
n416=    set -un %::text $5-
n417=    set -un %:echo echo $colour(kick) -mt $1
n418=    if ($knick == $me) { set -un %:echo echo -st }
n419=    mtsecho $mtsget($iif($knick == $me,KICKSELF,KICK))
n420=  }
n421=
n422=  if (%event == quit) {
n423=    set -un %:echo echo $colour(quit) -mt $3
n424=    set -un %::nick $1
n425=    set -un %::address $2
n426=    set -un %::text $4-
n427=    set -un %::chan $3
n428=    mtsecho $mtsget(quit)
n429=  }
n430=
n431=  if (%event == wallops) {
n432=    set -un %::nick $1 
n433=    set -un %::text $2- 
n434=    set -un %:echo echo $colour(wallop) -st 
n435=    mtsecho $mtsget(wallop)
n436=  }
n437=
n438=  if (%event == notify) {
n439=    ;  var %ignore = insert,nicks,that,you,don't,want,to,notify,here
n440=    if ($findtok(%ignore,$1,44)) halt
n441=    set -un %::nick $1
n442=    set -un %::text $notify($1).note
n443=    set -un %:echo echo $colour(notify) -at 
n444=    mtsecho $mtsget(notify)
n445=  }
n446=
n447=  if (%event == unotify) {
n448=    ;  var %ignore = insert,nicks,that,you,don't,want,to,notify,here
n449=    if ($findtok(%ignore,$1,44)) halt
n450=    set -un %::nick $1
n451=    set -un %::text $notify($1).note
n452=    set -un %:echo echo $colour(notify) -at 
n453=    mtsecho $mtsget(unotify)
n454=  }
n455=
n456=  if (%event == nick) {
n457=    var %mts = Nick
n458=    if ($2 == $me) || ($1 == $me) { var %mts = NickSelf | ;.timerredonicklist -m 1 500 mtsnicklist }
n459=    set -un %::nick $1
n460=    set -un %::newnick $2
n461=    var %q = 1
n462=    while $comchan($2,%q) {
n463=      set -un %::chan $comchan($2,%q) 
n464=      set -un %:echo echo $colour(nick) -mt %::chan
n465=      %:echo $mtsget(%mts)
n466=      inc %q
n467=    }
n468=  }
n469=
n470=
n471=  if (%event == raw) {
n472=    var %raw = $right(00 $+ $1,3) | tokenize 32 $2-
n473=    ; /list
n474=    if (%raw == 322) halt
n475=
n476=    ; /invite
n477=    if (%raw == 341) { set -un %::nick $2 | set -un %::chan $3 | set -un %:echo echo $colour(info) -tm $3 }
n478=
n479=    ; /server
n480=    if (%RAW == 001) { set -un %:echo echo $colour(info) -st }
n481=    if (%RAW == 002) { set -un %::address $5 | set -un %::value $8 | set -un %:echo echo $colour(info) -st }
n482=    if (%RAW == 003) { set -un %::value $6- | set -un %:echo echo $colour(info) -ts }
n483=    if (%RAW == 005) { set -un %::text $2- | set -un %:echo echo $colour(info) -ts }
n484=
n485=    ; /map
n486=    if (%RAW == 015) { echo $colour(info) -ts $2- | halt }
n487=
n488=    ; /links
n489=    if (%RAW == 364) { echo $colour(info) -ts $2- | halt }
n490=
n491=    ; /motd
n492=    if (%RAW == 372) { set -un %::text $2- | set -un %:echo echo $colour(info) -ts }
n493=    if (%RAW == 374) { set -un %:echo echo $colour(info) -st }
n494=    if (%RAW == 376) { set -un %:echo echo $colour(info) -st }
n495=
n496=    ; /Topic
n497=    if (%RAW == 328) { set -un %::chan $2 | set -un %::text $3- | set -un %:echo echo $colour(topic) -mt $2 }
n498=    if (%RAW == 332) { set -un %::chan $2 | set -un %::text $3- | set -un %:echo echo $colour(topic) -mt $2 }
n499=    if (%RAW == 333) { set -un %::chan $2 | set -un %::nick $3 | set -un %::text $asctime($4) | set -un %:echo echo $colour(topic) -tm $2 }
n500=
n501=    ; /Mode
n502=    if (%RAW == 324) { if ($me ison $2) { set -un %::chan $2 | set -un %::modes $3- | set -un %:echo echo $colour(info) -tm $2 } }
n503=    if (%RAW == 329) { if ($me ison $2) { set -un %::chan $2 | set -un %::text $asctime($3) | set -un %:echo echo $colour(info) -tm $2 }  }
n504=
n505=    ; /Names
n506=    if (%RAW == 353) { set -un %::chan $3 | set -un %::text $4- | set -un %:echo echo $colour(info2) -ts } 
n507=    if (%RAW == 366) { set -un %::chan $2 | set -un %:echo echo $colour(info2) -st } 
n508=
n509=    ; /Whois
n510=    if (%RAW == 307) { set -un %::nick $2 | set -un %::isreg is | set -un %:echo echo $colour(whois) -at | set -n %mu.nick $2 | set -n %mu.isreg is }
n511=
n512=    if (%RAW == 311) { 
n513=      set -un %::nick $2 | set -un %::address $+($3,@,$4) | set -un %::realname $6- | set -n %mu.address $+($3,@,$4) | set -n %mu.realname $6- | set -un %:echo echo $colour(whois) -at | if (!%mu.whois) { inc %mu.whois | goto skip }
n514=      if (%mu.whois) { set -un %::isreg $iif(%mu.isreg,%mu.isreg,is not) | set -un %::wserver %mu.wserver | set -un %::ircop $iif(%mu.ircop,%mu.ircop,is not) | set -un %::signontime %mu.signontime | set -un %::idletime %mu.idletime | set -un %::text %mu.text | set -un %::serverinfo %mu.serverinfo | set -un %::chan %mu.chan | unset %mu.* | unset %mu.text | mtsecho $mtsget(whois) }
n515=      :skip
n516=    }
n517=    if (%RAW == 319) { set -un %::nick $2 | set -un %::chan $3- | set -un %:echo echo $colour(whois) -at | set -n %mu.chan $3- }
n518=    if (%RAW == 312) { set -un %::nick $2 | set -un %::wserver $3 | set -un %::serverinfo $4- | set -n %mu.wserver $3 | set -n %mu.serverinfo $4- | set -un %:echo echo $colour(whois) -at }
n519=    if (%RAW == 301) { set -un %::nick $2 | set -un %::text $3- | set -n %mu.text $3- | set -un %:echo echo $colour(whois) -at }
n520=    if (%RAW == 317) { set -un %::nick $2 | set -un %::idletime $3 | set -un %::signontime $asctime($4) | set -un %:echo echo $colour(whois) -at | set -n %mu.idletime $3 | set -n %mu.signontime $asctime($4) }
n521=    if (%RAW == 318) { 
n522=      set -un %::nick $2 | set -un %:echo echo $colour(whois) -at 
n523=      if (%mu.whois) { set -un %::isreg $iif(%mu.isreg,%mu.isreg,is not) | set -un %::address %mu.address | set -un %::realname %mu.realname  | set -un %::wserver %mu.wserver | set -un %::ircop $iif(%mu.ircop,%mu.ircop,is not) | set -un %::signontime %mu.signontime | set -un %::idletime %mu.idletime | set -un %::text %mu.text | set -un %::serverinfo %mu.serverinfo | set -un %::chan %mu.chan | unset %mu.* | unset %mu.text | mtsecho $mtsget(whois) }
n524=    }
n525=    if (%RAW == 313) { set -un %::nick $2 | set -un %::ircop is | set -n %mu.ircop is | set -un %:echo echo $colour(whois) -at }
n526=
n527=    ; /Who
n528=    if (%RAW == 352) { set -un %::nick $6 | set -un %::chan $2 | set -un %::address $+($3,@,$4) | set -un %::wserver $5 | set -un %::away $7 | set -un %::value $8 | set -un %::realname $9- | set -un %:echo echo $colour(whois) -st }
n529=    if (%RAW == 315) { set -un %::value $2 | set -un %:echo echo $colour(whois) -st }
n530=
n531=    ; /Whowas
n532=    if (%RAW == 314) { 
n533=      set -un %::nick $2 | set -un %::address $+($3,@,$4) | set -un %::realname $6- | set -n %mu.nick $2 | set -n %mu.address $+($3,@,$4) | set -n %mu.realname $6- | set -un %:echo echo $colour(whois) -st 
n534=      if (!%mu.whowas) { inc %mu.whowas | goto skip }
n535=      if (%mu.whowas) { set -un %::wserver %mu.wserver | unset %mu.* | mtsecho $mtsget(whowas) } | :skip
n536=    }
n537=    if (%RAW == 369) { set -un %::nick $2 | set -un %:echo echo $colour(whois) -st | if (%mu.whowas) { set -un %::wserver %mu.wserver | set -un %::nick %mu.nick | set -un %::address %mu.address | set -un %::realname %mu.realname | unset %mu.* | mtsecho $mtsget(WHOWAS) } }
n538=
n539=    ; /lusers
n540=    if (%RAW == 251) { set -un %::users $4 | set -un %::text $7 | set -un %::value $10 | set -un %:echo echo $colour(info) -st }
n541=    if (%RAW == 252) { set -un %::value $2 | set -un %:echo echo $colour(info) -st }
n542=    if (%RAW == 253) { set -un %::value $2 | set -un %:echo echo $colour(info) -st }
n543=    if (%RAW == 254) { set -un %::value $2 | set -un %:echo echo $colour(info) -st }
n544=    if (%RAW == 255) { set -un %::users $4 | set -un %::value $7 | set -un %:echo echo $colour(info) -st }
n545=
n546=    ; /userhost
n547=    if (%RAW == 302) { set -un %::nick $gettok($2,1,62) | set -un %::address $remove($gettok($2,1,62),+,-,*) |  set -un %::value $remove($gettok($2,1,62),%%::address) | set -un %:echo echo $colour(whois) -at }
n548=
n549=    ; /away
n550=    if (%RAW == 305) { set -un %:echo echo $colour(info) -st }
n551=    if (%RAW == 306) { set -un %:echo echo $colour(info) -st }
n552=
n553=    ; Errors
n554=    if (%RAW == 401) { set -un %::nick $2 | set -un %:echo echo $colour(info2) -at }
n555=    if (%RAW == 402) { set -un %::server $2 | set -un %:echo echo $colour(info2) -st }
n556=    if (%RAW == 403) { set -un %::chan $2 | set -un %:echo echo $colour(info2) -st }
n557=    if (%RAW == 404) { set -un %::chan $2 | set -un %:echo echo $colour(info2) -at }
n558=    if (%RAW == 405) { set -un %::chan $2 | set -un %:echo echo $colour(info2) -st }
n559=    if (%RAW == 406) { set -un %::nick $2 | set -un %:echo echo $colour(info2) -st }
n560=    if (%RAW == 407) { set -un %::nick $2 | set -un %::chan $2 | set -un %:echo echo $colour(info2) -st }
n561=    if (%RAW == 408) { set -un %:echo echo $colour(info2) -st }
n562=    if (%RAW == 411) { set -un %::text $5- | set -un %:echo echo $colour(info2) -st }
n563=    if (%RAW == 412) { set -un %::text $1- | set -un %:echo echo $colour(info2) -st }
n564=    if (%RAW == 421) { set -un %::text $2 | set -un %::value $2 | set -un %:echo echo $colour(info2) -st }
n565=    if (%RAW == 422) { set -un %::text $2- | set -un %:echo echo $colour(info2) -st }
n566=    if (%RAW == 411) { set -un %::server $2 | set -un %:echo echo $colour(info2) -st }
n567=    if (%RAW == 431) { set -un %:echo echo $colour(info2) -st }
n568=    if (%RAW == 432) { set -un %::nick $2 | set -un %:echo echo $colour(info2) -st }
n569=    if (%RAW == 433) { set -un %::nick $2 | set -un %:echo echo $colour(info2) -at }
n570=    if (%RAW == 406) { set -un %::nick $2 | set -un %:echo echo $colour(info2) -st }
n571=    if (%RAW == 436) { set -un %::nick $2 | set -un %:echo echo $colour(info2) -st }
n572=    if (%RAW == 437) { set -un %:echo echo $colour(info2) -st }
n573=    if (%RAW == 438) { set -un %:echo echo $colour(info2) -st }
n574=    if (%RAW == 439) { set -un %:echo echo $colour(info2) -st }
n575=    if (%RAW == 441) { set -un %::nick $2 | set -un %::chan $3 | set -un %:echo echo $colour(info2) -st }
n576=    if (%RAW == 442) { set -un %::chan $2 | set -un %:echo echo $colour(info2) -st }
n577=    if (%RAW == 443) { set -un %::nick $2 | set -un %::chan $3 | set -un %:echo echo $colour(info2) -st }
n578=    if (%RAW == 461) { set -un %::text $2 | set -un %:echo echo $colour(info2) -st }
n579=    if (%RAW == 465) { set -un %:echo echo $colour(info2) -st }
n580=    if (%RAW == 467) { set -un %::chan $2 | set -un %:echo echo $colour(info2) -at }
n581=    if (%RAW == 471) { set -un %::chan $2 | set -un %:echo echo $colour(info2) -at }
n582=    if (%RAW == 473) { set -un %::chan $2 | set -un %:echo echo $colour(info2) -at }
n583=    if (%RAW == 474) { set -un %::chan $2 | set -un %:echo echo $colour(info2) -at }
n584=    if (%RAW == 475) { set -un %::chan $2 | set -un %:echo echo $colour(info2) -at }
n585=    if (%RAW == 482) { set -un %::chan $2 | set -un %:echo echo $colour(info2) -at }
n586=    mtsecho $mtsget($+(raw,.,%raw))
n587=  }
n588=}
n589=
n590=alias setfonts {
n591=  var %i = $scon(0)
n592=  while (%i) {
n593=    scon %i
n594=    var %a = $chan(0),%b = $query(0),%c = $chat(0)
n595=    var %d = $gettok($hget(theme,fontdefault),2,44) $gettok($hget(theme,fontdefault),1,44),%e = $gettok($hget(theme,fontchan),2,44) $gettok($hget(theme,fontchan),1,44),%f = $gettok($hget(theme,fontquery),2,44) $gettok($hget(theme,fontquery),1,44),%d = $iif(%d,%d,12 tahoma),%e = $iif(%e,%e,%d),%f = $iif(%f,%f,%d)
n596=    while (%a) { font $+(-d,$iif($gettok($mtsget(fontchan),3,44) == B,b)) $chan(%a) %e | dec %a }
n597=    while (%b) { font $+(-d,$iif($gettok($mtsget(fontquery),3,44) == B,b)) $query(%b) %f | dec %b } 
n598=    while (%c) { font $+(-d,$iif($gettok($mtsget(fontquery),3,44) == B,b)) $chat(%c) %f | dec %c } 
n599=    if (%d) { 
n600=      font $+(-ds,$iif($gettok($mtsget(fontdefault),3,44) == B,b)) %d 
n601=      var %a = $window(0) | while %a { font -d $window(%a) %d | dec %a } 
n602=    }
n603=    dec %i
n604=  }
n605=} 
n606=alias setfont {
n607=  var %d = $gettok($hget(theme,fontdefault),2,44) $gettok($hget(theme,fontdefault),1,44),%e = $gettok($hget(theme,fontchan),2,44) $gettok($hget(theme,fontchan),1,44),%f = $gettok($hget(theme,fontquery),2,44) $gettok($hget(theme,fontquery),1,44),%d = $iif(%d,%d,12 tahoma),%e = $iif(%e,%e,%d),%f = $iif(%f,%f,%d)
n608=  if ($1 ischan) { font $+(-d,$iif($gettok($mtsget(fontchan),3,44) == B,b)) $1 %e | dec %a }
n609=  if ($query($1)) { font $+(-d,$iif($gettok($mtsget(fontquery),3,44) == B,b)) $1 %f | dec %b } 
n610=  if ($chat($1)) { font $+(-d,$iif($gettok($mtsget(fontquery),3,44) == B,b)) $1 %f | dec %c } 
n611=  if (%d) { font $+(-ds,$iif($gettok($mtsget(fontdefault),3,44) == B,b)) %d }
n612=} 
n613=alias bgrep {
n614=  return $iif($1,$replace($1,fill,f,center,c,stretch,r,tile,t,photo,p),x)
n615=}
n616=alias bg {  
n617=  var %i = 1,%td = $nofile($gettok(%theme,3-,32))
n618=  while $scon(%i) {
n619=    scon %i
n620=    var %ch = $chan(0),%qu = $query(0),%cha = $chat(0)
n621=    while (%ch) { background -e $+ $bgrep($gettok($hget(theme,IMAGECHAN),1,32)) $chan(%ch) $+(%td,$gettok($hget(theme,IMAGECHAN),2-,32)) | dec %ch }  
n622=    while (%qu) { background -e $+ $bgrep($gettok($hget(theme,IMAGEQUERY),1,32)) $query(%qu) $+(%td,$gettok($hget(theme,IMAGEQUERY),2-,32)) | dec %qu }
n623=    while (%cha) { background -e $+ $bgrep($gettok($hget(theme,IMAGEQUERY).null,1,32)) $chat(%cha) $+(%td,$gettok($hget(theme,IMAGEQUERY),2-,32)) | dec %cha }
n624=    background -s $+ $bgrep($gettok($hget(theme,IMAGESTATUS),1,32)) $+(%td,$gettok($hget(theme,IMAGESTATUS),2-,32))
n625=    inc %i
n626=  }
n627=  background -m $+ $bgrep($gettok($mtsget(IMAGEMIRC).null,1,32)) $+(%td,$gettok($mtsget(IMAGEMIRC).null,2-,32))
n628=  if ($isfile($+(%td,$mtsget(imageswitchbar).null))) background -h $+(%td,$mtsget(imageswitchbar).null)
n629=  if (!$isfile($+(%td,$mtsget(imageswitchbar).null))) background -hx
n630=  if ($isfile($+(%td,$mtsget(imagetoolbar).null))) background -l $+(%td,$mtsget(imagetoolbar).null)
n631=  if (!$isfile($+(%td,$mtsget(imagetoolbar).null))) background -lx
n632=  if ($isfile($+(%td,$mtsget(imagebuttons).null))) background -u $+(%td,$mtsget(imagebuttons).null)
n633=  if (!$isfile($+(%td,$mtsget(imagebuttons).null))) background -ux
n634=}
n635=
n636=
n637=dialog theme {
n638=  title Themes Manager - Ms3.1
n639=  size -1 -1 440 303
n640=  box "Temi", 1, 2 4 238 46
n641=  combo 2, 10 20 222 150, size drop sort
n642=  box "Schemi", 3, 242 4 196 46
n643=  button "Applica", 6, 280 254 74 24
n644=  button "Chiudi", 7, 200 254 74 24, cancel
n645=  button "OK", 8, 120 254 74 24, ok
n646=  combo 10, 250 22 180 150, size drop
n647=  box "Informazioni", 11, 242 50 196 196
n648=  text "Nome:", 12, 248 64 42 16
n649=  text "Autore:", 13, 248 84 44 16
n650=  text "E-mail:", 14, 248 104 46 16
n651=  text "Website:", 15, 248 124 50 16
n652=  text "Descrizione:", 16, 248 168 88 16
n653=  edit "", 17, 246 182 188 58,multi,autovs,vsbar,return,read
n654=  edit "", 18, 310 64 124 20,read,autohs
n655=  edit "", 19, 310 84 124 20,read,autohs
n656=  edit "", 20, 310 104 124 20,read,autohs
n657=  edit "", 21, 310 122 124 20,read,autohs
n658=  text "Versione:", 22, 248 144 50 16
n659=  edit "", 23, 310 140 124 20,read,autohs
n660=  box "Anteprima", 24, 2 50 238 196
n661=  icon 25, 9 67 223 171
n662=  menu &File,26
n663=  item "",27
n664=  item &Chiudi,29
n665=  menu &About,30
n666=  item altri temi...,31
n667=  item break,32
n668=  item about,33
n669=  button Genera Anteprima,34, 70 125 100 25,flat hide
n670=  button "&Guida >>", 35, 360 254 74 24
n671=  list 36, 445 10 140 250,size
n672=  text "www.mIRCscript.it", 37, 470 265 85 21
n673=  icon 38, 10 250 32 32, images\icone\theme.ico
n674=}
n675=alias -l themepreview {
n676=  if ($isfile($2-)) {
n677=    did -g $1 25 " $+ $2- $+ "
n678=    did -v $1 25
n679=    did -h $1 34
n680=  }
n681=  else {
n682=    did -h $1 25
n683=    did -v $1 34
n684=  }
n685=}
n686=alias -l addschemes did -r $dname 10 | did -a $dname 10 ::Default:: | var %a = 1 | while $read(" $+ $1- $+ ",w,scheme $+ %a *) { did -a $dname 10 $gettok($read($1-,w,scheme $+ %a *),2-,32) | inc %a } | did -c $dname 10 1
n687=alias -l resel var %a = $did($dname,2).sel,%b = $did($dname,10).sel | did -u $dname 2,10 | .timerresel -m 1 100 if ($dialog(theme)) did -c $dname 2 %a | .timerresel2 -m 1 100 if ($dialog(theme)) did -c $dname 10 %b
n688=alias -l mtspreview {
n689=  if (!$2) { if ($show) echo -at /mtspreview: insuficient parameters | halt }
n690=  if (!$isfile($2-)) { if ($show) echo -at Cannot find $2- | halt }
n691=  var %bmp = $+($scriptdir,temp\,$left($nopath($2-),-4),$1,.bmp)
n692=  write -c " $+ %bmp $+ "
n693=  if ($window(@preview)) window -c @preview
n694=  window -fopk0h +fl @preview -1 -1 223 171
n695=  hsave -o theme temp-theme.erc
n696=  if ($hget(theme)) { hdel -w theme * }
n697=  if (!$hget(theme)) hmake theme 20 
n698=  window -h @theme 
n699=  loadbuf -t $+ MTS @theme " $+ $2- $+ "
n700=  var %a = $line(@theme,0) 
n701=  while %a { 
n702=    if ($left($line(@theme,%a),1) != $chr(59)) && ($gettok($line(@theme,%a),2,32)) { 
n703=      hadd theme $mtsdll($line(@theme,%a)) 
n704=    } 
n705=    dec %a 
n706=  } 
n707=  window -c @theme
n708=  if ($1 != mts) {
n709=    window -h @theme
n710=    loadbuf -t $+ $1 @theme " $+ $2- $+ "
n711=    var %a = $line(@theme,0) 
n712=    while %a { 
n713=      if ($left($line(@theme,%a),1) != $chr(59)) && ($gettok($line(@theme,%a),2,32)) { 
n714=        hadd theme $mtsdll($line(@theme,%a)) 
n715=      } 
n716=      dec %a 
n717=    } 
n718=    window -c @theme
n719=  }
n720=  if ($hget(theme,SCRIPT)) && (!$script($hget(theme,SCRIPT))) .load -rs " $+ $+($nofile($2-),$hget(theme,SCRIPT)) $+ "
n721=  var %cs = $hget(theme,BASECOLORS),%::c1 = $gettok(%cs,1,44),%::c2 = $gettok(%cs,2,44),%::c3 = $gettok(%cs,3,44),%::c4 = $gettok(%cs,4,44)
n722=  .timestamp $iif($hget(theme,TIMESTAMP) == ON,ON,OFF) 
n723=  if ($hget(theme,TIMESTAMPFORMAT)) .timestamp -f [ [ $ifmatch ] ] 
n724=  window -fopk0h +fl @preview -1 -1 223 171
n725=  var %color = $hget(theme,colors),%rgbs = $hget(theme,RGBColors)
n726=  set -un %f.name " $+ $gettok($hget(theme,fontdefault),1,44) $+ " | set -un %f.size $gettok($hget(theme,fontdefault),2,44) | set -un %f.pos 0
n727=  drawdot @preview $gettok(%color,1,44) 1000 0 0
n728=  set -un %:echo mtsprview $gettok(%color,8,44) $gettok(%color,1,44) | set -un %::nick preview | set -un %::chan #mIRCscript | set -un %::address theme@preview.com | mtsecho $mtsget(JOIN).null
n729=  set -un %:echo mtsprview $gettok(%color,16,44) $gettok(%color,1,44) | set -un %::nick ReNTo[N] | set -un %::me ReNTo[N] | set -un %::address staff@mircscript.it | set -un %::cmode @ | set -un %::text Ciao preview! | mtsecho $mtsget(TextChanSelf).null
n730=  set -un %:echo mtsprview $gettok(%color,10,44) $gettok(%color,1,44) | set -un %::address staff@mircscript.it | set -un %::nick ReNTo[N] | set -un %::modes +v preview | mtsecho $mtsget(Mode).null
n731=  set -un %:echo mtsprview $gettok(%color,12,44) $gettok(%color,1,44) | set -un %::nick preview | set -un %::address theme@preview.com | set -un %::cmode + | set -un %::text Ciao ReNTo[N] $+ ! Qualche problema? | mtsecho $mtsget(TextChan).null
n732=  set -un %:echo mtsprview $gettok(%color,21,44) $gettok(%color,1,44) | set -un %::nick preview | set -un %::address theme@preview.com | set -un %::realname mIRCscript.it $ver | set -un %::wserver *.tin.it | set -un %::idletime 21 | set -un %::signontime Jan 4th 1987 at 5:00pm
n733=  mtsecho $mtsget(WHOIS).null | mtsecho $mtsget(raw.311).null | mtsecho $mtsget(raw.319).null | mtsecho $mtsget(raw.312).null | mtsecho $mtsget(raw.317).null | mtsecho $mtsget(raw.318).null
n734=  set -un %:echo mtsprview $gettok(%color,16,44) $gettok(%color,1,44) | set -un %::nick ReNTo[N] | set -un %::address staff@mircscript.it | set -un %::cmode @ | set -un %::me ReNTo[N] | set -un %::text Nessuno, tu? | mtsecho $mtsget(TextChanSelf).null
n735=  set -un %:echo mtsprview $gettok(%color,2,44) $gettok(%color,1,44) | set -un %::nick preview | set -un %::address theme@preview.com | set -un %::cmode + | set -un %::text tutto ok :) | mtsecho $mtsget(ActionChan).null
n736=  set -un %:echo mtsprview $gettok(%color,16,44) $gettok(%color,1,44) | set -un %::nick ReNTo[N] | set -un %::address staff@mircscript.it | set -un %::cmode @ | set -un %::nick ReNTo[N] | set -un %::text perfetto :) | set -un %::me ReNTo[N] | mtsecho $mtsget(TextChanSelf).null
n737=  set -un %:echo mtsprview $gettok(%color,12,44) $gettok(%color,1,44) | set -un %::nick preview | set -un %::address theme@preview.com | set -un %::cmode + | set -un %::text Torno tra un po', ciao. | mtsecho $mtsget(TextChan).null
n738=  set -un %:echo mtsprview $gettok(%color,18,44) $gettok(%color,1,44) | set -un %::nick preview | set -un %::address theme@preview.com | set -un %::cmode + | set -un %::text http://www.mircscript.it | mtsecho $mtsget(quit).null
n739=  set -un %:echo mtsprview $gettok(%color,8,44) $gettok(%color,1,44) | set -un %::nick you-suck | set -un %::address I@am.du.mb | set -un %::chan #mIRCscript | mtsecho $mtsget(join).null
n740=  set -un %:echo mtsprview $gettok(%color,9,44) $gettok(%color,1,44) | set -un %::nick ReNTo[N] | set -un %::address staff@mircscript.it | set -un %::text Non rientrare. | set -un %::knick you-suck | set -un %::kaddress I@am.du.mb | set -un %::chan #mIRCscript | mtsecho $mtsget(Kick).null
n741=  set -un %:echo mtsprview $gettok(%color,6,44) $gettok(%color,1,44) $colour(info) :: End of $nopath($2-) preview
n742=  set -un %:echo mtsprview $gettok(%color,6,44) $gettok(%color,1,44) $colour(info) :: MTS Theme engine by Eric^^
n743=  var %c = 1
n744=  while (%c != 16) {
n745=    var %r = [ $rgb( [ $gettok(%rgbs,%c,32) ] ) ]
n746=    if ($gettok(%r,2,44)) var %r = [ $rgb( [ %r ] ) ]
n747=    if (%r) drawreplace -r @preview $colour($calc(%c -1)).rgb [ %r ]
n748=    inc %c
n749=  }
n750=  drawsave @preview " $+ %bmp $+ "
n751=  window -c @preview
n752=  if ($hget(theme,SCRIPT)) && ($script($hget(theme,SCRIPT))) { .unload -rs $hget(theme,SCRIPT) }
n753=  hdel -w theme * | hload theme temp-theme.erc | .remove temp-theme.erc
n754=  .timestamp $iif($hget(theme,TIMESTAMP) == ON,ON,OFF) 
n755=  if ($hget(theme,TIMESTAMPFORMAT)) .timestamp -f [ [ $ifmatch ] ]
n756=  return %bmp
n757=}
n758=alias mtsprview if ($3) { drawtext -pb @preview $1 $2 %f.name %f.size 2 %f.pos $3-    | inc %f.pos $height($3-,%f.name,%f.size)  }
n759=on *:dialog:theme:*:*:{
n760=  if (!$isdir($+($scriptdir,temp))) mkdir " $+ $+($scriptdir,temp) $+ "
n761=  var %dir = $did($dname,27)
n762=  if (($devent == sclick) && ($did == 34)) || (($devent == dclick) && ($did == 25)) {
n763=    if (%theme.halt) halt
n764=    mtspreview $iif($did($dname,10).sel != 1,scheme $+ $calc($ifmatch -1),MTS) $findfile(%dir,$did($dname,2),1)
n765=    themepreview $dname $result
n766=    set -u1 %theme.halt 1
n767=    halt
n768=  }
n769=  if ($devent == menu) {
n770=    if ($did == 27) { 
n771=      var %dir = $$sdir(Select a new themes directory:)
n772=      %themedir = %dir
n773=      did -o $dname 27 %dir
n774=      did -r $dname 2
n775=      var %addthemes = $findfile(%dir,*.mts,0,did -a $dname 2 $nopath($1-))
n776=      did -c $dname 2 1
n777=      var %a = $findfile(%dir,$did($dname,2).seltext,1)
n778=      if ($isfile(%a)) {
n779=        addschemes %a
n780=        themepreview $dname
n781=      }
n782=      halt
n783=    }
n784=    if ($did == 29) dialog -c $dname
n785=    if ($did == 31) url http://www.mircscript.it
n786=    if ($did == 33) {
n787=      echo $colour(info) -a *** MTS Theme engine by Eric^^
n788=      echo $colour(info) -a *** ericn@accesswave.ca / http://ericswebpage.org
n789=    }
n790=  }
n791=  if ($devent == init) {
n792=    dialog -s $dname -1 -1 440 303
n793=    unset %guidaMTS
n794=    mdxbegin 
n795=    mdx SetFont 2,6,7,8,10,12,13,14,15,16,17,18,19,20,21,22,23,34,35,36,37 12 400 Tahoma
n796=    mdx SetFont 1,3,11,24 12 700 Tahoma
n797=    mdx SetBorderStyle 6,7,8,11,24,34,35 staticedge
n798=    mdx SetControlMDX 36 ListView report rowselect showsel single labeltip headerdrag > sistema\dlls\ $+ views.mdx
n799=    did -i theme 36 1 headerdims 120:1 | did -i theme 36 1 headertext + 0 Guida all'uso:
n800=    var %rigo = 1 | while $lines(dati\guide\mts.txt) >= %rigo { did -az theme 36 $read -l $+ %rigo dati\guide\mts.txt | inc %rigo } 
n801=    if (!$hget(theme)) hmake theme 20
n802=    var %dir = $iif(($isdir(%themedir)) && (%themedir),%themedir,$scriptdirthemes\)
n803=    did -o $dname 27 %dir
n804=    var %addthemes = $findfile(%dir,*.mts,0,did -a $dname 2 $nopath($1-))
n805=    did -c $dname 2 1
n806=    var %a = $findfile(%dir,$did($dname,2).seltext,1)
n807=    if ($isfile(%a)) {
n808=      addschemes %a
n809=      goto init
n810=    }
n811=  }
n812=  var %a = $findfile(%dir,$did($dname,2).seltext,1)
n813=  if ($devent == sclick) && (%a) { 
n814=    if ($did == 2) || ($did == 10) {
n815=      if ($did != 10) addschemes %a
n816=      :init
n817=      var %scheme = $iif($did($dname,10).sel == 1,MTS,scheme $+ $calc($did($dname,10).sel -1))
n818=      var %bmp = $+($scriptdir,temp\,$left($nopath(%a),-4),%scheme,.bmp)
n819=      did -ra $dname 18 $gettok($read(%a,w,NAME *),2-,32)
n820=      did -ra $dname 19 $gettok($read(%a,w,AUTHOR *),2-,32)
n821=      did -ra $dname 20 $gettok($read(%a,w,EMAIL *),2-,32)
n822=      did -ra $dname 21 $gettok($read(%a,w,WEBSITE *),2-,32)
n823=      did -ra $dname 23 $gettok($read(%a,w,VERSION *),2-,32)
n824=      did -ra $dname 17 $gettok($read(%a,w,DESCRIPTION *),2-,32)
n825=      :skip
n826=      themepreview $dname %bmp
n827=      resel
n828=    }
n829=    if ($did == 35) { if (%guidaMTS) { did -ra $dname 35 &Guida >> | guidainMTS } | else { did -ra $dname 35 &Guida << | guidaoutMTS } }
n830=    var %s = $iif($did($dname,10).sel == 1,MTS,scheme $+ $calc($did($dname,10).sel -1))
n831=    if ($did == 6) { mtsload %s %a | resel | halt }
n832=    if ($did == 8) { var %th = mtsload %s %a | if (%theme == %th) goto noload | %th | :noload | dialog -x $dname | halt }
n833=  }
n834=}
n835=alias guidainMTS { 
n836=  unset %guidaMTS | var %guidainMTSX 590 | :diminuisci 
n837=  if (%guidainMTSX > 440) { dialog -s theme -1 -1 %guidainMTSX 303 | dec %guidainMTSX | goto diminuisci
n838=  }
n839=  else { halt }
n840=}
n841=
n842=alias guidaoutMTS { 
n843=  set %guidaMTS on | var %guidaoutMTSX 440 | :incrementa 
n844=  if (%guidaoutMTSX < 590) { dialog -s theme -1 -1 %guidaoutMTSX 303 | inc %guidaoutMTSX | goto incrementa
n845=  }
n846=  else { halt }
n847=}
n848=alias themereload mtsreload
