Welcome to SkriptTools.net!

SkriptTools is now part of the skUnity family! skUnity will keep SkriptTools running, updating and adding new features.


- You can now search scripts by author by doing "author:name". For example: "author:nfell2009"

- Login to SkriptTools using your skUnity account to save your favourite scripts and come back to them

Login

Script Viewer

View the code of the script directly in your browser without downloading anything.

Current File: skunitybackup-164.sk - Download / View on the skUnity Parser

#
#   ____                          __ _             
#  / __ \ _____ ___   ____   ____/ /(_)____ _ ____ 
# / / / // ___// _ \ / __ \ / __  // // __ `// __ \
#/ /_/ // /   /  __// / / // /_/ // // /_/ // /_/ /
#\____//_/    \___//_/ /_/ \__,_//_/ \__, / \____/ 
#                                   /____/         
#                                       ohhiya
#                   V 2.3
#
#Prerequisites:
#Skript                          - https://github.com/bensku/Skript/releases          - I think there are some other versions of skript floating around, but I'll just link this one.
#Umbaska                         - http://umbaska.gatt.space/                         - Uses Umbaska's 'set slot' functionality
#SkRayFall                       - http://dev.bukkit.org/bukkit-plugins/skrayfall/    - Used primarily for scoreboards
#SkQuery                         - http://umbaska.gatt.space/
#
#
#Also, I'm going to stress the importance of adding an independent CSV file Database for the script.
#Here's the format I use in my config.sk located in Skript's directory:
#
#	Connect4:
#		type: CSV
#		pattern: ~Connect4.*
#		file: ./plugins/Skript/databases/Connect4.csv
#		backup interval: 2 hours
#
#This is just the format I use, you can change it to fit your need; however, the 'pattern' section must be kept the same!

# uncomment the 5 lines below to enable SQL support.  Don't forget to enable it in the config as well!
#script options:
#	$ init com.mysql.jdbc.Driver
#	$ db url jdbc:mysql://HOST:PORT/DATABASE?autoReconnect=true
#	$ db username USERNAME
#	$ db password PASSWORD

#Table that will store the SQL statistics.
options:
	Table: Connect4Stats

#databaseVarSet... Sets a value within a provided SQL database.
function databaseVarSet(p: text, column: text, value: text):
	$ thread
	set {_Objects::*} to objects in column "%{_column}%" from result of query "SELECT * FROM {@Table} WHERE PlayerID = '%{_p}%'"
	if {_Objects::*} is not set:
		$ thread
		update "INSERT INTO `{@Table}` (`PlayerID`, `Wins`, `Loses`, `Draws`, `Forfeits`) VALUES ('%{_p}%', '0', '0', '0', '0')"
	$ thread
	update "UPDATE `{@Table}` SET `%{_column}%` = '%{_value}%' WHERE `{@Table}`.`PlayerID` ='%{_p}%'"

#databaseVarGet... Gets a value within a provided SQL database.
function databaseVarGet(p: text, column: text, type: text) :: number:
	set {_Objects::*} to objects in column "%{_column}%" from result of query "SELECT * FROM {@Table} WHERE PlayerID = '%{_p}%'"
	loop {_Objects::*}:
		if loop-value is set:
			set {_varValue} to loop-value
	if {_varValue} is set:
		set {_i} to "%{_varValue}%" parsed as number
		if "%{_type}%" contains "increment":
			add 1 to {_i}
			return {_i}
		else:
			return {_i}
	else:
		if "%{_type}%" contains "exist":
			return "%{_varValue}%" parsed as number
		else:
			return 0

#textFormat... Replaces placeholders from the config file
function textFormat(patient: text, replacer: text, donor: text, replacer1: text, donor1: text) :: text:
	replace "%{_replacer}%" in {_patient} with "%{_donor}%"
	replace "%{_replacer1}%" in {_patient} with "%{_donor1}%"
	return colored "%{_patient}%"

#winState... Activates the win state for players and spectators; disable all slots.
function winState(p: player, l: numbers):
	set {_target} to {~Connect4.CurrentGames::%{_p}%}
	set {~Connect4.winState::%{_p}%} to true
	set {~Connect4.winState::%{_target}%} to true
	set {_winnerMessage} to textFormat("%yaml value ""Connect4.Messages.Game.Win"" from file ""Connect4Config.yml""%", "%%PREFIX%%", "%{~Connect4.Messages::Prefix}%", "%%WINNER%%", "%{_p}%")
	set {_winnerMessage} to textFormat("%{_winnerMessage}%", "%%LOSER%%", "%{_target}%", "", "")
	message "%{_winnerMessage}%" to {_p}
	message "%{_winnerMessage}%" to {_target}
	loop {~Connect4.Spectators::*}:
		if "%loop-value%" contains "%{_p}%" or "%{_target}%":
			message "%{_winnerMessage}%" to loop-index parsed as player
			add loop-index to {_spectators::*}

	set {_winBlock} to "%yaml value ""Connect4.GUI.Game.WinBlock"" from file ""Connect4Config.yml""%" parsed as item
	if yaml value "Connect4.Animations.Winning" from file "Connect4Config.yml" is true:
		set {_playerTitleText} to textFormat("%yaml value ""Connect4.GUI.Game.Title"" from file ""Connect4Config.yml""%", "%%TARGET%%", "%{_target}%", "%%PLAYER%%", "%{_p}%")
		set {_targetTitleText} to textFormat("%yaml value ""Connect4.GUI.Game.Title"" from file ""Connect4Config.yml""%", "%%TARGET%%", "%{_p}%", "%%PLAYER%%", "%{_target}%")
		set {_waitTime} to "%yaml value ""Connect4.Animations.WinningTicks"" from file ""Connect4Config.yml""%" parsed as time span
		if {~Connect4.Players::%{_p}%} is 1:
			set {_block} to {~Connect4.Blocks::Player1}
		else:
			set {_block} to {~Connect4.Blocks::Player2}

		loop 3 times:
			loop {_l::*}:
				inventory name of {_p}'s current inventory is "%{_playerTitleText}%"
				set slot loop-value-2 of {_p}'s current inventory to {_winBlock} named "&eWinning Move"
				inventory name of {_target}'s current inventory is "%{_targetTitleText}%"
				set slot loop-value-2 of {_target}'s current inventory to {_winBlock} named "&eWinning Move"
				loop {_spectators::*}:
					set {_spector} to loop-value-3 parsed as player
					if inventory name of {_spector}'s current inventory contains "%{_p}%" or "%{_target}%":
						set slot loop-value-2 of {_spector}'s current inventory to {_winBlock} named "&eWinning Move"
			wait {_waitTime}
			loop {_l::*}:
				inventory name of {_p}'s current inventory is "%{_playerTitleText}%"
				set slot loop-value-2 of {_p}'s current inventory to {_block} named "%{_p}%"
				inventory name of {_target}'s current inventory is "%{_targetTitleText}%"
				set slot loop-value-2 of {_target}'s current inventory to {_block} named "%{_p}%"
				loop {_spectators::*}:
					set {_spector} to loop-value-3 parsed as player
					if inventory name of {_spector}'s current inventory contains "%{_p}%" or "%{_target}%":
						set slot loop-value-2 of {_spector}'s current inventory to {_block} named "%{_p}%"
			wait {_waitTime}
	loop {_l::*}:
		inventory name of {_p}'s current inventory is "%{_playerTitleText}%"
		set slot loop-value of {_p}'s current inventory to {_winBlock} named "&eWinning Move"
		inventory name of {_target}'s current inventory is "%{_targetTitleText}%"
		set slot loop-value of {_target}'s current inventory to {_winBlock} named "&eWinning Move"
		loop {_spectators::*}:
			set {_spector} to loop-value-2 parsed as player
			if inventory name of {_spector}'s current inventory contains "%{_p}%" or "%{_target}%":
				set slot loop-value-1 of {_spector}'s current inventory to {_winBlock} named "&eWinning Move"

	if yaml value "Connect4.Misc.Broadcast.Enabled" from file "Connect4Config.yml" is true:
		set {_broadcastMessage::*} to yaml list "Connect4.Misc.Broadcast.Wins" from file "Connect4Config.yml"
		if {_broadcastMessage::*} is empty:
			stop
		else:
			loop {_broadcastMessage::*}:
				set {_broadcast} to textFormat("%loop-value%", "%%WINNER%%", "%{_p}%", "%%LOSER%%", "%{_target}%")
				set {_broadcast} to textFormat("%{_broadcast}%", "%%PREFIX%%", "%{~Connect4.Messages::Prefix}%", "", "")
				broadcast "%{_broadcast}%"
	if yaml value "Connect4.Misc.Commands.Enabled" from file "Connect4Config.yml" is true:
		set {_commands::*} to yaml list "Connect4.Misc.Commands.Executables.Wins" from file "Connect4Config.yml"
		if {_commands::*} is empty:
			stop
		else:
			loop {_commands::*}:
				set {_cmd} to textFormat("%loop-value%", "%%WINNER%%", "%{_p}%", "%%LOSER%%", "%{_target}%")
				make console execute command "/%{_cmd}%"
	if yaml value "Connect4.Statistics" from file "Connect4Config.yml" is true:
		set {_puuid} to uuid of {_p}
		set {_tuuid} to uuid of {_target}
		if yaml value "Connect4.Database.Enabled" from file "Connect4Config.yml" is true:
			set {_winValue} to databaseVarGet("%{_puuid}%", "Wins", "increment")
			set {_loseValue} to databaseVarGet("%{_tuuid}%", "Loses", "increment")
			databaseVarSet("%{_puuid}%", "Wins", "%{_winValue}%")
			databaseVarSet("%{_tuuid}%", "Loses", "%{_loseValue}%")
		else:
			add 1 to {~Connect4.Wins::%{_puuid}%}
			add 1 to {~Connect4.Loses::%{_tuuid}%}

