// Made by Assault_Trooper
// Adv. Name v.1.0

local Changer = false
local Product = "[Adv.Name] "
local Ready = false

local function NameChanger()

if Changer then

RunConsoleCommand( "setinfo", "name", table.Random( player.GetAll() ):Nick() .. " " )

end

end

local function NameCapture( ply, cmd, args )

if args[1] == nil then

LocalPlayer():ChatPrint("Invalid name!")
hook.Remove("Think", "NameChange", NameChange)
Ready = false

else

Ready = true
local Name = args[1]

NameChange()
hook.Add("Think", "NameChange", NameChange)

end

end

local function NameChange()

if Ready then

RunConsoleCommand( "setinfo", "name", Name )

end

end

concommand.Add("name_change", NameCapture)

local function ControlPanel()

local panel = vgui.Create("DFrame")
panel:SetSize(500, 110)
panel:SetPos(ScrW() / 3, ScrH() / 3)
panel:SetTitle( "Advanced Name Control v1.0" )
panel:SetVisible( true )
panel:SetDraggable( true )
panel:ShowCloseButton( true )
panel:MakePopup()

local textbox = vgui.Create("DTextEntry", panel, "Message")  
textbox:SetSize( 100, 30)  
textbox:SetPos( 350, 50)  
textbox:SetKeyboardInputEnabled( true )  
textbox:SetEnabled( true )   
textbox:SetText( LocalPlayer():Nick() )
textbox.MessageBox = textbox  

local label = vgui.Create("DLabel", panel)  
label:SetSize( 200, 30)  
label:SetPos( 160, 80)   
label:SetText( "Created by Assault_Trooper" )

local enable = vgui.Create( "DButton", panel )
enable:SetPos( 20, 50 )
enable:SetSize( 100, 30 )
enable:SetText( "Name Changer On" )
enable.DoClick = function()

RunConsoleCommand( "+name_changer" )
 
end

local disable = vgui.Create( "DButton", panel )
disable:SetPos( 130, 50 )
disable:SetSize( 100, 30 )
disable:SetText( "Name Changer Off" )
disable.DoClick = function()

RunConsoleCommand( "-name_changer" )
 
end

local change = vgui.Create( "DButton", panel )
change:SetPos( 240, 50 )
change:SetSize( 100, 30 )
change:SetText( "Change Name" )
change.DoClick = function()

RunConsoleCommand( "name_change", textbox:GetValue() )

LocalPlayer():ChatPrint( Product .. "Name set as: " .. textbox:GetValue() )
 
end

end

concommand.Add( "name_menu", ControlPanel )

hook.Add( "Think", "NameChange", NameChange )

concommand.Add( "+name_changer", function()

Changer = true
LocalPlayer():ChatPrint( Product .. "Name Changer Enabled!" )

hook.Add( "Think", "random", NameChanger )

end )

concommand.Add( "-name_changer", function()

Changer = false
LocalPlayer():ChatPrint( Product .. "Name Changer Disabled!" )

hook.Remove( "Think", "random", NameChanger )

end )