;;;;Buzz-Zyrus SoulFly Multi-Gamer by d33j4y™  ©2009 EvolutionScriptz d0t c0m;;;;
;;;;;;;;;;;;Evolution Scriptz Website http://www.evolutionscriptz.com;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;Nicklogger Addon by err0r - http://tg007.net;;;;;;;;;;;;;;;;;;;

menu channel {
  History Options
  .History Per Chan
  ..$iif($istok(%History.Log,$chan,44),$style(1)) Log $replace($mid(#,3),\b,$chr(32)) : $iif($istok(%History.Log,$chan,44),set %History.Log $remtok(%History.Log,$chan,1,44),set %History.Log $addtok(%History.Log,$chan,44))
  ..$iif($istok(%History.Msg,$chan,44),$style(1)) Msg Room : $iif($istok(%History.Msg,$chan,44),set %History.Msg $remtok(%History.Msg,$chan,1,44),set %History.Msg $addtok(%History.Msg,$chan,44))
  ..$iif($istok(%History.Echo,$chan,44),$style(1)) Echo Room : $iif($istok(%History.Echo,$chan,44),set %History.Echo $remtok(%History.Echo,$chan,1,44),set %History.Echo $addtok(%History.Echo,$chan,44))
  .History Global Settings
  ..$iif(%History.NoGuest,$style(1)) No Guest Log : $iif(%History.NoGuest,unset %History.NoGuest,set %History.NoGuest on)
  ..$iif(%History.NoGhost,$style(1)) No Ghost Log : $iif(%History.NoGhost,unset %History.NoGhost,set %History.NoGhost on)
  ..-
  ..Clear Log : hfree history | $iif($exists(historyhash.txt),/remove -d historyhash.txt) | hmake history 500
  ..View Log : historylog
  -
}
on *:start: { hmake history 100 |  if ($exists(historyhash.txt)) { hload history historyhash.txt } }
on *:exit: { hsave -o history historyhash.txt | hfree history }
on !*:JOIN:#:{
  if ((!$istok(%History.Log,$chan,44)) || (%History.Join)) { halt }
  if (%History.NoGuest) && ($left($nick,1) == >) { halt }
  set -eu2 %History.Join on
  if ($hget(history,$address($nick,1))) {
    if (%History.NoGhost) {
      var %hs 1
      while ($gettok($hget(history,$address($nick,1)),%hs,44)) { if ($regsubex($nick, /[0-9]+$/gi,$null) == $v1) { set %match yes } | inc %hs  }
    }
    if (!%match) {
      if (!$istok($hget(history,$address($nick,1)),$nick,44)) {
        if ($istok(%History.Msg,$chan,44)) { msg $chan $nick has made a nick change. Previous $iif($gettok($hget(history,$address($nick,1)),2,44),nicks have been,nick was) $replace($sorttok($hget(history,$address($nick,1)),44,c),$chr(44),$chr(44) $chr(32)) }
        if ($istok(%History.Echo,$chan,44)) { echo $chan 7  $nick has made a nick change. Previous $iif($gettok($hget(history,$address($nick,1)),2,44),nicks have been,nick was) $replace($sorttok($hget(history,$address($nick,1)),44,c),$chr(44),$chr(44) $chr(32)) }
        if ($numtok($hget(history,$address($nick,1)),44) >= 5) { hadd -m history $address($nick,1) $+($deltok($hget(history,$address($nick,1)),1,44),$chr(44),$nick)  }
        else { hadd -m history $address($nick,1) $+($hget(history,$address($nick,1)),$chr(44),$nick) }
      }
    }
  }
  else { if ($istok(%History.Msg,$chan,44)) { msg $chan Haven't seen you before $nick ( logged ) } | hadd -m history $address($nick,1) $nick }
  hsave -o history historyhash.txt | unset %match
}
menu @historylog {
  Search: $iif(!$dialog(search),dialog -m hsearch hsearch)
  Remove Selected: { /hdel -s history $gettok($sline(@historylog,1),4,32) | historylog }
  Clear Log: { hfree history | $iif($exists(historyhash.txt),/remove -d historyhash.txt) | hmake history 500 | historylog }
}
alias historylog {
  if (!$window(@historylog)) { /window -blk -t2,21 +benstx @historylog verdana 11 }
  clear @historylog | aline @historylog $chr(9) Address $chr(9) Logged Nicks | aline @historylog $chr(160)
  %hh = 1 | %hhn = $hget(history, 0).item
  while (%hh <= %hhn) { aline -p @historylog $+(14,%hh,.) $chr(9) 1 $hget(history,%hh).item $chr(9) 1 $hget(history,%hh).data |  inc %hh  }
}

dialog hsearch {
  title "History Search"
  size -1 -1 150 25
  option dbu
  edit "", 1, 2 2 145 10
  button "Search/Find Next", 2, 3 13 50 10
  button "Close", 4, 105 13 41 10
  button "Remove Selected", 3, 54 13 50 10
}
on *:DIALOG:hsearch:sclick:2: {
  if (%hsearch.item != $did(hsearch,1).text) {
    set %hsearch.item $did(hsearch,1).text | set %hsearch.start 0 | set %hsearch.num $fline(@historylog,* $+ %hsearch.item $+ *,0,1)
  }
  set %hsearch.start $calc(%hsearch.start +1)
  if (%hsearch.start > %hsearch.num) { $input(End of Search,uodw,Attention!) | halt }
  /sline -s @historylog $fline(@historylog,* $+ %hsearch.item $+ *, $+ %hsearch.start $+ ,1)
}
on *:dialog:hsearch:sclick:3: { if ($gettok($sline(@historylog,1),4,32)) { /hdel -s history $gettok($sline(@historylog,1),4,32) | unset %hsearch.* | dialog -x hsearch | historylog } }
on *:dialog:hsearch:sclick:4: { unset %hsearch.* | dialog -x hsearch }
on *:dialog:hsearch:close:*: { unset %hsearch.* }
