-------------------
-- epsilonScript --
-------------------

epsilonScript = {};

-- Some main files.
AddCSLuaFile( "shared.lua" );
AddCSLuaFile( "cl_init.lua" );

include( "shared.lua" );

epsilonScript.Hints =
{
	"Bind a <key> to 'rp_toggleholster'",
	"Do not use OOC information IC!",
	"Type /holster with your gun out to put it into your inventory!",
	"Type /dropweapon to drop your weapon!"
};

function GM:Initialize()
	timer.Create( "HintTimer", 20, 0, function()
		for k, v in pairs( player.GetAll() ) do
			v:SendNotify( epsilonScript.Hints[ math.random( 1, #epsilonScript.Hints ) ] );
		end
	end );
end;

-- Called after the gamemode and map load and start.
function GM:InitPostEntity()
	-- Load the doors.
	epsilonScript.LoadDoors();
end;

-- Think.
function GM:Think()
	for k, v in pairs( player.GetAll() ) do
		if ( v:Alive() and !v:InVehicle() ) then
			if ( !ValidEntity( v.AnimatedLegs ) ) then
				v:GiveAnimatedLegs();
			end;
		else
			v:TakeAnimatedLegs();
		end;
		
		if ( ValidEntity( v.AnimatedLegs ) ) then
			if ( v:IsOnFire() ) then
				if ( !v.AnimatedLegs:IsOnFire() ) then
					v.AnimatedLegs:Ignite( 999, 0 );
				end;
			else
				v.AnimatedLegs:Extinguish();
			end;
		end;
	end;
end;

function GM:AcceptStream( ply, handler, id )
    return true
end

function GM:ShowHelp( ply ) 
	umsg.Start( "eps_mainmenu", ply );
	umsg.End();
end;

function GM:ShowSpare1( ply )
	ply:ConCommand( "eps_inventory" );
end;

-- Function to get a player easier.
function epsilonScript.FindPlayer( p )
	local s = player.GetAll();

	for k, v in pairs( s ) do
		if ( tonumber( p ) == v:UserID() ) then
			return v;
		end;
	end;

	for k, v in pairs( s ) do
		if ( p == v:SteamID() ) then
			return v;
		end;
	end;

	for k, v in pairs( s ) do
		if ( string.find( string.lower( v:Nick() ), string.lower( tostring( p ) ) ) ~= nil ) then
			return v;
		end;
	end;
	
	for k, v in pairs( s ) do
		if ( string.find( string.lower( v:Name() ), string.lower( tostring( p ) ) ) ~= nil ) then
			return v;
		end;
	end;
	
	return nil;
end;
