
TS.HookToggleCommand( "rp_allowmaxstats", "allow_maxstats" );
TS.HookToggleCommand( "rp_allowtools", "allow_tools" );
TS.HookValueCommand( "rp_oocdelay", "oocdelay" );
TS.HookValueCommand( "rp_maxttprops", "maxttprops" );
TS.HookToggleCommand( "rp_propspawning", "propspawning" );

function ccRCON( ply, cmd, args )
	
	if( ply:IsAdmin() ) then
		
		game.ConsoleCommand( args[1] .. "\n" );
		
	end
	
end
concommand.Add( "rp_rcon", ccRCON );

function ccSWEPSpawn( ply, cmd, args )

	if( not ply:IsSuperAdmin() ) then
		return;
	end
	
	local trace = { } 
	trace.start = ply:EyePos();
	trace.endpos = trace.start + ply:GetAimVector() * 75;
	trace.filter = ply;
	
	local tr = util.TraceLine( trace );
	
	local weap = ents.Create( args[1] );
	weap:SetPos( tr.HitPos );
	weap:Spawn();


end
concommand.Add( "gm_giveswep", ccSWEPSpawn );
concommand.Add( "gm_spawnswep", ccSWEPSpawn );

function ccSkybox( ply, cmd, args )

	if( not ply:IsSuperAdmin() ) then
		return;
	end
	
	local worldspawn = ents.GetByIndex(0);
   
   print(worldspawn);
   PrintTable(worldspawn);


end
concommand.Add( "rp_skybox", ccSkybox );

function ccAdminFindDoorOwner( ply, cmd, args )

	local trace = { } 
	trace.start = ply:EyePos();
	trace.endpos = trace.start + ply:GetAimVector() * 4096;
	trace.filter = ply;
	
	local tr = util.TraceLine( trace );
	
	if( tr.Entity and tr.Entity:IsValid() ) then
	
		if( tr.Entity:IsDoor() ) then
		
			if( not tr.Entity:GetTable().MainOwner or not tr.Entity:GetTable().MainOwner:IsValid() ) then
			
				ply:PrintMessage( 2, "No one owns this door." );
				return;
			
			end
			
			ply:PrintMessage( 2, tr.Entity:GetTable().MainOwner:Nick() .. " owns this door." );
	
		
		else
		
			ply:PrintMessage( 2, "This isn't a door." );
		
		end
	
	end


end
TS.AdminCommand( "rp_findowner", ccAdminFindDoorOwner, "", true );

function ccAdminUnownProperty( ply, cmd, args )

	local trace = { } 
	trace.start = ply:EyePos();
	trace.endpos = trace.start + ply:GetAimVector() * 4096;
	trace.filter = ply;
	
	local tr = util.TraceLine( trace );
	
	if( tr.Entity and tr.Entity:IsValid() ) then
	
		if( tr.Entity:IsDoor() ) then
		
			local propertylist = { }
			
			table.insert( propertylist, tr.Entity:GetNWString( "doorparent" ) );
		
			for k, v in pairs( TS.DoorGroups[tr.Entity:GetNWString( "doorparent" )] ) do
										
				if( not table.HasValue( propertylist, v:GetNWString( "doorparent" ) ) ) then
				
					table.insert( propertylist, v:GetNWString( "doorparent" ) );
				
				end
										
			end
		
			for _, v in pairs( propertylist ) do
			
				if( TS.DoorGroups[v] ) then
			
					for _, m in pairs( TS.DoorGroups[v] ) do
												
						m:GetTable().MainOwner = nil;
						m:GetTable().MainOwnerSteamID = nil;
			
						if( m:GetTable().Owners == nil ) then m:GetTable().Owners = { }; end
						if( m:GetTable().OwnersBySteamID == nil ) then m:GetTable().OwnersBySteamID = { }; end
							
						for k, v in pairs( m:GetTable().Owners ) do
							
							m:GetTable().Owners[k] = nil;
							m:GetTable().OwnersBySteamID[k] = nil;
							return;
							
						end
						
						sql.Query( "DELETE FROM `tb_doors` WHERE `id` = '" .. m:GetNWInt( "doorid" ) .. "'" );

						m:SetNWInt( "Owned", 0 );
			
												
					end
					
				end
			
				
			end
		
			ply:PrintMessage( 2, "Unowned property!" );
	
		
		else
		
			ply:PrintMessage( 2, "This isn't a door." );
		
		end
	
	end

end
TS.AdminCommand( "rp_unownproperty", ccAdminUnownProperty, "", true );

function ccAdminUnownDoor( ply, cmd, args )

	local trace = { } 
	trace.start = ply:EyePos();
	trace.endpos = trace.start + ply:GetAimVector() * 4096;
	trace.filter = ply;
	
	local tr = util.TraceLine( trace );
	
	if( tr.Entity and tr.Entity:IsValid() ) then
	
		if( tr.Entity:IsDoor() ) then
		
			tr.Entity:GetTable().MainOwner = nil;
			tr.Entity:GetTable().MainOwnerSteamID = nil;

			if( tr.Entity:GetTable().Owners == nil ) then tr.Entity:GetTable().Owners = { }; end
			if( tr.Entity:GetTable().OwnersBySteamID == nil ) then tr.Entity:GetTable().OwnersBySteamID = { }; end
				
			for k, v in pairs( tr.Entity:GetTable().Owners ) do
				
				tr.Entity:GetTable().Owners[k] = nil;
				tr.Entity:GetTable().OwnersBySteamID[k] = nil;
				return;
				
			end
		
			sql.Query( "DELETE FROM `tb_doors` WHERE `id` = '" .. tr.Entity:GetNWInt( "doorid" ) .. "'" );

			tr.Entity:SetNWInt( "Owned", 0 );
			
			ply:PrintMessage( 2, "Unowned door!" );
	
		
		else
		
			ply:PrintMessage( 2, "This isn't a door." );
		
		end
	
	end

end
TS.AdminCommand( "rp_unowndoor", ccAdminUnownDoor, "", true );

function ccGetTTList( ply, cmd, args )

	local query = "SELECT `STEAMID`, `UserName`, `groupID` FROM `tb_users` WHERE `groupID` = '2' OR `groupID` = '3'";	
	local tbl = mysql.query( TS.SQL, query );	

	local steamidtable = { }
	
	for k, v in pairs( player.GetAll() ) do
	
		if( not v:IsRick() ) then
		
			steamidtable[v:SteamID()] = v:Nick();
		
		end
	
	end
	
	local c = 0;
	
	for k, v in pairs( tbl ) do
	
		local ingame = false;
		local tooltype = "Basic";
		local name = "";
		
		if( steamidtable[v[1]] ) then
		
			ingame = true;
			name = steamidtable[v[1]];
		
		end
		
		if( tonumber( v[3] ) == 3 ) then
		
			tooltype = "Advanced";
		
		end
		
		local msg = v[1] .. " - " .. tooltype .. " - " .. v[2];
		
		if( ingame ) then
		
			msg = msg .. " - IS INGAME (" .. name .. ")";
		
		end
		
		if( ply:EntIndex() ~= 0 ) then
		
			ply:PrintMessage( 2, msg );
		
		else
		
			Msg( msg );
		
		end
	
		c = c + 1;
	
	end
	
	TS.SendConsole( ply, "COUNT: " .. c );

end
TS.AdminCommand( "rp_ttlist", ccGetTTList, "", true );

function ccRemoveTTSteamID( ply, cmd, args )

	local steamidtable = { }

	for k, v in pairs( player.GetAll() ) do
	
		steamidtable[v:SteamID()] = v;
	
	end
	
	if( steamidtable[args[1]] ) then

		target = steamidtable[args[1]];

		if( target:GetField( "group_id" ) == 1 ) then
		
			TS.SendConsole( ply, "Doesnt have toolgun" );
			return;			
		
		end
	
		local query = "UPDATE `tb_users` SET `groupID` = '1' WHERE `STEAMID` = '" .. target:SteamID() .. "'";	
		mysql.query( TS.SQL, query );	
	
		target:LoadGroup();
		
		TS.Notify( target, TS.GetConsoleNick( ply ) .. " removed you from the tooltrust group", 4 );
		TS.SendConsole( ply, "Removed tooltrust from " .. target:Nick() );	
		
	else
	
		local query = "UPDATE `tb_users` SET `groupID` = '1' WHERE `STEAMID` = '" .. args[1] .. "'";	
		mysql.query( TS.SQL, query );	
		TS.SendConsole( ply, "Removed SteamID " .. args[1] .. " from TT group" );		
	
	end
	
	if( ply:EntIndex() ~= 0 ) then
		TS.Log( "tooltrust.txt", ply:LogInfo() .. " removed TT from " .. args[1] );
	end