#checkDraw... Checks whether the board is full by checking max turns, leaving the players at a draw.
function checkDraw(p: player) :: boolean:
	if {~Connect4.Turns::%{_p}%} is 43:	
		set {_drawMessage} to textFormat("%yaml value ""Connect4.Messages.Game.Draw"" from file ""Connect4Config.yml""%", "%%PREFIX%%", "%{~Connect4.Messages::Prefix}%", "", "")
		message "%{_drawMessage}%" to {_p}
		message "%{_drawMessage}%" to {~Connect4.CurrentGames::%{_p}%}
		loop {~Connect4.Spectators::*}:
			set {_spectator} to loop-index parsed as player
			if "%loop-value%" contains "%{_p}%" or "%{~Connect4.CurrentGames::%{_p}%}%":
				message "%{_drawMessage}%" to {_spectator}

		if yaml value "Connect4.Misc.Broadcast.Enabled" from file "Connect4Config.yml" is true:
			set {_broadcastMessage::*} to yaml list "Connect4.Misc.Broadcast.Draws" from file "Connect4Config.yml"
			if {_broadcastMessage::*} is empty:
				stop
			else:
				loop {_broadcastMessage::*}:
					set {_broadcast} to textFormat("%loop-value%", "%%PLAYER%%", "%{_p}%", "%%TARGET%%", "%{~Connect4.CurrentGames::%{_p}%}%")
					set {_broadcast} to textFormat("%{_broadcast}%", "%%PREFIX%%", "%{~Connect4.Messages::Prefix}%", "", "")
					broadcast "%{_broadcast}%"
		if yaml value "Connect4.Misc.Commands.Enabled" from file "Connect4Config.yml" is true:
			set {_commands::*} to yaml list "Connect4.Misc.Commands.Executables.Draws" from file "Connect4Config.yml"
			if {_commands::*} is empty:
				stop
			else:
				loop {_commands::*}:
					set {_cmd} to textFormat("%loop-value%", "%%PLAYER%%", "%{_p}%", "%%TARGET%%", "%{~Connect4.CurrentGames::%{_p}%}%")
					make console execute command "/%{_cmd}%"

		if yaml value "Connect4.Statistics" from file "Connect4Config.yml" is true:
			set {_puuid} to uuid of {_p}
			set {_tuuid} to uuid of {~Connect4.CurrentGames::%{_p}%}
			if yaml value "Connect4.Database.Enabled" from file "Connect4Config.yml" is true:
				set {_pDraw} to databaseVarGet("%{_puuid}%", "Draws", "increment")
				set {_tDraw} to databaseVarGet("%{_tuuid}%", "Draws", "increment")
				databaseVarSet("%{_puuid}%", "Draws", "%{_pDraw}%")
				databaseVarSet("%{_tuuid}%", "Draws", "%{_tDraw}%")
			else:
				add 1 to {~Connect4.Draws::%{_puuid}%}
				add 1 to {~Connect4.Draws::%{_tuuid}%}
		set {~Connect4.winState::%{_p}%} to true
		set {~Connect4.winState::%{~Connect4.CurrentGames::%{_p}%}%} to true
		return true
	else:
		return false

#flatWin... Checks both the column and the row for a Connect4.
function flatWin(p: player, column: number, row: number) :: boolean:
	set {_i} to 0
	set {_x} to 0
	loop integers between 0 and 5:
		if "%{~Connect4.Game.%{_p}%::%{_column}%::%loop-integer%}%" contains "%{_p}%":
			add 1 to {_i}
			add ({_column} + (loop-integer*9)) to {_winningMove::*}
		else:
			set {_i} to 0
			clear {_winningMove::*}
		if {_i} >= 4:
			winState({_p}, {_winningMove::*})
			return true
	loop integers between 0 and 6:
		if "%{~Connect4.Game.%{_p}%::%loop-integer%::%{_row}%}%" contains "%{_p}%":
			add 1 to {_x}
			add (loop-integer + ({_row}*9)) to {_winningMove::*}
		else:
			set {_x} to 0
			clear {_winningMove::*}
		if {_x} >= 4:
			winState({_p}, {_winningMove::*})
			return true
	return false

#diagonalWin... Checks both diagonals for a Connect4.
function diagonalWin(p: player, column: number, row: number) :: boolean:
	set {_frontslash.column} to {_column} - 3
	set {_frontslash.row} to {_row} - 3
	set {_backslash.column} to {_column} + 3
	set {_backslash.row} to {_row} - 3
	loop 7 times:
		if "%{~Connect4.Game.%{_p}%::%{_frontslash.column}%::%{_frontslash.row}%}%" contains "%{_p}%":
			add 1 to {_i}
			add ({_frontslash.column} + ({_frontslash.row}*9)) to {_winningMove::*}
		else:
			set {_i} to 0
			clear {_winningMove::*}
		if {_i} >= 4:
			winState({_p}, {_winningMove::*})
			return true
		add 1 to {_frontslash.column}
		add 1 to {_frontslash.row}
	loop 7 times:
		if "%{~Connect4.Game.%{_p}%::%{_backslash.column}%::%{_backslash.row}%}%" contains "%{_p}%":
			add 1 to {_i}
			add ({_backslash.column} + ({_backslash.row}*9)) to {_winningMove::*}
		else:
			set {_i} to 0
			clear {_winningMove::*}
		if {_i} >= 4:
			winState({_p}, {_winningMove::*})
			return true
		subtract 1 from {_backslash.column}
		add 1 to {_backslash.row}
	return false

