I feel like you're overthinking it especially when it comes to checking module code. You can do one number check like JC suggested first and go with a single switch statement,.
void setMainMenu() {
int nCurrentModule = StringToInt(GetStringLeft(GetModuleName(), 3));
switch(nCurrentModule) {
case 0: // Ebon Hawk
SetGlobalNumber("GBL_MAIN_SITH_LORD", 1);
break;
case 1: // Peragus
SetGlobalNumber("GBL_MAIN_SITH_LORD", 1);
break;
case 2: // Telos
SetGlobalNumber("GBL_MAIN_SITH_LORD", 1);
break;
case 3: // Nar Shaddaa
SetGlobalNumber("GBL_MAIN_SITH_LORD", 2);
break;
case 4: // Dxun
SetGlobalNumber("GBL_MAIN_SITH_LORD", 3);
break;
/* and so on */
default: break;
}
}
Only problem I see with that is that you get a different background for the Ebon Hawk, and we probably don't want that.
Keep in mind though that there's already a 003EBO_BACKGROUND variable controlling the background outside of the Ebon Hawk, so maybe use that for planet reference instead - no idea if it ever sets properly for Telos 2 or Malachor, but we can force it to in proper modules.
So it's the same script but
int nCurrentModule = GetGlobalNumber("003EBO_BACKGROUND");
DP mentiond k_align_movie, which would be potentially a good script to use for this purpose, instead of modifying bunch of OnEnters, or even worse, adding OnExit scripts (sorry FS, but it's a bad idea if you think about compatibility issues - best to avoid this kind of module editing).
I don't really know when k_align_movie fires, or whether it fires at all in the end game, so that's the only potential problem I see.
Or just link it to the galaxy map script.