
local meta = FindMetaTable( "Player" );

if( SERVER ) then

	PlayerVars = { }

end

function CreatePlayerVariable( name, type, default )

	if( SERVER ) then
	
		if( default ~= nil ) then
		
			PlayerVars[name] = default;
		
		end

		meta["SetPlayer" .. name] = function( self, val )
			
			if( val == nil ) then return; end
			
			if( not self:GetTable().Vars ) then
				
				self:GetTable().Vars = { }
			
			end
			
			if( self:GetTable().Vars[name] ~= val ) then
			
				local update = true;
			
				if( meta["OnUpdatePlayer" .. name] ) then
				
					update = meta["OnUpdatePlayer" .. name]( self, self:GetTable().Vars[name], val ) or true;
				
				end
			
				if( update ) then
			
					self:GetTable().Vars[name] = val;
					
					umsg.Start( "R" .. name, self );
						umsg[type]( val );
					umsg.End();
					
				end
				
			end
	
		end
		
		meta["GetPlayer" .. name] = function( self )
		
			if( not self:GetTable().Vars ) then
				
				self:GetTable().Vars = { }
			
			end
		
			return self:GetTable().Vars[name];
		
		end
		
	end
	
	if( CLIENT ) then
	
		if( not ClientVars ) then
			
			ClientVars = { }
		
		end
		
		if( default ~= nil ) then
		
			ClientVars[name] = default;

		end
	
		local function setvar( msg )

			local val =  msg["Read" .. type]( msg );
			
			if( _G["OnUpdatePlayer" .. name] ) then
			
				_G["OnUpdatePlayer" .. name]( ClientVars[name], val );
			
			end		
			
			ClientVars[name] = val;
		
		end
		usermessage.Hook( "R" .. name, setvar );
	
	end

end

function FormatLine( str, font, size )

	local start = 1;
	local c = 1;
	
	surface.SetFont( font );
	
	local endstr = "";
	local n = 0;
	local lastspace = 0;
	local lastspacemade = 0;
	
	while( string.len( str ) > c ) do
	
		local sub = string.sub( str, start, c );
	
		if( string.sub( str, c, c ) == " " ) then
			lastspace = c;
		end

		if( surface.GetTextSize( sub ) >= size and lastspace ~= lastspacemade ) then
			
			local sub2;
			
			if( lastspace == 0 ) then
				lastspace = c;
				lastspacemade = c;
			end
			
			if( lastspace > 1 ) then
				sub2 = string.sub( str, start, lastspace - 1 );
				c = lastspace;
			else
				sub2 = string.sub( str, start, c );
			end
			
			endstr = endstr .. sub2 .. "\n";
			
			lastspace = c + 1;
			lastspacemade = lastspace;
			
			start = c + 1;
			n = n + 1;
		
		end
	
		c = c + 1;
	
	end
	
	if( start < string.len( str ) ) then
	
		endstr = endstr .. string.sub( str, start );
	
	end
	
	return endstr, n;

end

function GetMap()

	local ent = ents.GetByIndex( 0 );
	local model = ent:GetModel();
	
	model = string.gsub( model, "(%w*/)", "" );
	model = string.gsub( model, ".bsp", "" );
	
	return model;

end