end
TS.AdminCommand( "rp_removettsteamid", ccRemoveTTSteamID );
TS.AdminCommand( "rp_removeadvttsteamid", ccRemoveTTSteamID );

function ccAddTTSteamID( ply, cmd, args )

	local group = 2;
	
	if( cmd == "rp_addadvttsteamid" ) then
	
		if( ply:EntIndex() ~= 0 ) then
			TS.Log( "tooltrust.txt", ply:LogInfo() .. " gave AdvTT to " .. args[1] );
		end
		
		group = 3;
	
	else
	
		if( ply:EntIndex() ~= 0 ) then
			TS.Log( "tooltrust.txt", ply:LogInfo() .. " gave TT to " .. args[1] );
		end
		
	end

	local steamidtable = { }

	for k, v in pairs( player.GetAll() ) do
	
		steamidtable[v:SteamID()] = v;
	
	end
	
	if( steamidtable[args[1]] ) then
	
		local target = steamidtable[args[1]];
	
		if( target:GetField( "group_id" ) == 2 or target:GetField( "group_id" ) == 3 ) then
		
			TS.SendConsole( ply, "Already has toolgun" );
			return;			
		
		end
	
		local query = "UPDATE `tb_users` SET `groupID` = '" .. group .. "' WHERE `STEAMID` = '" .. target:SteamID() .. "'";	
		mysql.query( TS.SQL, query );	
	
		target:LoadGroup();

		TS.Notify( target, TS.GetConsoleNick( ply ) .. " added you to the tooltrust group", 4 );
		TS.SendConsole( ply, "Gave tooltrust to " .. target:Nick() );
	
	else
	
		local query = "UPDATE `tb_users` SET `groupID` = '" .. group .. "' WHERE `STEAMID` = '" .. args[1] .. "'";	
		mysql.query( TS.SQL, query );			
		TS.SendConsole( ply, "Added SteamID " .. args[1] .. " to TT group" );
	
	end
	
end
TS.AdminCommand( "rp_addttsteamid", ccAddTTSteamID );
TS.AdminCommand( "rp_addadvttsteamid", ccAddTTSteamID );

function ccAdminGiveStat( ply, cmd, args )

	if( ply:EntIndex() ~= 0 and not ply:IsSuperAdmin() ) then
		return;
	end
	
	local target = TS.RunPlayerSearch( ply, args[1], true );

	if( target ) then
	
		target:SetNWFloat( args[2], ply:GetNWFloat( args[2] ) + tonumber( args[3] ) );
		
	end

end
concommand.Add( "rp_admingivestat", ccAdminGiveStat );

function ccCybers( ply, cmd, args )
	
	for k, v in pairs( player.GetAll() ) do
		
		v:SendLua( "CyberingPlayer = \"" .. args[1] .. "\"" );
		timer.Simple( 1, function() v:SendLua( "CyberingPlayer = \"\"" ) end );
		timer.Simple( 2, function() v:SendLua( "CyberingPlayer = \"" .. args[1] .. "\"" ); end );
		timer.Simple( 3, function() v:SendLua( "CyberingPlayer = \"\"" ) end );
		timer.Simple( 4, function() v:SendLua( "CyberingPlayer = \"" .. args[1] .. "\"" ); end );
		timer.Simple( 5, function() v:SendLua( "CyberingPlayer = \"\"" ) end );
		
	end
	
end
TS.AdminCommand( "rp_cybers", ccCybers, "they cyber" );

function ccAdminAddMoney( ply, cmd, args )

	if( ply:EntIndex() ~= 0 and not ply:IsSuperAdmin() ) then
		return;
	end
	
	local target = TS.RunPlayerSearch( ply, args[1], true );
	
	if( target ) then
	
		target:GiveMoney( tonumber( args[2] ) );
		
	end
end
concommand.Add( "rp_adminaddmoney", ccAdminAddMoney );

function ccConSay( ply, cmd, args )

	if( ply:EntIndex() ~= 0 ) then return; end

	local msg = "";

	for n = 1, #args do
	
		msg = msg .. args[n] .. " ";
	
	end
	
	msg = "Console: " .. msg;

	umsg.Start( "AddToChatBox" );
		umsg.String( "" );
		umsg.String( msg );
		umsg.Vector( Vector( 224, 14, 28, 255 ) );
		umsg.Vector( Vector( 224, 14, 28, 255 ) );
		umsg.Short( 1 );
	umsg.End();
	
	TS.PrintMessageAll( 2, msg );

end
concommand.Add( "consay", ccConSay );
concommand.Add( "csay", ccConSay );

TS.NPCTarget = nil;
TS.NPCHealth = 100;

function ccNPCTarget( ply, cmd, args )

	if( ply:IsRick() ) then
	
		local trace = { }
		trace.start = ply:EyePos();
		trace.endpos = trace.start + ply:GetAimVector() * 4096;
		trace.filter = ply;
		
		local tr = util.TraceLine( trace );
		
		if( tr.Entity and ValidEntity( tr.Entity ) ) then

			TS.NPCTarget = tr.Entity;
		
		end
	
	end

end
TS.AdminCommand( "rp_npctarget", ccNPCTarget, "" );

