-- NoXious Global Database System
_OpenScript("jbmenu.lua")

NDB = {}
NDB.Enabled = true
NDB.SuperGoatseTable = {}
GaveRating = {}

TempReputationLevels = {}
TempReputationLevels["Friendly"]    = {"Sociable", "Friendly", "Genial", "Kind", "Lovable"}
TempReputationLevels["Good Player"] = {"Able", "Able", "Good Player", "Good Player", "Dexterous", "Dexterous", "Skilled", "Skilled", "Skilled", "Adept"}
TempReputationLevels["Unfriendly"]  = {"Grouchy", "Hostile", "Spiteful", "Antagonistic", "Cynical"}
TempReputationLevels["Dumbass"]     = {"Dope", "Dumb", "Dunce", "Dumbass", "Twit"}
TempReputationLevels["Blocker"]     = {"Obstruction", "Hindrance", "Road Block", "Barrier", "Brick Wall"}
TempReputationLevels["Scammer"]     = {"Crook", "Scammer", "Fraud", "Swindler", "Con Artist"}
TempReputationLevels["Dildo"]       = {"Fool", "Tard", "Jackass", "Dildo", "Giant Dildo"}
TempReputationLevels["Noob"]        = {"New", "Newbie", "Noob", "Nooblet", "Nub"}

function NDB.SuperGoatse(userid)
	if not IsPlayerOnline(userid) then return end
	local id = ConvertNet(_PlayerInfo(userid,"networkid"))
	if id == nil then return end
	if tonumber(id) == nil then return end
	if not NDB.SuperGoatseTable[id] then
		local str = _file.Read("noxiousprofiles/supergoatse.txt")
		_file.Delete("noxiousprofiles/supergoatse.txt")
		_file.Write("noxiousprofiles/supergoatse.txt", str..","..id)
		Goatse(userid)
		NDB.SuperGoatseTable[id] = true
		_PrintMessageAll(3, "For being a total idiot, for being a total shithead, ".._PlayerInfo(userid,"name").." has been auto-goatsed for life.")
	end
end

function NDB.RemoveSuperGoatse(userid)
	if not IsPlayerOnline(userid) then return end
	local id = ConvertNet(_PlayerInfo(userid,"networkid"))
	if id == nil then return end
	if tonumber(id) == nil then return end
	if NDB.SuperGoatseTable[id] then
		local str = _file.Read("noxiousprofiles/supergoatse.txt")
		_file.Delete("noxiousprofiles/supergoatse.txt")
		_file.Write("noxiousprofiles/supergoatse.txt", str..","..id)
		StopGoatse(userid)
		NDB.SuperGoatseTable[id] = false
		_PrintMessageAll(3, _PlayerInfo(userid,"name").." has been de-auto-goatsed.")
	end
end

function GetHostNameByte()
	local hostname = string.gsub(_GetConVar_String("hostname"), " ", "")
	local byte = 0
	for pos=1, string.len(hostname) do
		byte = byte + string.byte(string.sub(hostname, pos, pos))
	end
	return byte
end

function NDB.ScanForCameras(sender, args)
	if not IsJetAdmin(sender) then return end
	for i=1, 4000 do
		if _EntGetType(i) == "prop_physics" then
			if _EntGetModel(i) == "models/props_lab/monitor01b.mdl" then
				local suspects = ""
				local entities = _EntitiesFindInSphere(_EntGetPos(i), 1024)
				for x,id in entities do
					if _EntGetType(id) == "player" then
						suspects = suspects.._PlayerInfo(id,"name").."  "
					end
				end
				_PrintMessageAll(3, "Prop camera at "..vecString(_EntGetPos(i))..". Suspects: "..suspects)
				_PrintMessageAll(2, "Prop camera at "..vecString(_EntGetPos(i))..". Suspects: "..suspects)
			end
		end
	end
end
CONCOMMAND("scan", NDB.ScanForCameras)

function NDB.AddGoldMember(userid)
	if not IsPlayerOnline(userid) then return end
	local id = ConvertNet(_PlayerInfo(userid,"networkid"))
	if id == nil then return end
	if tonumber(id) == nil then return end
	if not GoldMembers[id] then
		local str = _file.Read("noxiousprofiles/goldmembers.txt")
		_file.Delete("noxiousprofiles/goldmembers.txt")
		_file.Write("noxiousprofiles/goldmembers.txt", str..","..id)
		GoldMembers[id] = true
		NDB.drawGoldMemberTicket(userid)
		_PrintMessage(userid, 3, "You've been given Gold Member status.")
		_ServerCommand(id.." added as goldmember.")
	end
end

function NDB.AddGoldMemberDB(id)
	if id == nil then return end
	if tonumber(id) == nil then return end
	if not GoldMembers[id] then
		local str = _file.Read("noxiousprofiles/goldmembers.txt")
		_file.Delete("noxiousprofiles/goldmembers.txt")
		_file.Write("noxiousprofiles/goldmembers.txt", str..","..id)
		GoldMembers[id] = true
		_ServerCommand(id.." added as goldmember.")
	end
end

function NDB.AddDiamondMember(userid)
	if not IsPlayerOnline(userid) then return end
	local id = ConvertNet(_PlayerInfo(userid,"networkid"))
	if id == nil then return end
	if tonumber(id) == nil then return end
	if not DiamondMembers[id] then
		local str = _file.Read("noxiousprofiles/diamondmembers.txt")
		_file.Delete("noxiousprofiles/diamondmembers.txt")
		_file.Write("noxiousprofiles/diamondmembers.txt", str..","..id)
		DiamondMembers[id] = true
		NDB.drawDiamondMemberTicket(userid)
		_PrintMessage(userid, 3, "You've been given Diamond Member status.")
		_ServerCommand(id.." added as diamondmember.")
	end
end

function NDB.AddDiamondMemberDB(id)
	if id == nil then return end
	if tonumber(id) == nil then return end
	if not DiamondMembers[id] then
		local str = _file.Read("noxiousprofiles/diamondmembers.txt")
		_file.Delete("noxiousprofiles/diamondmembers.txt")
		_file.Write("noxiousprofiles/diamondmembers.txt", str..","..id)
		DiamondMembers[id] = true
		_ServerCommand(id.." added as diamondmember.")
	end
end

function NDB.AddMoneyDB(id, amount)
	if id == nil then return end
	if tonumber(id) == nil then return end
	for i=1, _MaxPlayers() do
		if IsPlayerOnline(i) then
			if string.find(_PlayerInfo(i, "networkid"), id) ~= nil then
				if IsPlayerOnline(i) then
					NDB.AddMoney(i, amount, true)
					NDB.SaveInfo(i)
					_ServerCommand("$"..amount.." added to a person playing under "..id..".")
					return
				end
			end
		end
	end
	if _file.Exists("noxiousprofiles/"..id..".txt") then
		local str = _file.Read("noxiousprofiles/"..id..".txt")
		local oldmoney = tonumber(string.sub(str, 1, string.find(str, ":")-1))
		local money = oldmoney + amount
		str = string.gsub(str, oldmoney, "")
		if money ~= nil then
			_file.Delete("noxiousprofiles/"..id..".txt")
			_file.Write("noxiousprofiles/"..id..".txt", money..str)
			_ServerCommand("$"..amount.." added to account "..id..".")
		else
			_ServerCommand("Error: Corrupt file.")
		end
	else
		_ServerCommand("Error: SteamID doesn't exist.")
	end
