GSLog.Info("Switched to mode for " + GSCompany.GetName(companyIdx));
You need to store the result from GSCompanyMode() in a variable. The company mode is in effect for as long as this variable is in scope. Basically when the instance is destroyed, the company mode exits. Since you don't store it in a local variable, it is destroyed immediately.
local cm = GSCompanyMode(companyIdx);
_________________My OpenTTD contributions
(AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)Junctioneer
(a traffic intersection simulator)