#Connect4... The main game.
function Connect4(p: player, column: text):
	set {_column} to "%{_column}%" parsed as integer
	if {~Connect4.Turns::%{_p}%} is divisible by 2:
		if {~Connect4.Players::%{_p}%} is 1:
			set {_notTurn} to textFormat("%yaml value ""Connect4.Messages.Game.Error.NotTurn"" from file ""Connect4Config.yml""%", "%%PREFIX%%", "%{~Connect4.Messages::Prefix}%", "", "")
			message "%{_notTurn}%" to {_p}
			stop
		else:
			set {_block} to {~Connect4.Blocks::Player2}
	else:
		if {~Connect4.Players::%{_p}%} is 2:
			set {_notTurn} to textFormat("%yaml value ""Connect4.Messages.Game.Error.NotTurn"" from file ""Connect4Config.yml""%", "%%PREFIX%%", "%{~Connect4.Messages::Prefix}%", "", "")
			message "%{_notTurn}%" to {_p}
			stop
		else:
			set {_block} to {~Connect4.Blocks::Player1}

	set {_i} to 5
	loop 7 times:
		if {_i} < 0:
			stop
		if {~Connect4.Game.%{_p}%::%{_column}%::%{_i}%} is set:
			subtract 1 from {_i}
		else:
			exit loop

	set {~Connect4.Game.%{_p}%::%{_column}%::%{_i}%} to {_p}
	set {~Connect4.Game.%{~Connect4.CurrentGames::%{_p}%}%::%{_column}%::%{_i}%} to {_p}
	add 1 to {~Connect4.Turns::%{_p}%}
	add 1 to {~Connect4.Turns::%{~Connect4.CurrentGames::%{_p}%}%} 
	loop {~Connect4.Spectators::*}:
		if "%loop-value%" contains "%{_p}%" or "%{~Connect4.CurrentGames::%{_p}%}%":
			add loop-index to {_spectators::*}
	if yaml value "Connect4.Animations.Moves" from file "Connect4Config.yml" is true:
		set {_playerTitleText} to textFormat("%yaml value ""Connect4.GUI.Game.Title"" from file ""Connect4Config.yml""%", "%%TARGET%%", "%{~Connect4.CurrentGames::%{_p}%}%", "%%PLAYER%%", "%{_p}%")
		set {_targetTitleText} to textFormat("%yaml value ""Connect4.GUI.Game.Title"" from file ""Connect4Config.yml""%", "%%TARGET%%", "%{_p}%", "%%PLAYER%%", "%{~Connect4.CurrentGames::%{_p}%}%")
		set {_waitTime} to "%yaml value ""Connect4.Animations.MovesTicks"" from file ""Connect4Config.yml""%" parsed as time span
		loop integers between 0 and {_i}:
			set {_slot} to (loop-integer*9)+{_column}
			inventory name of {_p}'s current inventory is "%{_playerTitleText}%"
			set slot {_slot} of {_p}'s current inventory to {_block} named "%{_p}%"
			inventory name of {~Connect4.CurrentGames::%{_p}%}'s current inventory is "%{_targetTitleText}%"
			set slot {_slot} of {~Connect4.CurrentGames::%{_p}%}'s current inventory to {_block} named "%{_p}%"
			loop {_spectators::*}:
				set {_spector} to loop-value-2 parsed as player
				if inventory name of {_spector}'s current inventory contains "%{_p}%" or "%{~Connect4.CurrentGames::%{_p}%}%":
					set slot {_slot} of {_spector}'s current inventory to {_block} named "%{_p}%"
			wait {_waitTime}
			if loop-integer = {_i}:
				exit loop
			inventory name of {_p}'s current inventory is "%{_playerTitleText}%"
			set slot {_slot} of {_p}'s current inventory to {~Connect4.Blocks::Background}  named " "
			inventory name of {~Connect4.CurrentGames::%{_p}%}'s current inventory is "%{_targetTitleText}%"
			set slot {_slot} of {~Connect4.CurrentGames::%{_p}%}'s current inventory to {~Connect4.Blocks::Background}  named " "
			loop {_spectators::*}:
				set {_spector} to loop-value-2 parsed as player
				if inventory name of {_spector}'s current inventory contains "%{_p}%" or "%{~Connect4.CurrentGames::%{_p}%}%":
					set slot {_slot} of {_spector}'s current inventory to {~Connect4.Blocks::Background}  named " "
	else:
		set slot (({_i}*9)+{_column}) of {_p}'s current inventory to {_block} named "%{_p}%"
		set slot (({_i}*9)+{_column}) of {~Connect4.CurrentGames::%{_p}%}'s current inventory to {_block} named "%{_p}%"
		loop {_spectators::*}:
			set slot (({_i}*9)+{_column}) of loop-value's current inventory to {_block} named "%{_p}%"

	if yaml value "Connect4.Sounds" from file "Connect4Config.yml" is true:
		play "BLOCK_NOTE_PLING " to {_p}
		play "BLOCK_NOTE_PLING " to {~Connect4.CurrentGames::%{_p}%}
	set name of sidebar of {_p} to "Turns: %{~Connect4.Turns::%{_p}%} - 1%"
	set name of sidebar of {~Connect4.CurrentGames::%{_p}%} to "Turns: %{~Connect4.Turns::%{_p}%} - 1%"
	flatWin({_p}, {_column}, {_i}) is false
	diagonalWin({_p}, {_column}, {_i}) is false
	checkDraw({_p}) is false
	stop

#playerSetup... Sets up the players with the slots.
function playerSetup(p: player):
	set {_titleText} to textFormat("%yaml value ""Connect4.GUI.Game.Title"" from file ""Connect4Config.yml""%", "%%TARGET%%", "%{~Connect4.CurrentGames::%{_p}%}%", "%%PLAYER%%", "%{_p}%")
	open chest with 6 row named "%{_titleText}%" to {_p}
	wait 2 ticks
	loop integers between 0 and 6:
		set {_column} to loop-integer
		set {_slot} to loop-integer
		set slot {_slot} of {_p}'s current inventory to {~Connect4.Blocks::Background}  named " "
		loop 5 times:
			set {_slot} to {_slot} + 9
			set slot {_slot} of {_p}'s current inventory to {~Connect4.Blocks::Background}  named " "
	set {_i} to 7
	loop 6 times:
		set slot {_i} of {_p}'s current inventory to {~Connect4.Blocks::Divider} named " "
		add 9 to {_i}

	set slot 8 of {_p}'s current inventory to enchanted book named "&7Information:" with lore " &7Click anywhere on the|| &7board to place your move!"
	set slot 17 of {_p}'s current inventory to {~Connect4.Blocks::Player1Divider} named " "
	set slot 44 of {_p}'s current inventory to {~Connect4.Blocks::Player2Divider} named " "
	set slot 53 of {_p}'s current inventory to {~Connect4.MenuButtons::Exit} named "&8Exit" with lore " &7Click me to exit."

	if {~Connect4.Players::%{_p}%} is 1:
		set slot 26 of {_p}'s current inventory to skull of {_p} named "&3%{_p}%"
		set slot 35 of {_p}'s current inventory to skull of {~Connect4.CurrentGames::%{_p}%} named "&3%{~Connect4.CurrentGames::%{_p}%}%"
	else:
		set slot 35 of {_p}'s current inventory to skull of {_p} named "&3%{_p}%"
		set slot 26 of {_p}'s current inventory to skull of {~Connect4.CurrentGames::%{_p}%} named "&3%{~Connect4.CurrentGames::%{_p}%}%"
	set name of sidebar of {_p} to "Turns: 0"
	set score "Spectators:" in sidebar of {_p} to 0