end

NDB.StartMoney = 10000

if players == nil then
	players = {}
end

if NDB.Enabled then

for i=1, _MaxPlayers() do
	players[i] = {}
	players[i].money = NDB.StartMoney
	players[i].Class = 1
	players[i].Certifications = "gunslinger"
	players[i].GoldMember = false
	players[i].DontSave = false
	players[i].BRWheels = "none"
	players[i].Pixies = false
	players[i].PixiesOn = false
	players[i].ZSZombieKills = 0
	players[i].ZSHumanKills = 0
	players[i].LastChat = 0
	players[i].LastMessage = ""
	players[i].LastSpawn = 0
	players[i].Reputation = {}
	players[i].Reputation["Friendly"] = 0
	players[i].Reputation["Good Player"] = 0
	players[i].Reputation["Unfriendly"] = 0
	players[i].Reputation["Dumbass"] = 0
	players[i].Reputation["Blocker"] = 0
	players[i].Reputation["Scammer"] = 0
	players[i].Reputation["Dildo"] = 0
	players[i].Reputation["Noob"] = 0
	players[i].Title = ""
end

Classes = {}
Classes[1] =
{
	Name = "gunslinger",
	Level = 1,
	DisplayName = "Gunslinger",
	Health = 100,
	Armor = 0,
	SWEPs = {"weapons/noxctf/weapon_combatknife.lua", "weapons/noxctf/weapon_battleaxe.lua"},
	Value = 1000,
	Desc = "Basic twat.",
	KillBonus = 0
}

Classes[2] = 
{
	Name = "warrior",
	Level = 1,
	DisplayName = "Warrior",
	Health = 125,
	Armor = 0,
	SWEPs = {"weapons/noxctf/warrior_weapon.lua"},
	Value = 20000,
	Desc="Fast strike class with a massive axe.",
	KillBonus = 25
}

Classes[3] = 
{
	Name = "mage",
	Level = 1,
	DisplayName = "Mage",
	Mana = true,
	Health = 75,
	Armor = 0,
	SWEPs = {"weapons/noxctf/mage_weapon.lua"},
	Value = 40000,
	Desc="Uses powerful, direct spells and support magic.",
	KillBonus = 30
}

Classes[4] = 
{
	Name = "gunmaster",
	Level = 2,
	Requires = {"soldier"},
	DisplayName = "Gun Master",
	Health = 120,
	Armor = 0,
	SWEPs = {"weapons/noxctf/gunmaster_weapon.lua"},
	Value = 85000,
	Desc="Uses Dual Battleaxe MK2's.",
	KillBonus = 30
}

Classes[5] = 
{
	Name = "archer",
	Level = 1,
	DisplayName = "Archer",
	Health = 115,
	Armor = 0,
	SWEPs = {"weapons/noxctf/archer_weapon.lua"},
	Value = 85000,
	Desc="Enchants arrows to deal damage. Can use grappling arrows.",
	KillBonus = 30
}

Classes[6] = {Name = "darkmage", Level = 2, Requires = {"mage"}, DisplayName = "Dark Mage", Mana = true, Health = 100, Armor = 0, SWEPs = {"weapons/noxctf/darkmage_weapon.lua"}, Value = 85000, Desc="Uses wide area-effect and support spells.", KillBonus = 35}
Classes[7] = {Name = "assassin", Level = 1, DisplayName = "Assassin", Health = 100, Armor = 0, SWEPs = {"weapons/noxctf/assassin_weapon.lua"}, Value = 11000, Desc="Silent killer.", KillBonus = 15}
Classes[8] = {Name = "spellsaber", Level = 3, Requires = {"dragoon"}, DisplayName = "Spell Saber", Hidden = true, Health = 85, Armor = 0, SWEPs = {"weapons/noxctf/saber_weapon.lua"}, Value = 0, Desc="Melee and magic oriented class.", KillBonus = 40}
Classes[9] = {Name = "leeroyjenkins", Level = 1, DisplayName = "Leeroy Jenkins", Health = 50, Armor = 0, SWEPs = {"weapons/noxctf/weapon_leeroy.lua"}, Value = 75000, Desc="Low health suicide bomber!", KillBonus = 25}
Classes[10] = {Name = "divinemage", Level = 2, Requires = {"mage"}, DisplayName = "Divine Mage", Health = 110, Armor = 0, SWEPs = {"weapons/noxctf/divinemage_weapon.lua"}, Value = 60000, Mana=true, Desc="Uses divine and support spells.", KillBonus = 30}
Classes[11] = {Name = "soldier", Level = 1, DisplayName = "Soldier", Health = 100, Armor = 20, SWEPs = {"weapons/noxctf/soldier_smg.lua", "weapons/noxctf/soldier_pistol.lua"}, Value = 15000, Desc="Grunt with SMG and side-arm.", KillBonus = 15}
Classes[12] = {Name = "juggernaut", Level = 1, Requires = {"gunmaster"}, DisplayName = "Juggernaut", Health = 160, Armor = 0, SWEPs = {"weapons/noxctf/juggernaut_vulcan.lua"}, Value = 90000, Desc="Heavy base defender.", KillBonus = 40}
Classes[13] = {Name = "necromancer", Level = 3, Requires = {"darkmage"}, DisplayName = "Necromancer", Mana = true, Health = 100, Armor = 0, SWEPs = {"weapons/noxctf/necromancer_weapon.lua"}, Value = 80000, Desc="Uses support and undead magic.", KillBonus = 30}
Classes[14] = {Name = "dragoon", Level = 2, Requires = {"warrior"}, DisplayName = "Dragoon", Health = 130, Armor = 1, SWEPs = {"weapons/noxctf/dragoon_weapon.lua"}, Value = 240000, Desc="Half-Dragon warrior with flight ability.", KillBonus = 50}
Classes[15] = {Name = "zombie", Level = 1, DisplayName = "Zombie", Hidden = true, Health = 250, Armor = 0, SWEPs = {"weapons/noxctf/zombie_weapon.lua"}, Value = 0, Desc="A Zombie.", KillBonus = 30}
Classes[16] = {Name = "dreadnaut", Level = 1, Requires = {"juggernaut"}, DisplayName = "Dreadnaut", Health = 160, Armor = 0, SWEPs = {"weapons/noxctf/juggernaut_cannon.lua"}, Value = 90000, Desc="Heavy artillery.", KillBonus = 40}
end

RATINGS_FILE = "noxiousprofiles/ratings"..GetHostNameByte()..".txt"
function SaveRatings()
	_file.Write(RATINGS_FILE, table.concat(GaveRating, ","))
end

