--flags for reference
--A - Basic Admin 
-- B :Super Admin
-- C: Super-Super admin lol


function ccDay( ply, cmd, arg )

	if( !storm_active ) then
		SetGlobalString("weather","sunny")
	end
end
TS.AdminCommand( "rpa_day", ccDay )

function ccNight( ply, cmd, arg )

	if( not ply:CanUseCommand() ) then return; end
	if not storm_active then
		SetGlobalString("weather","dark")
	end
end
TS.AdminCommand( "rpa_nite", ccNight );
TS.AdminCommand( "rpa_night", ccNight );

function ccSlay( ply, cmd, arg )

	local name = arg[1];
	local succ, result = TS.FindPlayerByName( name );
	TS.ErrorMessage( ply, false, succ, result );
	
	if( succ ) then
	
		TS.PrintMessageAll( 3, ply:GetRPName() .. " slayed " .. result:GetRPName() );
	
		result:Slay();
	
	end

end
TS.AdminCommand( "rpa_slay", ccSlay );

function ccIgnite( ply, cmd, arg )

	if( not arg[2] ) then
	ply:PrintMessage( 2, "rpa_ignite <Name> <Time(secs)>" );
	end
	
	local name = arg[1];
	local burntime = tonumber( arg[2] );
	local succ, result = TS.FindPlayerByName( name );
	TS.ErrorMessage( ply, false, succ, result );
	
	if( succ ) then
	
		TS.PrintMessageAll( 3, ply:GetRPName() .. " ignited " .. result:GetRPName() .. " for " .. burntime .. " seconds." );
	
		result:Ignite(burntime,0);
	
	end

end
TS.AdminCommand( "rpa_ignite", ccIgnite );

function ccFaggot( ply, cmd, arg )

	local name = arg[1]
	
	if( not arg[1] ) then
		Console( ply, "rpa_faggot <name> - deem someone a faggot" )
		return
	end	

	
	
	local succ, result = TS.FindPlayerByName( name );
	TS.ErrorMessage( ply, false, succ, result );
	
	if( succ ) then
	
		if( result:GetNWBool( "Faggot" ) == false ) then
		
			result:SetNWBool( "Faggot", true )
			
			for k, v in pairs( player.GetAll() ) do
	
				if( v:IsPlayer() ) then
	
					Console( v, "Attention everyone! " .. result:GetRPName() .. "( " .. result:Nick() .. ") is a faggot!", true )
					v:EmitSound( "vo/heavy_singing01.wav" )
			
				end	
				
			end	
			
		elseif( result:GetNWBool( "Faggot" ) == true ) then
		
			result:SetNWBool( "Faggot", false )			
			
			for k, v in pairs( player.GetAll() ) do
	
				if( v:IsPlayer() ) then
	
					Console( v, "Attention everyone! " .. result:GetRPName() .. "( " .. result:Nick() .. ") is a not a faggot anymore.", true )
					v:EmitSound( "vo/heavy_jeers05.wav" )
			
				end	
				
			end	
			
		end		

	end	
		
end
TS.AdminCommand( "rpa_faggot", ccFaggot ) 

function ccExtinguish( ply, cmd, arg )

	
	local name = arg[1];
	local succ, result = TS.FindPlayerByName( name );
	TS.ErrorMessage( ply, false, succ, result );
	
	if( succ ) then
	
		TS.PrintMessageAll( 3, ply:GetRPName() .. " extinguished " .. result:GetRPName() );
	
		if ( result:IsOnFire() ) then
		   result:Extinguish()
		end
	
	end

end
TS.AdminCommand( "rpa_ext", ccExtinguish );

function ccSlap( ply, cmd, arg )

	local name = arg[1];
	local succ, result = TS.FindPlayerByName( name );
	TS.ErrorMessage( ply, false, succ, result );
	
	if( succ ) then
	
		TS.PrintMessageAll( 3, ply:GetRPName() .. " slapped " .. result:GetRPName() );
	
		local norm = result:GetAngles():Up();
		
		result:SetVelocity( norm * 500 + result:GetAngles():Forward() * math.random( -1000, 1000 ) );
		result:SetHealth( math.Clamp( result:Health() - 5, 1, 1000 ) );
	
	end

