function ccMakeRation( ply, cmd, arg )

	if( !ply:IsCombine() ) then return end
	
	local trace = { }
	trace.start = ply:EyePos()
	trace.endpos = trace.start + ply:GetAimVector() * 55
	trace.filter = ply
			
	local tr = util.TraceLine( trace )
	
	TS.CreateItemProp( "ration", tr.HitPos );
	
end
concommand.Add( "rp_makeration", ccMakeRation )	
	
function ccToggleThirdPerson( ply, cmd, args )

	ply:SetNWInt( "inversethirdperson", 0 );

	if( ply:GetNWInt( "thirdperson" ) == 1 ) then
	
		ply:SetViewEntity( ply );
		ply:SetNWInt( "thirdperson", 0 );
	
	else
		
		TS.ThirdPersonCam[ply:EntIndex()]:SetPos( ply:GetPos() );
		timer.Simple( .1, ply.SetViewEntity, ply, TS.ThirdPersonCam[ply:EntIndex()] );
		ply:SetNWInt( "thirdperson", 1 );
	
	end

end
concommand.Add( "rp_thirdperson", ccToggleThirdPerson );
function ccTryDoorRam( ply, cmd, arg )

	ply:TryDoorRam()
	
end
concommand.Add( "rp_ramdoor", ccTryDoorRam )	

function ccLookAtMe( ply, cmd, args )

	ccToggleThirdPerson( ply, cmd, args );

	ply:SetNWInt( "inversethirdperson", ply:GetNWInt( "thirdperson" ) );

end
concommand.Add( "rp_lookatme", ccLookAtMe );

function ccChangeName( ply, cmd, arg )

	ply:SetNWString( "RPName", arg[1] )
	
	ply:SaveData( "RPName", arg[1] )
	
end
concommand.Add( "rp_changename", ccChangeName )		


function ccWhatModelIsThis( ply, cmd, arg )

	local ent = ply:GetEyeTrace().Entity;
	
	Msg( ent:GetModel() .. "\n" );

end
concommand.Add( "whatmodelisthis", ccWhatModelIsThis );

function ccPrintUserList( ply, cmd, arg )

	for n = 1, MaxPlayers() do
	
		if( player.GetByID( n ):IsValid() ) then
		
			Console( ply, n .. " - " .. player.GetByID( n ):GetRPName() .. " (SF: " .. player.GetByID( n ):Nick() .. ") - " .. player.GetByID( n ):SteamID() );
		
		end
	
	end

end
concommand.Add( "rp_printuserlist", ccPrintUserList );
concommand.Add( "rp_userlist", ccPrintUserList );

function ccBuildList( ply, cmd, arg )

	Console( ply, "Name | STEAMID | Tool Trust" );

	for k, v in pairs( player.GetAll() ) do
	
		local tt = "No TT";
		
		if( v:HasTT() ) then
			tt = "Has TT";
		end
		
	
		Console( v, v:GetRPName() .. " | " .. v:SteamID() .. " | " .. tt );
	
	end

end
concommand.Add( "rp_buildlist", ccBuildList );

function ccSelectWeapon( ply, cmd, arg )

	if( not arg[1] ) then
		return;
	end
	
	if( ply:IsTied() ) then return; end 
	
	if( ply:HasWeapon( arg[1] ) ) then
		ply:SelectWeapon( arg[1] );
	end

end
concommand.Add( "rp_selectweapon", ccSelectWeapon );