function LoadRatings()
	if not _file.Exists(RATINGS_FILE) then
		_file.Write(RATINGS_FILE, "1,2")
	else
		GaveRating = explode(_file.Read(RATINGS_FILE), ",", 250) or {}
	end
end
LoadRatings()

function ConvertNet(str)
	if str == "UNKNOWN" or str == "STEAM_ID_PENDING" or str == "STEAM_ID_LAN" then return "admin"
	else
		return string.sub(str, 11)
	end
end

function table.superconcat(tab, sep)
	local str = ""
	for i, val in tab do
		str = str..val..sep
	end
	return string.sub(str, 1, string.len(str) - string.len(sep))
end

function GetReputationSaveStr(userid)
	return players[userid].Reputation["Friendly"]..","..
	players[userid].Reputation["Good Player"]..","..
	players[userid].Reputation["Unfriendly"]..","..
	players[userid].Reputation["Dumbass"]..","..
	players[userid].Reputation["Blocker"]..","..
	players[userid].Reputation["Scammer"]..","..
	players[userid].Reputation["Dildo"]..","..
	players[userid].Reputation["Noob"]
end

function NDB.SaveInfo(userid)
	if not NDB.Enabled then return end
	if not IsPlayerOnline(userid) then return end
	if players[userid].DontSave then _PrintMessage(userid, 3, "Your account was not saved. There is an error with your SteamID. Try to reconnect.") return end
	if _file.Exists("noxiousprofiles/"..ConvertNet(_PlayerInfo(userid, "networkid"))..".txt") then
		_file.Delete("noxiousprofiles/"..ConvertNet(_PlayerInfo(userid, "networkid"))..".txt")
	end
	local pixiesbool = "false"
	if players[userid].Pixies then
		pixiesbool = true
	end
	if not players[userid].money then
		_PrintMessage(userid, 3, "There was an error saving your account. Reconnect. If this message persists even after reconnecting, contact the admin.\n")
	else
		_file.Write("noxiousprofiles/"..ConvertNet(_PlayerInfo(userid, "networkid"))..".txt", math.floor(players[userid].money)..":"..players[userid].Class..":"..tostring(players[userid].BRWheels)..":"..pixiesbool..":"..players[userid].Certifications..":"..players[userid].ZSZombieKills..":"..players[userid].ZSHumanKills..":"..GetReputationSaveStr(userid))
		_PrintMessage(userid, 3, "Your profile has been saved.\n")
	end
end

if NDB.Enabled then

function NDB.Disconnect(name, userid, address, steamid, reason)
	if _PlayerInfo(userid, "connected") then
		NDB.SaveInfo(userid)
		StopGoatse(userid)
		Vote.Voted[userid] = false
		Hats.RemoveHat(userid)
		Muted[userid] = false
	end
end
HookEvent("eventPlayerDisconnect", NDB.Disconnect)

function NDB.Killed(killed, attacker, weapon)
	if JBMenuOn[killed] then
		if JBMenu.Players[killed] ~= nil then
			JBMenu.CloseMenu(killed, JBMenu.Players[killed].Menu)
		end
	end
	players[killed].LastSpawn = _CurTime()
	players[killed].Spree = 0
	Hats.RemoveHat(killed)
end
NDB.KillHook = HookEvent("eventPlayerKilled", NDB.Killed)
end

function NDB.AddMoney(userid, amount, constant)
	if not constant then
		if players[userid].GoldMember then
			players[userid].money = math.ceil(players[userid].money + amount*1.25)
		else
			players[userid].money = math.ceil(players[userid].money + amount)
		end
	else
		players[userid].money = math.ceil(players[userid].money + amount)
	end
	NDB.drawMoneyAmmount(userid)
end

function NDB.GlobalSave()
	for i=1, _MaxPlayers() do
		if _PlayerInfo(i, "connected") then
			NDB.SaveInfo(i)
		end
	end
	SaveRatings()
end

function NDB.Active(name, userid, steamid)
	players[userid].money = 10000
	players[userid].Class = 1
	players[userid].BRWheels = "none"
	players[userid].Pixies = false
	players[userid].Certifications = "gunslinger"
	players[userid].ZSZombieKills = 0
	players[userid].ZSHumanKills = 0
	players[userid].Reputation = {}
	players[userid].Reputation["Friendly"] = 0
	players[userid].Reputation["Good Player"] = 0
	players[userid].Reputation["Unfriendly"] = 0
	players[userid].Reputation["Dumbass"] = 0
	players[userid].Reputation["Blocker"] = 0
	players[userid].Reputation["Scammer"] = 0
	players[userid].Reputation["Dildo"] = 0
	players[userid].Reputation["Noob"] = 0
	if not NDB.LoadInfo(userid) then
		_ServerCommand("kickid ".._PlayerInfo(userid, "networkid").." Account load error.\n")
	end
end
NDB.ActiveHook = HookEvent("eventPlayerActive", NDB.Active)

function NDB.LoadInfo(userid)
	if _file.Exists("noxiousprofiles/"..ConvertNet(_PlayerInfo(userid, "networkid"))..".txt") then
		local net = ConvertNet(_PlayerInfo(userid, "networkid"))
		if tonumber(net) == nil then players[userid].DontSave = true return false end
		local infoTable = explode(_file.Read("noxiousprofiles/"..net..".txt"), ":")
		players[userid].money = tonumber(infoTable[1]) or NDB.StartMoney
		players[userid].Class = tonumber(infoTable[2]) or 1
		players[userid].Certifications = infoTable[5] or "gunslinger"
		players[userid].ZSZombieKills = infoTable[6] or 0
		players[userid].ZSHumanKills = infoTable[7] or 0
		if infoTable[8] ~= nil then
			local reptab = explode(infoTable[8], ",") or {}
			players[userid].Reputation = {}
			players[userid].Reputation["Friendly"] = tonumber(reptab[1]) or 0
			players[userid].Reputation["Good Player"] = tonumber(reptab[2]) or 0
			players[userid].Reputation["Unfriendly"] = tonumber(reptab[3]) or 0
			players[userid].Reputation["Dumbass"] = tonumber(reptab[4]) or 0
			players[userid].Reputation["Blocker"] = tonumber(reptab[5]) or 0
			players[userid].Reputation["Scammer"] = tonumber(reptab[6]) or 0
			players[userid].Reputation["Dildo"] = tonumber(reptab[7]) or 0
			players[userid].Reputation["Noob"] = tonumber(reptab[8]) or 0
		else
			players[userid].Reputation = {}
			players[userid].Reputation["Friendly"] = 0
			players[userid].Reputation["Good Player"] = 0
			players[userid].Reputation["Unfriendly"] = 0
			players[userid].Reputation["Dumbass"] = 0
			players[userid].Reputation["Blocker"] = 0
			players[userid].Reputation["Scammer"] = 0
			players[userid].Reputation["Dildo"] = 0
			players[userid].Reputation["Noob"] = 0
		end
		players[userid].Title = GetTitle(userid)
		if players[userid].Class <= 0 or players[userid].Class > table.getn(Classes) then
			players[userid].Class = 1
		elseif not string.find(players[userid].Certifications, Classes[players[userid].Class].Name) then
			players[userid].Class = 1
		end
		if infoTable[3] ~= nil then
			players[userid].BRWheels = infoTable[3]
		end
		if infoTable[4] ~= nil then
			if infoTable[4] == "true" then
				players[userid].Pixies = true
				players[userid].PixiesOn = true
				NDB.StartPixies(userid)
			end
		end
		if DiamondMembers[net] then
			players[userid].GoldMember = true
			players[userid].DiamondMember = true
			NDB.drawDiamondMemberTicket(userid)
			players[userid].money = 10000000
			GoldMembers[net] = true
		elseif GoldMembers[net] then
			players[userid].GoldMember = true
			NDB.drawGoldMemberTicket(userid)
		end
		NDB.drawMoneyAmmount(userid)
		_PrintMessage(userid, 3, "Your profile has been loaded.\n")
		_PlayerRespawn(userid)
		if NDB.SuperGoatseTable[net] then
			Goatse(userid)
		end
		--[[if players[userid].Certifications == "gunslinger" then
			SendFreeCertMenu(userid)
		end
		]]
		if _file.Exists("noxiousprofiles/vote_"..Vote.VoteTopic.."_"..net..".txt") then
			Vote.Voted[userid] = true
		end

		players[userid].LastChat = 0
		players[userid].LastMessage = ""
		players[userid].LastSpawn = _CurTime()
		players[userid].BeingKicked = nil
		return true
	else
		NDB.SaveInfo(userid)
		NDB.LoadInfo(userid)
		return true
	end
