Tournament script

By Daveoh on Sep 28, 2007

A tournament script I did for some people a while ago. Might still have a bug or two... leave a comment if so.
Modify it to your needs (might need quite a bit of changing) and replace all #CHANNEL with the channel you want it to work on.

Basic features:

  • Start a tournament of any amount of teams with any amount of players each.
  • Display teams, brackets and players.
  • Randomly brackets teams.

How to use:

  • Type .start
  • Players message the bot with .create to create a team and .join to join a team. (.remove to remove yourself from a team and .delete to delete a team)
  • Wait for full teams. Brackets will then be made when ready.
  • .assign (servers are set up by messaging the bot with .server)
  • .report to report which team wins in a match.
;;Tournament bot by Daveoh (#DAVEOH @ QuakeNet)

This work is licensed under the Creative Commons Attribution-Noncommercial 2.0 UK: England & Wales License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc/2.0/uk/ or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA.

alias tspam {
  set -u3 %tspam $calc(%tspam +1)
  if (%tspam > 5) return halt | else return $null
}
alias -l msg msg $1  7,1:: 0 $2-  7::
alias -l notice notice $1 7,1:: 0 $2- 7,1:: 
alias tourney {
  if ($1 == end) { unset %tourney* | unset %team* | unset %match* }
  if ($1 == checkteams) {
    var %i = 1
    while ($gettok(%teamlist,%i,32)) {
      if ($numtok(%team. [ $+ [ $gettok(%teamlist,%i,32) ] $+ .players ],32) == %tourney.matchstyle) { var %readyteams = %readyteams $v1 }
      else { var %notready = %notready $gettok(%teamlist,%i,32) ( $+ $numtok(%team. [ $+ [ $gettok(%teamlist,%i,32) ] $+ .players ],32) $+ / $+ %tourney.matchstyle $+ ) }
      inc %i
    }
    if (%notready) { msg #CHANNEL The following teams are not ready: %notready }
    elseif ($numtok(%teamlist,32) == %tourney.maxteams) { msg #CHANNEL All teams are ready! | .timer 1 2 tourney bracketteams }
  }
  if ($1 == bracketteams) {
    !msg #CHANNEL !rcon zb_readyup_max $calc(%tourney.matchstyle *2)
    !msg #CHANNEL !rcon zb_matchconfig %tourney.matchstyle $+ v $+ %tourney.matchstyle
    set %tourney.round $calc(%tourney.round +1)
    var %v = 1,%ubteams = %teamlist
    while (%ubteams) {
      if ($numtok(%ubteams,32) == 1) { msg #CHANNEL Team %ubteams cannot play, odd number of teams! | goto ubend }
      else {
        var %r1 = $r(1,$numtok(%ubteams,32)),%r2 = $r(1,$numtok(%ubteams,32))
        :rcheck
        if (%r2 == %r1) { var %r2 = $r(1,$numtok(%ubteams,32)) | goto rcheck }
        set %match. $+ %v $gettok(%ubteams,%r1,32) $gettok(%ubteams,%r2,32)
        set %team. $+ $gettok(%ubteams,%r1,32) $+ .match %v
        set %team. $+ $gettok(%ubteams,%r2,32) $+ .match %v
        inc %v
        if ($numtok(%ubteams,32) == 2) { unset %ubteams | goto ubend }
        var %ubteams = $remtok($remtok(%ubteams,$gettok(%ubteams,%r1,32),1,32),$gettok(%ubteams,%r2,32),1,32)
    } }
    :ubend
    var %i = 1
    while (%i < %v) {
      msg #CHANNEL Round %tourney.round $+ , Match %i $+ : $instok(%match. [ $+ [ %i ] ],vs,2,32)
      inc %i
    }
  }
  if ($1 == deleteteam) {
    var %i = 1
    while ($gettok(%team. [ $+ [ $2 ] $+ .players ],%i,32)) {
      var %msgnicks = $addtok(%msgnicks,$v1,44)
      unset %tourney.player. $+ $v1
      inc %i
    }
    msg %msgnicks You have been removed from your team.
    unset %team. [ $+ [ $2 ] ]
    unset %team. [ $+ [ $2 ] $+ .password ]
    unset %team. [ $+ [ $2 ] $+ .players ]
    $iif($remtok(%teamlist,$2,1,32) == $null,unset %teamlist,set %teamlist $v1)
    msg #CHANNEL Team $2 has left the tournament.
    if (%team. [ $+ [ $2 ] $+ .match ]) { msg #csstourney Match %team. [ $+ [ $2 ] $+ .match ] has been cancelled due to team %team. [ $+ [ $2 ] ] leaving. | if ($numtok(%teamlist,32) == 1) { msg $chan Congratulations team $3 $+ ! You have won the tournament! Well done. | tourney end } | elseif (!$var(%match.*,1)) { msg #csstourney Next round: | tourney bracketteams } | unset %match. [ $+ [ %team. [ $+ [ $2 ] $+ .match ] ] ] | unset %team. [ $+ [ $2 ] $+ .match ] }
  }
}
on *:TEXT:.start*:#CHANNEL:{
  if ($nick !isop $chan) { halt }
  elseif (%tourney) { if (!%tourney.spam) { msg $chan A tournament has already started. | set -u60 %tourney.spam 1 } }
  elseif (!$2) { msg $chan Usage: .start <no. of teams> <players per team> }
  elseif ($2 !isnum 2- && !%tourney) { msg $chan No. of teams must be higher than 1. }
  elseif (($gettok($3,1,118) isnum 1- || $3 isnum 1-) && $2 isnum 2- && !%tourney) { set %tourney 1 | set %tourney.maxteams $2 | set %tourney.matchstyle $iif($3 isnum,$3,$gettok($3,1,118)) | msg $chan $iif($3 isnum,$3 $+ v $+ $3,$3) tournament started! To join the tournament one player from each team must message the bot .create teamname password and the other .join teamname password }
}
on *:TEXT:.stop:#CHANNEL:{
  if ($nick isop $chan && %tourney) { tourney end | msg #CHANNEL The tournament has been stopped. }
}
on *:TEXT:.vent*:#CHANNEL:{ $tspam
  msg $chan Ventrilo IP: vent.cssevent.com Port: 3867
}
on *:TEXT:.help:#CHANNEL:{ $tspam
  if ($nick isop $chan) { msg $nick Admin commands: .start .stop .setmap .report .assign $chr(124) PM commands: .server .delete .players  }
  msg $chan Public Commands: .vent .teams .brackets .serverlist
  msg $nick To create a team type .create teamname password in this window. To join a team type .join teamname password in this window.
}
on *:TEXT:.setmap &:#CHANNEL:{
  if ($nick isop $chan && %tourney) { set %tourney.map $2 | msg $chan Tournament map is $2 | !msg $chan !rcon changelevel $2 }
}
on *:TEXT:.teams:#CHANNEL:{ $tspam
  if (!%tourney.teamspam && %tourney) {
    if (!%teamlist) { msg $chan There are no teams. | halt }
    var %i = 1
    while ($gettok(%teamlist,%i,32)) {
      var %msgteams = %msgteams $v1 ( $+ $numtok(%team. [ $+ [ $v1 ] $+ .players ],32) $+ / $+ %tourney.matchstyle $+ ) $+ $iif($gettok(%teamlist,$calc(%i +1),32),$chr(44))
      inc %i
    }
    msg $chan Teams: %msgteams
    set -u5 %tourney.teamspam 1
  }
}
on *:TEXT:.brackets:#CHANNEL:{ 
  if (%tourney.round) { $tspam
    var %i = 1
    while (%i <= %tourney.maxteams) {
      if (%match. [ $+ [ %i ] ]) { msg $chan Round %tourney.round $+ , Match %i $+ : $instok($v1,vs,2,32) }
      inc %i
    }
  }
}
on *:TEXT:.report*:#CHANNEL:{
  if ($nick isop $chan) {
    if (!$2) { msg $chan Usage: .report <match no.> <winning team> }
    elseif (!%match. [ $+ [ $2 ] ]) { msg $chan No such match. }
    elseif ($2 && !$3) { msg $chan Teams in match $2: %match. [ $+ [ $2 ] ] }
    elseif (!$istok(%match. [ $+ [ $2 ] ],$3,32)) { msg $chan Invalid team. }
    elseif ($istok(%match. [ $+ [ $2 ] ],$3,32)) { $iif($numtok($remtok(%teamlist,$remtok(%match. [ $+ [ $2 ] ],$3,1,32),1,32),32) != 1,msg $chan Congratulations team $3 for winning!) | unset %team. $+ $remtok(%match. [ $+ [ $2 ] ],$3,1,32) $+ * | set %teamlist $remtok(%teamlist,$remtok(%match. [ $+ [ $2 ] ],$3,1,32),1,32) | unset %match. $+ $2 $+ * | if ($numtok(%teamlist,32) == 1) { msg $chan Congratulations team $3 $+ ! You have won the tournament! Well done. | tourney end } | elseif (!$var(%match.*,1)) { msg $chan Next round: | tourney bracketteams } }
  }
}
on *:TEXT:.assign*:#CHANNEL:{
  if ($nick isop $chan) {
    if (!$2) { msg $chan Usage: .assign <match no.> <server id> }
    elseif (!%match. [ $+ [ $2 ] ]) { msg $chan Invalid match. }
    elseif ($2 && !$3) { if (%match. [ $+ [ $2 ] $+ .assign ]) { msg $chan Match $2 currently assigned to server $v1 $+ . } | else msg $chan Match $2 has not been assigned to a server. }
    elseif (!%server. [ $+ [ $3 ] ]) { msg $chan Invalid server. }
    else { set %match. $+ $2 $+ .assign $3 | msg $chan Match $2 has been set to server $3 ( $+ $gettok(%server. [ $+ [ $3 ] ],1,32)  $iif($gettok(%server. [ $+ [ $3 ] ],3,32), SrcTV port: $v1) $+ )
      var %i = 1
      while ($gettok(%match. [ $+ [ $2 ] ],%i,32)) {
        ;added more efficient way of messaging players their teams
        msg $replace(%team. [ $+ [ $v1 ] $+ .players ],$chr(32),$chr(44)) You have been assigned to server $3 ( $+ $gettok(%server. [ $+ [ $3 ] ],1,32) password: $gettok(%server. [ $+ [ $3 ] ],2,32)  $iif($gettok(%server. [ $+ [ $3 ] ],3,32), SrcTV port: $v1) $+ ) - Please join now!"
        /*
        var %v = 1
        while ($gettok(%team. [ $+ [ $v1 ] $+ .players ],%v,32)) {
          msg $v1 You have been assigned to server $3 ( $+ $gettok(%server. [ $+ [ $3 ] ],1,32) password: $gettok(%server. [ $+ [ $3 ] ],2,32)  $iif($gettok(%server. [ $+ [ $3 ] ],3,32), SrcTV port: $v1) $+ ) - Please join now!"
          inc %v
        }
        */
        inc %i
      }
    }
  }
}
on *:TEXT:.serverlist:#CHANNEL:{ $tspam
  if (%tourney.serverspam) { halt }
  var %i = 1
  while ($var(%server.*,%i)) {
    var %msgservers = %msgservers $gettok($v1,2,46) $+ : $gettok($var($v1,1).value,1,32)  $iif($gettok($var($v1,1).value,3,32), $+($chr(40),$v1,$chr(41))) $+ $iif($var(%server.*,$calc(%i +1)),$chr(44))
    inc %i
  }
  msg $chan Servers: %msgservers
  set -u5 %tourney.teamspam 1
}
on *:TEXT:.server*:?:{ $tspam
  if ($nick !isop #CHANNEL) { halt }
  elseif (!$2) { msg $nick Usage: .server <server id> (ip:port/-) (password) (SrcTV port) (to remove: .server remove <server id>) }
  elseif ($2 == remove) { if (!$3) { msg $nick Specify server id. } | elseif (%server. [ $+ [ $3 ] ]) { unset %server. [ $+ [ $3 ] ] | msg $nick Server $3 info removed. } | else { msg $nick No such server. } }  
  elseif ($2 && !$3) { msg $nick Server $2 $+ : $iif(%server. [ $+ [ $2 ] ],IP/port: $gettok(%server. [ $+ [ $2 ] ],1,32) SrcTV: $gettok(%server. [ $+ [ $2 ] ],3,32) Password: $gettok(%server. [ $+ [ $2 ] ],2,32),Info not set.) }
  elseif ($3 && !$4) { set %server. $+ $2 $3 $gettok(%server. [ $+ [ $2 ] ],2,32) $gettok(%server. [ $+ [ $2 ] ],3,32) | msg $nick Server $2 IP set: IP/port: $gettok(%server. [ $+ [ $2 ] ],1,32) SrcTV: $gettok(%server. [ $+ [ $2 ] ],3,32) Password: $gettok(%server. [ $+ [ $2 ] ],2,32) }
  elseif ($4 && !$5) { set %server. $+ $2 $iif($3 == - && $gettok(%server. [ $+ [ $2 ] ],1,32),$gettok(%server. [ $+ [ $2 ] ],1,32),$3) $4 $gettok(%server. [ $+ [ $2 ] ],3,32) | msg $nick Server $2 IP and password set: IP/port: $gettok(%server. [ $+ [ $2 ] ],1,32) $iif($gettok(%server. [ $+ [ $2 ] ],3,32),SrcTV: $v1 ) $+ Password: $gettok(%server. [ $+ [ $2 ] ],2,32) }
  elseif ($5) { set %server. $+ $2 $iif($3 == - && $gettok(%server. [ $+ [ $2 ] ],1,32),$gettok(%server. [ $+ [ $2 ] ],1,32),$3) $4 $5 | msg $nick Server $2 info set: IP/port: $gettok(%server. [ $+ [ $2 ] ],1,32) SrcTV: $gettok(%server. [ $+ [ $2 ] ],3,32) Password: $gettok(%server. [ $+ [ $2 ] ],2,32) }
}
on *:TEXT:.create*:*:{
  if (!%tourney || ($chan && $chan != #CHANNEL)) { halt }
  $tspam
  if ($chan) { msg $chan To use the .join .create .remove .delete commands you must pm me, $me $1 | halt }
  if ($nick ison #CHANNEL) {
    if (%tourney.round) { msg $nick The tournament has begun, you cannot create a team now. | halt }
    if (!$3) { msg $nick Usage: .create <team name> <password> | halt }
    if (%tourney.player. [ $+ [ $nick ] ]) { msg $nick You are already in a team! You must leave it to create another. | halt }
    if ($numtok(%teamlist,32) < %tourney.maxteams) {
      if (%team. [ $+ [ $2 ] ]) { msg $nick That team name is taken! | halt }
      if ($chr(40) isin $2 || $chr(41) isin $2) { msg $nick Invalid characters included, do not use ( or ) | halt }
      set %teamlist %teamlist $2
      set %team. $+ $2 $2
      set %team. $+ $2 $+ .password $3
      set %team. $+ $2 $+ .players $nick
      msg $nick Team $2 created.
      set %tourney.player. $+ $nick $2
      msg #CHANNEL Team $2 has joined the tournament. $numtok(%teamlist,32) out of %tourney.maxteams teams are signed up.
      if ($numtok(%teamlist,32) == %tourney.maxteams) {
        msg #CHANNEL All team slots have been filled.
        var %i = 1
        while ($gettok(%teamlist,%i,32)) {
          if ($numtok(%team. [ $+ [ $gettok(%teamlist,%i,32) ] $+ .players ],32) == %tourney.matchstyle) { var %readyteams = %readyteams $v1 }
          else { var %notready = $iif(%notready,$v1 $+ $chr(44)) $gettok(%teamlist,%i,32) ( $+ $numtok(%team. [ $+ [ $gettok(%teamlist,%i,32) ] $+ .players ],32) $+ / $+ %tourney.matchstyle $+ ) }
          inc %i
        }
        if (%notready) { msg #CHANNEL The following teams are not ready: %notready }
        else { msg #CHANNEL All teams are ready! | .timer 1 2 tourney bracketteams }
      }
    }
    else msg $nick The team list is full.
  }
}
on *:TEXT:.join*:*:{
  if (!%tourney || ($chan && $chan != #CHANNEL)) { halt }
  $tspam
  if ($chan) { msg $chan To use the .join .create .remove .delete commands you must pm me, $me $1 | halt }
  if ($nick ison #CHANNEL) {
    if (%tourney.round) { msg $nick The tournament has begun, you cannot join a team now. | halt }
    if (!$3) { msg $nick Usage: .join <team name> <password> | halt }
    if (%tourney.player. [ $+ [ $nick ] ]) { msg $nick You are already in a team! You must leave it to join another. }
    elseif (!%team. [ $+ [ $2 ] ]) { msg $nick That team doesn't exist. }
    elseif ($numtok(%team. [ $+ [ $2 ] $+ .players ],32) >= %tourney.matchstyle) { msg $nick This team is full. }
    elseif (%team. [ $+ [ $2 ] ] && $3 != %team. [ $+ [ $2 ] $+ .password ]) { msg $nick Incorrect password }
    elseif (%team. [ $+ [ $2 ] ] && $3 == %team. [ $+ [ $2 ] $+ .password ]) { set %team. $+ $2 $+ .players %team. [ $+ [ $2 ] $+ .players ] $nick | set %tourney.player. $+ $nick $2 | msg $nick You have joined team %team. [ $+ [ $2 ] ] $+ . | if ($numtok(%team. [ $+ [ $2 ] $+ .players ],32) == %tourney.matchstyle) { msg #CHANNEL Team %team. [ $+ [ $2 ] ] is ready! | tourney checkteams } }
  }
}
on *:TEXT:.remove:*:{
  if (!%tourney || ($chan && $chan != #CHANNEL)) { halt }
  $tspam
  if ($chan) { msg $chan To use the .join .create .remove .delete commands you must pm me, $me $1 | halt }
  if ($nick ison #CHANNEL) {
    if (%tourney.round) { msg $nick The tournament has begun, you cannot leave a team now. | halt }
    if (!%tourney.player. [ $+ [ $nick ] ]) { msg $nick You are not in a team. }
    elseif (%tourney.player. [ $+ [ $nick ] ]) { var %team = $v1 | if ($remtok(%team. [ $+ [ %team ] $+ .players ],$nick,1,32) == $null) { tourney deleteteam %tourney.player. [ $+ [ $nick ] ] } | else { set %team. $+ %team $+ .players $remtok(%team. [ $+ [ %team ] $+ .players ],$nick,1,32) } | unset %tourney.player. [ $+ [ $nick ] ] | msg $nick You have removed yourself from team %team $+ . }
  }
}
on *:QUIT:{
  if (%tourney.player. [ $+ [ $nick ] ]) { var %team = $v1 | if ($remtok(%team. [ $+ [ %team ] $+ .players ],$nick,1,32) == $null) { tourney deleteteam %tourney.player. [ $+ [ $nick ] ] } | else { set %team. $+ %team $+ .players $remtok(%team. [ $+ [ %team ] $+ .players ],$nick,1,32) } | unset %tourney.player. [ $+ [ $nick ] ] }
}
on *:NICK:{
  if (%tourney.player. [ $+ [ $nick ] ]) { var %team = $v1 | if ($remtok(%team. [ $+ [ %team ] $+ .players ],$nick,1,32) == $null) { tourney deleteteam %tourney.player. [ $+ [ $nick ] ] } | else { set %team. $+ %team $+ .players $addtok($remtok(%team. [ $+ [ %team ] $+ .players ],$nick,1,32),$newnick,32) } | unset %tourney.player. [ $+ [ $nick ] ] | set %tourney.player. $+ $newnick %team }
}
on *:TEXT:.delete*:*:{
  if (!%tourney || ($chan && $chan != #CHANNEL)) { halt }
  $tspam
  if ($chan) { msg $chan To use the .join .create .remove .delete commands you must pm me, $me $1 | halt }
  if ($nick ison #CHANNEL) {
    if (%tourney.round) { msg $nick The tournament has begun, you cannot delete a team now. | halt }
    if ($nick isop #CHANNEL && $2) { if (%team. [ $+ [ $2 ] ]) { tourney deleteteam $2 } | else msg $nick Invalid team. }
    elseif (!%tourney.player. [ $+ [ $nick ] ]) { msg $nick You are not in a team. }
    elseif (%tourney.player. [ $+ [ $nick ] ]) { unset %tourney.player. [ $+ [ $nick ] ] | tourney deleteteam $v1 }
  }
}
on *:TEXT:.players:?:{
  if (!%tourney || $nick !isop #CHANNEL) { halt }
  if (!%teamlist) { msg $nick There are no teams. }
  else {
    var %i = 1
    while ($gettok(%teamlist,%i,32)) {
      msg $nick Team $v1 $+ : %team. [ $+ [ $v1 ] $+ .players ]
      inc %i
    }
  }
}

Comments

Sign in to comment.
VersaX   -  May 30, 2010

where is syas if (%team. [ $+ [ $2 ] $+ .match ]) { msg #csstourney Match %team. [ $+ [ $2 ] $+ .match ] has been cancelled due to team %team. [ $+ [ $2 ] ] leaving. | if ($numtok(%teamlist,32) == 1) { msg $chan Congratulations team $3 $+ ! You have won the tournament! Well done. | tourney end } | elseif (!$var(%match.*,1)) { msg #csstourney Next round: | tourney bracketteams } | unset %match. [ $+ [ %team. [ $+ [ $2 ] $+ .match ] ] ] | unset %team. [ $+ [ $2 ] $+ .match ] }
do i change #csstourny with my channels name?

 Respond  
jub369   -  Dec 23, 2007

it allows you play tounes with your bot like my pokemonbotv.3

 Respond  
guest598594   -  Sep 28, 2007

what duz it do?

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.