Spectate permissions is handled by _spectating.gsc, which is in:
iw_07.iwd/maps/mp/gametypes
To make this work the way you want, you need to convert the cvars over to Ravir's cvardef() method. This is basically a way of defining a cvar which can be set true or false for certain maps, gametypes, or both. It extends the flexibility of cvars by adding in a check on the cvars getcvar("mapname") and getcvar("g_gametype").
Here is the converted _spectating.gsc file. Just copy and paste it into a GSC file, and name it _spectating.gsc, and place it in your mod, in the folder structure:
maps/mp/gametypes/_spectating.gsc
Code:
init()
{
level.spectatefree = cvardef( "scr_spectatefree", 1, 0, 1, "int" );
level.spectateenemy = cvardef( "scr_spectateenemy", 1, 0, 1, "int" );
level.no_spectating = cvardef( "scr_no_spectating", 0, 0, 1, "int" );
for(;;)
{
updateSpectateSettings();
wait 1;
}
}
updateSpectateSettings()
{
spectatefree = getCvarInt("scr_spectatefree");
spectateenemy = getCvarInt("scr_spectateenemy");
update = false;
if(level.spectatefree != spectatefree)
{
level.spectatefree = spectatefree;
update = true;
}
if(level.spectateenemy != spectateenemy)
{
level.spectateenemy = spectateenemy;
update = true;
}
if(update)
level thread updateSpectatePermissions();
}
updateSpectatePermissions()
{
players = getentarray("player", "classname");
for(i = 0; i < players.size; i++)
players[i] thread setSpectatePermissions();
}
setSpectatePermissions()
{
if(isdefined(self.killcam))
return;
if( !level.spectatefree || !level.spectateenemy || !level.no_spectating )
return;
spectatefree = true;
if( !level.spectatefree )
spectatefree = false;
spectateenemy = true;
if( !level.spectateenemy )
spectateenemy = false;
if( !level.no_spectating )
{
spectateenemy = false;
spectatefree = false;
}
switch(self.sessionteam)
{
case "allies":
self allowSpectateTeam("allies", true);
self allowSpectateTeam("axis", spectateenemy);
self allowSpectateTeam("freelook", spectatefree);
self allowSpectateTeam("none", false);
break;
case "axis":
self allowSpectateTeam("allies", spectateenemy);
self allowSpectateTeam("axis", true);
self allowSpectateTeam("freelook", spectatefree);
self allowSpectateTeam("none", false);
break;
default:
self allowSpectateTeam("allies", true);
self allowSpectateTeam("axis", true);
self allowSpectateTeam("freelook", true);
self allowSpectateTeam("none", true);
break;
}
}
cvardef (varname, vardefault, min, max, type)
{
mapname = getcvar("mapname");
gametype = getcvar ("g_gametype");
both = gametype + "_" + mapname;
tempvar = varname + "_" + gametype;
if (getcvar (tempvar) != "")
varname = tempvar;
tempvar = varname + "_" + mapname;
if (getcvar (tempvar) != "")
varname = tempvar;
tempvar = varname + "_" + both;
if (getcvar (tempvar) != "")
varname = tempvar;
switch(type)
{
case "int":
if(getcvar(varname) == "")
definition = vardefault;
else
definition = getcvarint(varname);
break;
case "float":
if(getcvar(varname) == "")
definition = vardefault;
else
definition = getcvarfloat(varname);
break;
case "string":
default:
if(getcvar(varname) == "")
definition = vardefault;
else
definition = getcvar(varname);
break;
}
if((type == "int" || type == "float") && definition < min)
definition = min;
if((type == "int" || type == "float") && definition > max)
definition = max;
return definition;
}
Now, to stop spectating for Zombies, but allow it for TDM, just do this:
set scr_no_spectating 0
set scr_no_spectating_tdm 1
That means spectating is off for all gametypes except TDM.
As the cvars scr_spectateenemy and scr_spectatefree are also defined using cvardef(), you can turn them on or off for gametypes as well:
set scr_spectatefree 0
set scr_spectatefree_tdm 1
set scr_spectateenemy 0
set scr_spectateenemy_tdm 1
All the big mods like AWE or Xtreme+ use the cvardef() method of defining cvars.