----------------------------
-- CakeScript (March 29, 2008)
-- by LuaBanana
--
-- Alpha Version
-- cl_init.lua
----------------------------

-- Set up the gamemode
DeriveGamemode( "sandbox" );
GM.Name = "OTF RP";

-- General GUI Color
GUIcolor = Color(75,75,100,255);
GUIcolor_trans = Color(75,75,100,225);

-- Define the global variables.
CAKE = {};
models = {};

-- Client Includes
include("shared.lua");
include("player_shared.lua");
include("cl_hud.lua");
include("cl_binds.lua");
include("cl_charactercreate.lua");
include("cl_playermenu.lua");
include("cl_chat.lua");
include("cl_search.lua");
include("cl_adminMenu.lua");
include("cl_radioMenu.lua");
include("cl_settings.lua");
include("cl_paperDoll.lua");


--include("hudTest.lua");
--include("concmd.lua");
--include("admin.lua");

-- Called once when client is ready
local function clientReady()

	hook.Remove("Think", "clientIsReady");
	
	-- do this before making chat 
	CLIENTLoadSettings();
	
	DrawNewChat();

	-- lets see if we can fix that lil chat frame huh?
	OpenChat();
	CloseChat();
	
	RunConsoleCommand("clientIsReadyForSetup", "\n");

end
hook.Add("Think", "clientIsReady", clientReady);

-- Initialize the gamemode
function GM:Initialize()

	self.BaseClass:Initialize();

end

function GM:StartChat()

	RunConsoleCommand("rp_openedchat", "\n");
	
end

function GM:FinishChat()

	RunConsoleCommand("rp_closedchat", "\n");
	
end

TeamTable = {};

function SetUpTeam(data)

	local newteam = {}
	newteam.id = data:ReadLong();
	newteam.name = data:ReadString();
	newteam.r = data:ReadLong();
	newteam.g = data:ReadLong();
	newteam.b = data:ReadLong();
	newteam.a = data:ReadLong();
	newteam.public = data:ReadBool();
	newteam.salary = data:ReadLong();
	newteam.flagkey = data:ReadString();
	newteam.business = data:ReadBool();
	
	team.SetUp(newteam.id, newteam.name, Color(newteam.r,newteam.g,newteam.b,newteam.a));
	TeamTable[newteam.id] = newteam;
end
usermessage.Hook("setupteam", SetUpTeam);

function GM:ScoreboardShow()
	ContextEnabled = true;
	gui.EnableScreenClicker(true)
	
	if( HiddenButton == nil ) then
		InitHiddenButton();
	else
		CAKE.HiddenButton:SetVisible(true);
	end
end

function GM:ScoreboardHide()
	ContextEnabled = false;
	gui.EnableScreenClicker(false);
	
	if( HiddenButton == nil ) then
		InitHiddenButton();
	else
		CAKE.HiddenButton:SetVisible(false);
	end
end


function GM:HUDShouldDraw( name )

	if(LocalPlayer():GetNWInt("charactercreate") == 1 or LocalPlayer():GetNWInt("charactercreate") == nil) then return false; end
	
	local nodraw = 
	{
	
		"CHudHealth",
		"CHudAmmo",
		"CHudSecondaryAmmo",
		"CHudBattery",
		"CHudChat",
		--"CHudWeaponSelection"
	}
	
	for k, v in pairs( nodraw ) do
	
		if( name == v ) then return false; end
	
	end
	
	return true;

end

function cloakCheck()

	for _,p in pairs(player.GetAll()) do
			local cloaked = p:GetNWBool("cloaked");
			if( cloaked == true ) then
			
				local weapon = p:GetActiveWeapon();
				local r,g,b,a = p:GetColor();
				
				a = 0;
				
				p:SetColor(r,g,b,a); -- Cloak, lol
				if(ValidEntity(weapon)) then
					weapon:SetColor(255,255,255,a); -- Cloak his weapon too
				end
				
			else
				
				local weapon = p:GetActiveWeapon();
				local r,g,b,a = p:GetColor();
				
				if( a == 0 ) then
					a = 255;
				
					p:SetColor(r,g,b,a); -- Cloak, lol
					if(ValidEntity(weapon)) then
						weapon:SetColor(255,255,255,a); -- Cloak his weapon too
					end
				end
			end
	end
end
hook.Add("Think","adminCloakThink",cloakCheck);

