mIRC Homepage
Posted By: NorxMAL Autocomplete with ", " added + cycling? - 07/07/12 03:54 PM
This is the code I wrote
Code:
on *:TABCOMP:#: {
  if ( $nick($chan,$1) != $null ) || ( $nick($chan,$left($1,$calc($len($1)-1))) != $null ) { 
    if ( $right($1,1) == $chr(44) ) { 
      /editbox -a left($1,1)
    }
    else {
      /editbox -ap $1 $+ $chr(44)
    }
    haltdef
  }
}


Problem is that I can't retrieve what was typed before TAB was pressed in the ON TABCOMP, and to cycle nicks one need to double tap TAB for the next one to show.
Posted By: argv0 Re: Autocomplete with ", " added + cycling? - 07/07/12 04:30 PM
FYI this belongs in "Scripts & Popups"

Originally Posted By: NorxMAL
Problem is that I can't retrieve what was typed before TAB


Sure you can, just use $editbox().selstart to get the position of the caret in the $editbox() line.
Posted By: NorxMAL Re: Autocomplete with ", " added + cycling? - 07/07/12 04:35 PM
I ask a moderator to move it now smile

Thanks for the tip smile
Posted By: NorxMAL Re: Autocomplete with ", " added + cycling? - 07/07/12 08:53 PM
I fixed it with this code smile
Code:
on *:TABCOMP:#: {
  if  ( $2 == $null ) {
    if ( %tabn != $left($1,$len(%tabn)) ) {  
      unset %tabm
      unset %tabn
    }
    if ( %tabm == $null ) { set %tabn $left($1,$calc($editbox($active).selstart -1)) }
    var %tabv 0
    :tab
    inc %tabv 1
    if ( %tabn == $left($nick($chan,%tabv),$len(%tabn)) ) { set %tabm $addtok(%tabm,$nick($chan,%tabv),58) }
    if ( $nick($chan,0) >= %tabv ) { goto tab }
    if ( %tabac >= $gettok(%tabm,0,58) ) { set %tabac 0 }
    inc %tabac 1
    /editbox -ap $gettok(%tabm,%tabac,58) $+ $chr(44)
    haltdef
  }
}


Edit : haltdef in the wrong place
Posted By: NorxMAL Re: Autocomplete with ", " added + cycling? - 08/07/12 11:59 AM
Improvement on the script
Code:
on *:TABCOMP:#: {
  if  ( $2 == $null ) {
    if ( %tabn != $left($1,$len(%tabn)) ) {
      unset %tabm
      unset %tabn
    }
    set %tabedit $left($1,$calc($editbox($active).selstart -1))
    var %tablen $len($remove($left($1,$calc($editbox($active).selstart -1)),$chr(44)))
    if ( %tabedit != $left(%tabm,%tablen) ) && ( $right(%tabedit,1) != $chr(44) ) {
      unset %tabm
    }
    if ( %tabm == $null ) { set %tabn $left($1,$calc($editbox($active).selstart -1)) }
    var %tabv 0
    :tab
    inc %tabv 1
    if ( %tabn == $left($nick($chan,%tabv),$len(%tabn)) ) { set %tabm $addtok(%tabm,$nick($chan,%tabv),58) }
    if ( $nick($chan,0) >= %tabv ) { goto tab }
    if ( %tabac >= $gettok(%tabm,0,58) ) { set %tabac 0 }
    if ( %tabm == $null ) { halt }
    inc %tabac 1
    /editbox -ap $gettok(%tabm,%tabac,58) $+ $chr(44)
    haltdef
  }
}


edit : did a /set to /var instead
edit 2 : Further improvement
Posted By: Tomao Re: Autocomplete with ", " added + cycling? - 08/07/12 03:29 PM
You can improve it a tad further by using:
Code:
unset %tabm %tabn
Or to remove all of the variables starting with %tab:
Code:
unset %tab*
Your overall snippet can be shortened even more, but good job on that nevertheless.
Posted By: r0ot Re: Autocomplete with ", " added + cycling? - 14/04/14 09:50 PM
This is an awesome script. Thank you.

I know I can make <nick> bold when it's first, but can't seem to figure out how I can do the same when <nick> is after or in the middle of a sentence.

Thanks!
Posted By: blessing Re: Autocomplete with ", " added + cycling? - 15/04/14 03:36 PM
Good snippet. Well done.

It can be improved not only for channel window. Also coloring, bold, etc. I will try if i have time.
Posted By: r0ot Re: Autocomplete with ", " added + cycling? - 15/04/14 04:27 PM
Thanks you blessing. Looking forward to it smile
Posted By: blessing Re: Autocomplete with ", " added + cycling? - 17/04/14 04:33 PM
This is what i have.

The script works on channel and chat window.
The nick can be customized and not only work on first word in editbox, but also anywhere after that.
You can put color, bold, underline on nick, or give some style to it like *nick* [~*<nick>*~] etc.

var %f1 is nick on first word in editbox
var %f2 is nick anywhere after %f1
You can edit it as you wish.

i hope it works as expected.

Code:
on *:tabcomp:*:{
  var %f1 nick:
  var %f2 *nick*
  
  var %t $target, %eb $1-, %nt $numtok(%eb,32), %f $iif(%nt > 1,%f2,%f1), %a 1
  while %a < $len(%f) {
    if $mid(%f,%a,4) == nick { dec %a | break }
    inc %a
  }
  var %aa $iif(%a,$mid(%f,1,%a)), %bb $mid(%f,$calc(%a + 5))
  var %et $gettok(%eb,1 - $calc(%nt - 1),32), %e $gettok(%eb,-1,32)
  var %ee $iif($remove(%e,%aa,%bb) == %nc.nick,%nc.nick,%e)
  var %p $iif($remove(%e,%aa,%bb) == %nc.nick,%nc.pos,$calc($editbox(%t).selstart - 1 - $iif(%nt > 1,$calc($len(%et) + 1),0))) 
  var %i $calc($nick(%t,%ee) + $iif($left(%nc.nick,%p) == $left(%ee,%p) && %nc.pos == %p,1,0))
  if %t ischan {
    var %n $nick(%t,$nc(%t,%i,%p,%ee))
    if !%n { var %n $nick(%t,$nc(%t,1,%p,%ee)) }
  }
  else { var %n $iif($+($mid(%ee,1,%p),*) iswm %t,%t) }
  if %n {
    haltdef
    var %lt $+(%aa,%n,%bb), %text $iif(%nt > 1,$+(%et,$chr(32),%lt),%lt)
    editbox -ap %text
    set -e %nc.pos %p
    set -e %nc.nick %n
  }    
}

alias -l nc {
  var %t $1, %i $2, %p $3, %ee $4, %b 1
  while $nick(%t,%i) {
    var %n $v1 
    if $+($mid(%ee,1,%p),*) iswm %n { var %b 0 | break }
    inc %i
  }
  return $calc(%i + %b) 
}
Posted By: r0ot Re: Autocomplete with ", " added + cycling? - 17/04/14 08:43 PM
Dude...its beautiful!
© mIRC Discussion Forums