#invitePlayer... Invites a player to a game.
function invitePlayer(p: player, t: player):
	set {_period} to yaml value "Connect4.Invitations.Period" from file "Connect4Config.yml"
	set {_sentInvite} to textFormat("%yaml value ""Connect4.Messages.Invite.Sent.Player"" from file ""Connect4Config.yml""%", "%%PREFIX%%", "%{~Connect4.Messages::Prefix}%", "%%TARGET%%", "%{_t}%")
	set {_sentInvite} to textFormat("%{_sentInvite}%", "%%PERIOD%%", "%{_period}%", "", "")
	set {_receivedInvite} to textFormat("%yaml value ""Connect4.Messages.Invite.Sent.Target"" from file ""Connect4Config.yml""%", "%%PREFIX%%", "%{~Connect4.Messages::Prefix}%", "%%PLAYER%%", "%{_p}%")
	message "%{_sentInvite}%" to {_p}
	message "%{_receivedInvite}%" to {_t}
	set {~Connect4.Invites::%{_t}%::%{_p}%} to true
	set {_i} to 1
	while {~Connect4.Invites::%{_t}%::%{_p}%} is true:
		wait 1 second
		if {~Connect4.accept::%{_t}%::%{_p}%} is true:
			set {_acceptInvite} to textFormat("%yaml value ""Connect4.Messages.Invite.Accept.Player"" from file ""Connect4Config.yml""%", "%%PREFIX%%", "%{~Connect4.Messages::Prefix}%", "%%TARGET%%", "%{_t}%")
			message "%{_acceptInvite}%" to {_p}
			set {~Connect4.CurrentGames::%{_p}%} to {_t}
			set {~Connect4.CurrentGames::%{_t}%} to {_p}
			set {~Connect4.Players::%{_p}%} to 1
			set {~Connect4.Players::%{_t}%} to 2
			set {~Connect4.Turns::%{_p}%} to 1
			set {~Connect4.Turns::%{_t}%} to 1
			playerSetup({_p})
			playerSetup({_t})
			exit loop
		else if {~Connect4.accept::%{_t}%::%{_p}%} is false:
			exit loop
		else:
			add 1 to {_i}
		if {_i} is {_period}:
			set {_timedOut} to textFormat("%yaml value ""Connect4.Messages.Invite.Error.TimedOut.Player"" from file ""Connect4Config.yml""%", "%%PREFIX%%", "%{~Connect4.Messages::Prefix}%", "%%TARGET%%", "%{_t}%")
			message "%{_timedOut} %" to {_p}
			exit loop
	delete {~Connect4.Invites::%{_t}%::%{_p}%}
	delete {~Connect4.accept::%{_t}%::%{_p}%}

#invitePage... Incorporates multiple pages into the invitation GUI.
function invitePage(p: player, i: number):
	set {_pageStart} to 27*{_i}
	set {_i} to 0
	set {_a} to 0
	open chest with 4 rows named "&3Invite Page %{_i}%" to {_p}
	wait 2 ticks
	loop all players:
		if {_i} < {_pageStart}:
			add 1 to {_i}
			escape 4
		set slot {_a} of {_p}'s current inventory to skull of loop-player named "&b%loop-player%"
		add 1 to {_a}
		if {_a} = ((27*{_i})-1):
			exit loop
	set slot 31 of {_p}'s current inventory to {~Connect4.MenuButtons::Back} named "&cBack"
	if (amount of all players) > {_pageStart} + 27:
		set {_r} to {_i} + 1
		format slot 32 of {_p} with {~Connect4.MenuButtons::Next} named "&9Next Page" to run [invitePage({_p}, {_r})]
	if (amount of all players) > 26:
		set {_r} to {_i} - 2
		format slot 30 of {_p} with {~Connect4.MenuButtons::Previous} named "&9Previous Page" to run [invitePage({_p}, {_r})]

#spectorSetup... Sets up the spectators.
function spectorSetup(p: player, t: player):
	set {_titleText} to textFormat("%yaml value ""Connect4.GUI.Game.SpectatorTitle"" from file ""Connect4Config.yml""%", "%%TARGET%%", "%{_t}%", "%%OPPONENT%%", "%{~Connect4.CurrentGames::%{_t}%}%")
	open chest with 6 row named "%{_titleText}%" to {_p}
	wait 2 ticks
	loop integers between 0 and 6:
		set {_column} to loop-integer
		set {_slot} to loop-integer
		set slot {_slot} of {_p}'s current inventory to {_backgroundBlock} named " "
		loop 5 times:
			set {_slot} to {_slot} + 9
			set slot {_slot} of {_p}'s current inventory to {_backgroundBlock} named " "
	set {_i} to 7
	loop 6 times:
		set slot {_i} of {_p}'s current inventory to {~Connect4.Blocks::Divider} named " "
		add 9 to {_i}

	set slot 8 of {_p}'s current inventory to enchanted book named "&7Information:" with lore " &7You are spectating!|| &7You can exit at any time."
	set slot 17 of {_p}'s current inventory to {~Connect4.Blocks::Player1Divider} named " "
	set slot 44 of {_p}'s current inventory to {~Connect4.Blocks::Player2Divider} named " "
	set slot 53 of {_p}'s current inventory to {~Connect4.MenuButtons::Exit} named "&8Exit" with lore " &7Click me to exit."

	if {~Connect4.Players::%{_t}%} is 1:
		set slot 26 of {_p}'s current inventory to skull of {_t} named "&3%{_t}%"
		set slot 35 of {_p}'s current inventory to skull of {~Connect4.CurrentGames::%{_t}%} named "&3%{~Connect4.CurrentGames::%{_t}%}%"
		set {_player1} to {_t}
		set {_player2} to {~Connect4.CurrentGames::%{_t}%}
	else:
		set slot 35 of {_p}'s current inventory to skull of {_t} named "&3%{_t}%"
		set slot 26 of {_p}'s current inventory to skull of {~Connect4.CurrentGames::%{_t}%} named "&3%{~Connect4.CurrentGames::%{_t}%}%"
		set {_player1} to {~Connect4.CurrentGames::%{_t}%}
		set {_player2} to {_t}

	set {~Connect4.Spectators::%{_p}%} to {_t}
	loop integers between 0 and 6:
		loop {~Connect4.Game.%{_t}%::%loop-value%::*}:
			if "%{~Connect4.Game.%{_t}%::%loop-value-1%::%loop-index%}%" is "%{_player1}%":
				set {_i} to (loop-index parsed as number)
				set slot (loop-value-1 + ({_i}*9)) of {_p}'s current inventory to {~Connect4.Blocks::Player1} named "%{_player1}%"
			else if "%{~Connect4.Game.%{_t}%::%loop-value-1%::%loop-index%}%" is "%{~Connect4.CurrentGames::%{_player1}%}%":
				set {_i} to (loop-index parsed as number)
				set slot (loop-value-1 + ({_i}*9)) of {_p}'s current inventory to {~Connect4.Blocks::Player2} named "%{_player2}%"

	set {_a} to 0
	loop {~Connect4.Spectators::*}:
		"%loop-value%" contains "%{_t}%" or "%{~Connect4.CurrentGames::%{_t}%}%"
		add 1 to {_a}
	set score "Spectators:" in sidebar of {_t} to {_a}
	set score "Spectators:" in sidebar of {~Connect4.CurrentGames::%{_t}%} to {_a}
	set score "&b&7%{_p}%" in sidebar of {_t} to 0
	set score "&b&7%{_p}%" in sidebar of {~Connect4.CurrentGames::%{_t}%} to 0