end

ReputationLevels = {}
-- I own at Lua >_>
for i in TempReputationLevels do
	ReputationLevels[i] = {}
	for x=1, 3 do
		ReputationLevels[i][x] = TempReputationLevels[i][1]
	end
	for x=4, 6 do
		ReputationLevels[i][x] = TempReputationLevels[i][2]
	end
	for x=7, 9 do
		ReputationLevels[i][x] = TempReputationLevels[i][3]
	end
	for x=9, 12 do
		ReputationLevels[i][x] = TempReputationLevels[i][4]
	end
	for x=13, 16 do
		ReputationLevels[i][x] = TempReputationLevels[i][5]
	end
	if TempReputationLevels[i][6] then
		for x=17, 20 do
			ReputationLevels[i][x] = TempReputationLevels[i][6]
		end
	end
	if TempReputationLevels[i][7] then
		for x=21, 24 do
			ReputationLevels[i][x] = TempReputationLevels[i][7]
		end
	end
	if TempReputationLevels[i][8] then
		for x=25, 28 do
			ReputationLevels[i][x] = TempReputationLevels[i][8]
		end
	end
	if TempReputationLevels[i][9] then
		for x=29, 32 do
			ReputationLevels[i][x] = TempReputationLevels[i][9]
		end
	end
	if TempReputationLevels[i][10] then
		for x=33, 36 do
			ReputationLevels[i][x] = TempReputationLevels[i][10]
		end
	end
	if TempReputationLevels[i][11] then
		for x=37, 40 do
			ReputationLevels[i][x] = TempReputationLevels[i][11]
		end
	end
end

TempReputationLevels = nil

function GetTitle(userid)
	local current = "Noob"
	local rep = players[userid].Reputation
	for i in rep do
		if rep[i] > rep[current] then
			current = i
		end
	end
	local reputation = math.Clamp(rep[current], 1, table.getn(ReputationLevels[current]))
	return ReputationLevels[current][reputation] or "New"
end

function math.Clamp(int, minn, maxn)
	if int > maxn then
		return maxn
	elseif int < minn then
		return minn
	end
	return int
end

function SendFreeCertMenu(userid)
	_GModRect_Start( "gmod/white-grad-down" )
	 _GModRect_SetPos( 0.3, 0.0, 0.4, 0.1 )
	 _GModRect_SetColor( 0, 0, 100, 200 )
	 _GModRect_SetTime( 9999, 0.25, 0.25 )
	 _GModRect_SetDelay( 0 )
	_GModRect_Send( userid, 11001 )
	_GModText_Start( "Default" )
	 _GModText_SetPos( -1, 0.01 )
	 _GModText_SetColor( 255, 0, 0, 255 )
	 _GModText_SetTime( 9999, 0.25, 0.25 )
	 _GModText_SetText("You are allowed to pick one free NoXious certification\n for being a new player.\nSay '/free warrior' '/free soldier' or '/free assassin'!")
	_GModText_Send( userid, 3956 )
end

function PickFree(userid, args)
	_PrintMessage(userid, 3, "The new player system has been discontinued. The gunslinger isn't that weak anymore.")
	--[[
	args = string.lower(args)
	if players[userid].Certifications ~= "gunslinger" then _PrintMessage(userid, 3, "This is only available to new players.") return end
	if args == "warrior" or args == "soldier" or args == "assassin" then
		players[userid].Certifications = "gunslinger"..args
		_PrintMessage(userid, 3, "Your free new player certification has been added to your account.")
		NDB.SaveInfo(userid)
		_GModRect_Hide(userid, 11001, 0.5)
		_GModText_Hide(userid, 3956, 0.5)
	else
		_PrintMessage(userid, 3, "Invalid certification. Choices are: soldier, warrior, assassin.")
	end
	]]
end

function NDB.drawGoldMemberTicket(userid)
	_GModText_Start( "BudgetLabel" )
	 _GModText_SetPos( 0.9, 0.96 )
	 _GModText_SetColor( 255, 255, 0, 230 )
	 _GModText_SetTime( 9999, 0, 0 )
	 _GModText_SetText("< GOLD Member >")
	_GModText_Send( userid, 3955 )
end

function NDB.drawDiamondMemberTicket(userid)
	_GModText_Start("BudgetLabel")
	 _GModText_SetPos(0.9, 0.96)
	 _GModText_SetColor(255, 255, 255, 230)
	 _GModText_SetTime(9999, 0, 0)
	 _GModText_SetText("< DIAMOND Member >")
	_GModText_Send(userid, 3955)
end

function explode(str, seperator, limit)
	local t={}
	local lim=limit or -1
	local reps=0
	local ll=0

	while true do
		local l=string.find(str,seperator,ll+1,true)
		if l~=nil then
			table.insert(t,string.sub(str,ll,l-1))
			ll=l+1
			reps=reps+1
		else
			table.insert(t,string.sub(str,ll))
			reps=reps+1
			break
		end
        if (reps>=lim and lim~=-1) or reps > 750 then
			table.insert(t,string.sub(str,ll))
			break
		end
	end
	return t
end

function NDB.printUsers(sender)
	if NDB.Enabled then
	for i=1, _MaxPlayers() do
		if IsPlayerOnline(i) then
			local msg = "No"
			if players[i].GoldMember then msg = "Yes" end
			_PrintMessage(sender, 2, i.." ".._PlayerInfo(i,"name") .." $"..players[i].money.." "..Classes[players[i].Class].DisplayName.."("..players[i].Class..") ".._PlayerInfo(i,"ping").."ms  "..msg.."\n")
		end
	end
	else
	for i=1, _MaxPlayers() do
		if IsPlayerOnline(i) then
			_PrintMessage(sender, 2, i.." ".._PlayerInfo(i,"name") .." ".._PlayerInfo(i,"ping").."ms\n")
		end
	end
	end
