[lagstuff]
style=small
oval=0
method=notice
color=16711680
face=0
text=4
[script]
n0=•[C]a§§IoPe[A] [S]cRiP[t]•
n1=
n2=;zLagbar by [F]iR[e] [A]nGe[L]
n3=
n4=on *:start:lag.start
n5=on *:unload:lag.unload
n6=
n7=alias lag.start {
n8=  if ($version < 6.01) { echo -a * Sorry, this addon does not work with your mIRC verson | unload -rs $lag.q($script) | halt }
n9=  if ($window(@zLagbar)) { window -ar @zLagbar | clear @zLagbar }
n10=  else { window -ahBfp +d @zLagbar 0 0 200 21 }
n11=  if (!%zlag.style) { %zlag.style = graph }
n12=  if (!$len(%zlag.peak)) { %zlag.peak = 5 }
n13=  if (!$len(%zlag.colour1)) { %zlag.colour1 = 16776960 }
n14=  if (!$len(%zlag.colour2)) { %zlag.colour2 = 0 }
n15=  if (!$len(%zlag.colour3)) { %zlag.colour3 = $rgb(text) }
n16=  if (!$len(%zlag.font)) { %zlag.font = Verdana }
n17=  if (!$len(%zlag.font.size)) { %zlag.font.size = 11 }
n18=  if (!$len(%zlag.delay)) { %zlag.delay = 5 }
n19=  if (!$len(%zlag.method)) { %zlag.method = pong }
n20=  if ($len(%zlag.checking)) { unset %zlag.checking  }
n21=  if (!$exists(tempcolour.bmp)) {
n22=    window -hBpf +d @temp.colour -1 -1 64 64
n23=    drawrect -fr @temp.colour $rgb(0,0,0) 1 0 0 64 64
n24=    drawsave @temp.colour tempcolour.bmp
n25=    window -c @temp.colour
n26=  }
n27=  drawrect -rf @zLagbar $rgb(face) 1 0 0 200 21
n28=  dll $lag.q($scriptdirtbwin.dll) Attach @zLagbar
n29=  dll $lag.q($scriptdirtbwin.dll) OnSize /lag.size
n30=  dll $lag.q($scriptdirtbwin.dll) Select @zLagbar
n31=  if ($appactive) { window -ar @zLagbar }
n32=  lag.size $dll($lag.q($scriptdirtbwin.dll), GetTBInfo, NOT_USED)
n33=  if (%zlag.style == graph) {
n34=    drawline -rn @zLagbar $rgb(shadow) 1 78 0 200 0
n35=    drawline -rn @zLagbar $rgb(shadow) 1 78 0 78 21
n36=    drawline -rn @zLagbar $rgb(hilight) 1 78 20 199 20
n37=    drawline -rn @zLagbar $rgb(hilight) 1 199 1 199 21
n38=    drawrect -rnf @zLagbar %zlag.colour2 1 79 1 120 19
n39=  }
n40=  if (%zlag.style == line) {
n41=    drawline -rn @zLagbar $rgb(shadow) 1 78 0 200 0
n42=    drawline -rn @zLagbar $rgb(shadow) 1 78 0 78 21
n43=    drawline -rn @zLagbar $rgb(hilight) 1 78 20 199 20
n44=    drawline -rn @zLagbar $rgb(hilight) 1 199 1 199 21
n45=    drawrect -rnf @zLagbar %zlag.colour2 1 79 1 120 19
n46=  }
n47=  if (%zlag.style == bar) {
n48=    drawline -rn @zLagbar $rgb(shadow) 1 78 5 200 5
n49=    drawline -rn @zLagbar $rgb(shadow) 1 78 5 78 16
n50=    drawline -rn @zLagbar $rgb(hilight) 1 78 15 199 15
n51=    drawline -rn @zLagbar $rgb(hilight) 1 199 5 199 16
n52=    drawrect -rnf @zLagbar %zlag.colour2 1 79 6 120 9
n53=  }
n54=  var %temp.textpos = $round($calc((21 - $height(Lag:,%zlag.font,%zlag.font.size)) / 2)),0)
n55=  drawtext -rnc @zLagbar %zlag.colour3 %zlag.font %zlag.font.size 1 %temp.textpos 75 18 Lag: N/A
n56=  drawdot @zLagbar
n57=  lag.check
n58=  .timerlag -io 0 %zlag.delay lag.check
n59=}
n60=alias lag.refresh {
n61=  drawrect -nrf @zLagbar $rgb(face) 1 0 0 200 21
n62=  if ($readini($mircini,Background,toolbar)) {
n63=    lag.temp.bkg
n64=    if (%zlag.style == bar) {
n65=      drawpic -nsl @zLagbar 78 0 122 5 $calc($gettok(%zlag.pos,1,32) + 78) $gettok(%zlag.pos,2,32) 122 5 $lag.q($scriptdirlagbkg.bmp)
n66=      drawpic -nsl @zLagbar 78 16 122 5 $calc($gettok(%zlag.pos,1,32) + 78) $calc($gettok(%zlag.pos,2,32) + 16) 122 5 $lag.q($scriptdirlagbkg.bmp)
n67=    }
n68=    drawpic -nsl @zLagbar 0 0 78 21 %zlag.pos 78 21 $lag.q($scriptdirlagbkg.bmp)
n69=    drawdot @zLagbar
n70=  }
n71=  if (%zlag.style == graph) {
n72=    drawline -rn @zLagbar $rgb(shadow) 1 78 0 200 0
n73=    drawline -rn @zLagbar $rgb(shadow) 1 78 0 78 21
n74=    drawline -rn @zLagbar $rgb(hilight) 1 78 20 199 20
n75=    drawline -rn @zLagbar $rgb(hilight) 1 199 1 199 21
n76=    drawrect -rnf @zLagbar %zlag.colour2 1 79 1 120 19
n77=  }
n78=  if (%zlag.style == line) {
n79=    drawline -rn @zLagbar $rgb(shadow) 1 78 0 200 0
n80=    drawline -rn @zLagbar $rgb(shadow) 1 78 0 78 21
n81=    drawline -rn @zLagbar $rgb(hilight) 1 78 20 199 20
n82=    drawline -rn @zLagbar $rgb(hilight) 1 199 1 199 21
n83=    drawrect -rnf @zLagbar %zlag.colour2 1 79 1 120 19
n84=  }
n85=  if (%zlag.style == bar) {
n86=    drawline -rn @zLagbar $rgb(shadow) 1 78 5 200 5
n87=    drawline -rn @zLagbar $rgb(shadow) 1 78 5 78 16
n88=    drawline -rn @zLagbar $rgb(hilight) 1 78 15 199 15
n89=    drawline -rn @zLagbar $rgb(hilight) 1 199 5 199 16
n90=    drawrect -rnf @zLagbar %zlag.colour2 1 79 6 120 9
n91=  }
n92=  var %temp.textpos = $round($calc((21 - $height(Lag:,%zlag.font,%zlag.font.size)) / 2)),0)
n93=  drawtext -rnc @zLagbar %zlag.colour3 %zlag.font %zlag.font.size 1 %temp.textpos 75 18 Lag: $iif(%zlag.current,%zlag.current $+ s,N/A)
n94=  drawdot @zLagbar
n95=}
n96=alias lag.check {
n97=  if ($appactive) { window -ar @zLagbar }
n98=  if ($server) {
n99=    if (%zlag.checking) return
n100=    if (%zlag.method == pong) { raw -q ping lag. [ $+ [ $ticks ] ] }
n101=    if (%zlag.method == ctcp) { .ctcp $me lag. [ $+ [ $ticks ] ] }
n102=    if (%zlag.method == raw) { lag. [ $+ [ $ticks ] ] }
n103=    set -u60 %zlag.checking on
n104=  }
n105=}
n106=alias lag.size {
n107=  %zlag.pos = $calc($1 - 204) $int($calc(($2 - 18) / 2))
n108=  if ($readini($mircini,Background,toolbar)) {
n109=    lag.temp.bkg
n110=    if (%zlag.style == bar) {
n111=      drawpic -nsl @zLagbar 78 0 122 5 $calc($gettok(%zlag.pos,1,32) + 78) $gettok(%zlag.pos,2,32) 122 5 $lag.q($scriptdirlagbkg.bmp)
n112=      drawpic -nsl @zLagbar 78 16 122 5 $calc($gettok(%zlag.pos,1,32) + 78) $calc($gettok(%zlag.pos,2,32) + 16) 122 5 $lag.q($scriptdirlagbkg.bmp)
n113=    }
n114=    drawpic -nsl @zLagbar 0 0 78 21 %zlag.pos 78 21 $lag.q($scriptdirlagbkg.bmp)
n115=    drawdot @zLagbar
n116=  }
n117=  window @zLagbar %zlag.pos 200 21
n118=}
n119=on *:close:@zLagbar:{ dll $lag.q($scriptdirtbwin.dll) Detach @zLagbar }
n120=menu @zLagbar {
n121=  Style
n122=  .$iif(%zlag.style == graph,$style(1)) Graph:{ set %zlag.style graph | lag.refresh }
n123=  .$iif(%zlag.style == line,$style(1)) Line Graph:{ set %zlag.style line | lag.refresh }
n124=  .$iif(%zlag.style == bar,$style(1)) Percent bar:{ set %zlag.style bar | lag.refresh }
n125=  Colour
n126=  .Text:{ set %temp.coloursel 3 | set %temp.colour3 $dialog(lagcolour.select,lagcolour.select,-2) | if ($len(%temp.colour3)) { set %zlag.colour3 %temp.colour3 | lag.refresh } | unset %temp.colour* }
n127=  .Foreground:{ set %temp.coloursel 1 | set %temp.colour1 $dialog(lagcolour.select,lagcolour.select,-2) | if ($len(%temp.colour1)) { set %zlag.colour1 %temp.colour1 | lag.refresh } | unset %temp.colour* }
n128=  .Background:{ set %temp.coloursel 2 | set %temp.colour2 $dialog(lagcolour.select,lagcolour.select,-2) | if ($len(%temp.colour2)) { set %zlag.colour2 %temp.colour2 | lag.refresh } | unset %temp.colour* }
n129=  Method
n130=  .$iif(%zlag.method == pong,$style(1)) Pong:{ %zlag.method = pong }
n131=  .$iif(%zlag.method == ctcp,$style(1)) CTCP:{ %zlag.method = ctcp }
n132=  .$iif(%zlag.method == raw,$style(1)) Raw:{ %zlag.method = raw }
n133=  Font:{ var %temp.font = $$?="Enter Font" | var %temp.font.size = $$?="Enter Font Size" | if (%temp.font) { %zlag.font = %temp.font } | if (%temp.font.size) { %zlag.font.size = %temp.font.size } }
n134=  Peak $chr(40) $+ %zlag.peak $+ s $+ $chr(41):{ var %zlag.temp.peak = $$?="Enter Peak number of seconds" | if (%zlag.temp.peak isnum) { %zlag.peak = %zlag.temp.peak } }
n135=  Delay $chr(40) $+ %zlag.delay $+ s $+ $chr(41):{ var %zlag.temp.delay = $$?="Enter Delay" | if (%zlag.temp.delay isnum) { %zlag.delay = %zlag.temp.delay | .timerlag -io 0 %zlag.delay lag.check } }
n136=  -
n137=  Reset to Defaults:{ lag.var.default }
n138=  -
n139=  Unload Lagbar:{ unload -rs $lag.q($script) | halt }
n140=}
n141=on ^*:pong:{ if (lag.* iswm $2) && (%zlag.method == pong) { lag.reply $gettok($2,2,46) | haltdef } }
n142=ctcp *:lag.*:?:{ if ($nick == $me) && ($gettok($1,2,46) isnum) && (%zlag.method == ctcp) { lag.reply $gettok($1,2,46) | haltdef } }
n143=raw 421:*:{ if (%zlag.method == raw) && (lag.* iswm $2) { lag.reply $gettok($2,2,46) | haltdef } }
n144=alias lag.reply {
n145=  if ($1) {
n146=    unset %zlag.checking
n147=    if (!%zlag.style) { %zlag.style = graph }
n148=    if (!$len(%zlag.peak)) { %zlag.peak = 5 }
n149=    if (!$len(%zlag.colour1)) { %zlag.colour1 = 16776960 }
n150=    if (!$len(%zlag.colour2)) { %zlag.colour2 = 0 }
n151=    if (!$len(%zlag.colour3)) { %zlag.colour3 = $rgb(text) }
n152=    if (!$len(%zlag.font)) { %zlag.font = Verdana }
n153=    if (!$len(%zlag.font.size)) { %zlag.font.size = 11 }
n154=    if (!$len(%zlag.method)) { %zlag.method = pong }
n155=    %zlag.old = %zlag.current
n156=    %zlag.current = $calc(($ticks - $1) / 1000)
n157=    %zlag.perc = $round($calc(%zlag.current * 100 / %zlag.peak),0)
n158=    %zlag.perc = $iif(%zlag.perc > 100,100,%zlag.perc)
n159=    %zlag.perc2 = $calc((18 / 100) * %zlag.perc)
n160=    if (%zlag.current > %zlag.highest) || (!%zlag.highest) { %zlag.highest = %zlag.current }
n161=    if (%zlag.current < %zlag.lowest) || (!%zlag.lowest) { %zlag.lowest = %zlag.current }
n162=    if ($appactive) { window -a @zLagbar }
n163=    drawrect -nrf @zLagbar $rgb(face) 1 0 0 78 21
n164=    if ($readini($mircini,Background,toolbar)) {
n165=      lag.temp.bkg
n166=      drawpic -nsl @zLagbar 0 0 78 21 %zlag.pos 78 21 $lag.q($scriptdirlagbkg.bmp)
n167=    }
n168=    var %temp.textpos = $round($calc((21 - $height(Lag:,%zlag.font,%zlag.font.size)) / 2)),0)
n169=    drawtext -nrc @zLagbar %zlag.colour3 %zlag.font %zlag.font.size 1 %temp.textpos 75 18 Lag: %zlag.current $+ s
n170=    if (%zlag.style == bar) {
n171=      if ($readini($mircini,Background,toolbar)) {
n172=        lag.temp.bkg
n173=        drawpic -nsl @zLagbar 78 0 122 5 $calc($gettok(%zlag.pos,1,32) + 78) $gettok(%zlag.pos,2,32) 122 5 $lag.q($scriptdirlagbkg.bmp)
n174=        drawpic -nsl @zLagbar 78 16 122 5 $calc($gettok(%zlag.pos,1,32) + 78) $calc($gettok(%zlag.pos,2,32) + 16) 122 5 $lag.q($scriptdirlagbkg.bmp)
n175=      }
n176=      if (!$readini($mircini,Background,toolbar)) {
n177=        drawrect -nrf @zLagbar $rgb(face) 1 78 0 122 5
n178=        drawrect -nrf @zLagbar $rgb(face) 1 78 16 122 5
n179=      }
n180=      drawrect -rnf @zLagbar %zlag.colour2 1 79 6 120 9
n181=      drawrect -nrf @zLagbar %zlag.colour1 1 79 6 $calc((120 / 100) * %zlag.perc) 9
n182=    }
n183=    if (%zlag.style == graph) || (!%zlag.style) {
n184=      drawline -rn @zLagbar %zlag.colour2 1 198 19 198 0
n185=      drawline -rn @zLagbar %zlag.colour1 1 198 19 198 $calc(19 - %zlag.perc2)
n186=      drawscroll -n @zLagbar -1 0 79 1 120 19
n187=    }
n188=    if (%zlag.style == line) {
n189=      var %zlag.oldperc = $round($calc(%zlag.old * 100 / %zlag.peak),0)
n190=      var %zlag.oldperc = $iif(%zlag.oldperc > 100,100,%zlag.oldperc)
n191=      var %zlag.oldperc2 = $calc((18 / 100) * %zlag.oldperc)
n192=      drawscroll -n @zLagbar -4 0 79 1 120 19
n193=      drawrect -rfn @zLagbar %zlag.colour2 1 194 1 5 19
n194=      drawline -rn @zLagbar %zlag.colour1 1 198 $calc(19 - %zlag.perc2) 192 $calc(19 - %zlag.oldperc2)
n195=    }
n196=    drawdot @zLagbar
n197=    unset %zlag.perc %zlag.perc2
n198=  }
n199=}
n200=alias lag {
n201=  if ($isid) {
n202=    if ($1 == highest) { return %zlag.highest }
n203=    if ($1 == lowest) { return %zlag.lowest }
n204=    return %zlag.current
n205=  }
n206=  if (!$isid) {
n207=    set %zlag.temp.message $chr(91) $+ Lag: %zlag.current $+ s $chr(40) $+ Highest: %zlag.highest $+ s Lowest: %zlag.lowest $+ s $+ $chr(41) $+ $chr(93)
n208=    if ($active ischan) || ($query($active)) { msg $active %zlag.temp.message }
n209=    else { echo $colour(info text).dd -at * %zlag.temp.message }
n210=    unset %zlag.temp.message
n211=  }
n212=}
n213=alias lag.unload { .timerlag off | dll $lag.q($scriptdirtbwin.dll) Detach @zLagbar | window -c @zLagbar }
n214=dialog lagcolour.select {
n215=  title "Select Colour"
n216=  size -1 -1 273 102
n217=  scroll "", 1, 48 7 150 16, range 255 horizontal bottom
n218=  scroll "", 2, 48 31 150 16, range 255 horizontal bottom
n219=  scroll "", 3, 48 55 150 16, range 255 horizontal bottom
n220=  button "Ok", 4, 127 79 70 21, ok
n221=  icon 5, 205 7 64 64, tempcolour.bmp, 0, noborder
n222=  edit "", 6, 3 5 40 21
n223=  edit "", 7, 3 29 40 21
n224=  edit "", 8, 3 53 40 21
n225=  edit "", 9, 30 78 70 21, result hide
n226=  button "Cancel", 10, 201 79 70 21, cancel
n227=}
n228=on *:dialog:lagcolour.select:init:*:{
n229=  if (%temp.coloursel) {
n230=    set %temp.colourrgb $rgb(%zlag.colour [ $+ [ %temp.coloursel ] ])
n231=    did -a $dname 6 $gettok(%temp.colourrgb,1,44) | did -a $dname 7 $gettok(%temp.colourrgb,2,44) | did -a $dname 8 $gettok(%temp.colourrgb,3,44) | did -a $dname 9 %zlag.colour [ $+ [ %temp.coloursel ] ]
n232=    did -c $dname 1 $gettok(%temp.colourrgb,1,44) | did -c $dname 2 $gettok(%temp.colourrgb,2,44) | did -c $dname 3 $gettok(%temp.colourrgb,3,44)
n233=  }
n234=  if (!%temp.coloursel) {
n235=    did -a $dname 6 0 | did -a $dname 7 0 | did -a $dname 8 0 | did -a $dname 9 0
n236=  }
n237=  window -hBpf +d @temp.colour -1 -1 64 64
n238=  drawrect -fr @temp.colour $rgb($did(6),$did(7),$did(8)) 1 0 0 64 64
n239=  drawsave @temp.colour tempcolour.bmp
n240=  did -g $dname 5 tempcolour.bmp
n241=}
n242=on *:dialog:lagcolour.select:scroll:*:{
n243=  if ($did == 1) { did -o $dname 6 1 $did(1).sel }
n244=  if ($did == 2) { did -o $dname 7 1 $did(2).sel }
n245=  if ($did == 3) { did -o $dname 8 1 $did(3).sel }
n246=  if ($istok(1 2 3,$did,32)) {
n247=    drawrect -fr @temp.colour $rgb($did(6),$did(7),$did(8)) 1 0 0 64 64
n248=    drawsave @temp.colour tempcolour.bmp
n249=    did -g $dname 5 tempcolour.bmp
n250=    did -o $dname 9 1 $rgb($did(6),$did(7),$did(8))
n251=  }
n252=}
n253=on *:dialog:lagcolour.select:edit:*:{
n254=  if ($did == 6) { if (!$len($did(6))) || ($did(6) !isnum) { did -o $dname 6 1 0 } | did -c $dname 1 $did(6) }
n255=  if ($did == 7) { if (!$len($did(7))) || ($did(7) !isnum) { did -o $dname 7 1 0 } | did -c $dname 2 $did(7) }
n256=  if ($did == 8) { if (!$len($did(8))) || ($did(8) !isnum) { did -o $dname 8 1 0 } | did -c $dname 3 $did(8) }
n257=  if ($istok(6 7 8,$did,32)) {
n258=    drawrect -fr @temp.colour $rgb($did(6),$did(7),$did(8)) 1 0 0 64 64
n259=    drawsave @temp.colour tempcolour.bmp
n260=    did -g $dname 5 tempcolour.bmp
n261=    did -o $dname 9 1 $rgb($did(6),$did(7),$did(8))
n262=  }
n263=}
n264=on *:dialog:lagcolour.select:close:*:{ window -c @temp.colour }
n265=alias lag.temp.bkg {
n266=  if ($exists($readini($mircini,Background,Toolbar))) {
n267=    if (!%zlag.temp.crc) || (%zlag.temp.crc != $crc($readini($mircini,Background,Toolbar))) {
n268=      window -hBfp +d @zlagtemp -1 -1 $window(-1).dw 100
n269=      drawpic -sl @zlagtemp 0 0 $window(-1).dw 100 $lag.q($readini($mircini,Background,Toolbar))
n270=      drawsave @zlagtemp $lag.q($scriptdirlagbkg.bmp)
n271=      window -c @zlagtemp
n272=      %zlag.temp.crc = $crc($readini($mircini,Background,Toolbar))
n273=    }
n274=  }
n275=}
n276=alias lag.var.default {
n277=  %zlag.peak = 5
n278=  %zlag.colour1 = 16776960
n279=  %zlag.colour2 = 0
n280=  %zlag.colour3 = $rgb(text)
n281=  %zlag.font = Verdana
n282=  %zlag.font.size = 11
n283=  %zlag.delay = 5
n284=}
n285=alias lag.q { return " $+ $1- $+ " }