function ccICSit( ply, cmd, arg )
	
	if( CurTime() - ply:GetTable().LastStanceAction < 2 ) then
		return;
	end

	ply:GetTable().LastStanceAction = CurTime();
	
	if( not ply:GetTable().InStanceAction ) then

		if( ply:Crouching() ) then return; end

		local trace = { }
		trace.start = ( ply:EyePos() - Vector( 0, 0, 30 ) );
		trace.endpos = trace.start - ply:GetAngles():Forward() * 22;
		trace.filter = ply;
		
		local tr = util.TraceLine( trace );
	
		if( not tr.Hit ) then
		
			local trace = { }
			trace.start = ( ply:EyePos() - Vector( 0, 0, 25 ) ) - ply:GetAngles():Forward() * 22;
			trace.endpos = trace.start - Vector( 0, 0, 25 );
			trace.filter = ply;
			
			local tr = util.TraceLine( trace );

			if( tr.Hit ) then
			
				local anim = 376;
				
				ply:GetTable().StanceSnapToPlayerPos = ply:GetPos();
				
				if( tonumber( arg[1] ) == 2 ) then
				
					anim = "d1_t02_Plaza_Sit02";
					ply:SetPos( ply:GetPos() + ply:GetAngles():Forward() * -24 );
				
				elseif( tonumber( arg[1] ) == 3 ) then
					
					anim = "silo_sit";
					ply:SetPos( ply:GetPos() + ply:GetAngles():Forward() * -24 );
				
				elseif( tonumber( arg[1] ) == 4 ) then
					
					anim = "sitccouchtv1";
					ply:SetPos( ply:GetPos() + ply:GetAngles():Forward() * -3 );
				
				else
				
					ply:SetPos( ply:GetPos() + ply:GetAngles():Forward() * -10 );
				
				end
				
				ply:SetPlayerFreezeHead( true );
				ply:GetTable().ForcedAnimationMode = true;
				ply:GetTable().ForcedAnimation = anim;
				ply:GetTable().InStanceAction = true;
				ply:GetTable().StanceSit = true;
				ply:GetTable().StanceSitPlayerPos = ply:GetPos();
				ply:GetTable().StanceSitEntPos = tr.Entity:GetPos();
				ply:GetTable().StanceSitEnt = tr.Entity;
				--ply:Freeze( true );
				ply:PrintMessage( 3, "Sitting down" );
			else
				ply:PrintMessage( 3, "Can't sit here" );
			end
			
		else
			ply:PrintMessage( 3, "Can't sit here" );
		end
	
	elseif( ply:GetTable().StanceSit ) then
		
		if( ply:GetTable().StanceSnapToPlayerPos ) then
			
			ply:SetPos( ply:GetTable().StanceSnapToPlayerPos );
		
		end
		
		ply:SnapOutOfStance();
		
	end

end
concommand.Add( "rp_ic_sit", ccICSit );

function ccAgainstTheWall( ply, cmd, arg )
	
	if( CurTime() - ply:GetTable().LastStanceAction < 2 ) then
		return;
	end

	ply:GetTable().LastStanceAction = CurTime();
	
	if( not ply:GetTable().InStanceAction ) then

		if( ply:Crouching() ) then return; end

		local trace = { }
		trace.start = ( ply:EyePos() );
		trace.endpos = trace.start + ply:GetAngles():Forward() * 18;
		trace.filter = ply;
		
		local tr = util.TraceLine( trace );
		
		if( tr.Hit and not tr.Entity:IsNPC() and not tr.Entity:IsPlayer() ) then
			
			local anim = "apcarrestidle";
			
			ply:GetTable().StanceSnapToPlayerPos = ply:GetPos();

			if( math.random( 1, 2 ) == 1 ) then
			
				anim = "spreadwallidle";
				ply:SetPos( ply:GetPos() + ply:GetAngles():Forward() * 12 );
	
			else
			
				ply:SetPos( ply:GetPos() + ply:GetAngles():Forward() * -24 );
			
			end
		
			ply:SetPlayerFreezeHead( true );
			ply:GetTable().ForcedAnimationMode = true;
			ply:GetTable().ForcedAnimation = anim;
			ply:GetTable().InStanceAction = true;
			ply:GetTable().StanceATW = true;
			ply:GetTable().StanceATWPlayerPos = ply:GetPos();
			ply:GetTable().StanceATWEntPos = tr.Entity:GetPos();
			ply:GetTable().StanceATWEnt = tr.Entity;
			ply:SetEyeAngles( tr.HitNormal );
			--ply:Freeze( true );
			ply:PrintMessage( 3, "Going against the wall" );
			
		else
			ply:PrintMessage( 3, "Can't do that here" );
		end
	
	elseif( ply:GetTable().StanceATW ) then
		
		if( ply:GetTable().StanceSnapToPlayerPos ) then
			
			ply:SetPos( ply:GetTable().StanceSnapToPlayerPos );
		
		end
		
		ply:SnapOutOfStance();
		
	end

end
concommand.Add( "rp_ic_atw", ccAgainstTheWall );
concommand.Add( "rp_ic_againstthewall", ccAgainstTheWall );