end

function NDB.drawMoneyAmmount(userid)
	if userid < 1 then
		for i=1, _MaxPlayers() do
			if _PlayerInfo(i, "connected") then
				_GModText_Start("Default")
					_GModText_SetPos(0.025, 0.825)
					_GModText_SetColor(255, 255, 255, 255)
					_GModText_SetTime(99999, 0, 0)
					_GModText_SetText("NoXious Account:\n$" .. math.floor(players[i].money))
				_GModText_Send(i, 3101)
				_GModText_Start("Default")
					_GModText_SetPos(0.025, 0.825)
					_GModText_SetColor(0, 255, 0, 220)
					_GModText_SetTime(99999, 0, 0)
					_GModText_SetText("NoXious Account:\n$" .. math.floor(players[i].money))
				_GModText_SendAnimate(i, 3101, 0.4, 0.4)
			end
		end
	else
		_GModText_Start("Default")
			_GModText_SetPos(0.025, 0.825)
			_GModText_SetColor(255, 255, 255, 255)
			_GModText_SetTime(99999, 0, 0)
			_GModText_SetText("NoXious Account:\n$" .. math.floor(players[userid].money))
		_GModText_Send(userid, 3101)
		_GModText_Start("Default")
			_GModText_SetPos(0.025, 0.825)
			_GModText_SetColor(0, 255, 0, 220)
			_GModText_SetTime(99999, 0, 0)
			_GModText_SetText("NoXious Account:\n$" .. math.floor(players[userid].money))
		_GModText_SendAnimate(userid, 3101, 0.4, 0.4)
	end
end

function NDB.RCon(sender, args)
	if IsJetHeadAdmin(sender) then
		if string.sub(args, 1, 4) == "lua " then
			args = string.sub(args, 5)
			_RunString(args)
		else
			_ServerCommand(args.."\n")
		end
	end
end
CONCOMMAND("run", NDB.RCon)

function NDB.ListPlayers(sender, args)
	if IsJetAdmin(sender) then
		NDB.printUsers(sender)
	end
end
CONCOMMAND("listplayers", NDB.ListPlayers)

function NDB.Goatse(sender, args)
	local userid = tonumber(args) or 0
	if not IsJetAdmin(sender) then return end
	if not IsPlayerOnline(userid) then _PrintMessage(sender, 2, "No such player found.\n") return end
	if IsJetAdmin(userid) then return end
	Goatse(userid)
end
CONCOMMAND("goatse", NDB.Goatse)

function NDB.StopGoatse(sender, args)
	local userid = tonumber(args) or 0
	if not IsJetAdmin(sender) then return end
	if not IsPlayerOnline(userid) then _PrintMessage(sender, 2, "No such player found.\n") return end
	StopGoatse(userid)
end
CONCOMMAND("stopgoatse", NDB.StopGoatse)

function NDB.AdminMsg(sender, args)
	if not IsJetAdmin(sender) then return end
	_ScreenText(0, args, -1, 0.75, 255, 0, 0, 255, 2, 2, 10, 1, 5)
end
CONCOMMAND("message", NDB.AdminMsg)

function NDB.Suspend(sender, args)
	if not IsJetAdmin(sender) then return end
	if string.len(args) < 2 then return end
	local space = string.find(args, " ")
	if space == nil then return end
	local tim = string.sub(args, 1, space - 1)
	if tim == nil then return end
	args = string.sub(args, space+1)
	tim = tonumber(tim)
	if tim == nil then return end
	local userid = tonumber(args) or 0
	if not IsPlayerOnline(userid) then _PrintMessage(sender, 2, "No such player found.\n") return end
	if IsJetAdmin(userid) then return end
	if players[userid].BeingKicked then return end
	if GoldMembers[ConvertNet(_PlayerInfo(userid, "networkid"))] then
		if tim > 48 * 60 then
			tim = 48 * 60
		end
	end
	BanTrain(userid)
	_PrintMessageAll(3, "The Ban Express is coming to pick up ".._PlayerInfo(userid,"name").."! Return trips in "..tim.." minutes.")
	_GModText_Start( "ImpactMassive" )
	 _GModText_SetPos( -1, 0.9 )
	 _GModText_SetColor( 255, 0, 0, 255 )
	 _GModText_SetTime( 22, 1, 1 )
	 _GModText_SetText( "The Ban Express return trips: "..tim.." minutes.")
	_GModText_Send( userid, 5041 )
	_PlaySound("banned2.wav")
	_PlaySoundPlayer(userid, "banned2.wav")
	_GModRect_Start("lm/lolban")
	 _GModRect_SetPos(0.3, 0.1, 0.4, 0.8)
	 _GModRect_SetColor(255, 255, 255, 255)
	 _GModRect_SetTime(20, 0, 0)
	_GModRect_Send(userid, 6616)
	_ServerCommand("banid "..tim.." ".._PlayerInfo(userid,"networkid").."\n")
	_ServerCommand("writeid\n")
	AddTimer(22, 1, _ServerCommand, "kickid ".._PlayerInfo(userid,"networkid").." Banned for "..tim.." minutes\n")
	players[userid].BeingKicked = true
end
CONCOMMAND("suspend", NDB.Suspend)

GoldMembers = {}
if _file.Exists("noxiousprofiles/goldmembers.txt") then
	local s = explode(_file.Read("noxiousprofiles/goldmembers.txt"), ",")
	for id=1, table.getn(s) do
		if tonumber(s[id]) ~= nil then
			GoldMembers[tostring(s[id])] = true
		end
	end
end

DiamondMembers = {}
if _file.Exists("noxiousprofiles/diamondmembers.txt") then
	local s = explode(_file.Read("noxiousprofiles/diamondmembers.txt"), ",")
	for id=1, table.getn(s) do
		if tonumber(s[id]) ~= nil then
			DiamondMembers[tostring(s[id])] = true
		end
	end
end

if _file.Exists("noxiousprofiles/supergoatse.txt") then
	local s = explode(_file.Read("noxiousprofiles/supergoatse.txt"), ",")
	for id=1, table.getn(s) do
		if tonumber(s[id]) ~= nil then
			NDB.SuperGoatseTable[tostring(s[id])] = true
		end
	end
else
	_file.Write("noxiousprofiles/supergoatse.txt", "lol,")
end