end
TS.AdminCommand( "rpa_slap", ccSlap );

function ccExplode( ply, cmd, arg )

	local name = arg[1];
	local succ, result = TS.FindPlayerByName( name );
	TS.ErrorMessage( ply, false, succ, result );
	
	if( succ ) then
	
		TS.PrintMessageAll( 3, ply:GetRPName() .. " exploded " .. result:GetRPName() );
	
		local exp = ents.Create( "env_explosion" );
			exp:SetKeyValue( "spawnflags", 128 );
			exp:SetPos( result:EyePos() );
		exp:Spawn();
		
		exp:Fire( "explode", "", 0 );
		
		timer.Simple( .2, result.SlaySilent, result );
		
	end

end
TS.AdminCommand( "rpa_explode", ccExplode );

function ccResetMap( ply, cmd, args )
	
	umsg.Start( "ConsoleChat" );
		umsg.String( "Admin " .. ply:GetRPName() .. " (" .. ply:Nick() .. ") is restarting the map"  );
	umsg.End();
	
	timer.Simple( 5, game.ConsoleCommand, "changelevel " .. game.GetMap() .. "\n" );

end
TS.AdminCommand( "rpa_restartmap", ccResetMap );

function ccBoobyTrap( 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().BoobyTrapped = true;
			ply:PrintMessage( 3, "Door has been boobytrapped" );
		
		end
	
	end


end
TS.AdminCommand( "rpa_boobytrapdoor", ccBoobyTrap );

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:GetRPName() .. " (" .. tr.Entity:GetTable().MainOwner:Nick() .. ") " .. "owns this door." );
	
		
		else
		
			ply:PrintMessage( 2, "This isn't a door." );
		
		end
	
	end


end
TS.AdminCommand( "rpa_findowner", ccAdminFindDoorOwner );

function ccPromptStorm( ply, cmd, arg )

	if not storm_active then
		Console( ply, "Promoted a storm.", true );
		BeginStorm();
	else 
		Console( ply, "A Storm is already in progress!", true );
	end
	
end
TS.AdminCommand( "rpa_storm", ccPromptStorm );
TS.AdminCommand( "rpa_promptstorm", ccPromptStorm );

function ccForceStopStorm( ply, cmd, arg )

	
	if( not storm_active ) then
		Console( ply, "There isn't a storm in progress.", true );
	else 
		storm_active = false
		SetGlobalString("weather","sunny")
		Console( ply, "Force stopped storm.", true );
	end
	
end
TS.AdminCommand( "rpa_endstorm", ccForceStopStorm );
TS.AdminCommand( "rpa_stopstorm", ccForceStopStorm );

function ccDeFlagPlayer( ply, cmd, arg )

	if( not arg[1] ) then 
		Console( ply, "rpa_deflag <Name> - Remove a players Combine Flags" );
		return;
	end

	
	local name = arg[1];
	
	local succ, result = TS.FindPlayerByName( name );
	TS.ErrorMessage( ply, false, succ, result );
	
	if( succ ) then
	
	if( result:NotFlagged() ) then
	
	Console( ply, result:GetRPName() .. " is not flagged.", true );
	
	else
		
		result:SetField( "combineflags", "" );

		Console( result, ply:GetRPName() .. "(" .. ply:SteamID() .. ") has removed your Combine flags.", true );
		Console( ply, "Removed " .. result:GetRPName() .. "'s flags.", true );
		
			
		result:RefreshShit();
		result:KillSilent();
		result:Spawn();
		result:SaveData( "combineflags", result:GetField( "combineflags" ) );
		result:SetField( "radiofreq", 0 )
		
		local query = "UPDATE `STALKERChars` SET `CombineFlags` = '" .. " " .. "' WHERE `id` = '" .. result:GetField( "charid" ) .. "' AND `RPName` = '" .. result:GetRPName()  .. "'";	
		
		sql.Query( query )

	end
	
	end
	
end
TS.AdminCommand( "rpa_combinedeflag", ccDeFlagPlayer );

