As far as the cogwheels/sticky areas go, you have to set the "AttachableBodyName" (The object to be attached) and attach function (Called when said object attaches) in the level editor. Both are found under the "Area" tab. Make sure you uncheck CanDetach, just for this example.
Here's a function you could use:
//But first declare a local variable in OnStart
SetLocalVarInt("Cogs",0);
//You might also have to set sticky area attachment in OnStart, try it with and without
SetAllowStickyAreaAttachment(true);
//This will be called each time a cog attaches
void Mount_Cog(string &in asStickyArea, string &in asBodyName)
{
if(GetLocalVarInt("Cogs") <= 3)
{
AddLocalVarInt("Cogs",1);
AddDebugMessage("Attaching cog "+asBodyName+" to area "+asStickyArea,false);
AddDebugMessage("Cogs is at "+GetLocalVarInt("Cogs"),false);
}
}
Try that out and make some adjustments. Let me know how it works!