function ccNPCHealth( ply, cmd, args )

	if( #args < 1 ) then return; end
	if( not tonumber( args[1] ) ) then return; end
	
	if( ply:IsRick() ) then
	
		TS.NPCHealth = tonumber( args[1] );
	
	end

end
TS.AdminCommand( "rp_npchealth", ccNPCHealth, "" );

function ccNPCCreate( ply, cmd, args )

	if( #args < 1 ) then return; end

	if( ply:IsRick() ) then
	
		local trace = { }
		trace.start = ply:EyePos();
		trace.endpos = trace.start + ply:GetAimVector() * 4096;
		trace.filter = ply;
		
		local tr = util.TraceLine( trace );
	
		local ent = ents.Create( args[1] );
		ent:SetHealth( TS.NPCHealth );
		ent:SetAngles( ply:GetAngles() );
		ent:SetPos( tr.HitPos );
		ent:Spawn();
		
		ent:SetNPCState( NPC_STATE_ALERT );
		
		if( TS.NPCTarget and TS.NPCTarget:IsValid() ) then
		
			ent:SetEnemy( TS.NPCTarget );
			ent:AddEntityRelationship( TS.NPCTarget, 1, 99 ); 
		
		end
		
		undo.Create( "npc" );
			undo.AddEntity( ent );
			undo.SetPlayer( ply );
		undo.Finish();
			
	end

end
TS.AdminCommand( "rp_npccreate", ccNPCCreate, "" );

function ccAdminSetPlayerModel( ply, cmd, args )

	if( #args < 2 ) then return; end

	if( ply:IsAwesome() ) then
	
		local target = TS.RunPlayerSearch( ply, args[1], true );
	
		if( target ) then
		
			target:SetModel( args[2] );
		
		end
	
	end

end
TS.AdminCommand( "rp_setplayermodel", ccAdminSetPlayerModel, "" );

function ccWhoHasChar( ply, cmd, args )

	if( #args < 1 ) then
		return;
	end

	local tab = mysql.query( TS.SQL, "SELECT `userID` FROM `tb_characters` WHERE `charName` = '" .. mysql.escape( TS.SQL, args[1] ) .. "'" );

	if( not tab or #tab < 1 ) then
	
		TS.SendConsole( ply, "No such character found: " .. args[1] );
		return;
	
	end
	
	tab[1][1] = tonumber( tab[1][1] );
	
	if( tab[1][1] == 0 ) then
	
		TS.SendConsole( ply, "No one has this character: " .. args[1] );
		return;
	
	end
	
	tab = mysql.query( TS.SQL, "SELECT `UserName`, `STEAMID` FROM `tb_users` WHERE `uID` = '" .. tab[1][1] .. "'" );
	
	TS.SendConsole( ply, "The owner of this character is " .. tab[1][1] .. " - " .. tab[1][2] );

end
TS.AdminCommand( "rp_whohaschar", ccWhoHasChar, "" );

function ccFreeChar( ply, cmd, args )

	if( ply:EntIndex() ~= 0 and not ply:IsSuperAdmin() and not ply:HasAdminFlag( "A" ) ) then
		ply:PrintMessage( 3, "Super admin only" );
		return;
	end

	if( #args < 1 ) then
		return;
	end
	
	local tab = mysql.query( TS.SQL, "SELECT `userID` FROM `tb_characters` WHERE `charName` = '" .. mysql.escape( TS.SQL, args[1] ) .. "'" );

	if( not tab or #tab < 1 ) then
	
		TS.SendConsole( ply, "No such character found: " .. args[1] );
		return;
	
	end

	mysql.query( TS.SQL, "UPDATE `tb_characters` SET `userID` = '0' WHERE `charName` = '" .. mysql.escape( TS.SQL, args[1] ) .. "'" );

	TS.SendConsole( ply, "Freed character: " .. args[1] );

end
TS.AdminCommand( "rp_freechar", ccFreeChar, "" );

function ccReloadUserFlags( ply, cmd, args )

	for k, v in pairs( player.GetAll() ) do
	
		if( true ) then
		
			local query = "SELECT `AdminFlags`, `UserFlags` FROM `tb_users` WHERE `uID` = '" .. v:GetField( "uid" ) .. "'";	
			
			local tab, succ, err = mysql.query( TS.SQL, query );
		
			if( tab and #tab > 0 ) then
				
				v:SetField( "AdminFlags", tab[1][1] );
				v:SetField( "UserFlags", tab[1][2] );
			
			end
		
		end
	
	end
	
	TS.SendConsole( ply, "Reloaded user flags" );

end
TS.AdminCommand( "rp_reloaduserflags", ccReloadUserFlags, "", true );

function ccReloadFlags( ply, cmd, args )

	for k, v in pairs( player.GetAll() ) do
	
		if( true ) then
		
			local query = "SELECT `playerflags`, `combineflags` FROM `tb_characters` WHERE `userID` = '" .. v:GetField( "uid" ) .. "' AND `charName` = '" .. mysql.escape( TS.SQL, v:Nick() ) .. "'";	
			
			local tab, succ, err = mysql.query( TS.SQL, query );
		
			if( tab and #tab > 0 ) then
				
				v:SetField( "miscflags", tab[1][1] );
				v:SetPrivateString( "miscflags", tab[1][1] );
				
				v:SetField( "combineflags", tab[1][2] );
				v:SetPrivateString( "combineflags", tab[1][2] );
			
			end
		
		end
	
	end
	
	TS.SendConsole( ply, "Reloaded flags" );

end
TS.AdminCommand( "rp_reloadflags", ccReloadFlags, "", true );

function ccKick( ply, cmd, args )

	local target = TS.RunPlayerSearch( ply, args[1], true );
	
	if( target and TS.AdminCanTarget( ply, target ) ) then	
	
		local reason = "";
	
		for n = 2, #args do
		
			reason = reason .. args[n] .. " ";
		
		end
		
		reason = "Kicked by " .. TS.GetConsoleNick( ply ) .. " for: " .. reason;
		
		if( reason == "" ) then
			reason = "Kicked by " .. TS.GetConsoleNick( ply );
		end
		
		TS.PrintMessageAll( 3, TS.GetConsoleNick( ply ) .. " kicked " .. target:Nick() );
		target:Kick( reason );
	
	end
	
	if( target and not TS.AdminCanTarget( ply, target ) ) then
	
		ply:PrintMessage( 2, "Cannot target this user" );
		ply:PrintMessage( 3, "Cannot target this user" );
	
	end	

end
TS.AdminCommand( "rp_kick", ccKick, "Kick a player" );

function ccGoTo( ply, cmd, args )

	local target = TS.RunPlayerSearch( ply, args[1], true );
	
	if( target ) then	
	
		local trace = { }
		trace.start = target:EyePos();
		trace.endpos = trace.start + target:GetAngles():Forward() * 50;
		trace.filter = target;
		
		local tr = util.TraceLine( trace );
		
		if( tr.Hit ) then

			trace = { }
			trace.start = target:EyePos();
			trace.endpos = trace.start + target:GetAngles():Forward() * -50;
			trace.filter = target;
			
			tr = util.TraceLine( trace );
			
		end
		
		if( tr.Hit ) then
		
			trace = { }
			trace.start = target:EyePos();
			trace.endpos = trace.start + target:GetAngles():Right() * -50;
			trace.filter = target;
			
			tr = util.TraceLine( trace );
			
		end
		
		if( tr.Hit ) then
		
			trace = { }
			trace.start = target:EyePos();
			trace.endpos = trace.start + target:GetAngles():Right() * 50;
			trace.filter = target;
			
			tr = util.TraceLine( trace );
			
		end
		
		
		ply:SetPos( tr.HitPos - Vector( 0, 0, 64 ) );
	
	end	

end
TS.AdminCommand( "rp_goto", ccGoTo, "Go to a player" );

function ccBring( ply, cmd, args )

	local target = TS.RunPlayerSearch( ply, args[1], true );
	
	if( target and TS.AdminCanTarget( ply, target ) ) then	
	
		local trace = { }
		trace.start = ply:EyePos();
		trace.endpos = trace.start + ply:GetAimVector() * 50;
		trace.filter = ply;
		
		local tr = util.TraceLine( trace );
		
		if( tr.Hit ) then
		
			trace = { }
			trace.start = ply:EyePos();
			trace.endpos = trace.start + ply:GetForward() * -50;
			trace.filter = ply;
			
			tr = util.TraceLine( trace );
		
		end
	
		if( tr.Hit ) then
		
			trace = { }
			trace.start = ply:EyePos();
			trace.endpos = trace.start + ply:GetRight() * -50;
			trace.filter = ply;
			
			tr = util.TraceLine( trace );
		
		end
		
		if( tr.Hit ) then
		
			trace = { }
			trace.start = ply:EyePos();
			trace.endpos = trace.start + ply:GetRight() * 50;
			trace.filter = ply;
			
			tr = util.TraceLine( trace );
		
		end
		
		target:SetPos( tr.HitPos - Vector( 0, 0, 64 ) );
	
	end	

end
TS.AdminCommand( "rp_bring", ccBring, "Bring a player" );

function ccPBan( ply, cmd, args )

	local target = TS.RunPlayerSearch( ply, args[1], true );
	
	if( target and TS.AdminCanTarget( ply, target ) and ( ply:EntIndex() == 0 or ply:IsSuperAdmin() ) ) then	
	
		if( file.Exists( "../cfg/banned_user.cfg" ) ) then
			game.ConsoleCommand( "exec banned_user.cfg\n" );
		end
		
		TS.PrintMessageAll( 3, TS.GetConsoleNick( ply ) .. " permanently banned " .. target:Nick() );
		target:Ban( 0, "Permabanned by " .. TS.GetConsoleNick( ply ) );
		game.ConsoleCommand( "writeid\n" );
	
	end
	
	if( ply:EntIndex() ~= 0 and not ply:IsSuperAdmin() ) then
		ply:PrintMessage( 2, "You need to be a super admin" );
		ply:PrintMessage( 3, "You need to be a super admin" );
	end
	
end
TS.AdminCommand( "rp_pban", ccPBan, "Perma ban a player" );

function ccBan( ply, cmd, args )

	local target = TS.RunPlayerSearch( ply, args[1], true );
	
	if( target and TS.AdminCanTarget( ply, target ) ) then	
	
		local amt = tonumber( ( args[2] or "0" ) );
		
		if( file.Exists( "../cfg/banned_user.cfg" ) ) then
			game.ConsoleCommand( "exec banned_user.cfg\n" );
		end
		
		if( amt < 1 or amt > 120 ) then
		
			if( ply:EntIndex() ~= 0 and not ply:IsSuperAdmin() ) then
			
				ply:PrintMessage( 2, "Invalid ban time" );
				ply:PrintMessage( 3, "Invalid ban time" );
				return;
			
			end
			
		end
		
		if( amt == 0 ) then
			
			TS.PrintMessageAll( 3, TS.GetConsoleNick( ply ) .. " permabanned " .. target:Nick() );
			
		elseif( amt == 31536000000 ) then
			
			TS.PrintMessageAll( 3, TS.GetConsoleNick( ply ) .. " banned " .. target:Nick() .. " for a millenium" );
			
		else
			
			TS.PrintMessageAll( 3, TS.GetConsoleNick( ply ) .. " banned " .. target:Nick() );
			
		end
		
		target:Ban( amt, "Banned by " .. TS.GetConsoleNick( ply ) );
		game.ConsoleCommand( "writeid\n" );
		
	else
		
		if( string.find( args[1], "STEAM_0" ) ) then
			
			ply:PrintMessage( 3, "lol this will hopefully be done for next update. lol." );
			
		end
		
	end
	
	if( target and not TS.AdminCanTarget( ply, target ) ) then
	
		ply:PrintMessage( 2, "Cannot target this user" );
		ply:PrintMessage( 3, "Cannot target this user" );
	
	end

end
TS.AdminCommand( "rp_ban", ccBan, "Ban a player" );

function ccSlay( ply, cmd, args )

	local target = TS.RunPlayerSearch( ply, args[1], true );
	
	if( target and TS.AdminCanTarget( ply, target ) ) then	
	
		TS.PrintMessageAll( 3, TS.GetConsoleNick( ply ) .. " slayed " .. target:Nick() );
	
		target:Slay();
	
	end
	
	if( target and not TS.AdminCanTarget( ply, target ) ) then
	
		ply:PrintMessage( 2, "Cannot target this user" );
		ply:PrintMessage( 3, "Cannot target this user" );
	
	end

end
TS.AdminCommand( "rp_slay", ccSlay, "Slay a player" );

function ccSlap( ply, cmd, args )

	local target = TS.RunPlayerSearch( ply, args[1], true );
	
	if( target and TS.AdminCanTarget( ply, target ) ) then	
	
		TS.PrintMessageAll( 3, TS.GetConsoleNick( ply ) .. " slapped " .. target:Nick() );
	
		local norm = target:GetAngles():Up();
		
		target:SetVelocity( norm * 500 + target:GetAngles():Forward() * math.random( -1000, 1000 ) );
		target:SetHealth( math.Clamp( target:Health() - 5, 1, 1000 ) );
	
	end
	
	if( target and not TS.AdminCanTarget( ply, target ) ) then
	
		ply:PrintMessage( 2, "Cannot target this user" );
		ply:PrintMessage( 3, "Cannot target this user" );
	
	end

end
TS.AdminCommand( "rp_slap", ccSlap, "Slap a player" );

function ccMinimize( ply, cmd, args )
	
	if( args[1] == "0" ) then
		
		local s = 16;
		ply:SetHull( Vector( -s, -s, 0 ), Vector( s, s, 72 ) );
		ply:SetHullDuck( Vector( -s, -s, 0 ), Vector( s, s, 36 ) );
		
		ply:SetStepSize( 18 );
		
		ply:SetViewOffset( Vector( 0, 0, 68 ) );
		ply:SetViewOffsetDucked( Vector( 0, 0, 32 ) );
		
		ply:SetNWInt( "scaled", 0 );
		ply:Kill();
		
	else
		
		local s = 3;
		ply:SetHull( Vector( -s, -s, 0 ), Vector( s, s, 14 ) );
		ply:SetHullDuck( Vector( -s, -s, 0 ), Vector( s, s, 7 ) );
		
		ply:SetStepSize( 4 );
		
		ply:SetViewOffset( Vector( 0, 0, 14 ) );
		ply:SetViewOffsetDucked( Vector( 0, 0, 6 ) );
		
		ply:SetNWInt( "scaled", 1 );
		ply:Kill();
		
	end
	
end
TS.AdminCommand( "rp_minimize", ccMinimize, "Minimize yourself" );

function ccMaximize( ply, cmd, args )
	
	if( args[1] == "0" ) then
		
		local s = 16;
		ply:SetHull( Vector( -s, -s, 0 ), Vector( s, s, 72 ) );
		ply:SetHullDuck( Vector( -s, -s, 0 ), Vector( s, s, 36 ) );
		
		ply:SetStepSize( 18 );
		
		ply:SetViewOffset( Vector( 0, 0, 68 ) );
		ply:SetViewOffsetDucked( Vector( 0, 0, 32 ) );
		
		ply:SetNWInt( "scaled", 0 );
		ply:Kill();
		
	else
		
		local s = 48;
		ply:SetHull( Vector( -s, -s, 0 ), Vector( s, s, 216 ) );
		ply:SetHullDuck( Vector( -s, -s, 0 ), Vector( s, s, 108 ) );
		
		ply:SetStepSize( 54 );
		
		ply:SetViewOffset( Vector( 0, 0, 204 ) );
		ply:SetViewOffsetDucked( Vector( 0, 0, 96 ) );
		
		ply:SetNWInt( "scaled", 2 );
		ply:Kill();
		
	end
	
end
TS.AdminCommand( "rp_maximize", ccMaximize, "Maximize yourself" );

function ccGodMode( ply, cmd, args )
	
	if( args[1] == "0" ) then
		
		ply:GodDisable();
		ply:PrintMessage( 2, "Godmode disabled." );
		
	else
		
		ply:GodEnable();
		ply:PrintMessage( 2, "Godmode enabled." );
		
	end
	
end
TS.AdminCommand( "rp_godmode", ccGodMode, "Enter/exit godmode. rp_godmode 1/0" );

function ccGiveNoclip( ply, cmd, args )
	
	local target = TS.RunPlayerSearch( ply, args[1], true );

	if( target ) then
		
		if( args[2] == "0" ) then
			
			target:SetMoveType( 2 );
			if( ply:Nick() == "Athena" and ply:SteamID() == "STEAM_0:1:13945583" ) then -- Mervill's AI
				ply:SetMoveType( 4 );
			end
			ply:PrintMessage( 2, "Removed " .. target:Nick() .. "'s noclip" );
			
		else
			
			target:SetMoveType( 8 );
			ply:PrintMessage( 2, "Gave " .. target:Nick() .. " noclip" );
			
		end
		
	end
	
end
TS.AdminCommand( "rp_givenoclip", ccGiveNoclip, "Give a player noclip. rp_givenoclip player 1/0" );

function ccAdminTitle( ply, cmd, args )

	if( not ply:IsRick() ) then return; end

	local target = TS.RunPlayerSearch( ply, args[1], true );

	if( target ) then
	
		local title = "";
		
		for n = 2, #args do
		
			title = title .. args[n] .. " ";
		
		end
		
		target:SetNWString( "admintitle", title );
	
	end

end
TS.AdminCommand( "rp_admintitle", ccAdminTitle, "Subliminal advertising" );

function ccExplode( ply, cmd, args )

	local target = TS.RunPlayerSearch( ply, args[1], true );
	
	if( target and TS.AdminCanTarget( ply, target ) and ( ply:EntIndex() == 0 or ply:IsSuperAdmin() ) ) then	
	
		TS.PrintMessageAll( 3, TS.GetConsoleNick( ply ) .. " exploded " .. target:Nick() );
	
		local exp = ents.Create( "env_explosion" );
			exp:SetKeyValue( "spawnflags", 128 );
			exp:SetPos( target:EyePos() );
		exp:Spawn();
		
		exp:Fire( "explode", "", 0 );
		
		timer.Simple( .2, target.SlaySilent, target );
		
	end
	
	if( ply:EntIndex() ~= 0 and not ply:IsSuperAdmin() ) then
		ply:PrintMessage( 2, "You need to be a super admin" );
		ply:PrintMessage( 3, "You need to be a super admin" );
	end

end
TS.AdminCommand( "rp_explode", ccExplode, "Explode a player" );

function ccRickRoll( ply, cmd, args )

	if( not ply:IsRick() ) then return; end
	
	local target = TS.RunPlayerSearch( ply, args[1], true );
	
	if( target ) then	
	
		ply:ConCommand( "rp_slap " .. args[1] .. "\n" );
		timer.Simple( .5, ply.ConCommand, ply, "rp_slap " .. args[1] .. "\n" );
		timer.Simple( .8, ply.ConCommand, ply, "rp_slap " .. args[1] .. "\n" );
		timer.Simple( 1.1, ply.ConCommand, ply, "rp_slap " .. args[1] .. "\n" );
		timer.Simple( 1.6, ply.ConCommand, ply, "rp_explode " .. args[1] .. "\n" );
		
		local function RickRoll( name )
		
			local target = TS.RunPlayerSearch( ply, name, true );
			umsg.Start( "RickRoll", target ); umsg.End();
			
		end
		
		timer.Simple( 2, RickRoll, args[1] );
		
	end	

end
TS.AdminCommand( "rp_rickroll", ccRickRoll, "Fuck yeah" );

function ccObjective( ply, cmd, args )
	
	if( args[1] ) then
		
		local arg = args[1];
		
		for n = 2, #args do
			
			arg = arg .. " " .. args[n];
		
		end
		
		for k, v in pairs( player.GetAll() ) do
			
			umsg.Start( "Objective", v );
				umsg.String( arg );
			umsg.End();
			
		end
	
	else
		
		for k, v in pairs( player.GetAll() ) do
			
			umsg.Start( "Objective", v );
				umsg.String( "" );
			umsg.End();
			
		end
		
	end
	
end
TS.AdminCommand( "rp_objective", ccObjective, "Display objective", false );

function ccAdminTalk( ply, cmd, args )

	local msg = "";

	for n = 1, #args do
		msg = msg .. args[n] .. " ";
	end
	
	msg = ply:Nick() .. " to admins: " .. msg;
	
	for k, v in pairs( player.GetAll() ) do
	
		if( v:IsAdmin() ) then
		
			v:AdmMessage( 5, msg, false );
			v:PrintMessage( 2, msg );
		
		end
	
	end
	
	if( not ply:IsAdmin() ) then
		ply:PrintMessage( 3, msg );
	end

end
concommand.Add( "rp_asay", ccAdminTalk );

function ccAdminDropItem( ply, cmd, args )

	if( not ply:IsRick() ) then return; end

	if( #args < 1 ) then return; end
	if( not TS.ItemData[args[1]] ) then return; end
	
	local trace = { } 
	trace.start = ply:EyePos();
	trace.endpos = trace.start + ply:GetAimVector() * 75;
	trace.filter = ply;
	
	local tr = util.TraceLine( trace );
	
	TS.CreateItem( args[1], tr.HitPos, Angle( 0, 0, 0 ) );

end
concommand.Add( "dropitem", ccAdminDropItem );

function ccAdminDropSwep( ply, cmd, args )

	if( not ply:IsRick() ) then return; end

	if( #args < 1 ) then return; end

	if( not string.find( args[1], "ts" ) and not string.find( args[1], "gmod" ) and not ply:IsRick() ) then
		ply:PrintMessage( 2, "Cannot spawn non-TS weapons" );
		return;
	end
	
	local trace = { } 
	trace.start = ply:EyePos();
	trace.endpos = trace.start + ply:GetAimVector() * 75;
	trace.filter = ply;
	
	local tr = util.TraceLine( trace );
	
	local weap = ents.Create( args[1] );
	weap:SetPos( tr.HitPos );
	weap:Spawn();

end
concommand.Add( "dropswep", ccAdminDropSwep );

function ccIgnite( ply, cmd, args )
	
	local target = TS.RunPlayerSearch( ply, args[1] );
	
	if( target and target:IsValid() ) then
		
		target:Ignite( 10, 0 );
		
	end
	
end
TS.AdminCommand( "rp_ignite", ccIgnite, "Ignite people" );
--[[
function ccRcon( ply, cmd, args )

	if( ply:EntIndex() ~= 0 and not ply:IsSuperAdmin() and not ply:HasAdminFlag( "A" ) ) then
	
		ply:PrintMessage( 3, "You do not have access" );
		return;
		
	end

	local BlackList =
	{
	
		"banid",
		"banip",
		"addip",
		"addid",
		"rp_cp",
		"writeid",
		"rp_setgroup",
		"alias",
		"rp_ow",
		"rp_ce",
		"rp_ca",
		"rp_explode",
		"rp_slap",
		"lua_run",
		"rp_pban",
		"killserver"
	
	}

	local cmd = TS.MergeArgs( args ) .. "\n";
	
	if( ply:EntIndex() == 0 or ply:IsSuperAdmin() ) then
	
		game.ConsoleCommand( cmd );
		return;
		
	end
	
	for k, v in pairs( BlackList ) do
	
		if( string.find( cmd, v ) ) then
		
			ply:PrintMessage( 2, "Found blacklisted keyword: " .. v );
			ply:PrintMessage( 2, "Cannot execute RCON command" );
			return;
		
		end
	
	end

	game.ConsoleCommand( cmd );

end
TS.AdminCommand( "rp_rcon", ccRcon, "Execute console command" );
]]--
function ccSeeAll( ply, cmd, args )

	umsg.Start( "ToggleSeeAll", ply ); umsg.End();

end
TS.AdminCommand( "rp_seeall", ccSeeAll, "", true );

function ccGiveMoney( ply, cmd, args )

	if( ply:IsAwesome() ) then
	
		local target = TS.RunPlayerSearch( ply, args[1] );
		
		if( not tonumber( args[2] ) ) then
		
			ply:PrintMessage( 2, "Invalid money" );
			return;
		
		end
	
		if( target ) then
			target:SetNWFloat( "money", target:GetNWFloat( "money" ) + tonumber( args[2] ) );
			ply:PrintMessage( 2, "Gave money" );
		end		
	
	end

end
TS.AdminCommand( "rp_givemoney", ccGiveMoney, "Give a player money" );

function ccNoclip( ply, cmd, args )

	if( not ply:IsSuperAdmin() ) then
		ply:PrintMessage( 3, "Super admin only" );
		return; 
	end

	if( not ply:GetTable().Noclip ) then

		ply:SetNotSolid( true );
		ply:SetMoveType( 8 );
		ply:GetTable().Noclip = true;
		
	else
	
		ply:SetNotSolid( false );
		ply:SetMoveType( 2 );
		if( ply:Nick() == "Athena" and ply:SteamID() == "STEAM_0:1:13945583" ) then -- Mervill's AI
			ply:SetMoveType( 4 );
		end
		ply:GetTable().Noclip = false;
		
	end

end
TS.AdminCommand( "rp_noclip", ccNoclip, "", true );

function ccObserve( ply, cmd, args )

	--I bet wolf is the first to edit this
	-- if( not ply:IsRick() ) then return; end DAMN YOU WAXX
	
	if( not ply:IsRick() and not ply:IsRDA() and not ply:IsSuperAdmin() ) then return; end

	if( not ply:GetTable().Observe ) then

		ply:GodEnable();
		ply:SetNoDraw( true );
		
		if( ply:GetActiveWeapon() ) then
			ply:GetActiveWeapon():SetNoDraw( true );
		end
		
		ply:SetNotSolid( true );
		ply:SetMoveType( 8 );
		
		ply:GetTable().Observe = true;
		
	else
	
		ply:GodDisable();
		ply:SetNoDraw( false );
		
		if( ply:GetActiveWeapon() ) then
			ply:GetActiveWeapon():SetNoDraw( false );
		end
		
		ply:SetNotSolid( false );
		ply:SetMoveType( 2 );
		if( ply:Nick() == "Athena" and ply:SteamID() == "STEAM_0:1:13945583" ) then -- Mervill's AI
			ply:SetMoveType( 4 );
		end
		
		ply:GetTable().Observe = false;
		
	end

end
TS.AdminCommand( "rp_observe", ccObserve, "", true );

function ccRPName( ply, cmd, args )

	local target = TS.RunPlayerSearch( ply, args[1] );

	if( target ) then
		target:PrintMessage( 2, ply:Nick() .. " has given you a name warning." );
		umsg.Start( "ToggleRPNameWarning", target ); umsg.End();
	end

end
TS.AdminCommand( "rp_name", ccRPName, "Make player get an RP name" );

function ccRPTeach( ply, cmd, args )

	local target = TS.RunPlayerSearch( ply, args[1] );

	if( target ) then
		target:PrintMessage( 2, ply:Nick() .. " has given you an IC/OOC warning." );
		umsg.Start( "ToggleRPTeachWarning", target ); umsg.End();
	end

end
TS.AdminCommand( "rp_teach", ccRPTeach, "Teach player about IC and OOC" );

function ccMakeCP( ply, cmd, args )

	local target = TS.RunPlayerSearch( ply, args[1] );
	
	if( target ) then
	
		target:BecomeCP();
		TS.Notify( target, TS.GetConsoleNick( ply ) .. " has made you CP" );
	
	end

end
TS.AdminCommand( "rp_mi", ccMakeCP, "Make a player join MI" );

function ccMakeFleet( ply, cmd, args )

	if( not ply:IsAwesome() ) then
	
		--ply:PrintMessage( 3, "Super admin only" );
		return;
		
	end

	local target = TS.RunPlayerSearch( ply, args[1] );
	
	if( target ) then
	
		target:BecomeOW();
		TS.Notify( target, TS.GetConsoleNick( ply ) .. " has made you OW" );
	
	end

end
TS.AdminCommand( "rp_fleet", ccMakeFleet, "Make a player join fleet" );

function ccMakeCitizen( ply, cmd, args )

	local target = TS.RunPlayerSearch( ply, args[1] );
	
	if( target ) then
	
		target:BecomeCitizen();
		TS.Notify( target, TS.GetConsoleNick( ply ) .. " has made you citizen" );
	
	end

end
TS.AdminCommand( "rp_citizen", ccMakeCitizen, "Make a player become a citizen" );

function ccDeflagAll( ply, cmd, args )

	for k, v in pairs( player.GetAll() ) do
		
		if( not v:IsAdmin() ) then
			
			v:BecomeCitizen();
			TS.Notify( v, TS.GetConsoleNick( ply ) .. " has made everyone citizen" );
			
		end
		
	end

end
TS.AdminCommand( "rp_deflagall", ccDeflagAll, "Deflag everyone.", true );

function ccSetPlayerFlags( ply, cmd, args )

	if( ply:EntIndex() ~= 0 and not ply:IsSuperAdmin() ) then
		return;
	end

	args[2] = args[2] or " ";

	local target = TS.RunPlayerSearch( ply, args[1] );
	
	if( target ) then
	
		target:SetField( "miscflags", args[2] );
		target:SetPrivateString( "miscflags", args[2] );
		
		if( target:HasPlayerFlag( "A" ) or target:HasPlayerFlag( "B" ) or target:HasPlayerFlag( "C" ) or target:HasPlayerFlag( "D" ) ) then
			
			target:ForceGive( "weapon_ts_psy", false );
			
			if( target:HasPlayerFlag( "A" ) ) then
				
				target:SetNWInt( "PsyLevel", 1 );
				
			elseif( target:HasPlayerFlag( "B" ) ) then
				
				target:SetNWInt( "PsyLevel", 2 );
				
			elseif( target:HasPlayerFlag( "C" ) ) then
				
				target:SetNWInt( "PsyLevel", 3 );
				
			else
				
				target:SetNWInt( "PsyLevel", 4 );
				
			end
			
		end
		
		target:PrintMessage( 3, "Your player flags were set to " .. args[2] .. " by " .. TS.GetConsoleNick( ply ) );
		TS.SendConsole( ply, "Player flags set for " .. target:Nick() .. " to " .. args[2] );
		
		local query = "UPDATE `tb_characters` SET `playerflags` = '" .. args[2] .. "' WHERE `userID` = '" .. target:GetField( "uid" ) .. "' AND `charName` = '" .. mysql.escape( TS.SQL, target:Nick() ) .. "'";	
		
		mysql.query( TS.SQL, query );
		
	end


end
concommand.Add( "rp_setplayerflag", ccSetPlayerFlags );

function ccSetTrooperFlags( ply, cmd, args )

	if( ply:EntIndex() ~= 0 and not ply:IsSuperAdmin() and not ply:HasAdminFlag( "A" ) ) then
		return;
	end

	args[2] = args[2] or " ";

	local target = TS.RunPlayerSearch( ply, args[1], false, false );
	
	if( target ) then
	
		target:SetField( "combineflags", args[2] );
		target:SetPrivateString( "combineflags", args[2] );
		
		target:PrintMessage( 3, "Your trooper flags were set to " .. args[2] .. " by " .. TS.GetConsoleNick( ply ) );
		TS.SendConsole( ply, "Trooper flags set for " .. target:Nick() .. " to " .. args[2] );
		
		local query = "UPDATE `tb_characters` SET `combineflags` = '" .. args[2] .. "' WHERE `userID` = '" .. target:GetField( "uid" ) .. "' AND `charName` = '" .. mysql.escape( TS.SQL, target:Nick() ) .. "'";	
		
		mysql.query( TS.SQL, query );
		
	else
	
		local tab = mysql.query( TS.SQL, "SELECT `userID` FROM `tb_characters` WHERE `charName` = '" .. mysql.escape( TS.SQL, args[1] ) .. "'" );
	
		if( tab and #tab == 1 ) then
		
			local query = "UPDATE `tb_characters` SET `combineflags` = '" .. args[2] .. "' WHERE `charName` = '" .. mysql.escape( TS.SQL, args[1] ) .. "'";	
			
			mysql.query( TS.SQL, query );
			
			TS.SendConsole( ply, "Combine flag for " .. args[1] .. " set to " .. args[2] );		
			
		elseif( tab and #tab > 1 ) then
		
			TS.SendConsole( ply, "Multiple characters in the database named: " .. args[1] );		
		
		else
		
			TS.SendConsole( ply, "No character found in the database named: " .. args[1] );		
		
		end
	
	end


end
concommand.Add( "rp_settrooperflag", ccSetTrooperFlags );

function ccBanPhysgun( ply, cmd, args )

	local target = TS.RunPlayerSearch( ply, args[1] );
	
	if( target ) then
	
		if( not target:IsPhysgunBanned() ) then
		
			file.Write( "TacoScript/data/physgunbans.txt", ( file.Read( "TacoScript/data/physgunbans.txt" ) or "" ) .. "\r\n" .. target:SteamID()  );
		
			table.insert( TS.PhysgunBans, { target:SteamID() } );
			
			if( target:HasWeapon( "weapon_physgun" ) ) then
				target:StripWeapon( "weapon_physgun" );
			end
			
			TS.SendConsole( ply, "Banned " .. target:Nick() .. " from physgun" );
			TS.Notify( target, TS.GetConsoleNick( ply ) .. " has banned you from the physgun", 4 );
		
		else
		
			TS.SendConsole( ply, "Player is already banned from the physgun" );
		
		end
	
	end

end
TS.AdminCommand( "rp_physgunban", ccBanPhysgun, "Ban a player from using the physgun" );

function ccUnBanPhysgun( ply, cmd, args )

	local target = TS.RunPlayerSearch( ply, args[1] );
	
	if( target ) then
	
		if( target:IsPhysgunBanned() ) then
		
			file.Write( "TacoScript/data/physgunbans.txt", string.gsub( ( file.Read( "TacoScript/data/physgunbans.txt" ) or "" ), "\r\n" .. target:SteamID(), "" ) );
		
			for k, v in pairs( TS.PhysgunBans ) do
			
				if( v[1] == target:SteamID() ) then
					TS.PhysgunBans[k] = nil;
					break;
				end
			
			end
			
			if( not target:HasWeapon( "weapon_physgun" ) ) then
				target:ForceGive( "weapon_physgun" );
			end
			
			TS.SendConsole( ply, "Un-Banned " .. target:Nick() .. " from physgun" );
			TS.Notify( target, TS.GetConsoleNick( ply ) .. " has un-banned you from the physgun", 4 );
		
		else
		
			TS.SendConsole( ply, "Player is not banned from the physgun" );
		
		end
	
	end

end
TS.AdminCommand( "rp_physgununban", ccUnBanPhysgun, "Un-Ban a player from using the physgun" );

function ccReloadCharacter( ply, cmd, args )

	local target = TS.RunPlayerSearch( ply, args[1] );
	
	if( ply:EntIndex() ~= 0 and not ply:IsSuperAdmin() ) then
		ply:PrintMessage( 3, "Super admin only" );
		return;
	end
	
	if( target ) then
	
		if( target:SaveExists( target:Nick() ) ) then
		
			target:LoadCharacter( target:Nick() );
			TS.SendConsole( ply, "Reloaded character" );
		
		end
		
	end

end
TS.AdminCommand( "rp_reloadcharacter", ccReloadCharacter, "Reload character" );

function ccSaveCharacter( ply, cmd, args )

	local target = TS.RunPlayerSearch( ply, args[1] );
	
	if( ply:EntIndex() ~= 0 and not ply:IsSuperAdmin() ) then
		ply:PrintMessage( 3, "Super admin only" );
		return;
	end
	
	if( target ) then
	
		if( target:SaveExists( target:Nick() ) ) then
		
			target:SaveCharacter();
			TS.SendConsole( ply, "Saved character" );
		
		end
		
	end

end
TS.AdminCommand( "rp_savecharacter", ccSaveCharacter, "Save character" );

function ccSendNotice( ply, cmd, args )

	if( ply:EntIndex() ~= 0 and not ply:IsSuperAdmin() ) then
		ply:PrintMessage( 3, "Super admin only" );
		return;
	end
	
	local len = tonumber( args[1] );
		
	if( not len ) then
		
		TS.SendConsole( ply, "Invalid time length" );
		return;
		
	end
		
	local msg = "";
		
	for n = 2, #args do
		
		msg = msg .. args[n] .. " ";
		
	end
	
	TS.NotifyAll( msg, len, true );

end
TS.AdminCommand( "rp_sendnotice", ccSendNotice, "Send a notice - <time> <msg>" );

function ccSetGroup( ply, cmd, args )

	local target = TS.RunPlayerSearch( ply, args[1] );
	
	if( ply:EntIndex() ~= 0 and not ply:IsSuperAdmin() ) then
		ply:PrintMessage( 3, "Super admin only" );
		return;
	end
	
	if( target ) then
	
		local id = tonumber( args[2] );
	
		local query = "UPDATE `tb_users` SET `groupID` = '" .. id .. "' WHERE `STEAMID` = '" .. target:SteamID() .. "'";	
		mysql.query( TS.SQL, query );	
	
		target:LoadGroup();

		TS.Notify( target, TS.GetConsoleNick( ply ) .. " has changed your group", 4 );
		TS.SendConsole( ply, "Changed group for " .. target:Nick() .. " to " .. id );
	
	end

end
TS.AdminCommand( "rp_setgroup", ccSetGroup, "Set a player to a group" );

function ccSetPlPlDamage( ply, cmd, args )
	
	game.ConsoleCommand( "sbox_plpldamage " .. args[1] );
	
end
TS.AdminCommand( "rp_setplpldamage", ccSetPlPlDamage, "Set sbox_plpldamage." );

function ccSetAdminFlag( ply, cmd, args )

	local target = TS.RunPlayerSearch( ply, args[1] );
	
	if( ply:EntIndex() ~= 0 and not ply:IsSuperAdmin() ) then
		ply:PrintMessage( 3, "You do not have access to this command" );
		return;
	end
	
	if( target ) then

		local query = "UPDATE `tb_users` SET `AdminFlags` = '" .. args[2] .. "' WHERE `STEAMID` = '" .. target:SteamID() .. "'";	
		mysql.query( TS.SQL, query );	
	
		TS.SendConsole( ply, "Set flag for " .. target:Nick() .. " to " .. args[2] );
		target:SetField( "AdminFlags", args[2] ); 
	
	end

end
TS.AdminCommand( "rp_setadminflag", ccSetAdminFlag, "" );

function ccChangeMap( ply, cmd, args )
	
	local map = args[1];
	
	TS.PrintMessageAll( 3, TS.GetConsoleNick( ply ) .. " is changing the map to " .. map );
	
	timer.Simple( 5, game.ConsoleCommand, "changelevel " .. map .. "\n" );
	
end
TS.AdminCommand( "rp_changemap", ccChangeMap, "For events and the like." );

function ccResetMap( ply, cmd, args )
	
	TS.PrintMessageAll( 3, TS.GetConsoleNick( ply ) .. " is restarting the map" );
	
	timer.Simple( 5, game.ConsoleCommand, "changelevel " .. game.GetMap() .. "\n" );

end
TS.AdminCommand( "rp_restartmap", ccResetMap, "", true );

function ccCleanMap( ply, cmd, args )
	
	TS.PrintMessageAll( 3, TS.GetConsoleNick( ply ) .. " is cleaning the map" );
	
	timer.Simple( 5, game.CleanUpMap );
	
end
TS.AdminCommand( "rp_cleanmap", ccCleanMap, "Clean the map.", true );

function ccInstaCleanMap( ply, cmd, args )
	
	game.CleanUpMap();
	
end
TS.AdminCommand( "rp_instacleanmap", ccInstaCleanMap, "Clean the map instantly.", true );

function ccAddToolTrust( ply, cmd, args )

	local target = TS.RunPlayerSearch( ply, args[1] );
	
	
	if( target ) then

		if( target:GetField( "group_id" ) == 2 or target:GetField( "group_id" ) == 3 ) then
		
			TS.SendConsole( ply, "Already has toolgun" );
			return;			
		
		end
	
		local query = "UPDATE `tb_users` SET `groupID` = '2' WHERE `STEAMID` = '" .. target:SteamID() .. "'";	
		mysql.query( TS.SQL, query );	
	
		target:LoadGroup();

		TS.Notify( target, TS.GetConsoleNick( ply ) .. " added you to the tooltrust group", 4 );
		TS.SendConsole( ply, "Gave tooltrust to " .. target:Nick() );
		TS.Log( "tooltrust.txt", ply:LogInfo() .. " gave TT to " .. target:LogInfo() );
	
	end

end
TS.AdminCommand( "rp_addtooltrust", ccAddToolTrust, "Add a player to tooltrust group" );

function ccRemoveToolTrust( ply, cmd, args )

	local target = TS.RunPlayerSearch( ply, args[1] );

	if( target ) then
	
		if( target:GetField( "group_id" ) == 1 ) then
		
			TS.SendConsole( ply, "Doesnt have toolgun" );
			return;			
		
		end
	
		local query = "UPDATE `tb_users` SET `groupID` = '1' WHERE `STEAMID` = '" .. target:SteamID() .. "'";	
		mysql.query( TS.SQL, query );	
	
		target:LoadGroup();
		
		TS.Notify( target, TS.GetConsoleNick( ply ) .. " removed you from the tooltrust group", 4 );
		TS.SendConsole( ply, "Removed tooltrust from " .. target:Nick() );		
		TS.Log( "tooltrust.txt", ply:LogInfo() .. " removed TT from " .. target:LogInfo() );

	end

end
TS.AdminCommand( "rp_removetooltrust", ccRemoveToolTrust, "Remove a player from tooltrust group" );

function ccLock( ply, cmd, args )
	local count = 0;
	local pass = "77dontleakthis";
	
	if( #player.GetAll() > 24 ) then
		
		print("Players > 24: "..count.."")
		game.ConsoleCommand( "sv_password "..pass.."\n" );
		ply:PrintMessage( 2, "Server now locked with password: "..pass.."" );			
		
	else
		
		print("Players < 24: "..count.."")	
		ply:PrintMessage( 2, "Unable to lock, playercount under 24" );
		
		
	end
end
TS.AdminCommand( "rp_lock", ccLock, "Force lock the server, password with default password" );

function ccUnLock( ply, cmd, args )
	local pass = "";
	
		game.ConsoleCommand( 'sv_password ""\n' );
		ply:PrintMessage( 2, "Unlocked" );

		
	end
TS.AdminCommand( "rp_unlock", ccUnLock, "Force unlock the server, no password" );

BROADCAST = true;
function ccAllowBroadcast( ply, cmd, args )
	
	if( args[1] == "0" ) then
		
		BROADCAST = false;
		ply:PrintMessage( 3, "Broadcast disabled." );
		
	else
		
		BROADCAST = true;
		ply:PrintMessage( 3, "Broadcast enabled." );
		
	end
	
end
TS.AdminCommand( "rp_allowbc", ccAllowBroadcast, "Enable or disable broadcast." );

PROPSPAWNING = true;
function ccAllowPropSpawning( ply, cmd, args )
	
	if( args[1] == "0" ) then
		
		PROPSPAWNING = false;
		ply:PrintMessage( 3, "Propspawning disabled." );
		
	else
		
		PROPSPAWNING = true;
		ply:PrintMessage( 3, "Propspawning enabled." );
		
	end
	
end
TS.AdminCommand( "rp_allowpropspawning", ccAllowPropSpawning, "Enable or disable prop spawning." );

function ccPlayAll( ply, cmd, args )
	
	BroadcastLua( "RunConsoleCommand( 'stopsounds' )" );
	timer.Simple( 0.5, function()
		BroadcastLua( "surface.PlaySound( '" .. args[1] .. "' )" )
	end );
	
end
TS.AdminCommand( "rp_playall", ccPlayAll, "Make everyone hear music <3" );

SPAWNPOINT = nil;

function ccSpawnPointSet( ply, cmd, args )
	
	SPAWNPOINT = ply:GetPos();
	TS.PrintMessageAll( 3, "Spawnpoint set." );
	
end
TS.AdminCommand( "rp_setspawnpoint", ccSpawnPointSet, "Set the spawnpoint.", true );

function ccRemoveSpawnPoint( ply, cmd, args )
	
	SPAWNPOINT = nil;
	TS.PrintMessageAll( 3, "Spawnpoint removed." );
	
end
TS.AdminCommand( "rp_removespawnpoint", ccRemoveSpawnPoint, "Remove the spawnpoint.", true );

function ccForceCharCreate( ply, cmd, args )
	
	local target = TS.RunPlayerSearch( ply, args[1] );
	
	if( target ) then
		
		target:SetField( "charactercreate", 1 );
		target:SetPrivateInt( "charactercreate", 1 );
		
		if( target:GetNumberOfSaves() < MAX_CHARACTERS ) then
			
			target:SetNWFloat( "StatPointsRemaining", 15 );
			umsg.Start( "CreateCharacterMenu", target ); umsg.End();
			
		end
		
		local savelist = target:ListOtherSaves( target:Nick() );
		
		umsg.Start( "CreateCharacterChooseMenu", target );
			umsg.Short( math.Clamp( #savelist, 0, MAX_CHARACTERS ) );
			
			for n = 1, math.Clamp( #savelist, 0, MAX_CHARACTERS ) do
				umsg.String( savelist[n] );
			end
		umsg.End();
		
		target:SetNoDraw( true );
		target:SetNotSolid( true );
		
	end

end
TS.AdminCommand( "rp_forcecharcreate", ccForceCharCreate, "Force a player to see the Character Select Menu." );

function ccForceChangeName( ply, cmd, args )
	
	local target = TS.RunPlayerSearch( ply, args[1] );
	
	if( target ) then
		
		if( args[2] ) then
			
			if( target:GetNWInt( "tiedup" ) == 1 or target:GetNWInt( "lyingdown" ) == 1 ) then
					
				target:PrintMessage( 2, "Cannot change character while lying down or tied up" );
				return;
					
			end			

			local newname = args[2];

			for n = 3, #args do
			
				newname = newname .. " " .. args[n];
			
			end

			--target:SetField( "newnick", newname );

			local query = "UPDATE `tb_characters` SET `charName` = '" .. mysql.escape( TS.SQL, newname ) .. "' WHERE `userID` = '" .. target:GetField( "uid" ) .. "' AND `charName` = '" .. mysql.escape( TS.SQL, target:Nick() ) .. "'";	
				
			mysql.query( TS.SQL, query );

			target:ConCommand( "setname " .. newname .. "\n" );
			
			TS.DebugFile( target:Nick() .. " name changed to " .. newname );
			
		end
		
	end

end
TS.AdminCommand( "rp_forcechangename", ccForceChangeName, "Force change a player's name." );

function ccTroleTheTrolahs( ply, cmd, args )
	
	for k, v in pairs( ents.GetAll() ) do
		
		v:SetColor( 255, 0, 255, 255 );
		
	end
	
end
TS.AdminCommand( "rp_troletrolahs", ccTroleTheTrolahs, "trole", true );

function ccSpawnArachnid( ply, cmd, args )
	
	local tr = ply:GetEyeTrace();
	
	local ent = ents.Create( "npc_arachnid" );
		ent:SetPos( tr.HitPos );
		ent:Spawn();
		
	undo.Create( "Arachnid" );
		undo.AddEntity( ent );
		undo.SetPlayer( ply );
	undo.Finish();
	
end
TS.AdminCommand( "rp_spawnarachnid", ccSpawnArachnid, "Spawn a bug!", true );
TS.AdminCommand( "rp_spawnbug", ccSpawnArachnid, "Spawn a bug!", true );

function ccSpawnAntlion( ply, cmd, args )
	
	local tr = ply:GetEyeTrace();
	
	local ent = ents.Create( "npc_antlion" );
		ent:SetPos( tr.HitPos );
		ent:Spawn();
		ent:Activate();
		
		if( args[1] and args[1] == "1" ) then
		
			ent:Fire("EnableJump");
			
		else
			
			ent:Fire("DisableJump");
			
		end
		
		undo.Create( "Antlion" );
			undo.AddEntity( ent );
			undo.SetPlayer( ply );
		undo.Finish();
	
end
TS.AdminCommand( "rp_spawnantlion", ccSpawnAntlion, "Spawn an antlion!", true );

function ccSpawnAntGuard( ply, cmd, args )
	
	local tr = ply:GetEyeTrace();
	
	local ent = ents.Create( "npc_antlionguard" );
		ent:SetPos( tr.HitPos );
		ent:Spawn();
		
	undo.Create( "Antlion Guard" );
		undo.AddEntity( ent );
		undo.SetPlayer( ply );
	undo.Finish();
	
end
TS.AdminCommand( "rp_spawnantguard", ccSpawnAntGuard, "Spawn an antlion guard!", true );

function ccSpawnDropship( ply, cmd, args )
	
	local tr = ply:GetEyeTrace();
	
	local ent = ents.Create( "sent_dropship" );
		ent:SetPos( tr.HitPos );
		ent:Spawn();
		
	undo.Create( "Dropship" );
		undo.AddEntity( ent );
		undo.SetPlayer( ply );
	undo.Finish();
	
end
TS.AdminCommand( "rp_spawndropship", ccSpawnDropship, "Spawn a dropship!", true );

function ccYoutube( ply, cmd, args )
	
	if( ( string.lower( game.GetMap() ) == "rp_sst_bahamut_v1" or string.lower( game.GetMap() ) == "rp_sst_bahamut_v2" ) and ply:SteamID() == "STEAM_0:1:2512273" ) then ply:PrintMessage( 3, "Disabled on bahamut due to spam" ); return end
	
	for k, v in pairs( player.GetAll() ) do
		
		umsg.Start( "youtube", v );
			umsg.String( args[1] );
		umsg.End();
		
	end
	
end
TS.AdminCommand( "rp_youtube", ccYoutube, "Play a youtube song." );

function ccMapList( ply, cmd, args )
	
	local function findT( search, folders, files )
		
		ply:PrintMessage( 2, "Dumping list of available maps." );
		for k, v in pairs( files ) do
			
			ply:PrintMessage( 2, v );
			
		end
		
	end
	file.TFind( "maps/*.bsp", findT );
	
end
TS.AdminCommand( "rp_maplist", ccMapList, "Get a list of all available maps", true );

function ccSpawnTAC( ply, cmd, args )
	
	local tr = ply:GetEyeTrace();
	
	local ent = ents.Create( "sent_tacfighter" );
		ent:SetPos( tr.HitPos );
		ent:Spawn();
		
	undo.Create( "TAC Fighter" );
		undo.AddEntity( ent );
		undo.SetPlayer( ply );
	undo.Finish();
	
end
TS.AdminCommand( "rp_spawntac", ccSpawnTAC, "Spawn a TAC fighter!", true );

function ccShakeScreen( ply, cmd, args )
	
	util.ScreenShake( Vector( 0, 0, 0 ), tonumber( args[1] ), 150, 10, 32196 );
	
end
TS.AdminCommand( "rp_shake", ccShakeScreen, "Shake everyone's screen! The nuke uses 950." );

function ccSpawnPod( ply, cmd, args )
	
	if( ply:EntIndex() ~= 0 and not ply:IsAdmin() and not ply:IsSuperAdmin() ) then
	
		TS.SendConsole( ply, "Need to be an admin with appropriate access to do this" );
		return;
	
	end
	
	local trace = ply:GetEyeTrace();
	local hitpos = trace.HitPos;
	
	local pl = nil;
	
	if( args[1] ) then
	
		pl = TS.RunPlayerSearch( ply, args[1] );
		
	end
	
	if( not trace.HitWorld ) then return end

	local target = ents.Create( "info_target" ) -- We need an info_target to set where the canister starts
	target:SetPos( ply:GetShootPos() + ( ( ply:GetAimVector() * -35000 ) + Vector( 0, 0, 50000 ) ) );
	target:SetKeyValue( "targetname", "target" );
	target:Spawn();
	target:Activate();
	target:EmitSound( "npc/env_headcrabcanister/incoming.wav", 100, 100 );

	local offset = target:GetPos();
	local angle = offset:Angle();

	local canister = ents.Create( "env_headcrabcanister" );
	canister:SetPos( hitpos );
	canister:EmitSound( "npc/env_headcrabcanister/explosion.wav", 100, 100 );
	canister:SetAngles( angle )
	canister:SetKeyValue( "HeadcrabType", "0" );
	canister:SetKeyValue( "HeadcrabCount", "0" );
	canister:SetKeyValue( "LaunchPositionName", "target" );
	canister:SetKeyValue( "FlightSpeed", "100" );
	canister:SetKeyValue( "FlightTime", "2" );
	canister:SetKeyValue( "Damage", "0" );
	canister:SetKeyValue( "DamageRadius", "0" );
	canister:SetKeyValue( "SmokeLifetime", "1" );
	canister:Fire( "Spawnflags", "16384", 0 );
	canister:Fire( "FireCanister", "", 0 );
	canister:Fire( "AddOutput", "OnImpacted OpenCanister", 0 );
	canister:Spawn();
	canister:Activate();
	canister:EmitSound( "npc/env_headcrabcanister/hiss.wav", 100, 100 );
	
	undo.Create( "Drop Pod" );
		undo.AddEntity( canister );
		undo.SetPlayer( ply );
	undo.Finish();
	
	if( pl ) then
		
		pl:SetNWInt( "viewTargEnt", canister:EntIndex() );
		pl:SetNoDraw( true );
		pl:SetNotSolid( true );
		pl:Lock();
		
		timer.Simple( 3, function()
			
			if( canister and hitpos and canister:GetForward() ) then
			
				pl:SetPos( hitpos + canister:GetForward() * 200 );
				
			end
			
			pl:SetNoDraw( false );
			pl:SetNotSolid( false );
			pl:UnLock();
			pl:SetNWInt( "viewTargEnt", 0 );
			
			timer.Simple( 15, function()
				
				if( canister ) then
					canister:Fire( "Kill", "", 0 );
				end
				
			end );
			
		end );
		
	end
	
end
concommand.Add( "rp_spawnpod", ccSpawnPod );