function ccICSitGround( ply, cmd, arg )
	
	if( CurTime() - ply:GetTable().LastStanceAction < 2 ) then
		return;
	end

	ply:GetTable().LastStanceAction = CurTime();

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

		local anim = 373;
		
		if( tonumber( arg[1] ) == 2 ) then
		
			anim = "sitcouchknees1";

		end

		ply:SetPlayerFreezeHead( true );
		ply:GetTable().ForcedAnimationMode = true;
		ply:GetTable().ForcedAnimation = anim;
		ply:GetTable().InStanceAction = true;
		ply:GetTable().StanceGroundSit = true;
		ply:GetTable().StanceGroundSitPos = ply:GetPos();
		--ply:Freeze( true );
		ply:PrintMessage( 3, "Sitting down" );
		ply:ConCommand( "+duck" );
	
	elseif( ply:GetTable().StanceGroundSit ) then
	
		ply:SnapOutOfStance();
		ply:ConCommand( "-duck" );
		
	end

end
concommand.Add( "rp_ic_sitground", ccICSitGround );

function ccICLean( ply, cmd, arg )
	
	if( CurTime() - ply:GetTable().LastStanceAction < 2 ) then
		return;
	end

	ply:GetTable().LastStanceAction = CurTime();
	
	local TurnOffLean = function()
	
		ply:SnapOutOfStance();
	
	end
	
	if( not ply:GetTable().InStanceAction ) then

		local trace = { }
		trace.start = ply:EyePos();
		trace.endpos = ( trace.start - Vector( 0, 0, 25 ) ) - ply:GetAngles():Forward() * 20;
		trace.filter = ply;
		
		local tr = util.TraceLine( trace );
		
		if( tr.Hit ) then
	
			ply:SetPlayerFreezeHead( true );
			ply:GetTable().ForcedAnimationMode = true;
			ply:GetTable().ForcedAnimation = 370;
			ply:GetTable().InStanceAction = true;
			ply:GetTable().StanceLean = true;
			ply:GetTable().StanceLeanPos = ply:GetPos();
			--ply:Freeze( true );
			ply:PrintMessage( 3, "Leaning" );
			
		end
		
		local function leanthink()
		
			if( ply:GetTable().StanceLean ) then
			
				local trace = { }
				trace.start = ply:EyePos();
				trace.endpos = ( trace.start - Vector( 0, 0, 25 ) ) - ply:GetAngles():Forward() * 20;
				trace.filter = ply;
				
				local tr = util.TraceLine( trace );
				
				if( not tr.Hit ) then
			
					TurnOffLean();
					
				else
				
					timer.Simple( 1, leanthink );
				
				end
			
			end
		
		end
		
		timer.Simple( 1, leanthink );
		
	elseif( ply:GetTable().StanceLean ) then
	
		TurnOffLean();
		
	end

end
concommand.Add( "rp_ic_lean", ccICLean );

function ccMOTD( ply )
	
	if( CurTime() - ply:GetTable().LastMOTDPrompt < 2 ) then
		return;
	end
	
	if( not ply:GetTable().CanInitialize ) then
		return;
	end

	ply:GetTable().LastMOTDPrompt = CurTime();

	ply:PromptMOTD();	

end
concommand.Add( "rp_motd", ccMOTD );

function CCSpawnSWEP( player, command, arguments ) 

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

function ccSetPlayerClassMark( ply, cmd, arg )

	if( !ply:IsCombineDefense() ) then
		Console( ply, "Need to be combine" )
		return
	end
	
	if( not arg[1] ) then 
		Console( ply, "rp_setclassmark <Mark> - Set a players Mark(A-F)" );
		return;
	end

	local trace = { }
	trace.start = ply:EyePos();
	trace.endpos = trace.start + ply:GetAimVector() * 90;
	trace.filter = ply;
	
	local tr = util.TraceLine( trace );

	if( tr.Entity and tr.Entity:IsValid() and tr.Entity:IsPlayer() ) then
			
		--tr.Entity:SetField( "ClassMark", arg[1] )
		tr.Entity:SetClassMark( arg[1] )
		
		umsg.Start( "ICAction", tr.Entity );
			umsg.String( ply:GetRPName() );
			umsg.String( " set your class mark to " .. arg[1] );
		umsg.End();	

		umsg.Start( "ICAction", ply );
			umsg.String( "You" );
			umsg.String( " set " .. tr.Entity:GetRPName() .. "'s classmark to " .. arg[1] )
		umsg.End();	
		
		tr.Entity:SaveData( "ClassMark", arg[1] )
		
	end

