Objects that cast a shadow must have the second tag ‘shadow’ in their material.
Sorting when casting shadows is by Z (in view coordinates), if you introduce your own sorting of objects in the render script in the following, you should take this into account for casting shadows as well.