#spectatePage... Incorporates multiple pages into the spectator GUI.
function spectatePage(p: player, l: number):
	set {_pageStart} to 27*{_l}
	set {_i} to 0
	set {_a} to 0
	open chest with 4 rows named "&8Spectate Page %{_l}%" to {_p}
	wait 2 ticks
	loop {~Connect4.CurrentGames::*}:
		if {_i} < {_pageStart}:
			add 1 to {_i}
			escape 5
		set {_t} to loop-index parsed as player
		set slot {_a} of {_p}'s current inventory to skull of {_t} named "&b%{_t}% vs. %{~Connect4.CurrentGames::%{_t}%}%"
		add 1 to {_a}
		if {_a} = ((27*{_l})-1):
			exit loop
	set slot 31 of {_p}'s current inventory to {~Connect4.MenuButtons::Back} named "&cBack"
	if (amount of {~Connect4.CurrentGames::*}) > {_pageStart} + 27:
		set {_r} to {_l} + 1
		format slot 32 of {_p} with {~Connect4.MenuButtons::Next} named "&9Next Page" to run [spectatePage({_p}, {_r})]
	if (amount of all players) > 26:
		set {_r} to {_l} - 2
		format slot 30 of {_p} with {~Connect4.MenuButtons::Previous} named "&9Previous Page" to run [invitePage({_p}, {_r})]

#/Connect4... The main command.
command /Connect4 [<text="GUI">] [<text>] [<integer=1>]:
	aliases: /c4
	permission: connect4.use
	trigger:
#/Connect4 Help... Displays the help menu.
		arg 1 is "help":
			set {_helpMenu} to textFormat("%yaml value ""Connect4.Messages.Help"" from file ""Connect4Config.yml""%", "%%PREFIX%%", "%{~Connect4.Messages::Prefix}%", "", "")
			message "%{_helpMenu}%" to player

#/Connect4 GUI... The default prompt; opens the User Interface.
		arg 1 is "GUI":
			open chest with 2 rows named "%{~Connect4.Text::MenuTitle}%" to player
			wait 2 ticks
			set slot 2 of player's current inventory to {~Connect4.MenuButtons::Invite} named "&3Invite a Player"
			set slot 4 of player's current inventory to {~Connect4.MenuButtons::Spectate} named "&7Spectate a Game"
			set slot 6 of player's current inventory to {~Connect4.MenuButtons::Invitations} named "&bMy Invitations"
			set slot 12 of player's current inventory to {~Connect4.MenuButtons::Stats} named "&eMy Stats"
			set slot 14 of player's current inventory to {~Connect4.MenuButtons::Help} named "&8Help Information"

		set {_target} to (arg 2 parsed as offline player)
#/Connect4 Spectate <player>... Spectates a specific player's game.
		arg 1 is "spectate" or "spec":
			if arg 2 is not set:
				set {_noArgument} to textFormat("%yaml value ""Connect4.Messages.Invite.Error.NoArgument"" from file ""Connect4Config.yml""%", "%%PREFIX%%", "%{~Connect4.Messages::Prefix}%", "", "")
				message "%{_noArgument}%" to player
				stop
			if "%arg 2%" is "%player%":
				set {_selfSpectateError} to textFormat("%yaml value ""Connect4.Messages.Spectate.Error.Self"" from file ""Connect4Config.yml""%", "%%PREFIX%%", "%{~Connect4.Messages::Prefix}%", "", "")
				message "%{_selfSpectateError}%" to player
				stop
			if {~Connect4.CurrentGames::%{_target}%} is not set:
				set {_notInGameError} to textFormat("%yaml value ""Connect4.Messages.Spectate.Error.NotInGame"" from file ""Connect4Config.yml""%", "%%PREFIX%%", "%{~Connect4.Messages::Prefix}%", "%%TARGET%%", "%{_target}%")
				message "%{_notInGameError}%" to player
				stop
			spectorSetup(player, {_target})

#/Connect4 Statistics <player>... Views the Connect4 Statistics on a specific player.
		arg 1 is "stats" or "statistics":
			if arg 2 is not set:
				set {_target} to player
			set {_puuid} to uuid of {_target}
			if yaml value "Connect4.Database.Enabled" from file "Connect4Config" is true:
				set {_winsValue} to databaseVarGet("%{_puuid}%", "Wins", "exist")
				if {_winsValue} is not set:
					set {_noRecord} to textFormat("%yaml value ""Connect4.Messages.Statistics.Error.NoRecord"" from file ""Connect4Config.yml""%", "%%PREFIX%%", "%{~Connect4.Messages::Prefix}%", "%%TARGET%%", "%{_target}%")
					message "%{_noRecord}%" to player
					stop
				set {_losesValue} to databaseVarGet("%{_puuid}%", "Loses", "")
				set {_drawValue} to databaseVarGet("%{_puuid}%", "Draws", "")
				set {_forfeitValue} to databaseVarGet("%{_puuid}%", "Forfeits", "")
				open chest with 2 rows named "&3%{_target}%'s Stats" to player
				wait 2 ticks
				set slot 0 of player's current inventory to {~Connect4.StatsItems::Wins} named "&eWins" with lore " &9Wins: %{_winsValue}%"
				set slot 2 of player's current inventory to {~Connect4.StatsItems::Loses} named "&eLoses" with lore " &9Loses: %{_LosesValue}%"
				set slot 4 of player's current inventory to {~Connect4.StatsItems::Draws} named "&eDraws" with lore " &9Draws: %{_drawValue}%"
				set slot 6 of player's current inventory to {~Connect4.StatsItems::Forfeits} named "&eForfeits" with lore " &9Forfeits: %{_forfeitValue}%"
				set slot 8 of player's current inventory to {~Connect4.StatsItems::GamesPlayed} named "&eGames Played" with lore " &9Games Played: %{_winsValue}+{_LosesValue}+{_drawValue}+{_forfeitValue}%"
				set slot 10 of player's current inventory to {~Connect4.StatsItems::Others} named "&eStatistics" with lore " &9Use /Connect4 Stats <player>"
				set slot 16 of player's current inventory to {~Connect4.MenuButtons::Back} named "&cBack"
			else:
				if {~Connect4.Wins::%{_puuid}%} does not exist:
					set {_noRecord} to textFormat("%yaml value ""Connect4.Messages.Statistics.Error.NoRecord"" from file ""Connect4Config.yml""%", "%%PREFIX%%", "%{~Connect4.Messages::Prefix}%", "%%TARGET%%", "%{_target}%")
					message "%{_noRecord}%" to player
					stop
				open chest with 2 rows named "&3%{_target}%'s Stats" to player
				wait 2 ticks
				set slot 0 of player's current inventory to {~Connect4.StatsItems::Wins} named "&eWins" with lore " &9Wins: %{~Connect4.Wins::%{_puuid}%}%"
				set slot 2 of player's current inventory to {~Connect4.StatsItems::Loses} named "&eLoses" with lore " &9Loses: %{~Connect4.Loses::%{_puuid}%}%"
				set slot 4 of player's current inventory to {~Connect4.StatsItems::Draws} named "&eDraws" with lore " &9Draws: %{~Connect4.Draws::%{_puuid}%}%"
				set slot 6 of player's current inventory to {~Connect4.StatsItems::Forfeits} named "&eForfeits" with lore " &9Forfeits: %{~Connect4.Forfeits::%{_puuid}%}%"
				set slot 8 of player's current inventory to {~Connect4.StatsItems::GamesPlayed} named "&eGames Played" with lore " &9Games Played: %{~Connect4.Wins::%{_puuid}%}+{~Connect4.Loses::%{_puuid}%}+{~Connect4.Draws::%{_puuid}%}+{~Connect4.Forfeits::%{_puuid}%}%"
				set slot 10 of player's current inventory to {~Connect4.StatsItems::Others} named "&eStatistics" with lore " &9Use /Connect4 Stats <player>"
				set slot 16 of player's current inventory to {~Connect4.MenuButtons::Back} named "&cBack"

