datastream.Hook( "RecieveSavedInventory", function( handler, id, enc, dec )
	LocalPlayer().Inventory = dec[ 1 ];
	LocalPlayer().CurrentInventoryWeight = dec[ 2 ];
	LocalPlayer().MaxInventoryWeight = dec[ 3 ];
end );

usermessage.Hook( "PISUM", function( um )
	LocalPlayer().Flags = {};
	LocalPlayer().Stats = {};
	LocalPlayer().Inventory = {};
	LocalPlayer().MaxInventoryWeight = 10;
	LocalPlayer().CurrentInventoryWeight = 0;
	LocalPlayer().DoneIntro = true;
end );

-- Function to update the players money.
usermessage.Hook( "UpdateMoney", function( um )
	LocalPlayer().Money = um:ReadLong();
end );

usermessage.Hook( "GiveItem", function( um )
	local ID = um:ReadString();
	local Num = um:ReadLong();
	
	if ( LocalPlayer().Inventory[ ID ] ) then
		LocalPlayer().Inventory[ ID ] = LocalPlayer().Inventory[ ID ] + Num;
	else
		LocalPlayer().Inventory[ ID ] = 0;
		LocalPlayer().Inventory[ ID ] = LocalPlayer().Inventory[ ID ] + Num;
	end;
	
	LocalPlayer().CurrentInventoryWeight = um:ReadFloat();
end );

usermessage.Hook( "RemoveItem", function( um )
	local ID = um:ReadString();
	local Num = um:ReadLong();
	
	if ( LocalPlayer().Inventory[ ID ] ) then
		LocalPlayer().Inventory[ ID ] = LocalPlayer().Inventory[ ID ] - Num;
	end;
	
	if ( LocalPlayer().Inventory[ ID ] <= 0 ) then
		LocalPlayer().Inventory[ ID ] = nil;
	end;
	
	LocalPlayer().CurrentInventoryWeight = um:ReadFloat();
end );

usermessage.Hook( "ResetInventory", function( um )
	LocalPlayer().Flags = {}; -- Why not ;)
	LocalPlayer().Inventory = {};
	LocalPlayer().MaxInventoryWeight = 10;
	LocalPlayer().CurrentInventoryWeight = 0;
end );

usermessage.Hook( "RIW", function( um )
	LocalPlayer().MaxInventoryWeight = um:ReadLong();
end );

local NotifySound = CreateClientConVar( "eps_notifysound_enabled", "1", true, false );
usermessage.Hook( "RN", function( um )
	local Tbl = {};
	Tbl.Text = um:ReadString();
	Tbl.Time = CurTime();
	
	if ( NotifySound:GetInt() == 1 ) then
		surface.PlaySound( "ui/buttonclick.wav" );
	end;
	
	epsilonScript.Messages[ #epsilonScript.Messages + 1 ] = Tbl
end );