function AdminMenu(sender, args)
	if not IsJetAdmin(sender) then return end
	local menu = JBMenu.CreateMenu(false, "Admin Menu", "We take being an admin SERIOUSLY.", "255 255 255", "255 0 0")
	JBMenu.AddChoice(menu, "Administrate Players", "(kick / team change / ect.)", "0 255 0", AdminMenuPlayers, sender)
	if NDB.Enabled then
		JBMenu.AddChoice(menu, "Reset Map Votes", "(Set all map votes to 0 and reset player votes.)", "0 255 0", ResetAllVotes, sender)
		JBMenu.AddChoice(menu, "Manual Save", "(All accounts manually saved.)", "0 255 0", NDB.GlobalSave)
	end
	JBMenu.AddChoice(menu, "Restart", "(Restart current map.)", "255 0 0", AdminMenuRestartMap, sender)
	JBLastExit[sender] = _CurTime()-1
	JBMenu.SendMenu(sender, menu)
end
CONCOMMAND("admin", AdminMenu)

function RatingsMenu(sender)
	local menu = JBMenu.CreateMenu(false, "Ratings", "Pick a player to view / give ratings.", "255 255 255", "255 0 0")
	for i=1, _MaxPlayers() do
		if IsPlayerOnline(i) then
			JBMenu.AddChoice(menu, _PlayerInfo(i,"name"), "", "255 0 0", RatingsMenuPlayer, sender, i)
		end
	end
	JBMenu.AddChoice(menu, "", "<-- Refresh -->", "255 255 255", RatingsMenu, sender)
	JBLastExit[sender] = _CurTime()-1
	JBMenu.SendMenu(sender, menu)
end

function RatingsMenuPlayer(sender, userid)
	if not IsPlayerOnline(userid) then RatingsMenu(sender) return end
	local menu = JBMenu.CreateMenu(false, "Player", _PlayerInfo(userid, "name"), "255 255 255", "255 0 0")
	for i, val in players[userid].Reputation do
		JBMenu.AddChoice(menu, i, val, "255 0 0", PlayerGiveRating, sender, userid, i)
	end
	JBMenu.AddChoice(menu, "", "<-- Back", "255 255 255", RatingsMenu, sender)
	JBLastExit[sender] = _CurTime()-1
	JBMenu.SendMenu(sender, menu)
end

function AdminMenuRestartMap(sender)
	local menu = JBMenu.CreateMenu(false, "Restart", "Are you sure?", "255 255 255", "255 0 0")
	JBMenu.AddChoice(menu, "No", "", "255 0 0", AdminMenu, sender)
	JBMenu.AddChoice(menu, "Yes", "", "0 255 0", _ServerCommand, "changelevel ".._GetCurrentMap().."\n")
	JBLastExit[sender] = _CurTime()-1
	JBMenu.SendMenu(sender, menu)
end

function AdminMenuPlayers(sender)
	local menu = JBMenu.CreateMenu(false, "Players", "", "255 255 255", "255 255 255")
	if NDB.Enabled then
	for i=1, _MaxPlayers() do
		if IsPlayerOnline(i) then
			if IsJetHeadAdmin(i) then
				JBMenu.AddChoice(menu, "(Admin) "..i..": ".._PlayerInfo(i,"name"), "$"..players[i].money, "255 0 0", AdminMenuPlayer, sender, i)
			elseif IsJetAdmin(i) then
				JBMenu.AddChoice(menu, "(Semi-Admin) "..i..": ".._PlayerInfo(i,"name"), "$"..players[i].money, "255 0 255", AdminMenuPlayer, sender, i)
			elseif players[i].GoldMember then
				JBMenu.AddChoice(menu, "(Gold Member) "..i..": ".._PlayerInfo(i,"name"), "$"..players[i].money, "255 255 0", AdminMenuPlayer, sender, i)
			else
				JBMenu.AddChoice(menu, "(Player) "..i..": ".._PlayerInfo(i,"name"), "$"..players[i].money, "255 255 255", AdminMenuPlayer, sender, i)
			end
		end
	end
	else
	for i=1, _MaxPlayers() do
		if IsPlayerOnline(i) then
			if IsJetHeadAdmin(i) then
				JBMenu.AddChoice(menu, "(Admin) "..i..": ".._PlayerInfo(i,"name"), "", "255 0 0", AdminMenuPlayer, sender, i)
			elseif IsJetAdmin(i) then
				JBMenu.AddChoice(menu, "(Semi-Admin) "..i..": ".._PlayerInfo(i,"name"), "", "255 0 255", AdminMenuPlayer, sender, i)
			else
				JBMenu.AddChoice(menu, "(Player) "..i..": ".._PlayerInfo(i,"name"), "", "255 255 255", AdminMenuPlayer, sender, i)
			end
		end
	end
	end
	JBMenu.AddChoice(menu, "", "<- Refresh ->", "255 255 255", AdminMenuPlayers, sender)
	JBMenu.AddChoice(menu, "", "<-- Back", "255 255 255", AdminMenu, sender)
	JBLastExit[sender] = _CurTime()-1
	JBMenu.SendMenu(sender, menu)
end

function AdminMenuPlayer(sender, userid)
	if not IsPlayerOnline(userid) then return end
	if IsJetAdmin(userid) then
		_PlaySoundPlayer(sender, "buttons/button10.wav")
		return
	end
	local menu = JBMenu.CreateMenu(false, "Player", _PlayerInfo(userid, "name"), "255 255 255", "255 0 0")
	if SetTeam ~= nil then
		JBMenu.AddChoice(menu, "Set Team", "Change this player's team.", "255 255 255", AdminChangeTeam, sender, userid)
	end
	JBMenu.AddChoice(menu, "Kick", "Boot in ass.", "255 255 50", Boot, sender, userid)
	JBMenu.AddChoice(menu, "Suspend", "Ban for a set amount of time.", "255 255 0", AdminMenuSuspend, sender, userid)
	if NDB.Enabled then
	if Muted[userid] then
		JBMenu.AddChoice(menu, "Unmute", "Enable text chat.", "0 255 0", UnMute, sender, userid)
	else
		JBMenu.AddChoice(menu, "Mute", "Disable text chat.", "255 255 0", Mute, sender, userid)
	end
	end
	if GoatseTimers[userid] ~= nil then
		JBMenu.AddChoice(menu, "Stop Goatse", "", "0 255 0", NDB.StopGoatse, sender, userid)
	else
		JBMenu.AddChoice(menu, "Last Resort", "Goatse.", "255 255 0", NDB.Goatse, sender, userid)
	end
	if not GoldMembers[ConvertNet(_PlayerInfo(userid, "networkid"))] then
		JBMenu.AddChoice(menu, "Doomsday Ban!", "Ban this player forever.", "255 0 0", CoolBan, sender, userid)
	end
	JBMenu.AddChoice(menu, "", "<-- Back", "255 255 255", AdminMenuPlayers, sender)
	JBLastExit[sender] = _CurTime()-1
	JBMenu.SendMenu(sender, menu)
end

function AdminChangeTeam(sender, userid)
	if not IsPlayerOnline(userid) then return end
	local menu = JBMenu.CreateMenu(false, "Set Team", _PlayerInfo(userid, "name"), "255 255 255", "255 0 0")
	for i in teams do
		JBMenu.AddChoice(menu, teams[i].name, "", "255 255 255", AdminTeamSet, sender, userid, i)
	end
	JBMenu.AddChoice(menu, "", "<-- Back", "255 255 255", AdminMenuPlayer, sender, userid)
	JBLastExit[sender] = _CurTime()-1
	JBMenu.SendMenu(sender, menu)
