;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;  mIRC Counter-Strike Scorebot  ;;
;;  by bunkahumpa                 ;;
;;  bh@scriptsurge.org            ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

on *:unload:{
  sockclose scorebot*
  unset %scorebot.*
  if ($hget(cs_scorebot)) hfree cs_scorebot
}

menu @cs_scorebot {
  Clear Log Window:clear @cs_scorebot
}

alias scorebot {
  if (!$dialog(cs_scorebot)) dialog -m cs_scorebot cs_scorebot
  else dialog -v cs_scorebot
}

alias -l chans {
  did -r cs_scorebot 13
  var %x = 1
  while (%x <= $chan(0)) {
    did -a cs_scorebot 13 $chan(%x)
    inc %x
  }
  did -c cs_scorebot 13 1
}

alias -l ipverify {
  ;; Checks for a valid ip/port
  ;; Usage: $ipverify(ip[:port])[.ip|port]
  var %regex = /((?:\d{1,3}\.){3}\d{1,3})((?::|\s)\d{1,5})*$/
  if ($regex(ip,$1,%regex)) {
    var %x = 1
    while (%x <= $gettok($regml(ip,1),0,46)) {
      if ($gettok($regml(ip,1),%x,46) > 255) return Invalid
      inc %x
    }
    if ($prop == ip) return Valid - $regml(ip,1)
    if ($prop == port) {
      if ($regml(ip,2)) {
        if ($right($ifmatch,-1) <= 65535) return Valid - $ifmatch
        else return Invalid
      }
    }
    else return Valid - $iif($regml(ip,2),$regml(ip,1) $+ $regml(ip,2),$regml(ip,1))
  }
  else return Invalid
}

dialog cs_scorebot {
  title "mIRC Counter-Strike Scorebot"
  size -1 -1 167 101
  option dbu
  tab "Setup", 2, 1 -2 165 87
  text "Server IP Address:", 3, 5 19 46 8, tab 2
  edit "", 4, 82 18 80 10, autohs tab 2
  text "RCON Password:", 5, 5 32 42 8, tab 2
  edit "", 6, 82 31 80 10, pass autohs tab 2
  text "Show in-game chat?", 7, 5 43 51 8, tab 2
  radio "No", 8, 82 42 16 10, tab 2 left
  radio "Yes", 9, 143 42 20 10, tab 2
  text "Network:", 10, 5 54 25 8, tab 2
  combo 11, 82 53 80 38, tab 2 size vsbar drop
  text "Channel:", 12, 5 68 24 8, tab 2
  combo 13, 82 67 80 38, tab 2 size drop
  tab "Server Log", 1
  button , 17, 5 15 157 67, tab 1
  button "Start", 15, 1 88 37 12
  button "Stop", 16, 42 88 37 12, disable
  button "Close", 14, 129 88 37 12, ok
}

on *:dialog:cs_scorebot:init:0:{
  dll $mdx MarkDialog $dname
  dll $mdx SetMircVersion $version
  dll $mdx SetControlMDX $dname 17 Window > $dialogm
  if ($window(@cs_scorebot)) window -c @cs_scorebot
  window -h @cs_scorebot Tahoma -7
  did -a $dname 17 grab $window(@cs_scorebot).hwnd @cs_scorebot
  did -v $dname 17
  did -c $dname 8
  var %x = 1
  while (%x <= $scon(0)) {
    did -a $dname 11 $iif(!$scon(%x).network,$scon(%x).server,$scon(%x).network)
    if ($scon(%x).network == $network) var %network = %x
    inc %x
  }
  did -c $dname 11 %network 1
  chans
}