function ccPlayerFlagPlayer( ply, cmd, arg )

	if( not arg[1] or not arg[2] ) then 
		Console( ply, "rpa_flag <Name> <Flag> - Set someones player flags" );
		Console( ply, "Flags:" );
		Console( ply, "T - Trader Menu" );		
		Console( ply, "C - Map Editor" );
		return;
	end
	
	local name = arg[1];
	
	local succ, result = TS.FindPlayerByName( name );
	TS.ErrorMessage( ply, false, succ, result );
	
	if( succ ) then
	
		result:SetPlayerFlags( arg[2] )

		Console( result, ply:GetRPName() .. "(" .. ply:SteamID() .. ") has set your playerflags to " .. arg[2] .. ".", true );
		Console( ply, "Set " .. result:GetRPName() .. "'s playerflags to " .. arg[2] .. ".", true );
		
		local query = "UPDATE `STALKERChars` SET `PlayerFlags` = '" .. arg[2] .. "' WHERE `id` = '" .. result:GetField( "charid" ) .. "' AND `RPName` = '" .. result:GetRPName()  .. "'";	
		
		sql.Query( query )
		
		
	end
	
end
TS.AdminCommand( "rpa_playerflag", ccPlayerFlagPlayer );

function ccFactionFlag( ply, cmd, arg )

	if( not arg[1] or not arg[2] ) then 
		Console( ply, "rpa_flag <Name> <Flag> - Set someones player flags" );
		Console( ply, "Flags:" );
		Console( ply, "A - Freedom" );		
		Console( ply, "B - Duty" );
		Console( ply, "Ba - Duty Exo" );
		Console( ply, "C - Vet Bandit" );
		Console( ply, "D - Vet Loner" );
		Console( ply, "E - Ecologist" );
		Console( ply, "F - Merc" );
		Console( ply, "H - Military" );
		Console( ply, "Ha - Military Merc" );
		Console( ply, "Hb - Experienced Merc" );
		return;
	end
	
	local name = arg[1];
	
	local succ, result = TS.FindPlayerByName( name );
	TS.ErrorMessage( ply, false, succ, result );
	
	if( succ ) then
	
		result:SetPlayerFlags( arg[2] )

		Console( result, ply:GetRPName() .. "(" .. ply:SteamID() .. ") has set your faction flag to " .. arg[2] .. ".", true );
		Console( ply, "Set " .. result:GetRPName() .. "'s faction flag to " .. arg[2] .. ".", true );
		
		local query = "UPDATE `STALKERUsers` SET `FactionFlags` = '" .. arg[2] .. "' WHERE `SteamID` = '" .. result:SteamID() .. "'";	
		
		sql.Query( query )
		
		
	end
	
end
TS.AdminCommand( "rpa_factionflag", ccFactionFlag )	

function ccSendPopUp( ply, cmd, arg )

	if( not arg[1] ) then 
		Console( ply, "rpa_sendpopup <Name> <Message Title> <Message> - Send a Pop-up message to a player" );
		return;
	end
	
	local name = arg[1];
	
	local succ, result = TS.FindPlayerByName( name );
	TS.ErrorMessage( ply, false, succ, result );
	
	if( succ ) then
		
		Console( ply, "Sent pop-up message to " .. result:GetRPName(), true );
		Console( ply, "Title: " .. arg[2], true );
		Console( ply, "Message: " .. arg[3], true );
		
		umsg.Start( "PPM", result );
			umsg.String( arg[2] );
			umsg.String( arg[3] );
		umsg.End();
		
		
	end

end
TS.AdminCommand( "rpa_sendpopup", ccSendPopUp );

function ccWarnPlayer( ply, cmd, arg )

	if( not arg[1] ) then 
		Console( ply, "rpa_warn <Name> <Message> - Send a warning message to player." );
		return;
	end
	
	local name = arg[1];
	
	local succ, result = TS.FindPlayerByName( name );
	TS.ErrorMessage( ply, false, succ, result );
	
	if( succ ) then
		
		Console( ply, "Sent warning message to " .. result:GetRPName(), true );
		Console( ply, "Message: " .. arg[2], true );
		
		umsg.Start( "PPM", result );
			umsg.String( "Warning from admin " .. ply:Nick() .. " (" .. ply:GetRPName() .. ")" );
			umsg.String( arg[2] );
		umsg.End();
		
		
	end

