How do I stop townies running into a battle to collect gel/bones etc?

Solution 1:

It's likely that you have raw material barrels or stockpiles lying around. When these barrels and stockpiles have space, your townies will search for items to fill these spaces. If bones and gels are not disabled, then your townies will mindlessly kill themselves for these materials so you can make colored hats.

To prevent this, right-click on your raw material barrels/stockpiles and disable bones and gels.