end	
concommand.Add( "rp_setclassmark", ccSetPlayerClassMark )

function ccCPPush( ply, cmd, args )

	local function MetroPlayerPush( ply )

		local trace = { }
		trace.start = ply:EyePos();
		trace.endpos = trace.start + ply:GetAimVector() * 35;
		trace.filter = ply;
	
		local tr = util.TraceLine( trace );
	
		if( ValidEntity( tr.Entity ) and tr.Entity:IsPlayer() ) then
		
			local norm = ( tr.Entity:GetPos() - ply:GetPos() ):Normalize();
			local push = 100 * norm;
					
			tr.Entity:SetVelocity( push );
		
			tr.Entity:EmitSound( Sound( "weapons/crossbow/hitbod1.wav" ) );
	
		end

	end
	
	if( CurTime() - ply:GetTable().LastStanceAction < 2 ) then
		return;
	end

	ply:GetTable().LastStanceAction = CurTime();
	
	if( not ply:GetTable().InStanceAction ) then
	
		anim = "pushplayer";
		
		MetroPlayerPush( ply )

		ply:GetTable().ForcedAnimationMode = true;
		ply:GetTable().ForcedAnimation = anim;
		ply:GetTable().InStanceAction = true;
		
	end

	local function Stop()
	
		ply:SnapOutOfStance();
		
	end

	timer.Simple( .5, function() Stop() end )	
	
	
end	
concommand.Add( "rp_ic_cppush", ccCPPush );

function ccCPKickDoor( ply, cmd, arg )

	local trace = { }
	trace.start = ply:EyePos();
	trace.endpos = trace.start + ply:GetAimVector() * 140;
	trace.filter = ply
		
	local tr = util.TraceLine( trace );

	if( CurTime() - ply:GetTable().LastStanceAction < 2 ) then
			return;
		end

	ply:GetTable().LastStanceAction = CurTime();	
	
	if( ply:HasCPModel() ) then
		
		if( not ply:GetTable().InStanceAction ) then
		
		anim = "adoorkick";

		ply:GetTable().ForcedAnimationMode = true;
		ply:GetTable().ForcedAnimation = anim;
		ply:GetTable().InStanceAction = true;
		
		if( tr.Entity:IsValid() and tr.Entity:GetClass() == "prop_door_rotating" ) then
		
			local pos = tr.Entity:GetPos();
			local ang = tr.Entity:GetAngles();
			local model = tr.Entity:GetModel();
			local skin = tr.Entity:GetSkin();
					
			tr.Entity:SetNotSolid( true );
			tr.Entity:SetNoDraw( true );
					
			local function ResetDoor( door, fakedoor )
				door:SetNotSolid( false );
				door:SetNoDraw( false );
				fakedoor:Remove();
			end
					
			local norm = ( pos - ply:GetPos() ):Normalize();
			local push = 10000 * norm;

			local ent = ents.Create( "prop_physics" );
			ent:SetPos( pos );
			ent:SetAngles( ang );
			ent:SetModel( model );
			if( skin ) then
				ent:SetSkin( skin );
			end
			ent:Spawn();
					
			timer.Simple( .5, ent.SetVelocity, ent, push );					
			timer.Simple( .5, ent:GetPhysicsObject().ApplyForceCenter, ent:GetPhysicsObject(), push );
																
			timer.Simple( 300, ResetDoor, tr.Entity, ent );
		end
		
		end	
	
	end
		
	local function Stop()
	
		ply:SnapOutOfStance();
		
	end

	timer.Simple( 1.7, function() Stop() end )	
	
end
concommand.Add( "rp_ic_kick", ccCPKickDoor );	

function ccSetCPModel( ply, cmd, arg )
	
	if( !arg[1] ) then
	Console( ply, "rp_setcpmodel <model> - Set your model, abuse will get you removed", true ) 
		return;
	end
	
	ply:SetModel( args[1] );
	ply:PrintMessage( 3, "Model changed to: " .. args[1] );
	
	local model = string.lower( ply:GetModel() );


end
concommand.Add( "rp_setcpmodel", ccSetCPModel );

	
		