end
TS.AdminCommand( "rpa_warn", ccWarnPlayer );
	
function ccCreateItem( ply, cmd, arg )

	if( not arg[1] ) then return; end
	
	if( arg[1] == "ts2_kanyewest" and not ply:IsAwesome() ) then
		ply:PrintMessage( 3, "How about NO" );
	end
	
	if( not TS.ItemsData[arg[1]] ) then return; end
	
	local trace = { }
	trace.start = ply:EyePos();
	trace.endpos = trace.start + ply:GetAimVector() * 150;
	trace.filter = ply;
	
	local tr = util.TraceLine( trace );
	
	TS.CreateItemProp( arg[1], tr.HitPos );

end
TS.AdminCommand( "rpa_createitem", ccCreateItem );

function ccSetPlayerMoney( ply, cmd, arg )

	if( not arg[1] ) then 
		Console( ply, "rpa_setmoney <Name> <Value> - Set a players money" );
		return;
	end
	
	
	local name = arg[1];
	
	local succ, result = TS.FindPlayerByName( name );
	TS.ErrorMessage( ply, false, succ, result );
	
	if( succ ) then
		
		result:SetPlayerRubles( arg[2] );
		
		Console( result, "Admin " .. ply:GetRPName() .. "(" .. ply:SteamID() .. ") has set your money to " .. arg[2], true );
		Console( ply, "Set " .. result:GetRPName() .. "'s money to " .. arg[2], true );
		
		local query = "UPDATE `STALKERChars` SET `Tokens` = '" .. arg[2] .. "' WHERE `id` = '" .. result:GetField( "charid" ) .. "' AND `RPName` = '" .. result:GetRPName()  .. "'";	
		
		sql.Query( query )
		
		
	end

end
TS.AdminCommand( "rpa_setmoney", ccSetPlayerMoney );

function ccConsoleChat( ply, cmd, arg )

	if( not arg[1] ) then return; end

	local chat = "";
	
	for n = 1, #arg do
		chat = chat .. arg[n] .. " ";
	end

	umsg.Start( "ConsoleChat" );
		umsg.String( chat );
	umsg.End();
	
	TS.PrintMessageAll( 2, "Console: " .. chat );

end
TS.AdminCommand( "csay", ccConsoleChat );

function ccCanDuplicate( ply, cmd, arg )

	if( not arg[1] or not tonumber( arg[2] ) ) then 
		Console( ply, "rpa_candupe <Name> <1 or 0> - Sets if a player can use the duplicator tool" );
		return;
	end
	
	local name = arg[1];
	local val = tonumber( arg[2] );
	
	local succ, result = TS.FindPlayerByName( name );
	TS.ErrorMessage( ply, false, succ, result );
	
	if( succ ) then
	
		local bool = true;
		
		if( val == 0 ) then

			bool = false;

			Console( result, "Admin " .. ply:GetRPName() .. "(" .. ply:SteamID() .. ") took away your duplicator access", true );
			Console( ply, "Took away duplicator access from " .. result:GetRPName(), true );	
			
			local query = "UPDATE `STALKERUsers` SET `CanDupe` = '" .. "no" .. "' WHERE `id` = '" .. result:GetField( "charid" ) .. "' AND `RPName` = '" .. result:GetRPName()  .. "'";		
			sql.Query( query )

		else
		
			Console( result, "Admin " .. ply:GetRPName() .. "(" .. ply:SteamID() .. ") gave you duplicator access", true );
			Console( ply, "Gave duplicator access to " .. result:GetRPName(), true );
			
			local query = "UPDATE `STALKERUsers` SET `CanDupe` = '" .. "yes" .. "' WHERE `id` = '" .. result:GetField( "charid" ) .. "' AND `RPName` = '" .. result:GetRPName()  .. "'";		
			sql.Query( query )

			
		end
	
		result:GetTable().CanUseDuplicator = bool;
		
	end


end
TS.AdminCommand( "rpa_candupe", ccCanDuplicate );

