Trail - How to do?

How can make a trail follow an entity like on sbox? How can I change the trail’s texture?

Take a look at the code in sandbox maybe?