Fix RepairBuilding not working for AI and Lua scripts

Fixes #5861