function ccBring( ply, cmd, arg )

	if( not arg[1] ) then 
		Console( ply, "rpa_bring <Name> - Bring a player" );
		return;
	end
	
	
	local name = arg[1];
	
	local succ, result = TS.FindPlayerByName( name );
	TS.ErrorMessage( ply, false, succ, result );
	
	if( succ ) then
			
		trace = { }
		trace.start = ply:EyePos();
		trace.endpos = trace.start + ply:GetAngles():Forward() * 50;
		trace.filter = ply;
		
		tr = util.TraceLine( trace );

	
		if( tr.Hit ) then

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

end
TS.AdminCommand( "rpa_bring", ccBring );

function ccGoTo( ply, cmd, arg )

	if( not arg[1] ) then 
		Console( ply, "rpa_goto <Name> - Go to a player" );
		return;
	end
	
	local name = arg[1];
		
	local succ, result = TS.FindPlayerByName( name );
	TS.ErrorMessage( ply, false, succ, result );
	
	if( succ ) then
			
		local trace = { }
		trace.start = result:EyePos();
		trace.endpos = trace.start + result:GetAngles():Up() * 90;
		trace.filter = result;
		
		local tr = util.TraceLine( trace );
	
		if( tr.Hit ) then

			trace = { }
			trace.start = result:EyePos();
			trace.endpos = trace.start + result:GetAngles():Forward() * 50;
			trace.filter = result;
			
			tr = util.TraceLine( trace );
			
		end
		
		if( tr.Hit ) then

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

end
TS.AdminCommand( "rpa_goto", ccGoTo );

function ccShowMOTD( ply, cmd, arg )

	if( not arg[1] ) then 
		Console( ply, "rpa_showmotd <Name> - Show MOTD to a player" );
		return;
	end
	
	
	
	local name = arg[1];
	
	local succ, result = TS.FindPlayerByName( name );
	TS.ErrorMessage( ply, false, succ, result );
	
	if( succ ) then
		
		Console( result, "Admin " .. ply:GetRPName() .. "(" .. ply:SteamID() .. ") prompted the MOTD on you", true );
		Console( ply, "Prompted the MOTD on " .. result:GetRPName(), true );
		
		result:PromptMOTD();
	
	end

end
TS.AdminCommand( "rpa_showmotd", ccShowMOTD );

function ccAdminYell( ply, cmd, arg )

	if( not arg[1] ) then 
		Console( ply, "rpa_yell <Text> - Yell at the server angrily" );
		return;
	end
	
	
	
	local msg = "";
	
	for n = 1, #arg do
	
		if( msg ~= "" ) then
			msg = msg .. " ";
		end
	
		msg = msg .. arg[n];
	
	end
	
	
	local name;
	
	if( ply:EntIndex() == 0 ) then
		name = "Console";
	else
		name = ply:GetRPName();
	end
	umsg.Start( "Ayell" );
		umsg.String( name );
		umsg.String( msg );
	umsg.End();

end
TS.AdminCommand( "rpa_yell", ccAdminYell );

function ccPermaBan( ply, cmd, arg )

	if( not arg[1] ) then 
		Console( ply, "rpa_pban <Name> <Reason> - Permaban name with reason" );
		return;
	end
	
	
	
	local msg = "";
	
	if( arg[2] ) then
	
		for n = 2, #arg do
		
			if( msg ~= "" ) then
				msg = msg .. " ";
			end
		
			msg = msg .. arg[n];
		
		end
		
	end

	local name = arg[1];
	
	local succ, result = TS.FindPlayerByName( name );
	TS.ErrorMessage( ply, true, succ, result );
	
	if( succ ) then
		
		result:PermaBan( msg, ply:GetRPName() );
	
	end

end
TS.AdminCommand( "rpa_pban", ccPermaBan );

function ccBan( ply, cmd, arg )

	if( not arg[1] or not tonumber( arg[2] ) ) then 
		Console( ply, "rpa_ban <Name> <Time> <Reason> - Ban name for time minutes with reason." );
		return;
	end
	
	
	
	local msg = "";
	
	if( arg[3] ) then
	
		for n = 3, #arg do
		
			if( msg ~= "" ) then
				msg = msg .. " ";
			end
		
			msg = msg .. arg[n];
		
		end
		
	end
	
	
	local name = arg[1];
	local time = tonumber( arg[2] );
	
	local succ, result = TS.FindPlayerByName( name );
	TS.ErrorMessage( ply, true, succ, result );
	
	if( succ ) then
		
		result:Ban( time, msg, ply:GetRPName() );
	
	end