on *:dialog:cs_scorebot:sclick:*:{
  if ($did == 11) {
    if ($did($dname,11) == $network) chans
    else {
      var %x = 1
      while (%x <= $scon(0)) {
        if ($did($dname,11) == $scon(%x).network) scon %x chans
        inc %x
      }
    }
  }
  if ($did == 15) {
    var %ip = $did($dname,4), %rcon = $did($dname,6)
    if ($gettok($ipverify(%ip),1,32) != Valid) {
      var %msg = $input(That IP address is not valid.,o)
      return
    }
    if (%rcon == $null) {
      var %msg = $input(Please enter an RCON password.,o)
      return
    }
    if (!$did($dname,13)) {
      var %msg = $input(You cannot run a scorebot without selecting a channel.,o)
      return
    }
    set %scorebot.network $did($dname,11).sel
    set %scorebot.chan $did($dname,13)
    if ($did($dname,9).state == 1) set %scorebot.says 1
    else unset %scorebot.says
    set %scorebot.ip $gettok(%ip,1,58)
    set %scorebot.port $gettok(%ip,2,58)
    set %scorebot.rcon %rcon
    if (%scorebot.port == $null) set %scorebot.port 27015
    challenge %scorebot.ip %scorebot.port
    did -b $dname 15
    did -e $dname 16
    did -f $dname 1
  }
  if ($did == 16) {
    if ($sock(scorebot)) nologs %scorebot.ip %scorebot.port %scorebot.challenge %scorebot.rcon
  }
}

on *:dialog:cs_scorebot:close:0:{
  if ($sock(scorebot)) nologs %scorebot.ip %scorebot.port %scorebot.challenge %scorebot.rcon
  sockclose scorebot
  sockclose scorebotcommand
  unset %scorebot.*
  if ($hget(cs_scorebot)) hfree cs_scorebot
}

alias -l dialogm return $shortfn($scriptdirdialog.mdx)
alias -l mdx return $shortfn($scriptdirmdx.dll)
alias -l challenge sockudp -kn scorebot 7131 $1 $2 ˙˙˙˙challenge rcon
alias -l logs {
  var %ip = $1, %port = $2, %challenge = $3, %password = $4-
  ; remove your address from the server in case it's already there (prevents double sending)
  sockudp -kn scorebot %ip %port ˙˙˙˙rcon %challenge " $+ %password $+ " logaddress_del $ip 7131
  ; enable server log stuff
  sockudp -kn scorebotcommand %ip %port ˙˙˙˙rcon %challenge " $+ %password $+ " mp_logmessages 1
  sockudp -kn scorebotcommand %ip %port ˙˙˙˙rcon %challenge " $+ %password $+ " mp_logfile 1
  ; enable logging
  sockudp -kn scorebotcommand %ip %port ˙˙˙˙rcon %challenge " $+ %password $+ " log on
  ; set log address
  set %scorebot.first 1
  sockudp -kn scorebot 7131 %ip %port ˙˙˙˙rcon %challenge " $+ %password $+ " logaddress_add $ip 7131
}
alias -l nologs {
  var %ip = $1, %port = $2, %challenge = $3, %password = $4-
  sockudp -kn scorebot %ip %port ˙˙˙˙rcon %challenge " $+ %password $+ " logaddress_del $ip 7131
  sockclose scorebotcommand
  sockclose scorebot
  scon %scorebot.network
  if ($me ison %scorebot.chan) scon %scorebot.network msg %scorebot.chan *** mIRC Counter-Strike Scorebot STOPPED ***
  if ($dialog(cs_scorebot)) {
    did -b cs_scorebot 16
    did -e cs_scorebot 15
  }
}
alias -l scorebotquery {
  sockclose scorebotquery
  sockudp -k scorebotquery $1 $2 $str($chr(255),4) $+ infostring
}

on *:udpread:scorebotquery:{
  sockread &temp
  breplace &temp 0 160
  var %return = $bvar(&temp,1,$bvar(&temp,0)).text, %name = $gettok(%return,21,92), %map = $gettok(%return,23,92), %players = $+($gettok(%return,7,92),/,$gettok(%return,13,92))
  scon %scorebot.network
  if ($me ison %scorebot.chan) scon %scorebot.network msg %scorebot.chan Server Name: %name - Map: %map - Players: %players
  sockclose scorebotquery
} 