#/Connect4 Accept <player>... Accepts any incoming invitations.
		arg 1 is "accept":
			if arg 2 is not set:
				set {_noArgument} to textFormat("%yaml value ""Connect4.Messages.Invite.Error.NoArgument"" from file ""Connect4Config.yml""%", "%%PREFIX%%", "%{~Connect4.Messages::Prefix}%", "", "")
				message "%{_noArgument}%" to player
				stop
			if {~Connect4.Invites::%player%::*} is empty:
				set {_inviteEmpty} to textFormat("%yaml value ""Connect4.Messages.Invite.Error.Empty"" from file ""Connect4Config.yml""%", "%%PREFIX%%", "%{~Connect4.Messages::Prefix}%", "", "")
				message "%{_inviteEmpty}%" to player
				stop
			else:
				if {~Connect4.Invites::%player%::%{_target}%} is not set:
					set {_noInvitation} to textFormat("%yaml value ""Connect4.Messages.Invite.Error.NoInvite"" from file ""Connect4Config.yml""%", "%%PREFIX%%", "%{~Connect4.Messages::Prefix}%", "%%TARGET%%", "%{_target}%")
					message "%{_noInvitation}%" to player
					stop
				if {~Connect4.CurrentGames::%{_target}%} is set:
					set {_inGame} to textFormat("%yaml value ""Connect4.Messages.Invite.Error.InGame"" from file ""Connect4Config.yml""%", "%%PREFIX%%", "%{~Connect4.Messages::Prefix}%", "%%TARGET%%", "%{_target}%")
					message "%{_inGame}%" to player
					stop
				set {_acceptMessage} to textFormat("%yaml value ""Connect4.Messages.Invite.Accept.Target"" from file ""Connect4Config.yml""%", "%%PREFIX%%", "%{~Connect4.Messages::Prefix}%", "%%PLAYER%%", "%{_target}%")
				message "%{_acceptMessage}%" to player
				set {~Connect4.accept::%player%::%{_target}%} to true
				stop

#/Connect4 Deny <player>... Denies any incoming invitations.
		arg 1 is "deny" or "decline":
			if arg 2 is not set:
				set {_noArgument} to textFormat("%yaml value ""Connect4.Messages.Invite.Error.NoArgument"" from file ""Connect4Config.yml""%", "%%PREFIX%%", "%{~Connect4.Messages::Prefix}%", "", "")
				message "%{_noArgument}%" to player
				stop
			if {~Connect4.Invites::%player%::*} is empty:
				set {_inviteEmpty} to textFormat("%yaml value ""Connect4.Messages.Invite.Error.Empty"" from file ""Connect4Config.yml""%", "%%PREFIX%%", "%{~Connect4.Messages::Prefix}%", "", "")
				message "%{_inviteEmpty}%" to player
				stop
			else if {~Connect4.Invites::%player%::%{_target}%} is not set:
				set {_noInvitation} to textFormat("%yaml value ""Connect4.Messages.Invite.Error.NoInvite"" from file ""Connect4Config.yml""%", "%%PREFIX%%", "%{~Connect4.Messages::Prefix}%", "%%TARGET%%", "%{_target}%")
				message "%{_noInvitation}%" to player
				stop
			set {_playerDeclined} to textFormat("%yaml value ""Connect4.Messages.Invite.Deny.Player"" from file ""Connect4Config.yml""%", "%%PREFIX%%", "%{~Connect4.Messages::Prefix}%", "%%TARGET%%", "%player%")
			set {_targetDeclined} to textFormat("%yaml value ""Connect4.Messages.Invite.Deny.Target"" from file ""Connect4Config.yml""%", "%%PREFIX%%", "%{~Connect4.Messages::Prefix}%", "%%PLAYER%%", "%{_target}%")
			message "%{_playerDeclined}%" to {_target}
			message "%{_targetDeclined}%" to player
			set {~Connect4.accept::%player%::%{_target}%} to false
			stop

#/Connect4 Invite <player>... Invites a player.
		arg 1 is "invite":
			if arg 2 is not set:
				set {_noArgument} to textFormat("%yaml value ""Connect4.Messages.Invite.Error.NoArgument"" from file ""Connect4Config.yml""%", "%%PREFIX%%", "%{~Connect4.Messages::Prefix}%", "", "")
				message "%{_noArgument}%" to player
				stop
			if {_target} is offline:
				set {_offlineError} to textFormat("%yaml value ""Connect4.Messages.Invite.Error.Offline"" from file ""Connect4Config.yml""%", "%%PREFIX%%", "%{~Connect4.Messages::Prefix}%", "%%TARGET%%", "%{_target}%")
				message "%{_offlineError}%" to player
				stop
			if "%arg 2%" is "%name of player%":
				set {_selfInviteError} to textFormat("%yaml value ""Connect4.Messages.Invite.Error.Self"" from file ""Connect4Config.yml""%", "%%PREFIX%%", "%{~Connect4.Messages::Prefix}%", "", "")
				message "%{_selfInviteError}%" to player
				stop
			if yaml value "Connect4.Invitations.Multiple" from file "Connect4Config.yml" is false:
				loop all players:
					loop {~Connect4.Invites::%loop-player%::*}:
						if "%loop-index%" contains "%player%":
							set {_q} to loop-player
							set {_pendingError} to textFormat("%yaml value ""Connect4.Messages.Invite.Error.Pending.Self"" from file ""Connect4Config.yml""%", "%%PREFIX%%", "%{~Connect4.Messages::Prefix}%", "%%TARGET%%", "%{_q}%")
							message "%{_pendingError}%" to player
							stop
				loop {~Connect4.Invites::%{_target}%::*}:
					if {~Connect4.Invites::%{_target}%::%loop-index%} is set:
						set {_pendingError} to textFormat("%yaml value ""Connect4.Messages.Invite.Error.Pending.Target"" from file ""Connect4Config.yml""%", "%%PREFIX%%", "%{~Connect4.Messages::Prefix}%", "%%TARGET%%", "%{_target}%")
						message "%{_pendingError}%" to player
						stop
			if {~Connect4.Invites::%{_target}%::%player%} is set:
				set {_pendingError} to textFormat("%yaml value ""Connect4.Messages.Invite.Error.Pending.Self"" from file ""Connect4Config.yml""%", "%%PREFIX%%", "%{~Connect4.Messages::Prefix}%", "%%TARGET%%", "%{_target}%")
				message "%{_pendingError}%" to player
				stop
			invitePlayer(player, {_target})