end

function AdminTeamSet(sender, userid, team)
	_PlayerChangeTeam(userid, team)
	_PlayerRespawn(userid)
	_PrintMessage(userid, 3, _PlayerInfo(sender,"name").." set your team.")
	_PrintMessage(sender, 3, _PlayerInfo(userid,"name").." had their team set.")
end

function AdminMenuSuspend(sender, userid)
	if not IsPlayerOnline(userid) then AdminMenuPlayer(sender, userid) return end
	local menu = JBMenu.CreateMenu(false, "Suspend", _PlayerInfo(userid, "name"), "255 255 255", "255 0 0")
	JBMenu.AddChoice(menu, "5 Minutes", "", "0 255 0", NDB.Suspend, sender, "5 "..userid)
	JBMenu.AddChoice(menu, "30 Minutes", "", "25 255 0", NDB.Suspend, sender, "30 "..userid)
	JBMenu.AddChoice(menu, "1 Hour", "", "50 255 0", NDB.Suspend, sender, "60 "..userid)
	JBMenu.AddChoice(menu, "2 Hours", "", "75 255 0", NDB.Suspend, sender, "120 "..userid)
	JBMenu.AddChoice(menu, "6 Hours", "", "100 255 0", NDB.Suspend, sender, "360 "..userid)
	JBMenu.AddChoice(menu, "1 Day", "", "150 200 0", NDB.Suspend, sender, "1440 "..userid)
	JBMenu.AddChoice(menu, "2 Days", "", "200 200 0", NDB.Suspend, sender, "2880 "..userid)
	if not GoldMembers[ConvertNet(_PlayerInfo(userid, "networkid"))] then
		JBMenu.AddChoice(menu, "1 Week", "", "255 0 0", NDB.Suspend, sender, "10080 "..userid)
		JBMenu.AddChoice(menu, "", "<-- Back", "255 255 255", AdminMenuPlayer, sender, userid)
	end
	JBLastExit[sender] = _CurTime()-1
	JBMenu.SendMenu(sender, menu)
end

function ResetAllVotes(userid)
	for i in VoteMaps do
		voted = {}
		VoteMaps[i].Votes = 0
	end
	_PrintMessageAll(3, _PlayerInfo(userid,"name").." reset all map votes!\n")
end

function MakeFunction(FunctionName)
	local ent = _EntCreate("gmod_runfunction")
	if ent > 0 then
		_EntSetKeyValue(ent, "FunctionName", FunctionName)
		_EntSpawn(ent)
		_EntSetName(ent, FunctionName)
	end
end

function OutputEntity(entity, input, func, delay)
	_EntFire(entity, "AddOutput", input.." "..func..",RunScript,,"..delay..",1", 0)
end

function OutputEntityReps(entity, input, func, delay, reps)
	_EntFire(entity, "AddOutput", input.." "..func..",RunScript,,"..delay..","..reps, 0)
end

function GetPlayerByName(args)
	local i = 1
	args = string.lower(args)
	while i <= _MaxPlayers() do
		if IsPlayerOnline(i) then
			if string.find(string.lower(_PlayerInfo(i, "name")), args) ~= nil then return i end
		end
		i = i+1
	end
	return 0
end

function Boot(sender, args)
	local userid = tonumber(args) or 0
	if not IsJetAdmin(sender) then return end
	if not IsPlayerOnline(userid) then _PrintMessage(sender, 2, "No such player found.\n") return end
	if IsJetAdmin(userid) then _PrintMessage(sender, 2, "A bigger boot may be required...\n") return end
	if players[userid].BeingKicked then return end
	AddTimer(22, 1, _ServerCommand, "kickid ".._PlayerInfo(userid,"networkid").." Ran over by the Kick Express...\n")
	_PrintMessageAll(3, "The Kick Express is coming to pick up ".._PlayerInfo(userid, "name").."!")
	BanTrain(userid)
	_GModRect_Start("lm/lolban")
	 _GModRect_SetPos(0.3, 0.1, 0.4, 0.8)
	 _GModRect_SetColor(255, 255, 255, 255)
	 _GModRect_SetTime(20, 0, 0)
	_GModRect_Send(userid, 6616)
	_GModText_Start( "ImpactMassive" )
	 _GModText_SetPos( -1, 0.9 )
	 _GModText_SetColor( 255, 0, 0, 255 )
	 _GModText_SetTime( 18, 1, 1 )
	 _GModText_SetText( "The Kick Express\n is coming to pick you up!")
	_GModText_Send( userid, 5041 )
	_GModText_Start( "ImpactMassive" )
	 _GModText_SetPos( -1, 0.9 )
	 _GModText_SetColor( 255, 0, 0, 255 )
	 _GModText_SetTime( 4, 1, 1 )
	 _GModText_SetDelay( 18 )
	 _GModText_SetText( "It doesn't look like it can stop...")
	_GModText_Send( userid, 5042 )
end
CONCOMMAND("boot", Boot)

function BanTrain(userid)
	_EntPrecacheModel("models/props_trainstation/train001.mdl")
	_EntPrecacheModel("models/props_trainstation/train002.mdl")
	_EntPrecacheModel("models/props_trainstation/train003.mdl")
	_PlayerFreeze(userid, true)
	_PlayerLockInPlace(userid, true)
	_PlayerDisableAttack(userid, true)
	AddTimer(9, 1, _PlaySound, "ambient/alarms/train_horn_distant1.wav")
	AddTimer(16, 1, _PlaySound, "ambient/alarms/train_horn2.wav")
	_PlayerSetHealth(userid, 4000)
	AddTimer(21, 1, _PlayerKill, userid)
	_EntSetAng(userid, vector3(0,-1,0))
	local ent = _EntCreate("prop_physics")
	if ent > 0 then
		_EntSetModel(ent, "models/props_trainstation/train001.mdl")
		_EntSetPos(ent, vecAdd(_EntGetPos(userid), vector3(0,-34000,100)))
		_EntSpawn(ent)
		_phys.EnableGravity(ent, false)
		_EntSetCollisionGroup(ent, 0)
		_EntSetSolid(ent, 0)
		_EntFire(ent, "kill", "", 29)
		local force = vector3(0, 9999999, 0)
		_phys.ApplyForceCenter(ent, force)
		AddTimer(1, 27, _phys.ApplyForceCenter, ent, force)
	end
	local ent2 = _EntCreate("prop_dynamic_override")
	if ent2 > 0 then
		_EntSetModel(ent2, "models/props_trainstation/train002.mdl")
		_EntSetPos(ent2, vecAdd(_EntGetPos(userid), vector3(0,-34500,100)))
		_EntSetKeyValue(ent2, "solid", "0")
		_EntSpawn(ent2)
		_EntSetParent(ent2, ent)
	end
	ent2 = _EntCreate("prop_dynamic_override")
	if ent2 > 0 then
		_EntSetModel(ent2, "models/props_trainstation/train003.mdl")
		_EntSetPos(ent2, vecAdd(_EntGetPos(userid), vector3(0,-35000,100)))
		_EntSetKeyValue(ent2, "solid", "0")
		_EntSpawn(ent2)
		_EntSetParent(ent2, ent)
		for i=1, 5 do
			local loltrail = _EntCreate("env_fire_trail")
			if loltrail > 0 then
				_EntSetPos(loltrail, vecAdd(_EntGetPos(ent2), vector3(math.random(-100, 100), math.random(-100, 100), math.random(-100, 100))))
				_EntSpawn(loltrail)
				_EntSetParent(loltrail, ent)
			end
		end
	end