end
TS.AdminCommand( "rpa_ban", ccBan );

function ccKick( ply, cmd, arg )

	if( not arg[1] ) then 
		Console( ply, "rpa_kick <Name> <Reason> - Kick name with reason." );
		return;
	end
	
	
	
	local msg = "";
	
	if( arg[2] ) then
	
		for n = 2, #arg do
		
			if( msg ~= "" ) then
				msg = msg .. " ";
			end
		
			msg = msg .. arg[n];
		
		end
		
	end
	
	
	local name = arg[1];
	
	local succ, result = TS.FindPlayerByName( name );
	TS.ErrorMessage( ply, true, succ, result );
	
	if( succ ) then
		
		result:Kick( msg, ply:GetRPName() );
	
	end

end
TS.AdminCommand( "rpa_kick", ccKick );

function ccSetDonatorModel( ply, cmd, arg )
	
	if( not arg[1] or !arg[2] ) then 
		Console( ply, "rpa_donatormodel <name> <modeldirectory>" )
	end
	
	
	
	local name = arg[1]
	local model = arg[2]
	
	local succ, result = TS.FindPlayerByName( name );
	TS.ErrorMessage( ply, true, succ, result );
	
	if( not succ ) then
		succ, result = TS.FindPlayerBySteamID( name );
	end
	
	if( succ ) then
	
		cmd = "UPDATE `STALKERChars` SET `Model` = '" .. arg[2] .. "' WHERE `RPName` = '" .. result:GetRPName() .. "'" 
		sql.Query( cmd );
		
		result:SetModel( arg[2] )
		
		Console( result, "Admin " .. ply:GetRPName() .. "(" .. ply:SteamID() .. ") has set your model permanently to " .. arg[2], true )
		Console( ply, "Set " .. result:GetRPName() .. "s model permanently to " .. arg[2], true )
		
	end

end
TS.AdminCommand( "rpa_donatormodel", ccSetDonatorModel )	

function ccSetModel( ply, cmd, arg )
	
	if( not arg[1] or !arg[2] ) then 
		Console( ply, "rpa_setplayermodel <name> <modeldirectory>" )
	end
	
	
	
	local name = arg[1]
	local model = arg[2]
	
	local succ, result = TS.FindPlayerByName( name );
	TS.ErrorMessage( ply, true, succ, result );
	
	if( not succ ) then
		succ, result = TS.FindPlayerBySteamID( name );
	end
	
	if( succ ) then
	
		result:SetModel( arg[2] )
		
		Console( result, "Admin " .. ply:GetRPName() .. "(" .. ply:SteamID() .. ") has set your model to " .. arg[2], true )
		Console( ply, "Set " .. result:GetRPName() .. "s model to " .. arg[2], true )
		
	end

end
TS.AdminCommand( "rpa_setplayermodel", ccSetModel )		

function ccAdvancedTT( ply, cmd, arg )

	if( not arg[1] ) then 
		Console( ply, "rpa_givett <Name>/<SteamID> - Toggles tool trust on a player" );
		return;
	end
	
	
	
	local name = arg[1];
	
	local succ, result = TS.FindPlayerByName( name );
	TS.ErrorMessage( ply, true, succ, result );
	
	if( not succ ) then
		succ, result = TS.FindPlayerBySteamID( name );
	end
	
	if( succ ) then
		
		local action = !result:HasTT();
		
		if( action ) then
		
			result:Give( "gmod_tool" );
			result:GetTable().TT = true;
							
			Console( result, "Admin " .. ply:GetRPName() .. "(" .. ply:SteamID() .. ") has given you tool trust", true );
			Console( ply, "Gave TT to " .. result:GetRPName(), true );
			
			
			cmd = "UPDATE `STALKERUsers` SET `HasToolTrust` = '" .. "advanced" .. "' WHERE `SteamID` = '" .. result:SteamID() .. "'" 
			sql.Query( cmd );
		
		else
		
			result:StripWeapon( "gmod_tool" );
			result:GetTable().TT = false;
			
			Console( result, "Admin " .. ply:GetRPName() .. "(" .. ply:SteamID() .. ") has removed your tool trust", true );
			Console( ply, "Removed TT from " .. result:GetRPName(), true );
			
			cmd = "UPDATE `STALKERUsers` SET `HasToolTrust` = '" .. " " .. "' WHERE `SteamID` = '" .. result:SteamID() .. "'" 
			sql.Query( cmd );
		
		end

		elseif( string.find( name, "STEAM_" ) ) then --We add TT to a steamid not on the server
		
	
	end