#Inventory Click Event... Utilizing Umbaska's new chest GUI format.  I miss being able to use lambda then and there ;-;
on inventory click:
	#Main Menu
	if inventory name of player's current inventory is "%{~Connect4.Text::MenuTitle}%":
		cancel event
		#Invite Menu Button
		if clicked slot is 2:
			"%clicked item%" is "%{~Connect4.MenuButtons::Invite}%"
			"%clicked item name%" does not contain "<none>"
			invitePage(player, 0)

		#Spectate Menu Button
		else if clicked slot is 4:
			"%clicked item%" is "%{~Connect4.MenuButtons::Spectate}%"
			"%clicked item name%" does not contain "<none>"
			spectatePage(player, 0)

		#Invitations Menu Button
		else if clicked slot is 6:
			"%clicked item%" is "%{~Connect4.MenuButtons::Invitations}%"
			"%clicked item name%" does not contain "<none>"
			open chest with 3 rows named "&bMy Invitations" to player
			wait 2 ticks
			set {_i} to 0
			loop {~Connect4.Invites::%player%::*}:
				set {_t} to loop-index parsed as player
				set slot {_i} of player's current inventory to skull of {_t} named "&3%{_t}%" with lore " &bLeft Click: Accept|| &cRight Click: Deny"
				if {_i} = 26:
					exit loop
				add 1 to {_i}
			set slot 22 of player's current inventory to {~Connect4.MenuButtons::Back} named "&cBack"

		#Stats Menu Button
		else if clicked slot is 12:
			"%clicked item%" is "%{~Connect4.MenuButtons::Stats}%"
			"%clicked item name%" does not contain "<none>"
			close player's inventory
			make player execute command "/Connect4 Statistics %player%"

		#Help Menu Button
		else if clicked slot is 14:
			"%clicked item%" is "%{~Connect4.MenuButtons::Help}%"
			"%clicked item name%" does not contain "<none>"
			close player's inventory
			make player execute command "/Connect4 Help"

	#Stats Menu
	if inventory name of player's current inventory contains "Stats":
		cancel event
		clicked slot is not -999
		if clicked slot is 16:
			"%clicked item%" contains "%{~Connect4.MenuButtons::Back}%"
			close player's inventory
			make player execute command "/Connect4 GUI"
			stop

	#Invite Page Menu
	if inventory name of player's current inventory contains "&3Invite Page ":
		cancel event
		clicked slot is not -999
		if clicked slot is 31:
			"%clicked item%" contains "%{~Connect4.MenuButtons::Back}%"
			close player's inventory
			make player execute command "/Connect4 GUI"
			stop
		clicked item is head
		"%clicked item name%" does not contain "<none>"
		set {_t} to uncolored "%clicked item name%" parsed as player
		close player's inventory
		make player execute command "/Connect4 invite %{_t}%"

	#Spectate Page Menu
	if inventory name of player's current inventory contains "&8Spectate ":
		cancel event
		clicked slot is not -999
		if clicked slot is 31:
			"%clicked item%" contains "%{~Connect4.MenuButtons::Back}%"
			close player's inventory
			make player execute command "/Connect4 GUI"
			stop
		clicked item is head
		"%clicked item name%" does not contain "<none>"
		set {_s} to "%clicked item name%"
		set {_t} to the first (index of "vs." in {_s} - 2) characters of {_s}
		set {_t} to uncolored {_t} parsed as player
		close player's inventory
		make player execute command "/Connect4 spectate %{_t}%"

	#Invitations Menu
	if inventory name of player's current inventory is "&bMy Invitations":
		cancel event
		clicked slot is not -999
		if clicked slot is 22:
			"%clicked item%" contains "%{~Connect4.MenuButtons::Back}%"
			close player's inventory
			make player execute command "/Connect4 GUI"
			stop
		clicked item is head
		"%clicked item name%" does not contain "<none>"
		set {_t} to (uncolored "%clicked item name%") parsed as player
		if "%click type%" contains "LEFT":
			close player's inventory
			make player execute command "/Connect4 accept %{_t}%"
		else if "%click type%" contains "RIGHT":
			make player execute command "/Connect4 deny %{_t}%"
		stop

	#Exit Button
	if {~Connect4.Spectators::%player%} is set:
		cancel event
		if clicked slot is 53:
			close player's inventory

	#Game Menu
	if {~Connect4.CurrentGames::%player%} is set:
		cancel event
		if clicked slot is 53:
			close player's inventory
		if {~Connect4.winState::%player%} is true:
			stop
		set {_i} to clicked slot mod 9
		{_i} is between 0 and 6
		clicked slot is not -999
		"%clicked item%" contains "%{~Connect4.Blocks::Background}%" or "%{~Connect4.Blocks::Player1}%" or "%{~Connect4.Blocks::Player2}%"
		"%clicked item name%" does not contain "<none>"
		Connect4(player, "%{_i}%")

#Inventory Close Event... Removes all the Connect4 variables created for the game; closes the other player's and spectator's inventory as well.
on inventory close:
	if {~Connect4.CurrentGames::%player%} is set:
		if {~Connect4.winState::%player%} is not set:
			set {_forfeitsMessage} to textFormat("%yaml value ""Connect4.Messages.Game.Forfeit"" from file ""Connect4Config.yml""%", "%%PREFIX%%", "%{~Connect4.Messages::Prefix}%", "%%LOSER%%", "%player%")
			set {_forfeitsMessage} to textFormat("%{_forfeitsMessage}%", "%%WINNER%%", "%{~Connect4.CurrentGames::%player%}%", "", "")
			message "%{_forfeitsMessage}%" to player
			message "%{_forfeitsMessage}%" to {~Connect4.CurrentGames::%player%}

			if yaml value "Connect4.Misc.Broadcast.Enabled" from file "Connect4Config.yml" is true:
				set {_broadcastMessage::*} to yaml list "Connect4.Misc.Broadcast.Forfeits" from file "Connect4Config.yml"
				if {_broadcastMessage::*} is empty:
					stop
				else:
					loop {_broadcastMessage::*}:
						set {_broadcast} to textFormat("%loop-value%", "%%WINNER%%", "%{~Connect4.CurrentGames::%player%}%", "%%LOSER%%", "%player%")
						set {_broadcast} to textFormat("%{_broadcast}%", "%%PREFIX%%", "%{~Connect4.Messages::Prefix}%", "", "")
						broadcast "%{_broadcast}%"
			if yaml value "Connect4.Misc.Commands.Enabled" from file "Connect4Config.yml" is true:
				set {_commands::*} to yaml list "Connect4.Misc.Commands.Executables.Forfeits" from file "Connect4Config.yml"
				if {_commands::*} is empty:
					stop
				else:
					loop {_commands::*}:
						set {_cmd} to textFormat("%loop-value%", "%%WINNER%%", "%{~Connect4.CurrentGames::%player%}%", "%%LOSER%%", "%player%")
						make console execute command "/%{_cmd}%"

			if yaml value "Connect4.Statistics" from file "Connect4Config.yml" is true:
				set {_puuid} to uuid of player
				set {_tuuid} to uuid of {~Connect4.CurrentGames::%player%}
				if yaml value "Connect4.Forfeits" from file "Connect4Config.yml" is true:
					if yaml value "Connect4.Database.Enabled" from file "Connect4Config.yml" is true:
						set {_winValue} to databaseVarGet("%{_tuuid}%", "Wins", "increment")
						set {_forfeitsValue} to databaseVarGet("%{_puuid}%", "Forfeits", "increment")
						databaseVarSet("%{_tuuid}%", "Wins", "%{_winValue}%")
						databaseVarSet("%{_puuid}%", "Forfeits", "%{_forfeitsValue}%")
					else:
						add 1 to {~Connect4.Forfeits::%{_puuid}%}
						add 1 to {~Connect4.Wins::%{_tuuid}%}
				else:
					if yaml value "Connect4.Database.Enabled" from file "Connect4Config.yml" is true:
						set {_winValue} to databaseVarGet("%{_tuuid}%", "Wins", "increment")
						set {_LosesValue} to databaseVarGet("%{_puuid}%", "Loses", "increment")
						databaseVarSet("%{_tuuid}%", "Wins", "%{_winValue}%")
						databaseVarSet("%{_puuid}%", "Loses", "%{_losesValue}%")
					else:
						add 1 to {~Connect4.Loses::%{_puuid}%}
						add 1 to {~Connect4.Wins::%{_tuuid}%}
		delete {~Connect4.Turns::%player%}
		delete {~Connect4.Turns::%{~Connect4.CurrentGames::%player%}%}
		loop {~Connect4.Spectators::*}:
			set {_spectator} to loop-index parsed as player
			if "%loop-value%" contains "%player%" or "%{~Connect4.CurrentGames::%player%}%":
				close {_spectator}'s inventory
		delete {~Connect4.Game.%player%::*}
		delete {~Connect4.Game.%{~Connect4.CurrentGames::%player%}%::*}
		delete {~Connect4.Players::%player%}
		delete {~Connect4.Players::%{~Connect4.CurrentGames::%player%}%}
		delete {~Connect4.CurrentGames::%{~Connect4.CurrentGames::%player%}%}
		delete {~Connect4.winState::%player%}
		delete {~Connect4.winState::%{~Connect4.CurrentGames::%player%}%}
		close {~Connect4.CurrentGames::%player%}'s inventory
		wipe player's sidebar
		wipe {~Connect4.CurrentGames::%player%} sidebar
		delete {~Connect4.CurrentGames::%player%}

	else if {~Connect4.Spectators::%player%} is set:
		if {~Connect4.Turns::%{~Connect4.Spectators::%player%}%} is not set:
			delete {~Connect4.Spectators::%player%}
		else:
			set {_a} to 0
			loop {~Connect4.Spectators::*}:
				"%loop-value%" contains "%{~Connect4.Spectators::%player%}%" or "%{~Connect4.CurrentGames::%{~Connect4.Spectators::%player%}%}%"
				add 1 to {_a}
			set score "Spectators:" in sidebar of {~Connect4.Spectators::%player%} to {_a} - 1
			set score "Spectators:" in sidebar of {~Connect4.CurrentGames::%{~Connect4.Spectators::%player%}%} to {_a} - 1
			delete score "&b&7%player%" in sidebar of {~Connect4.Spectators::%player%}
			delete score "&b&7%player%" in sidebar of {~Connect4.CurrentGames::%{~Connect4.Spectators::%player%}%}
			delete {~Connect4.Spectators::%player%}