on *:udpread:scorebotcommand:{
  if ($sockerr > 0) return
  :nextread
  var %data | sockread -f %data
  if ($sockbr == 0) return
  if (%data == $null) goto nextread
  else {
    var %temp | sockread -f %temp
    if (%temp) {
      if ($dialog(cs_scorebot)) aline -p @cs_scorebot $asctime([HH:nn:ss]) %temp
    }
  }
  goto nextread
}

on *:udpread:scorebot:{
  if ($sockerr > 0) return
  :nextread
  var %data | sockread -f %data
  if ($sockbr == 0) return
  if (%data == $null) goto nextread
  else {
    if (*"*from*"*"* iswm %data) var %data = $null
    if ($gettok(%data,1,32) == ˙˙˙˙challenge) {
      set %scorebot.challenge $gettok(%data,3,32)
      logs %scorebot.ip %scorebot.port %scorebot.challenge %scorebot.rcon
      var %data = $null
      goto nextread
    }
    if (Couldn't find address in list isin %data) var %data = $null
    if (No addresses added yet isin %data) var %data = $null
    if (˙˙˙˙ldeleting: isin %data) var %data = $null
    if (%data == ˙˙˙˙lBad rcon_password.) {
      var %data = $null
      sockclose scorebot
      if ($dialog(cs_scorebot)) {
        aline -p @cs_scorebot $asctime([HH:nn:ss]) --> Bad RCON Password.
        did -b cs_scorebot 16
        did -e cs_scorebot 15
      }
    }
    else {
      if (%scorebot.first) {
        unset %scorebot.first
        scon %scorebot.network
        if ($me ison %scorebot.chan) scon %scorebot.network msg %scorebot.chan *** mIRC Counter-Strike Scorebot STARTED ***
        scorebotquery %scorebot.ip %scorebot.port
        if ($hget(cs_scorebot)) hfree cs_scorebot
        hmake cs_scorebot 10
      }
    }
    if ($gettok(%data,1,32) == ˙˙˙˙log) var %data = $gettok(%data,6-,32)
    if ($gettok(%data,1-5,32) == Server logging data to file) {
      if ($dialog(cs_scorebot)) aline -p @cs_scorebot $asctime([HH:nn:ss]) %data
      var %data = $null
    }
    if (logaddress isin $gettok(%data,1,32)) var %data = $null
    if ($gettok(%data,1,32) == L) {
      if ($dialog(cs_scorebot)) aline -p @cs_scorebot $asctime([HH:nn:ss]) %data
      var %data = $null
    }
    if ($gettok(%data,1,32) == $+($chr(91),ADMIN,$chr(93))) var %data = $null
    if ($gettok(%data,1,32) == $+($chr(91),META,$chr(93))) var %data = $null
    if ($gettok(%data,1,32) == $+($chr(91),STATSME,$chr(93))) var %data = $null
    if ($gettok(%data,1,32) == ERROR:) var %data = $null
    if ($regex(%data,/"(.*?)(?:<[^>]+>){2}<([^>]*)>"/g)) {
      var %scorebot.player = $regml(1)
      var %scorebot.team = $regml(2)
      if (($regml(3)) && ($regml(4))) {
        var %scorebot.player2 = $regml(3)
        var %scorebot.team2 = $regml(4)
        if (%scorebot.team2 == CT) {
          var %scorebot.player2 = 12 $+ %scorebot.player2
          var %scorebot.team2 = 12CT
        }
        if (%scorebot.team2 == TERRORIST) {
          var %scorebot.player2 = 04 $+ %scorebot.player2
          var %scorebot.team2 = 4T
        }
      }
      if (%scorebot.team == CT) {
        var %scorebot.player = 12 $+ %scorebot.player
        var %scorebot.team = 12CT
      }
      if (%scorebot.team == TERRORIST) {
        var %scorebot.player = 04 $+ %scorebot.player
        var %scorebot.team = 4T
      }
      else {
        var %scorebot.player = 03 $+ %scorebot.player
        var %scorebot.team = 3 $+ %scorebot.team
      }
    }
  }
  if (say_team isin $gettok(%data,2,34)) {
    var %data = %scorebot.player $+ ( $+ %scorebot.team $+ ) 3says (team): $gettok(%data,3,34)
    if (!%scorebot.says) {
      if ($dialog(cs_scorebot)) aline -p @cs_scorebot $asctime([HH:nn:ss]) %data
      var %data = $null
    }
  }
  elseif (say isin $gettok(%data,2,34)) {
    var %data = %scorebot.player $+ ( $+ %scorebot.team $+ ) 3says: $gettok(%data,3,34)
    if (!%scorebot.says) {
      if ($dialog(cs_scorebot)) aline -p @cs_scorebot $asctime([HH:nn:ss]) %data
      var %data = $null
    }
  }
  else {
    if (Rcon: "rcon* iswm %data) var %data = $null
    if (%data == ") var %data = $null
    if (Server cvar* iswm %data) var %data = $null
    if (Server say "* iswm %data) var %data = 3Server say: $iif($right($gettok(%data,3-,32),1) != ",$gettok(%data,3-,32) $+ ",$gettok(%data,3-,32))
    if (Log file* iswm %data) var %data = $null
    if (*connected, address "*:*" iswm %data) var %data = %scorebot.player 3connected
    if (*STEAM USERID validated iswm %data) var %data = $null
    if (*entered the game iswm %data) var %data = %scorebot.player 3entered the game
    if (*disconnected iswm %data) {
      var %player = $replace(%scorebot.player,$chr(32),_)
      if ($left(%player,3) == $+($chr(3),03)) var %player = $remove(%player,$left(%player,3))
      hdel cs_scorebot %player
      var %data = %scorebot.player 3disconnected
    }
    if (changed name to isin $gettok(%data,2,34)) {
      if (12 isin %scorebot.player) {
        var %player = $replace(%scorebot.player,$chr(32),_)
        if ($left(%player,3) == $+($chr(3),03)) var %player = $remove(%player,$left(%player,3))
        var %score = $hget(cs_scorebot,%player)
        var %player_new = $replace($gettok(%data,3,34),$chr(32),_)
        hadd -m cs_scorebot $+(12,%player_new) $iif(%score == $null,$+(0,$chr(255),0),%score)
        var %data = %scorebot.player 3changed name to 12 $+ $gettok(%data,3,34)
      }
      if (04 isin %scorebot.player) {
        var %player = $replace(%scorebot.player,$chr(32),_)
        if ($left(%player,3) == $+($chr(3),03)) var %player = $remove(%player,$left(%player,3))
        var %score = $hget(cs_scorebot,%player)
        var %player_new = $replace($gettok(%data,3,34),$chr(32),_)
        hadd -m cs_scorebot $+(04,%player_new) $iif(%score == $null,$+(0,$chr(255),0),%score)
        var %data = %scorebot.player 3changed name to 04 $+ $gettok(%data,3,34)
      }
      if ($hget(cs_scorebot,%player)) hdel cs_scorebot %player
    }
    if (%data == World triggered "Round_End") {
      if ($hget(cs_scorebot,cs_scorebotbomber)) hdel cs_scorebot cs_scorebotbomber
      var %data = $null
    }
    if (%data == World triggered "Round_Start") var %data = $null
    if (Kick: " isin %data) {
      var %player = $replace(%scorebot.player,$chr(32),_)
      if ($left(%player,3) == $+($chr(3),03)) var %player = $remove(%player,$left(%player,3))
      if ($hget(cs_scorebot)) hdel cs_scorebot %player
      var %data = %scorebot.player was kicked by console
    }
    if (triggered "Game_idle_kick" (auto) isin %data) {
      var %player = $replace(%scorebot.player,%chr(32),_)
      if ($left(%player,3) == $+($chr(3),03)) var %player = $remove(%player,$left(%player,3))
      if ($hget(cs_scorebot)) hdel cs_scorebot %player
      var %data = %scorebot.player was auto-kicked for being idle too long
    }
    if (World triggered "Game_Commencing" isin %data) {
      if ($hget(cs_scorebot)) hfree cs_scorebot
      var %data = $null
    }
    if (Loading map "*" iswm %data) var %data = 03Loading Map: $gettok(%data,3,32)
    if (Started map "*" $chr(40) $+ CRC "*" $+ $chr(41) iswm %data) var %data = 03Started Map: $gettok(%data,3,32)
    if (World triggered "Round_Draw" isin %data) var %data = *** 3Round Draw! 12 $+ $remove($gettok(%data,4-5,32),") 4 $+ $remove($gettok(%data,6-7,32),")
    if (World triggered "Restart_Round_ isin %data) {
      if ($hget(cs_scorebot)) hfree cs_scorebot
      var %seconds = $gettok($gettok(%data,3,95),1,40)
      if (%seconds == 1) var %secondsword = second
      else var %secondsword = seconds
      var %data = *** 3Restart Round:  $+ %seconds $+  %secondsword
    }
    if (triggered "Spawned_With_The_Bomb" isin %data) var %data = %scorebot.player 3spawned with the Bomb
    if (Team "CT" scored isin %data) var %data = 12CT: $remove($gettok(%data,4,32),")
    if (Team "TERRORIST" scored isin %data) var %data = 4T: $remove($gettok(%data,4,32),")
    if (joined team "CT" isin %data) {
      var %player = $replace(%scorebot.player,$chr(32),_)
      if ($left(%player,3) == $+($chr(3),03)) var %player = $remove(%player,$left(%player,3))
      var %score = $hget(cs_scorebot,%player)
      if ($hget(cs_scorebot)) hdel cs_scorebot %player
      hadd -m cs_scorebot $+(12,$strip(%player)) $iif(%score == $null,$+(0,$chr(255),0),%score)
      var %data = %scorebot.player 3joined team 12CT
    }
    if (joined team "TERRORIST" isin %data) {
      var %player = $replace(%scorebot.player,$chr(32),_)
      if ($left(%player,3) == $+($chr(3),03)) var %player = $remove(%player,$left(%player,3))
      var %score = $hget(cs_scorebot,%player)
      if ($hget(cs_scorebot)) hdel cs_scorebot %player
      hadd -m cs_scorebot $+(04,$strip(%player)) $iif(%score == $null,$+(0,$chr(255),0),%score)
      var %data = %scorebot.player 3joined team 4T
    }
    if (joined team "SPECTATOR" isin %data) {
      var %player = $replace(%scorebot.player,$chr(32),_)
      if ($hget(cs_scorebot)) hdel cs_scorebot %player
      var %data = %scorebot.player joined the spectators
    }
    if (committed suicide with "world" isin %data) {
      var %player = $replace(%scorebot.player,$chr(32),_)
      if ($left(%player,3) == $+($chr(3),03)) var %player = $remove(%player,$left(%player,3))
      var %kills = $calc($gettok($hget(cs_scorebot,%player),1,255) - 1), %deaths = $calc($gettok($hget(cs_scorebot,%player),2,255) + 1)
      hadd -m cs_scorebot $iif($left(%player,3) == $+($chr(3),03),$remove(%player,$left(%player,3)),%player) $+(%kills,$chr(255),%deaths)
      var %data = %scorebot.player $+ ( $+ %scorebot.team $+ $+(:,%kills,/,%deaths) $+ ) 3typed kill in console
    }
    if (committed suicide with "worldspawn" (world) isin %data) {
      var %player = $replace(%scorebot.player,$chr(32),_)
      if ($left(%player,3) == $+($chr(3),03)) var %player = $remove(%player,$left(%player,3))
      var %kills = $gettok($hget(cs_scorebot,%player),1,255), %deaths = $calc($gettok($hget(cs_scorebot,%player),2,255) + 1)
      if (%kills = $null) var %kills = 0
      hadd -m cs_scorebot $iif($left(%player,3) == $+($chr(3),03),$remove(%player,$left(%player,3)),%player) $+(%kills,$chr(255),%deaths)
      var %data = %scorebot.player $+ ( $+ %scorebot.team $+ $+(:,%kills,/,%deaths) $+ ) 3fell and died
    }
    if (committed suicide with "grenade" isin %data) {
      var %player = $replace(%scorebot.player,$chr(32),_)
      if ($left(%player,3) == $+($chr(3),03)) var %player = $remove(%player,$left(%player,3))
      var %kills = $calc($gettok($hget(cs_scorebot,%player),1,255) - 1), %deaths = $calc($gettok($hget(cs_scorebot,%player),2,255) + 1)
      hadd -m cs_scorebot $iif($left(%player,3) == $+($chr(3),03),$remove(%player,$left(%player,3)),%player) $+(%kills,$chr(255),%deaths)
      var %data = %scorebot.player $+ ( $+ %scorebot.team $+ $+(:,%kills,/,%deaths) $+ ) 3commited suicide with grenade
    }
    if (triggered "Dropped_The_Bomb" isin %data) var %data = %scorebot.player 3dropped the bomb
    if (triggered "Got_The_Bomb" isin %data) var %data = %scorebot.player 3got the bomb
    if (triggered "Planted_The_Bomb" isin %data) {
      var %player = $replace(%scorebot.player,$chr(32),_)
      if ($left(%player,3) == $+($chr(3),03)) var %player = $remove(%player,$left(%player,3))
      hadd -m cs_scorebot cs_scorebotbomber %player
      var %data = %scorebot.player 3planted the bomb
    }
    if (triggered "Begin_Bomb_Defuse_Without_Kit" isin %data) var %data = %scorebot.player 3started defusing the bomb without a kit
    if (triggered "Begin_Bomb_Defuse_With_Kit" isin %data) var %data = %scorebot.player 3started defusing the bomb with a kit
    if (triggered "Defused_The_Bomb" isin %data) {
      hdel cs_scorebot cs_scorebotbomber
      var %player = $replace(%scorebot.player,$chr(32),_)
      if ($left(%player,3) == $+($chr(3),03)) var %player = $remove(%player,$left(%player,3))
      var %kills = $gettok($hget(cs_scorebot,%player),1,255), %deaths = $gettok($hget(cs_scorebot,%player),2,255)
      hadd -m cs_scorebot %player $+($calc(%kills + 3),$chr(255),$iif(%deaths == $null,0,%deaths))
      var %data = %scorebot.player 3defused the bomb (+3 kills)
    }
    if (Team "TERRORIST" triggered "Target_Bombed" isin %data) {
      var %player = $hget(cs_scorebot,cs_scorebotbomber)
      if ($left(%player,3) == $+($chr(3),03)) var %player = $remove(%player,$left(%player,3))
      var %kills = $gettok($hget(cs_scorebot,%player),1,255), %deaths = $gettok($hget(cs_scorebot,%player),2,255)
      hadd -m cs_scorebot %player $+($calc(%kills + 3),$chr(255),$iif(%deaths == $null,0,%deaths))
      var %data = *** 4Terrorists Win: Target Bombed 12 $+ $remove($gettok(%data,5-6,32),") 4 $+ $remove($gettok(%data,7-8,32),") (+3 kills for $hget(cs_scorebot,cs_scorebotbomber) $+ )
      hdel cs_scorebot cs_scorebotbomber
    }
    if (Team "TERRORIST" triggered "Terrorists_Win" isin %data) {
      hdel cs_scorebot cs_scorebotbomber
      var %data = *** 4Terrorists Win: Eliminated Opponents 12 $+ $remove($gettok(%data,5-6,32),") 4 $+ $remove($gettok(%data,7-8,32),")
    }
    if (Team "CT" triggered "Target_Saved" isin %data) var %data = *** 12Counter-Terrorists Win: Target Saved 12 $+ $remove($gettok(%data,5-6,32),") 4 $+ $remove($gettok(%data,7-8,32),")
    if (Team "CT" triggered "Bomb_Defused" isin %data) var %data = *** 12Counter-Terrorists Win: Bomb Defused 12 $+ $remove($gettok(%data,5-6,32),") 4 $+ $remove($gettok(%data,7-8,32),")
    if (Team "CT" triggered "CTs_Win" isin %data) var %data = *** 12Counter-Terrorists Win: Eliminated Opponents 12 $+ $remove($gettok(%data,5-6,32),") 4 $+ $remove($gettok(%data,7-8,32),")
    if (*attacked*with* iswm %data) var %data = $null
    if (*killed*with* iswm %data) {
      var %player1 = $replace(%scorebot.player,$chr(32),_), %player2 = $replace(%scorebot.player2,$chr(32),_)
      if ($left(%player1,3) == $+($chr(3),03)) var %player1 = $remove(%player1,$left(%player1,3))
      if ($left(%player2,3) == $+($chr(3),03)) var %player2 = $remove(%player2,$left(%player2,3))
      if ($left(%player1,3) != $left(%player2,3)) {
        var %kills1 = $calc($gettok($hget(cs_scorebot,%player1),1,255) + 1), %kills2 = $gettok($hget(cs_scorebot,%player2),1,255)
        var %deaths1 = $gettok($hget(cs_scorebot,%player1),2,255), %deaths2 = $calc($gettok($hget(cs_scorebot,%player2),2,255) + 1)
        if (%deaths1 == $null) var %deaths1 = 0
        if (%kills2 == $null) var %kills2 = 0
        hadd -m cs_scorebot %player1 $+(%kills1,$chr(255),%deaths1)
        hadd -m cs_scorebot %player2 $+(%kills2,$chr(255),%deaths2)
        var %data = %scorebot.player $+ ( $+ %scorebot.team $+ $+(:,%kills1,/,%deaths1) $+ ) 3killed %scorebot.player2 $+ ( $+ %scorebot.team2 $+ $+(:,%kills2,/,%deaths2) $+ ) 3with $remove($gettok(%data,$numtok(%data,32),32),")
      }
      else {
        var %kills1 = $calc($gettok($hget(cs_scorebot,%player1),1,255) - 1), %kills2 = $gettok($hget(cs_scorebot,%player2),1,255)
        var %deaths1 = $gettok($hget(cs_scorebot,%player1),2,255), %deaths2 = $calc($gettok($hget(cs_scorebot,%player2),2,255) + 1)
        if (%deaths1 == $null) var %deaths1 = 0
        if (%kills2 == $null) var %kills2 = 0
        hadd -m cs_scorebot %player1 $+(%kills1,$chr(255),%deaths1)
        hadd -m cs_scorebot %player2 $+(%kills2,$chr(255),%deaths2)
        var %data = %scorebot.player $+ ( $+ %scorebot.team $+ $+(:,%kills1,/,%deaths1) $+ ) 3killed their teammate %scorebot.player2 $+ ( $+ %scorebot.team2 $+ $+(:,%kills2,/,%deaths2) $+ ) 3with $remove($gettok(%data,$numtok(%data,32),32),")
      }    
    }
  }
  if (%data != $null) {
    if ($dialog(cs_scorebot)) aline -p @cs_scorebot $asctime([HH:nn:ss]) %data
    scon %scorebot.network
    if ($me ison %scorebot.chan) scon %scorebot.network msg %scorebot.chan $iif($chr(99) isin $gettok($chan(%scorebot.chan).mode,1,32),$strip($!eval(%data),c),$!eval(%data))
    else echo -a Incoming data not sent because you are not in %scorebot.chan $+  - %data
  }
  goto nextread
}