end
TS.AdminCommand( "rpa_givett", ccAdvancedTT );

function ccOOCDelay( ply, cmd, arg )

	if( not arg[1] or not tonumber( arg[1] ) ) then 
		Console( ply, "rpa_oocdelay <Delay> - Set an OOC delay" );
		return;
	end
		
	local delay = tonumber( arg[1] );
	
	umsg.Start( "ODC" );
		umsg.String( ply:GetRPName() );
		umsg.Float( delay );
	umsg.End();
	
	for k, v in pairs( player.GetAll() ) do
	
		v:GetTable().NextTimeCanChatOOC = CurTime();
	
	end
	
	TS.PrintMessageAll( 2, "Admin " .. ply:GetRPName() .. " has set the OOC delay to " .. delay ); 
	TS.OOCDelay = delay;
	
end
TS.AdminCommand( "rpa_oocdelay", ccOOCDelay );

function ccMaxStats( ply, cmd, arg )

	if( not arg[1] ) then 
		Console( ply, "rpa_givemaxstats <Name> - Give player max stats" );
		return;
	end
	
	
	
	local name = arg[1];
	
	local succ, result = TS.FindPlayerByName( name );
	TS.ErrorMessage( ply, false, succ, result );
	
	if( succ ) then
	
		if( result:GetTable().CharCreateMenu ) then return; end
		
		result:SetPlayerStrength( 100 );
		result:SetPlayerSpeed( 100 );
		result:SetPlayerEndurance( 100 );
		result:SetPlayerAim( 100 );
		
		Console( result, "Admin " .. ply:GetRPName() .. "(" .. ply:SteamID() .. ") has given you max stats", true );
		Console( ply, "Gave max stats to " .. result:GetRPName(), true );
		
		result:SaveData( "STATAim", 100 )
		result:SaveData( "STATStrength", 100 )
		result:SaveData( "STATSpeed", 100 )
		result:SaveData( "STATEndurance", 100 )
		
	end


end
TS.AdminCommand( "rpa_givemaxstats", ccMaxStats );

function ccObserve( ply, cmd, arg )

	if( ply:GetTable().ObserveMode ) then
	
		ply:Observe( false );
	
	else
	
		ply:Observe( true );
	
	end

end
TS.AdminCommand( "rpa_observe", ccObserve );

function ccNoclip( ply, cmd, arg )
	
	if( ply:GetTable().NoclipMode ) then
	
		ply:Noclip( false );
	
	else
	
		ply:Noclip( true );
	
	end

end
TS.AdminCommand( "rpa_noclip", ccNoclip );

function ccSeeAll( ply, cmd, arg )

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

end
TS.AdminCommand( "rpa_seeall", ccSeeAll );

function ccTeam( ply, cmd, arg )

	if( not arg[1] or not tonumber( arg[2] ) ) then 
		Console( ply, "rpa_team <Name> <Team Number> - Set player to a team" );
		return;
	end
	
	
	
	local name = arg[1];
	local team = tonumber( arg[2] );
	
	local succ, result = TS.FindPlayerByName( name );
	TS.ErrorMessage( ply, false, succ, result );
	
	if( succ ) then
		
		result:SetTeam( team );
		result:Die();
		
	end


end
TS.AdminCommand( "rpa_team", ccTeam );

function ccCreateInvisibleHTML( ply, cmd, arg )

	if( not arg[1] ) then 
		Console( ply, "rpa_invishtml <Link> - Open this link to everyone.  Don't include the http:// prefix." );
		return;
	end
	
	
	
	local link = arg[1];
	
	umsg.Start( "IHTML" );
		umsg.String( link );
	umsg.End();


end
TS.AdminCommand( "rpa_invishtml", ccCreateInvisibleHTML );

