Share Pastebin
Guest
Public paste!

Coboney

By: a guest | Jul 4th, 2009 | Syntax: None | Size: 37.99 KB | Hits: 5 | Expires: Never
Copy text to clipboard
  1. ;;--------------------------------------------------------------------------------
  2. ; Mtg-Temple Judge Script v1.0.0.1
  3. ; © LordHawk
  4. ; Last updated: 27.12.2008
  5. ;--------------------------------------------------------------------------------
  6. ; Updating
  7. ; You should update only if the Build specified in the header of the script
  8. ; differs from the one you are running.
  9. ; The updating is easy:
  10. ; 1. Back up any changes you've done to messages/colors/etc
  11. ; 2. Simply replace the script
  12. ; 3. Apply the backup changes
  13. ; 4. Run /initVars in irc
  14. ;--------------------------------------------------------------------------------
  15.  
  16.  
  17.  
  18. ;--------------------------------------------------------------------------------
  19. ; This is Judge Script v1.0.0.1 menu which pops up when you right-click on the channel
  20. ; We specify "channel" menu, because it works with that 'popup' (click Popup tab
  21. ; and see View menu for more common 'popups'
  22. ; Syntax: [{<dropdown menu level>}<menu line>{:<alias>}]
  23. ; No dot means top-level, [.] is first level of dropdown menu [..] second, etc.
  24. ; Menu line is either a [-] horizontal delimiter or string or variable/expression
  25. ; that outputs a string/submenu. If that string is null, line is not displayed.
  26. ; Alias is a function, if its present and you click on that line, it would
  27. ; execute the alias, if no alias is specified, mIRC expects that line to be a
  28. ; title of following drop down menu
  29. ;--------------------------------------------------------------------------------
  30. menu channel {
  31.   Mtg-Temple Judge Script v1.0.0.1
  32.   .Start a New Tournament: createTournament
  33.   .-
  34.   .Start Quick Tournament
  35.   ..$submenu($startQuickDisplay($1))
  36.   .-
  37.   .$submenu($startPresetsDisplay($1))
  38.   .-
  39.   .$submenu($extendEntriesDisplay($1))
  40.   .-
  41.   .$submenu($roundStartDisplay($1))
  42.   .-
  43.   .$submenu($extendRoundDisplay($1))  
  44.   .-
  45.   .$submenu($remainingTimeDisplay($1))
  46.   .-
  47.   .$submenu($cancelTournamentDisplay($1))
  48.   .-
  49.   .$submenu($informNonReportedDisplay($1))
  50.   .-
  51.   .Continue Tournament (take over): continueTournament
  52. }
  53.  
  54. ;--------------------------------------------------------------------------------
  55. ; Init alias (it is executed only once, when you click "Start a New Tournament")
  56. ; Syntax: [set %<variable name> <value>]; you should edit only values
  57. ; If you want to customize, edit statements below, save then type /initVars
  58. ;--------------------------------------------------------------------------------
  59. alias initVars {
  60.   ; Formats
  61.   ; There should be as many [%TCformat<number>] variables as %formats specifies
  62.   set %TCformats 4
  63.   set %TCformat1 Standard (T2)
  64.   set %TCformat2 Extended (T1.X)
  65.   set %TCformat3 Legacy (T1.5)
  66.   set %TCformat4 Vintage (T1)
  67.   set %TCformat5 Myos
  68.   ; Default format (choose number from the above) when creating tournaments
  69.   set %TCdefaultFormat 1
  70.  
  71.   ; Default gaming application 5=OCTGN, 6=OPT, 7=MWS
  72.   set %TCdefaultApplication 7
  73.  
  74.   ; Default K-Value 9=Mini, 10=Temple Challenge, 11=Temple Open
  75.   set %TCdefaultKValue 9
  76.  
  77.   ; Default maximum amount of participants 13=4, 14=8, 15=32 16=64 17=No Max
  78.   set %TCdefaultMaxParticipants 13
  79.  
  80.   ; Default entires time 19=10, 20=15, 21=20 22=30
  81.   set %TCdefaultEntriesTime 21
  82.  
  83.   ; Default tournament type 25=Single Elimination, 26=RFT
  84.   set %TCdefaultTournamentType 25
  85.  
  86.   ; Default format category 28=Constructed 29=Sealed
  87.   set %TCdefaultformatCategory 28
  88.  
  89.   ; Default time to repeat entries announcement (usually every 3 minutes)
  90.   set %TCdefaultRepeatEntriesTime $calc(3 * 60)
  91.  
  92.   ; Default round length 31=45 32=50 33=60
  93.   set %TCdefaultRoundLength 31
  94.  
  95.   ; Messages
  96.   ; Feel free to change colors and text, do not touch the variables though
  97.   ; If you are to set background (use comma in n,n) in %entriesNotice (or other
  98.   ; such notices) you have to use variable (just like %entriesColor),
  99.   ; because otherwise double evaluation would mess it up
  100.   ; Footer
  101.   ; set %poweredNotice 8,5Powered by Judge Script V1.0.0.1  
  102.  
  103.   ; Entries are open
  104.   set %entriesColor 1,4
  105.   set %entriesNotice $+(%,entriesColor) Entries are open for a 8>>0 $+(%, tournamentName) 8<<1 Entries are open for $+(%,timeLeft) minutes or until the maximum amount of participants is reached. Join this tournament on the Home page of www.Magic-Temple.com! $+(%,poweredNotice)
  106.   ; Cancelled tournament
  107.   set %cancelledColor 15,5
  108.   set %cancelledNotice $+(%,cancelledColor) Attention! 8>>0 $+(%, tournamentName) 8<<15 has been cancelled. Sorry for caused inconvenience. $+(%,poweredNotice)
  109.   ; player vs player
  110.   set %vsmessage 5*1 $+(%,player1) 5VS1 $+(%,player2) 5*
  111.   ; player got a bye
  112.   set %byemessage 5*1 $+(%,player1) got a bye 5*
  113.   ; Round notices color
  114.   set %roundColor 4,1
  115.     ; Round timers
  116.   set %roundBegin $+(%roundColor) You may begin playing the  $+(%,roundName)  of the 2>>1 $+(%, tournamentName) 2<<12 Check the pairings on the Home page of www.Magic-Temple.com. The round is $+(%,timeLeft) minutes long. You can type !Time in this channel to find out how much time there's left in the round. $+(%,poweredNotice)
  117.   set %roundFinals $+(%roundColor) You may begin playing the  Finals  of the 2>>1 $+(%, tournamentName) 2<<12 Check the pairings on the Home page of www.Magic-Temple.com. The finals are untimed. $+(%,poweredNotice)
  118.   set %roundgameloss $+(%roundColor) You have won game one of the  $+(%,roundName)  if your opponent hasn't shown up! 2>>1 $+(%, tournamentName) 2<<12 Questions -> 1#TempleJudge12. Please report result on the Home page of www.Magic-Temple.com! $+(%,poweredNotice)
  119.   set %roundmatchloss $+(%roundColor) You have won the match of the  $+(%,roundName)  if your opponent hasn't shown up! 2>>1 $+(%, tournamentName) 2<<12 Questions -> 1#TempleJudge12. Please report result on the Home page of www.Magic-Temple.com! $+(%,poweredNotice)
  120.   set %round20left $+(%roundColor) There are 20 minutes remaining in the  $+(%,roundName)  of the 2>>1 $+(%, tournamentName) 2<<12 Questions -> 1#TempleJudge12. Please report result on the Home page of www.Magic-Temple.com! $+(%,poweredNotice)
  121.   set %round10left $+(%roundColor) There are 10 minutes remaining in the  $+(%,roundName)  of the 2>>1 $+(%, tournamentName) 2<<12 Questions -> 1#TempleJudge12. Please report result on the Home page of www.Magic-Temple.com! $+(%,poweredNotice)
  122.   set %round5left $+(%roundColor) There are 5 minutes remaining in  the $+(%,roundName)  of the 2>>1 $+(%, tournamentName) 2<<12 Questions -> 1#TempleJudge12. Please report result on the Home page of www.Magic-Temple.com! $+(%,poweredNotice)
  123.   set %roundTimeColor 4,1
  124.   set %roundTime $+(%,roundTimeColor) TIME TIME TIME is over in the  $+(%,roundName)  of the 0>>8 $+(%, tournamentName) 0<<11 Active player finish turn and report result on the Home page of www.Magic-Temple.com! Questions -> 15#TempleJudge11 $+(%,poweredNotice)
  125.   ; !time message
  126.   set %timeLeftNoticeColor 15,5
  127.   set %timeLeftNotice $+(%,timeLeftNoticeColor) There are $+(%,timeLeft) minutes remaining in the  $+(%,roundName)  of the 8>>0 $+(%, tournamentName) 8<<15 $+(%,poweredNotice)
  128.   set %reportPleaseMessage 2,8 TIME IS OVER Start your 5 extra turns, Report when Finished!
  129.   set %TCinit true
  130.   ; Message that appears when you take over a tournament
  131.   set %takeOverColor 15,5
  132.   set %takeOverNotice $+(%,takeOverColor) Attention! 8>>0 $+(%, tournamentName) 8<<15 has been passed to new TC: $+($, me). $+(%,poweredNotice)
  133.  
  134. }
  135.  
  136. ;--------------------------------------------------------------------------------
  137. ; This alias displays "Tournament Options" dialog box and creates tournament
  138. ;--------------------------------------------------------------------------------
  139. alias createTournament {
  140.   ; If init alias haven't been run yet, do so
  141.   if (%TCinit != true) {
  142.     initVars
  143.   }
  144.  
  145.   ; Unset some temporary variables (in case something messed up)
  146.   unset %tempCustomEntriesTime
  147.   unset %tempChannel
  148.   unset %tempCounter
  149.   unset %tempCustomRoundLength
  150.  
  151.   ; Fetch channel we are clicking on
  152.   set %tempChannel $chan
  153.  
  154.   ; Invoke tournament creation dialog window using table tournamentOptions
  155.   var %result = $dialog(newTournamentDialog, tournamentOptions)
  156.  
  157.   ; Outputs the open entries message via timer
  158.   if (%tempCreated == true) {
  159.     unset %tempCreated
  160.     entriesTimer %TCtournamentId
  161.   }
  162. }
  163.  
  164. ;--------------------------------------------------------------------------------
  165. ; Handles the entries timer
  166. ;--------------------------------------------------------------------------------
  167. alias entriesTimer {
  168.   var %prefix = $+(%, TC, tournament, $1)
  169.   var %timerId = $+(., timer, Entries, $1)
  170.   var %entriesTime = $+(%prefix, entriesTime)
  171.  
  172.   displayEntries %channel $1
  173.   ; Starts the countdown
  174.   dec -z $eval(%entriesTime)
  175.   var %repeatitions = $floor($calc(%entriesTime / %TCdefaultRepeatEntriesTime))
  176.   if (%repeatitions > 0) {
  177.     ; Invoke timer
  178.     $eval(%timerId) %repeatitions %TCdefaultRepeatEntriesTime displayEntries $1
  179.   }
  180. }
  181.  
  182. ;--------------------------------------------------------------------------------
  183. ; Merely displays the open entries notice
  184. ;--------------------------------------------------------------------------------
  185. alias displayEntries {
  186.   var %prefix = $+(%, TC, tournament, $1)
  187.   var %tournamentName = $eval($+(%prefix, name), 2)
  188.   var %channel = $eval($+(%prefix, channel), 2)
  189.   var %timeLeft = $ceil($calc($eval($+(%prefix, entriesTime), 2) / 60))
  190.   notice %channel $eval(%entriesNotice, 2)
  191. }
  192.  
  193. ;--------------------------------------------------------------------------------
  194. ; "Tournament Options" dialog table (simply a layout scheme).
  195. ; Stuff here is mostly self-explanatory
  196. ;--------------------------------------------------------------------------------
  197. dialog tournamentOptions {
  198.   title "Tournament Options"
  199.   ; Coordinates, x = -1  y = -1 means its centered
  200.   ; Next two coordinates determine width and height
  201.   size -1 -1 121 184  
  202.   option dbu
  203.  
  204.   ; Syntax: [<element> "<text>", <element id>, <coordinates>{,<option>}]
  205.   box "Specify or pick playing format", 1, 0 0 121 20
  206.   edit "", 2, 1 8 59 11, autohs        
  207.   combo 3, 61 8 59 70, drop
  208.  
  209.   box "Choose application", 4 , 0 22 60 34, group
  210.   radio "OCTGNv2", 5, 1 30 58 8
  211.   radio "OPT", 6, 1 38 58 8
  212.   radio "Magic Workstation", 7, 1 46 58 8
  213.  
  214.   box "K-Value", 8 , 61 22 60 34, group
  215.   radio "Mini (K16)", 9, 62 30 58 8
  216.   radio "Temple Challenge (K24)", 10, 62 38 58 8
  217.   radio "Temple Open (K32)", 11, 62 46 58 8
  218.  
  219.   box "Maximum Participants", 12 , 0 56 60 50, group
  220.   radio "4 Max", 13, 1 64 58 8
  221.   radio "8 Max", 14, 1 72 58 8
  222.   radio "32 Max", 15, 1 80 58 8
  223.   radio "64 Max", 16, 1 88 58 8
  224.   radio "No Max", 17, 1 96 58 8
  225.  
  226.   box "Entries open for:", 18 , 61 56 60 50, group
  227.   radio "10 minutes", 19, 62 64 58 8
  228.   radio "15 minutes", 20, 62 72 58 8
  229.   radio "20 minutes", 21, 62 80 58 8
  230.   radio "30 minutes", 22, 62 88 58 8  
  231.   radio "Custom", 23, 62 96 58 8
  232.  
  233.   box "Tournament Type", 24 , 0 106 60 26, group
  234.   radio "Single Elimination", 25, 1 114 58 8
  235.   radio "RFT", 26, 1 122 58 8
  236.  
  237.   box "Format Category", 27 , 61 106 60 26, group
  238.   radio "Constructed", 28, 62 114 58 8
  239.   radio "Sealed", 29, 62 122 58 8
  240.  
  241.   box "Round Length", 30 , 0 132 121 26, group
  242.   radio "45 minutes", 31, 1 140 58 8
  243.   radio "50 minutes", 32, 1 148 58 8
  244.   radio "60 minutes", 33, 62 140 58 8
  245.   radio "Custom", 34, 62 148 58 8
  246.  
  247.   check "Save as quick tournament", 35, 1 158 120 10
  248.  
  249.   button "Open entries", 36, 0 168 121 16
  250. }
  251.  
  252. ;--------------------------------------------------------------------------------
  253. ; This event occurs "Tournament Options" dialog is created
  254. ; and assigns a couple of default variables to that dialog
  255. ;--------------------------------------------------------------------------------
  256. on *:dialog:newTournamentDialog:init:0: {
  257.   ; step counter
  258.   var %i = 1
  259.   ; Simply step through all the format variables
  260.   while (%i <= %TCformats) {
  261.     ; Syntax: did -[flags] <dialog name> <element id> {number} {<value>}
  262.     ; this alias modifies given element of given dialog with given value
  263.     ; -a flag means add a line
  264.     ; Value here is format variable, its composed using step counter, evaluated
  265.     ; and then added to the dropdown list in "Tournament Options" dialog
  266.     did -a newTournamentDialog 3 $eval($+(%, TCformat, %i), 2)
  267.     ; increment step counter
  268.     inc %i
  269.   }
  270.  
  271.   ; Sets default format
  272.   did -c newTournamentDialog 3 %TCdefaultFormat
  273.  
  274.   ; Sets default gaming application
  275.   did -c newTournamentDialog %TCdefaultApplication
  276.  
  277.   ; Sets default tournament type
  278.   did -c newTournamentDialog %TCdefaultKValue
  279.  
  280.   ; Sets default maximum amount of participants
  281.   did -c newTournamentDialog %TCdefaultMaxParticipants
  282.  
  283.   ; Sets default entries time
  284.   did -c newTournamentDialog %TCdefaultEntriesTime
  285.  
  286.   ; Sets default tournament type
  287.   did -c newTournamentDialog %TCdefaultTournamentType
  288.  
  289.   ; Sets default format category
  290.   did -c newTournamentDialog %TCdefaultFormatCategory
  291.  
  292.   ; Sets default round length
  293.   did -c newTournamentDialog %TCdefaultRoundLength
  294. }
  295.  
  296. ;--------------------------------------------------------------------------------
  297. ; This event occurs when you click on custom entries time radio button
  298. ; that asks you to enter value inbetween 4-60 minutes
  299. ;--------------------------------------------------------------------------------
  300. on *:dialog:newTournamentDialog:sclick:23: {
  301.   ; Using local variable here, because while loop wouldn't work with global
  302.   var %time = $$?="Specify entries time (4-60 minutes)"
  303.   while (%time !isnum 4-60) {
  304.     var %time = $$?="Specify entries time (4-60 minutes)"
  305.   }
  306.   ; Settting global after we're out of loop
  307.   set %tempCustomEntriesTime %time
  308. }
  309.  
  310. ;--------------------------------------------------------------------------------
  311. ; This event occurs when you click on custom entries round button
  312. ; that asks you to enter value inbetween 30-120 minutes
  313. ;--------------------------------------------------------------------------------
  314. on *:dialog:newTournamentDialog:sclick:34: {
  315.   var %time = $$?="Specify round length (minutes)"
  316.   while (%time !isnum 30-120) {
  317.     var %time = $$?="Specify entries time (30-120 minutes)"
  318.   }
  319.   set %tempCustomRoundLength %time
  320. }
  321.  
  322. ;--------------------------------------------------------------------------------
  323. ; This event occurs when you click on sealed radio button. It brings up a dialog
  324. ; that asks you to enter value inbetween 15-20 minutes
  325. ;--------------------------------------------------------------------------------
  326. on *:dialog:newTournamentDialog:sclick:29: {
  327.   var %time = $$?="Specify deckbuilding time (15-20 minutes)"
  328.   while (%time !isnum 15-20) {
  329.     var %time = $$?="Specify deckbuilding time (15-20 minutes)"
  330.   }
  331.   set %TCsealedDeckbuildingTime %time
  332. }
  333.  
  334. ;--------------------------------------------------------------------------------
  335. ; This event occurs when you click on Open Entries button
  336. ; It saves the data about tournament
  337. ;--------------------------------------------------------------------------------
  338. on *:dialog:newTournamentDialog:sclick:36: {
  339.   ; As we created a new tournament, we increment the tournament counter and
  340.   ; tournament id counter
  341.   inc %TCtournaments
  342.   inc %TCtournamentId
  343.  
  344.   ; Fetch selected (specified) format
  345.   var %format = $iif($did(2).text, $did(2).text, $did(3).text)
  346.  
  347.   ; Fetch application
  348.   var %i = 5
  349.   while ( %i <= 7) {
  350.     if ($did(%i).state == 1) {
  351.       var %application = $did(%i ).text
  352.       break
  353.     }
  354.     inc %i
  355.   }
  356.  
  357.   ; Fetch K-Value
  358.   var %i = 9
  359.   while ( %i <= 11) {
  360.     if ($did(%i).state == 1) {
  361.       var %kvalue = $did(%i).text
  362.     }
  363.     inc %i
  364.   }
  365.  
  366.   ; Fetch maximum participants
  367.   var %i = 13
  368.   while ( %i <= 17) {
  369.     if ($did(%i).state == 1) {
  370.       var %max = $did(%i).text
  371.     }
  372.     inc %i
  373.   }
  374.  
  375.   ; Save tournament name string
  376.   var %prefix = $+(%, TC, tournament, %TCtournamentId)
  377.   var %tournamentName = $+(%prefix, name)
  378.   var %name = %format %max %application %kvalue
  379.   set $eval(%tournamentName) %name
  380.  
  381.   ; Save tournament type
  382.   var %tournamentType = $+(%prefix, type)
  383.   var %type = $iif($did(25).state, $did(25).text, $did(26).text)
  384.   set $eval(%tournamentType) %type
  385.  
  386.   ; Save format category
  387.   var %formatCategory = $+(%prefix, category)
  388.   var %category = $iif($did(28).state, $did(28).text, $did(29).text)
  389.   set $eval(%formatCategory) %category
  390.  
  391.   ; Save channel where tournament is created
  392.   var %channel = $+(%prefix, channel)
  393.   set $eval(%channel) %tempChannel
  394.  
  395.   ; Fetch entries time
  396.   var %entriesTime = $+(%prefix, entriesTime)
  397.  
  398.   var %i = 19
  399.   while (%i <= 22) {
  400.     if ($did(%i).state == 1) {
  401.       ; Convert string to integer and multiply it by 60 (minutes --> seconds)
  402.       set $eval(%entriesTime) $calc($abs($did(%i).text) * 60)
  403.     }
  404.     inc %i
  405.   }
  406.   if ($did(23).state == 1) {
  407.     if (%tempCustomEntriesTime) set $eval(%entriesTime) $calc(%tempCustomEntriesTime * 60)
  408.     else set $eval(%entriesTime) $calc(15 * 60)
  409.     unset %tempCustomEntriesTime
  410.   }
  411.  
  412.   ; Fetch round length
  413.   var %roundLength = $+(%prefix, roundLength)
  414.  
  415.   var %i = 31
  416.   while (%i <= 33) {
  417.     if ($did(%i).state == 1) {      
  418.       set $eval(%roundLength) $calc($abs($did(%i).text))
  419.     }
  420.     inc %i
  421.   }
  422.   if ($did(34).state == 1) {
  423.     if (%tempCustomRoundLength) set $eval(%roundLength) $calc(%tempCustomRoundLength * 60)
  424.     else set $eval(%roundLength) 45
  425.     unset %tempCustomRoundLength
  426.   }
  427.  
  428.   ; If "Save as Quick Tournament" checkbox clicked do so
  429.   if ($did(35).state == 1) {
  430.     inc %TCquickPresets
  431.     var %prefix = $+(%, TC, tournament, Quick, %TCquickPresets)
  432.     var %tournamentName = $+(%prefix, name)
  433.     set $eval(%tournamentName) %name
  434.     var %tournamentType = $+(%prefix, type)
  435.     set $eval(%tournamentType) %type
  436.     var %formatCategory = $+(%prefix, category)
  437.     set $eval(%formatCategory) %category  
  438.     var %channel = $+(%prefix, channel)
  439.     set $eval(%channel) %tempChannel
  440.     var %time = $+(%prefix, entriesTime)
  441.     set $eval(%time) $eval(%entriesTime, 2)
  442.     var %length = $+(%prefix, roundLength)
  443.     set $eval(%length) $eval(%roundLength, 2)
  444.   }
  445.  
  446.   ; No longer needed
  447.   unset %tempChannel
  448.  
  449.   ; Closes dialog with flag -x
  450.   dialog -x newTournamentDialog tournamentOptions
  451.  
  452.   ; Temporary variable to inform startTournament alias that button was pressed
  453.   set %tempCreated true
  454. }
  455.  
  456. ;--------------------------------------------------------------------------------
  457. ; This alias outputs the submenu that displays the tournaments which entries have
  458. ; expired and may need the extension
  459. ;--------------------------------------------------------------------------------
  460. alias extendEntriesDisplay {
  461.   if ($1 == begin) return -
  462.   var %i = 1
  463.   while (%i <= %TCtournamentId) {
  464.     var %prefix = $+(%, TC, tournament, %i)
  465.     var %round = $+(%prefix, round)
  466.     var %name = $+(%prefix, name)
  467.     var %timerId = $+(Entries, %i)
  468.     if ($1 == %i) && ($eval(%name, 2)) && (!$timer(%timerId)) && (!$eval(%round, 2)) return [# $+ %i $+ ] Extend entries for $eval(%name) $+ : extendEntries %i
  469.     else if ($1 == %i) return -
  470.     inc %i
  471.   }
  472.   if ($1 == end) return -
  473. }
  474.  
  475. ;--------------------------------------------------------------------------------
  476. ; Extends the entries
  477. ;--------------------------------------------------------------------------------
  478. alias extendEntries {
  479.   var %time = $$?="Extend for (4-60 minutes)"
  480.   while (%time !isnum 4-60) {
  481.     var %time = $$?="Extend for (4-60 minutes)"
  482.   }
  483.   var %entriesTime = $+(%, TC, tournament, $1, entriesTime)
  484.   set $eval(%entriesTime) $calc(%time * 60)
  485.   entriesTimer $1
  486. }
  487.  
  488. ;--------------------------------------------------------------------------------
  489. ; This alias outputs the submenu that displays the tournaments cancellation
  490. ;--------------------------------------------------------------------------------
  491. alias cancelTournamentDisplay {
  492.   if ($1 == begin) return -
  493.   var %i = 1
  494.   while (%i <= %TCtournamentId) {
  495.     var %prefix = $+(%, TC, tournament, %i)
  496.     var %name = $+(%prefix, name)
  497.     var %round = $+(%prefix, round)
  498.     if (!$eval(%round, 2)) var %action Cancel
  499.     else var %action End
  500.     if ($1 == %i) && ($eval(%name, 2)) return [# $+ %i $+ ] %action $eval(%name) $+ : cancelTournament %i %action
  501.     else if ($1 == %i) return -
  502.     inc %i
  503.   }
  504.   if ($1 == end) return -
  505. }
  506.  
  507. ;--------------------------------------------------------------------------------
  508. ; Cancels/ends the tournament
  509. ; Note that cancelling on entries step would cause the message to be displayed
  510. ; to players in the channel
  511. ;--------------------------------------------------------------------------------
  512. alias cancelTournament {
  513.   ; Display the dialog asking confirmation
  514.   if (!$input(Are you sure to $iif($2 == Cancel, cancel, end) this tournament?)) halt
  515.   ; If its the latest created tournament decrement id counter
  516.   if ($1 == %TCtournamentId) dec %TCtournamentId
  517.   ; Decrement the amount tournaments counter
  518.   dec %TCtournaments
  519.   ; If there are no tournaments id goes to 0 too
  520.   if (%TCtournaments == 0) set %TCtournamentId 0
  521.  
  522.   var %prefix = $+(%, TC, tournament, $1)
  523.   var %tournamentName = $eval($+(%prefix, name), 2)
  524.  
  525.   if ($2 == Cancel) {
  526.     ; Disable Entries timers
  527.     var %timerId = $+(., timer, Entries, $1)
  528.     $eval(%timerId) off
  529.     ; Display the notice to players        
  530.     var %channel = $eval($+(%prefix, channel), 2)
  531.     notice %channel $eval(%cancelledNotice, 2)
  532.   }
  533.   if ($2 == End) {
  534.     ; Disable round timers
  535.     var %timerId = $+(., timer, tournament, $1, round)
  536.     $eval(%timerId) off
  537.     ; Disable finals timers if so
  538.     var %timerId = $+(., timer, tournament, $1, finals)
  539.     $eval(%timerId) off
  540.  
  541.     echo -a 0,3* You have ended the >> %tournamentName << Don't forget to end it on the Home page of www.Magic-Temple.com too! *
  542.   }
  543.   var %prefix = $+(%, TC, tournament, $1, *)
  544.   ; Unset everything that starts with a prefix
  545.   unset $eval(%prefix)
  546.  
  547. }
  548.  
  549. ;--------------------------------------------------------------------------------
  550. ; This alias outputs the line that lets you start Quick Tournament (if its set)
  551. ;--------------------------------------------------------------------------------
  552. alias startQuickDisplay {
  553.   if ($1 == begin) return -
  554.   var %i = 1
  555.   while (%i <= %TCquickPresets) {
  556.     var %name = $+(%, TC, tournament, Quick, %i, name)
  557.     if ($1 == %i) return Start $eval(%name) $+ : startQuickTournament %i
  558.     else if ($1 == %i) return -
  559.     inc %i
  560.   }
  561.   if ($1 == %i) && (%TCquickPresets) return ..Clear quick tournaments: ClearQuickTournaments
  562.  
  563.   if ($1 == end) return -
  564. }
  565.  
  566. ;--------------------------------------------------------------------------------
  567. ; Starts quick tournament
  568. ;--------------------------------------------------------------------------------
  569. alias startQuickTournament {
  570.   inc %TCtournaments
  571.   inc %TCtournamentId
  572.   var %prefix = $+(%, TC, tournament, %TCtournamentId)
  573.   var %prefixQ = $+(%, TC, tournament, Quick, $1)
  574.   var %tournamentQuickName = $+(%prefixQ, name)
  575.   var %tournamentName = $+(%prefix, name)  
  576.   set $eval(%tournamentName) $eval(%tournamentQuickName, 2)
  577.   var %tournamentQuickType = $+(%prefixQ, type)
  578.   var %tournamentType = $+(%prefix, type)  
  579.   set $eval(%tournamentType) $eval(%tournamentQuickType, 2)
  580.   var %tournamentQuickCategory = $+(%prefixQ, category)
  581.   var %tournamentCategory = $+(%prefix, category)  
  582.   set $eval(%tournamentCategory) $eval(%tournamentQuickCategory, 2)
  583.   var %channel = $+(%prefix, channel)
  584.   set $eval(%channel) $chan
  585.   var %tournamentQuickEntriesTime = $+(%prefixQ, entriesTime)
  586.   var %tournamentEntriesTime = $+(%prefix, entriesTime)  
  587.   set $eval(%tournamentEntriesTime) $eval(%tournamentQuickEntriesTime, 2)
  588.   var %tournamentQuickRoundLength = $+(%prefixQ, roundLength)
  589.   var %tournamentRoundLength = $+(%prefix, roundLength)
  590.   set $eval(%tournamentRoundLength) $eval(%tournamentQuickRoundLength, 2)
  591.   entriesTimer %TCtournamentId
  592. }
  593.  
  594. ;--------------------------------------------------------------------------------
  595. ; Erases every saved preset
  596. ;--------------------------------------------------------------------------------
  597. alias clearQuickTournaments {
  598.   var %prefix = $+(%, TC, tournament, Quick, *)
  599.   unset $eval(%prefix)
  600.   unset %TCquickPresets
  601. }
  602.  
  603. ;--------------------------------------------------------------------------------
  604. ; This alias displays the start round option
  605. ;--------------------------------------------------------------------------------
  606. alias roundStartDisplay {
  607.   if ($1 == begin) return -
  608.   var %i = 1
  609.   while (%i <= %TCtournamentId) {
  610.     var %prefix = $+(%, TC, tournament, %i)
  611.     var %name = $+(%prefix, name)
  612.     var %round = $+(%prefix, round)
  613.     var %roundName = $eval($+(%prefix, roundName), 2)
  614.     if ($1 == %i) && ($eval(%name, 2)) && (%roundName != Finals) return [# $+ %i $+ ] Start Round $calc(%round + 1) for $eval(%name, 2) $+ : roundStart %i
  615.     else if ($1 == %i) return -
  616.     inc %i
  617.   }
  618.   if ($1 == end) return -
  619. }
  620.  
  621. ;--------------------------------------------------------------------------------
  622. ; Starts the round (posts pairings, executes timers)
  623. ;--------------------------------------------------------------------------------
  624. alias roundStart {
  625.   var %prefix = $+(%, TC, tournament, $1)
  626.   var %category = $eval($+(%prefix, category), 2)
  627.   var %round = $+(%prefix, round)
  628.   var %pairs = $+(%prefix, pairs)
  629.   var %roundN $+(%prefix, roundName)
  630.  
  631.   ; Check if pairings are correct
  632.   if ($eval(%round, 2)) || (%category != Sealed) {
  633.     if (%type != Swiss) && ($eval(%pairs, 2)) {
  634.       if ($eval(%pairs, 2) <= $cb(0)) {
  635.         var %noPairings = true
  636.       }
  637.     }
  638.     var %reg ([\w-\[\]]+)\svs\.\s([\w-\[\]]+)
  639.     var %i = 1
  640.     while (%i <= $cb(0)) {    
  641.       if (!$regex(match, $cb(%i), %reg)) {
  642.         var %noPairings = true
  643.       }
  644.       inc %i
  645.     }
  646.   }
  647.  
  648.   ; Disable Entries timers if needed
  649.   if (!$eval(%round, 2)) {
  650.     var %entries = $+(%prefix, entriesTime)
  651.     unset $eval(%entries)
  652.     var %timerId = $+(., timer, Entries, $1)
  653.     $eval(%timerId) off
  654.   }
  655.  
  656.   ; Disable previous round timers if needed
  657.   if ($eval(%round, 2)) {
  658.     var %timerId = $+(., timer, tournament, $1, round)
  659.     $eval(%timerId) off
  660.   }
  661.  
  662.   ; Special deckbuilding round
  663.   if (!$eval(%round, 2)) && (%category == Sealed) {
  664.     set $eval(%roundN) Deckbuilding Round
  665.     roundTimer $1 %TCsealedDeckbuildingTime
  666.   }
  667.  
  668.   ; Regular round
  669.   if ($eval(%round, 2)) || (%category != Sealed) {
  670.     var %roundLength = $eval($+(%prefix, roundLength), 2)
  671.     var %type = $eval($+(%prefix, type), 2)
  672.     if (%category == Sealed) var %roundName Round $eval(%round, 2)
  673.     else var %roundName Round $calc($eval(%round, 2) + 1)
  674.     if (%type != Swiss) && (%noPairings != true) {
  675.       if ($cb(0) <= 4) var %roundName Quaterfinals
  676.       if ($cb(0) <= 2) var %roundName Semifinals
  677.       if ($cb(0) == 1) var %roundName Finals
  678.       set $eval(%pairs) $cb(0)
  679.     }
  680.     set $eval(%roundN) %roundName
  681.     roundTimer $1 %roundLength
  682.     ; Paste pairings in the channel
  683.     set %tempCounter 1
  684.     ; Using timer for antikick for flood
  685.     if (%noPairings != true) .timerpairings -m $ceil($calc($cb(0) / 4)) 50 pairing $1
  686.   }
  687.  
  688.   ; Round++
  689.   inc $eval(%round)w
  690.   unset %tempCounter
  691. }
  692.  
  693. ;--------------------------------------------------------------------------------
  694. ; Anti-flood measure. This alias outputs pairings
  695. ;--------------------------------------------------------------------------------
  696. alias pairing {
  697.   var %reg ([\w-\[\]]+)\svs\.\s([\w-\[\[]+)
  698.   var %prefix = $+(%, TC, tournament, $1)
  699.   var %channel = $eval($+(%prefix, channel), 2)
  700.   var %i = 0
  701.   while (%i <= 4) {
  702.     var %regexp = $regex(match, $cb($calc(%tempCounter)), %reg)
  703.     var %player1 = $regml(match, 1)
  704.     var %player2 = $regml(match, 2)
  705.     ; Anti excess floood measure
  706.     if (%regexp) {
  707.       if (%player2 != Bye) msg %channel $eval(%vsmessage, 2)
  708.       else msg %channel $eval(%byemessage, 2)
  709.     }
  710.     inc %i
  711.     inc %tempCounter
  712.   }  
  713. }
  714.  
  715. ;--------------------------------------------------------------------------------
  716. ; Handles the round timer
  717. ;--------------------------------------------------------------------------------
  718. alias roundTimer {
  719.   var %prefix = $+(%, TC, tournament, $1)
  720.   var %roundCountdown = $+(%prefix, roundCountdown)
  721.   var %tournamentName = $eval($+(%prefix, name), 2)
  722.   var %channel = $eval($+(%prefix, channel), 2)
  723.   var %timeLeft = $2
  724.   var %roundName = $eval($+(%prefix, roundName), 2)
  725.  
  726.   if (%roundName != Finals) {
  727.     var %timerId = $+(., timer, tournament, $1, round)
  728.     set $eval(%roundCountdown) $2    
  729.     notice %channel $eval(%roundBegin, 2)
  730.     ; Invoke timer call every minute
  731.     $eval(%timerId) $2 $calc(1 * 60) roundNotices $1 %roundName
  732.   }
  733.  
  734.   if (%roundName == Finals) {
  735.     var %timerId = $+(., timer, tournament, $1, finals)
  736.     set $eval(%roundCountdown) 15
  737.     notice %channel $eval(%roundFinals, 2)
  738.     $eval(%timerId) 15 $calc(1 * 60) roundFinals $1 %roundName    
  739.   }
  740.  
  741. }
  742.  
  743. ;--------------------------------------------------------------------------------
  744. ; Merely displays the round notices
  745. ;--------------------------------------------------------------------------------
  746. alias roundNotices {
  747.   var %prefix = $+(%, TC, tournament, $1)
  748.   var %tournamentName = $eval($+(%prefix, name), 2)
  749.   var %channel = $eval($+(%prefix, channel), 2)
  750.   var %roundLength = $eval($+(%prefix, roundLength), 2)
  751.   dec $eval($+(%prefix, roundCountdown))
  752.   var %timeLeft = $eval($+(%prefix, roundCountdown), 2)
  753.   var %roundName = $eval($+(%prefix, roundName), 2)
  754.   if ($calc(%roundLength - %timeleft) == 10) && (%roundLength > 29) notice %channel $eval(%roundgameloss, 2)
  755.   if ($calc(%roundLength - %timeleft) == 15)  && (%roundLength > 29) notice %channel $eval(%roundmatchloss, 2)
  756.   if (%timeLeft == 20) notice %channel $eval(%round20left, 2)
  757.   if (%timeLeft == 10) notice %channel $eval(%round10left, 2)
  758.   if (%timeLeft == 5) notice %channel $eval(%round5left, 2)
  759.   if (%timeLeft == 0) notice %channel $eval(%roundTime, 2)
  760. }
  761.  
  762. ;--------------------------------------------------------------------------------
  763. ; Handles the finals notices
  764. ;--------------------------------------------------------------------------------
  765. alias roundFinals {
  766.   var %prefix = $+(%, TC, tournament, $1)
  767.   var %tournamentName = $eval($+(%prefix, name), 2)
  768.   var %channel = $eval($+(%prefix, channel), 2)
  769.   var %roundLength = $eval($+(%prefix, roundLength), 2)
  770.   dec $eval($+(%prefix, roundCountdown))
  771.   var %timeLeft = $eval($+(%prefix, roundCountdown), 2)
  772.   var %roundName = $eval($+(%prefix, roundName), 2)
  773.   if (%timeLeft == 5) {
  774.     notice %channel $eval(%roundgameloss, 2)
  775.   }
  776.   if (%timeLeft == 0) {
  777.     notice %channel $eval(%roundmatchloss, 2)
  778.     endFinals $1
  779.   }
  780. }
  781.  
  782. ;--------------------------------------------------------------------------------
  783. ; Ends the finals
  784. ;--------------------------------------------------------------------------------
  785. alias endFinals {
  786.   ; If its the latest created tournament decrement id counter
  787.   if ($1 == %TCtournamentId) dec %TCtournamentId
  788.   ; Decrement the amount tournaments counter
  789.   dec %TCtournaments
  790.   ; If there are no tournaments id goes to 0 too
  791.   if (%TCtournaments == 0) set %TCtournamentId 0
  792.   var %prefix = $+(%, TC, tournament, $1, *)
  793.   ; Unset everything that starts with a prefix
  794.   unset $eval(%prefix)
  795.   ; Display that it ended
  796.   echo -a 0,3* You have ended the tournament. Don't forget to end it on the Home page of www.Mtg-Temple.com too! *
  797. }
  798.  
  799. ;--------------------------------------------------------------------------------
  800. ; Displays the time left if player types !time
  801. ;--------------------------------------------------------------------------------
  802. on 1:TEXT:!time:#:{
  803.   var %i = 1
  804.   while (%i <= %TCtournamentId) {
  805.     var %prefix = $+(%, TC, tournament, %i)
  806.     var %tournamentName = $eval($+(%prefix, name), 2)
  807.     var %roundName = $eval($+(%prefix, roundName), 2)
  808.     var %roundCountdown = $eval($+(%prefix, roundCountdown), 2)
  809.     var %timeLeft = %roundCountdown
  810.     var %channel = $eval($+(%prefix, channel), 2)
  811.     var %timerId = $+(tournament, %i, round)
  812.     if (%tournamentName) && ($chan == %channel) && ($timer(%timerId)) .notice $nick $eval(%timeLeftNotice, 2)
  813.     inc %i
  814.   }
  815. }
  816.  
  817. ;--------------------------------------------------------------------------------
  818. ; Show remaining time
  819. ;--------------------------------------------------------------------------------
  820. alias showRemainingTime {
  821.   var %i = 1
  822.   while (%i <= %TCtournamentId) {
  823.     var %prefix = $+(%, TC, tournament, %i)
  824.     var %tournamentName = $eval($+(%prefix, name), 2)
  825.     var %roundName = $eval($+(%prefix, roundName), 2)
  826.     var %roundCountdown = $eval($+(%prefix, roundCountdown), 2)
  827.     var %timeLeft = %roundCountdown
  828.     var %timerId = $+(tournament, %i, round)
  829.     if (%tournamentName) && ($timer(%timerId)) echo -a $eval(%timeLeftNotice, 2)
  830.     inc %i
  831.   }
  832. }
  833.  
  834. ;--------------------------------------------------------------------------------
  835. ; This alias outputs the submenu that displays the tournaments which round
  836. ; expired and may need the extension
  837. ;--------------------------------------------------------------------------------
  838. alias extendRoundDisplay {
  839.   if ($1 == begin) return -
  840.   var %i = 1
  841.   while (%i <= %TCtournamentId) {
  842.     var %prefix = $+(%, TC, tournament, %i)
  843.     var %round = $+(%prefix, round)
  844.     var %name = $+(%prefix, name)
  845.     var %timerId = $+(tournament, %i, round)
  846.     var %timerFinalsId = $+(tournament, %i, finals)
  847.     if ($1 == %i) && ($eval(%name, 2)) && (!$timer(%timerId)) && (!$timer(%timerFinalsId)) && ($eval(%round, 2)) return [# $+ %i $+ ] Extend round for $eval(%name) $+ : extendRound %i
  848.     else if ($1 == %i) return -
  849.     inc %i
  850.   }
  851.   if ($1 == end) return -
  852. }
  853.  
  854. ;--------------------------------------------------------------------------------
  855. ; Extends the round
  856. ;--------------------------------------------------------------------------------
  857. alias extendRound {
  858.   var %time = $$?="Extend for (1-25 minutes)"
  859.   while (%time !isnum 1-25) {
  860.     var %time = $$?="Extend for (1-25 minutes)"
  861.   }
  862.   var %prefix = $+(%, TC, tournament, $1)
  863.   var %roundName = $+(%prefix, roundName)
  864.   set $eval(%roundName) $eval(%roundName, 2) Extension
  865.   roundTimer $1 %time
  866. }
  867.  
  868. ;--------------------------------------------------------------------------------
  869. ; Displays submenu that lets you check the remaining time in all active
  870. ; tournaments
  871. ;--------------------------------------------------------------------------------
  872. alias remainingTimeDisplay {
  873.   if ($1 == begin) return -
  874.   var %prefix = $+(%, TC, tournament, %i)
  875.   var %i = 1
  876.   while (%i <= %TCtournamentId) {
  877.     var %timerId = $+(tournament, %i, round)
  878.     if ($timer(%timerId)) {
  879.       var %active = true
  880.       break
  881.     }    
  882.     inc %i
  883.   }
  884.   if ($1 == 1) && (%active == true) return Show Remaining Time: showRemainingTime
  885.   if ($1 == end) return -
  886. }
  887.  
  888.  
  889. ;--------------------------------------------------------------------------------
  890. ; This alias outputs the submenu that displays if you can trod the players
  891. ; who didn't report (just copy paste table from site)
  892. ;--------------------------------------------------------------------------------
  893. alias informNonReportedDisplay {
  894.   if ($1 == begin) return -
  895.   var %i = 1
  896.   while (%i <= %TCtournamentId) {
  897.     var %prefix = $+(%, TC, tournament, %i)
  898.     var %round = $+(%prefix, round)
  899.     var %name = $+(%prefix, name)
  900.     var %timerId = $+(tournament, %i, round)
  901.     var %timerFinalsId = $+(tournament, %i, finals)
  902.     if ($1 == %i) && ($eval(%name, 2)) && (!$timer(%timerId)) && (!$timer(%timerFinalsId)) && ($eval(%round, 2)) return Inform the nonreported: informNonReported | break
  903.     else if ($1 == %i) return -
  904.     inc %i
  905.   }
  906.   if ($1 == end) return -
  907. }
  908.  
  909. ;--------------------------------------------------------------------------------
  910. ; Parses the clipboard and messages all the players who did not report
  911. ;--------------------------------------------------------------------------------
  912. alias informNonReported {
  913.   var %reg [\s]*[\w-\[\]]+[\s]*\(([\w-\[\]]+)\)[\s]*vs\.[\s]*[\w-\[\]]+[\s]*\(([\w-\[\]]+)\)[\s]*-[\s]*(TC|both|[\w-\[\]]+|)[\s]*
  914.   var %i = 1
  915.   while (%i <= $cb(0)) {    
  916.     if ($regex(match, $cb(%i), %reg)) {
  917.       var %player1 = $regml(match, 1)
  918.       var %player2 = $regml(match, 2)
  919.       var %reportStatus = $regml(match, 3)
  920.       if (%reportStatus != TC) && (%reportStatus != both) {
  921.         if (%reportStatus == %player1) {
  922.           .msg %player2 %reportPleaseMessage
  923.         }
  924.         if (%reportStatus == %player2) {
  925.           .msg %player1 %reportPleaseMessage
  926.         }
  927.         if (%reportStatus != %player1) && (%reportStatus != %player2) {
  928.           .msg %player2 %reportPleaseMessage
  929.           .msg %player1 %reportPleaseMessage
  930.         }
  931.       }
  932.     }
  933.     inc %i
  934.   }
  935. }
  936.  
  937.  
  938. ;--------------------------------------------------------------------------------
  939. ; This alias is rather simple and lets you to take over someone's tournament
  940. ;--------------------------------------------------------------------------------
  941. alias continueTournament {
  942.   var %name = $$?="Specify tournament name"
  943.   var %round = $$?="Specify round (1-n)"
  944.   while (%round !isnum 1-30) {
  945.     var %round = $$?="Specify round (1-n)"
  946.   }
  947.  
  948.   var %timeLeft = $$?="Specify time left till end of round (1-45)"
  949.   while (%timeLeft !isnum 1-45) {
  950.     var %timeLeft = $$?="Specify time left till end of round (1-45)"
  951.   }
  952.  
  953.   inc %TCtournaments
  954.   inc %TCtournamentId
  955.  
  956.   var %prefix = $+(%, TC, tournament, %TCtournamentId)
  957.   var %tournamentName = $+(%prefix, name)
  958.   var %tournamentRound = $+(%prefix, round)
  959.   var %roundCountdown = $+(%prefix, roundCountdown)
  960.   var %roundName = $+(%prefix, roundName)
  961.   var %roundLength = $+(%prefix, roundLength)
  962.   var %channel = $+(%prefix, channel)
  963.  
  964.   set $eval(%tournamentName) %name
  965.   set $eval(%tournamentRound) %round
  966.   set $eval(%roundCountdown) %timeLeft
  967.   set $eval(%channel) $chan
  968.   set $eval(%roundLength) 45
  969.   set $eval(%roundName) Round %round
  970.  
  971.   var %tournamentName = %name
  972.  
  973.   notice $chan $eval(%takeOverNotice, 2)
  974.   var %timerId = $+(., timer, tournament, %TCtournamentId, round)
  975.   ; Invoke timer call every minute
  976.   $eval(%timerId) %timeLeft $calc(1 * 60) roundNotices %TCtournamentId %name
  977.  
  978. }