#Script Load Event... Loads commonly used variables to prevent constant grabbing from yml file (Not actually sure if it matters).
on script load:
	update "CREATE TABLE IF NOT EXISTS `{@Table}` (`PlayerID` varchar(255),`Wins` varchar(255),`Loses` varchar(255),`Draws` varchar(255),`Forfeits` varchar(255))"

	set {~Connect4.Messages::Prefix} to colored "%yaml value ""Connect4.Messages.Prefix"" from file ""Connect4Config.yml""%"
	set {~Connect4.Text::MenuTitle} to colored "%yaml value ""Connect4.GUI.Menu.Title"" from file ""Connect4Config.yml""%"
	set {~Connect4.MenuButtons::Invite} to "%yaml value ""Connect4.GUI.Menu.Buttons.Invite"" from file ""Connect4Config.yml""%" parsed as item
	set {~Connect4.MenuButtons::Spectate} to "%yaml value ""Connect4.GUI.Menu.Buttons.Spectate"" from file ""Connect4Config.yml""%" parsed as item
	set {~Connect4.MenuButtons::Invitations} to "%yaml value ""Connect4.GUI.Menu.Buttons.Invitations"" from file ""Connect4Config.yml""%" parsed as item
	set {~Connect4.MenuButtons::Stats} to "%yaml value ""Connect4.GUI.Menu.Buttons.Stats"" from file ""Connect4Config.yml""%" parsed as item
	set {~Connect4.MenuButtons::Help} to "%yaml value ""Connect4.GUI.Menu.Buttons.Help"" from file ""Connect4Config.yml""%" parsed as item
	set {~Connect4.MenuButtons::Back} to "%yaml value ""Connect4.GUI.Menu.Buttons.Back"" from file ""Connect4Config.yml""%" parsed as item
	set {~Connect4.MenuButtons::Next} to "%yaml value ""Connect4.GUI.Menu.Buttons.Next"" from file ""Connect4Config.yml""%" parsed as item
	set {~Connect4.MenuButtons::Previous} to "%yaml value ""Connect4.GUI.Menu.Buttons.Previous"" from file ""Connect4Config.yml""%" parsed as item
	set {~Connect4.MenuButtons::Exit} to "%yaml value ""Connect4.GUI.Menu.Buttons.Exit"" from file ""Connect4Config.yml""%" parsed as item

	set {~Connect4.StatsItems::Wins} to "%yaml value ""Connect4.GUI.Menu.Stats.Wins"" from file ""Connect4Config.yml""%" parsed as item
	set {~Connect4.StatsItems::Loses} to "%yaml value ""Connect4.GUI.Menu.Stats.Loses"" from file ""Connect4Config.yml""%" parsed as item
	set {~Connect4.StatsItems::Draws} to "%yaml value ""Connect4.GUI.Menu.Stats.Draws"" from file ""Connect4Config.yml""%" parsed as item
	set {~Connect4.StatsItems::Forfeits} to "%yaml value ""Connect4.GUI.Menu.Stats.Forfeits"" from file ""Connect4Config.yml""%" parsed as item
	set {~Connect4.StatsItems::GamesPlayed} to "%yaml value ""Connect4.GUI.Menu.Stats.GamesPlayed"" from file ""Connect4Config.yml""%" parsed as item
	set {~Connect4.StatsItems::Others} to "%yaml value ""Connect4.GUI.Menu.Stats.Others"" from file ""Connect4Config.yml""%" parsed as item

	set {~Connect4.Blocks::Background} to "%yaml value ""Connect4.GUI.Game.BackgroundBlock"" from file ""Connect4Config.yml""%" parsed as item
	set {~Connect4.Blocks::Divider} to "%yaml value ""Connect4.GUI.Game.DividerBlock"" from file ""Connect4Config.yml""%" parsed as item
	set {~Connect4.Blocks::Player1} to "%yaml value ""Connect4.GUI.Game.Player1Block"" from file ""Connect4Config.yml""%" parsed as item
	set {~Connect4.Blocks::Player2} to "%yaml value ""Connect4.GUI.Game.Player2Block"" from file ""Connect4Config.yml""%" parsed as item
	set {~Connect4.Blocks::Player1Divider} to "%yaml value ""Connect4.GUI.Game.DividerBlockPlayer1"" from file ""Connect4Config.yml""%" parsed as item 
	set {~Connect4.Blocks::Player2Divider} to "%yaml value ""Connect4.GUI.Game.DividerBlockPlayer2"" from file ""Connect4Config.yml""%" parsed as item

	loop {~Connect4.CurrentGames::*}:
		set {_p} to loop-index parsed as player
		set {~Connect4.winState::%{_p}%} to -1
		close {_p}'s inventory

	delete {~Connect4.CurrentGames::*}
	delete {~Connect4.Invites::*}
	delete {~Connect4.winState::*}