So, an attacking creep can be made by attacking ATTACK or RANGED_ATTACK parts to your creep body in createCreep(). To know when to create it, make a find(FIND_HOSTILE_CREEPS) call in your room. However, you shouldn't need to make an attacking creep to secure your base. A single tower can defend against most invader attacks. If the attack was an organized attack by a player, I'd say you probably wouldn't have been able to defend against it even with attacking creeps.