Made castle gate script functional for any castle.