-- Name Checker by HeLLFox and Hemirox.
if SERVER then

	function spawnNameCheck( ply )
        ValidCharacterNums = {}     
		for i = 33,125 do
			if i != 37 then
				table.insert(ValidCharacterNums,i)
			end
		end
		
		myNameTable = string.ToTable(ply:GetName())
		nameCheck( ply )
	end
	hook.Add( "PlayerInitialSpawn", "spawnNameCheck", spawnNameCheck )
	
    function nameCheck( ply )
        checkname = true
        for i = 1, string.len(ply:Name()) do 
            if ( ply:IsValid() and ply:Name() and string.len(ply:Name()) >= 3 and table.HasValue( ValidCharacterNums, string.byte(myNameTable[i]) ) ) then
                checkname = false
            end
        end
        if checkname then
            ply:ChatPrint("Your Name: " .. tostring(ply:Name()) .. " | Seems to have too many invalid characters.\n Try using a diffrent name." )
            ply:Kick("Error: Invalid Name. (See Console.)")
        else
            if ( ply:IsFrozen() ) then
                ply:UnLock()
                ply:Freeze( false )
            end
        end
    end

end --If SERVER

hook.Add("EntityTakeDamage","__ap",function(t,d) 
    if ( d:GetAttacker():GetClass() == "prop_physics" or d:GetInflictor():GetClass() == "prop_physics" ) or ( d:GetDamageType() == DMG_CRUSH ) then 
        d:SetDamage(0) 
    end 
end);

hook.Add( "PlayerSpawnedProp", "__ex", function( _, _, p ) if( p and IsValid(p) ) then p:SetKeyValue("ExplodeDamage", "0") p:SetKeyValue("ExplodeRadius", "0") end end)

--------------

local oldrpname = DarkRP.storeRPName

function DarkRP.storeRPName(ply, name) return oldrpname(ply, name) end -- Nake sure to clean the table before we overwrite it.

function DarkRP.storeRPName(ply, name) 
    ply.DarkRPNameChanges = ply.DarkRPNameChanges or 1;
    ply.DarkRPNameChanges = ply.DarkRPNameChanges + 1;
    if ply.DarkRPNameChanges > 3 then ply:ChatPrint("Warning: You only have " .. tostring(ply.DarkRPNameChanges - 5) .. " name changes left!") end
    if ply.DarkRPNameChanges >= 5 then
        MsgAll(tostring(ply) .. " [" .. tostring(ply:SteamID()) .. "] " .. "has been kicked for changing their name too many times!")  
        ply:Kick("Number of allowed name changes exceeded please rejoin!") 
    end; MsgAll(tostring(ply) .. " [" .. tostring(ply:SteamID()) .. "] " .. "has changed their name to " .. tostring(name));
    return oldrpname(ply, name);
end; 

timer.Simple( 60, function()
    for _,ply in pairs(player.GetAll()) do
        if ply.DarkRPNameChanges then
            if ply.DarkRPNameChanges >= 5 then return end;
            if ply.DarkRPNameChanges > 0 then 
                ply.DarkRPNameChanges = ply.DarkRPNameChanges - 1
                ply:ChatPrint("Note: You currently have " .. tostring(ply.DarkRPNameChanges) .. " name changes." )
            end
        end
    end
end)

for _,v in pairs(player.GetAll()) do v:ChatPrint("Simple Anti Minge - Is Now Active!") end;