Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;============================== Start Auto-Execution Section ==============================
- ; Always run as admin
- if not A_IsAdmin
- {
- Run *RunAs "%A_ScriptFullPath%" ; Requires v1.0.92.01+
- ExitApp
- }
- ; Determines how fast a script will run (affects CPU utilization)
- ; The value -1 means the script will run at it's max speed possible
- SetBatchLines, -1
- ; Avoids checking empty variables to see if they are environment variables
- ; Recommended for performance and compatibility with future AutoHotkey releases
- #NoEnv
- ; Ensures that there is only a single instance of this script running
- #SingleInstance, Force
- ; Makes a script unconditionally use its own folder as its working directory
- ; Ensures a consistent starting directory
- SetWorkingDir %A_ScriptDir%
- ; sets title matching to search for "containing" instead of "exact"
- SetTitleMatchMode, 2
- ; Sets the key send input type
- ; Use Event to make use of KeyDelay below
- SendMode, Input
- ; return
- ;============================== Main Script ==============================
- ; Normally I'd do this with a GUI but I'm trying something different.
- ; This formats the MsgBox to look like how I want it.
- ; A SetTimer is used because the MsgBox must be up before it's controls
- ; can be changed.
- SetTimer, FormatMsgBox, 20
- ; MsgBox I'll be using as a lazy GUI
- ; Yes assigns 1 to team. 2 assigns no.
- MsgBox, 515, Teams, How many teams are there?
- IfMsgBox, Yes
- team := 1
- IfMsgBox, No
- team := 2
- IfMsgBox, Cancel
- CancelCheck(1)
- gosub, GetScores
- gosub, CalcScore
- GetScores:
- InputBox, threePt1, Team 1 - 3 Pointers, How many 3 pointers were made by team 1?
- CancelCheck(ErrorLevel)
- NumCheck(threePt1)
- InputBox, twoPt1, Team 1 - 2 Pointers, How many 2 pointers were made by team 1?
- CancelCheck(ErrorLevel)
- NumCheck(twoPt1)
- InputBox, freeTh1, Team 1 - Free Throws, How many free throws were made by team 1?
- CancelCheck(ErrorLevel)
- NumCheck(freeTh1)
- ; NumCheck(threePt1)
- ; NumCheck(twoPt1)
- ; NumCheck(freeTh1)
- if (team = 2){
- InputBox, threePt2, Team 2 - 3 Pointers, How many 3 pointers were made by team 2?
- CancelCheck(ErrorLevel)
- NumCheck(threePt2)
- InputBox, twoPt2, Team 2 - 2 Pointers, How many 2 pointers were made by team 2?
- CancelCheck(ErrorLevel)
- NumCheck(twoPt2)
- InputBox, freeTh2, Team 2 - Free Throws, How many free throws were made by team 2?
- CancelCheck(ErrorLevel)
- NumCheck(freeTh2)
- }
- return
- CalcScore:
- team1Total := threePt1 * 3 + twoPt1 * 2 + freeTh1
- team2Total := threePt2 * 3 + twoPt2 * 2 + freeTh2
- if (team = 1){
- MsgBox % "The team's total score is: " . team1Total
- ExitApp
- }
- if (team1Total = team2Total)
- gosub, TieBreaker
- winner := team1Total > team2Total ? "Team 1" : "Team 2"
- MsgBox % "The winner is " . winner . "`nTeam 1 Total: " . team1Total . "`nTeam 2 Total: " . team2Total
- ExitApp
- TieBreaker:
- MsgBox % "It's a tie!`nTeam 1 Total: " . team1Total . "`nTeam 2 Total: " . team2Total . "`nPlease click OK to flip a coin and randomly choose a winner.`n`nHeads, team 1 wins." . A_Tab A_Tab A_Tab . "Tails, team 2 wins."
- Random, coinFlip, 1, 100
- result := (mod(coinFlip, 2)) = 1 ? "Tails" : "Heads"
- winner := result = 1 ? "Team 2" : "Team 1"
- MsgBox, % "Coin Flip.`n`nIt's " . result . "!`n`n" . winner . " wins!"
- ExitApp
- ; Changes button names on msgbox to 1 Team and 2 Teams. Cancel is untouched.
- FormatMsgBox:
- ; SetTimer keeps running until Teams window is found
- IfWinNotExist, Teams
- return
- ; Once found, turn off SetTimer
- SetTimer, FormatMsgBox, Off
- ; Activate window and change button text
- WinActivate
- ControlSetText, button1, 1 Team
- ControlSetText, button2, 2 Teams
- return
- ; Checks if cancel is pushed when using an input box.
- ; If yes, tell user then exit script.
- CancelCheck(EL){
- if (EL = 1){
- MsgBox, Cancel was pressed.`nThe script will now exit.
- ExitApp
- }
- return
- }
- NumCheck(temp){
- MsgBox numcheck start
- ; Check to ensure there are only number but there is at least one number
- if (RegExMatch(temp, "^[0-9]+$")){
- MsgBox This is a number.
- return
- }
- ; Check to see if value is blank
- if (RegExMatch(temp, "^\s*$")){
- MsgBox, You cannot leave a number blank
- gosub, GetScores
- return
- }
- else{
- MsgBox % temp . " is not a number."
- gosub, GetScores
- }
- }
- ;============================== GroggyOtter ==============================
- ;============================== End Script ==============================
Advertisement
Add Comment
Please, Sign In to add comment