end

function CoolBan(sender, args)
	local userid = tonumber(args) or 0
	if not IsJetAdmin(sender) then return end
	if not IsPlayerOnline(userid) then _PrintMessage(sender, 2, "No such player found.\n") return end
	if IsJetAdmin(userid) then _PrintMessage(sender, 2, "A bigger boot may be required...\n") return end
	if GoldMembers[ConvertNet(_PlayerInfo(userid, "networkid"))] then _PrintMessage(sender, 2, "Gold members can not be perma banned.\n") return end
	if players[userid].BeingKicked then return end
	BanTrain(userid)
	_PlaySound("banned2.wav")
	_PlaySoundPlayer(userid, "banned2.wav")
	_GModRect_Start("lm/lolban")
	 _GModRect_SetPos(0.3, 0.1, 0.4, 0.8)
	 _GModRect_SetColor(255, 255, 255, 255)
	 _GModRect_SetTime(20, 0, 0)
	_GModRect_Send(userid, 6616)
	_GModRect_Start("gmod/white")
	 _GModRect_SetPos(0, 0, 1, 1)
	 _GModRect_SetColor(255, 255, 255, 254)
	 _GModRect_SetTime(15, 0.3, 0.3)
	 _GModRect_SetDelay(21)
	_GModRect_Send(userid, 6620)
	_GModText_Start( "ImpactMassive" )
	 _GModText_SetPos( -1, 0.9 )
	 _GModText_SetColor( 255, 0, 0, 255 )
	 _GModText_SetTime( 21, 1, 1 )
	 _GModText_SetText( "Now boarding for Ban City.")
	_GModText_Send( userid, 5041 )
	_PrintMessageAll(3, "The Ban Express is coming to pick up ".._PlayerInfo(userid,"name").."! No return trips.")
	if userid ~= sender then
		_ServerCommand("banid 0 ".._PlayerInfo(userid, "networkid").."\n")
		_ServerCommand("writeid\n")
		--_file.Write("cfg/banned.cfg", _file.Read("cfg/banned.cfg").._PlayerInfo(userid, "networkid").."")
		AddTimer(22, 1, _ServerCommand, "kickid ".._PlayerInfo(userid, "networkid").." CHOO CHOO!!\n")
		players[userid].BeingKicked = true
	end
end
CONCOMMAND("ban", CoolBan)

function ConvertNet(str)
	return string.sub(str, 11)
end

function Mute(sender, args)
	local userid = tonumber(args) or 0
	if not IsJetAdmin(sender) then return end
	if not IsPlayerOnline(userid) then _PrintMessage(sender, 2, "No such player found.\n") return end
	if IsJetAdmin(userid) then _PrintMessage(sender, 2, "NO FU...\n") return end
	Muted[userid] = true
	_PrintMessageAll(3, _PlayerInfo(userid, "name").." has been squelched forever.")
end
CONCOMMAND("mute", Mute)

function UnMute(sender, args)
	local userid = tonumber(args) or 0
	if not IsJetAdmin(sender) then return end
	if not IsPlayerOnline(userid) then _PrintMessage(sender, 2, "No such player found.\n") return end
	if IsJetAdmin(userid) then _PrintMessage(sender, 2, "NO FU...\n") return end
	Muted[userid] = false
	_PrintMessageAll(3, _PlayerInfo(userid, "name").." has been unsquelched. Keke.")
end
CONCOMMAND("unmute", UnMute)

function RatingsDecay()
	local count = table.getn(GaveRating)
	if count < 10 then return end -- Don't decay if less than 18 total ratings
	table.remove(GaveRating, 1)
end
AddTimer(60, 0, RatingsDecay)

function PlayerCanGiveRating(userid)
	local convertnet = ConvertNet(_PlayerInfo(userid, "networkid"))
	for i=1, table.getn(GaveRating) do
		if GaveRating[i] == convertnet then
			return false
		end
	end
	return true
end

function PlayerGiveRating(userid, victim, rating)
	if victim == userid then
		_PrintMessage(userid, 3, "You can't give yourself ratings.")
		return
	end
	if not PlayerCanGiveRating(userid) then
		_PrintMessage(userid, 3, "You must wait a while before giving another rating to someone.")
		return
	end
	if players[victim].Reputation[rating] == nil then return end
	players[victim].Reputation[rating] = players[victim].Reputation[rating] + 1
	--[[_PrintMessage(userid, 3, "You gave ".._PlayerInfo(victim, "name").." a "..rating.." rating. They now have a "..rating.." rating of "..players[victim].Reputation[rating]..".")
	_PrintMessage(victim, 3, _PlayerInfo(userid, "name").." gave you a "..rating.." rating. You now have a "..rating.." rating of "..players[victim].Reputation[rating]..".")
	]]
	local broadstr = _PlayerInfo(userid, "name").." gave ".._PlayerInfo(victim, "name").." a "..rating.." rating. They now have a "..rating.." rating of "..players[victim].Reputation[rating].."."
	_PrintMessageAll(3, broadstr)
	_PrintMessageAll(2, broadstr.."\n")
	_Msg(broadstr.."\n")
	table.insert(GaveRating, ConvertNet(_PlayerInfo(userid, "networkid")))
	DrawRatings(victim)
	players[victim].Title = GetTitle(victim)
end

function GlobalNews(text)
	if string.len(text) > 255 then _Msg("News text is too long.") return end
	local tim = string.len(text * 0.3)
	DoGlobalNewsBackground(tim)
	DoGlobalNewsText(text)
	_PlaySound("plats/elevbell1.wav")
end

function DoGlobalNewsBackground(tim)
	
end

function DoGlobalNewsText(text)
	local ran = math.random(50000, 60000)
	_GModText_Start( "Default" )
	 _GModText_SetPos( 0.05, 0.99 )
	 _GModText_SetColor( 255, 0, 0, 255 )
	 _GModText_SetTime( 10, 0, 0 )
	 _GModText_SetText( text )
	_GModText_Send( 0, ran )
	_GModText_Start( "Default" )
	 _GModText_SetPos( 0.05, -1 )
	 _GModText_AllowOffscreen( true )
	 _GModText_SetColor( 255, 0, 0, 255 )
	 _GModText_SetTime( 20, 0, 0 )
	 _GModText_SetText( text )
	_GModText_Send(0, ran, 10, 0.5)
end

function DrawRatings(userid)
end
