Might have something to do with this line:
DelayCommand(0.5, RemoveEffect(oPC, eLoop));
I don't think you mean to remove the effect from a player (oPC) but rather oLight?
It also seems like you are trying to advance nNth twice?:
nNth++;
oLight = GetObjectByTag("LIGHT_" + sSwitch, nNth++);
I am also a bit confused about how you are checking the "nOn" integer. Are you just checking the first light source and going off of that? Why not just set it on the switch itself to see if it is on or off? Just a thought.
Maybe structured a bit more like so?:
void main()
{
object oSwitch = OBJECT_SELF;
string sSwitch = GetTag(oSwitch); //Tag of the light switch.
string sLight = "LIGHT" + sSwitch;
int nOn = GetLocalInt(oSwitch, "nOn");
int nNth = 1;
object oLight = GetNearestObjectByTag(sLight, oSwitch, nNth);
if (nOn == 0)//light is off
{
while (GetIsObjectValid(oLight))
{
effect eLight = EffectVisualEffect(VFX_DUR_LIGHT_GREY_10);
ApplyEffectToObject(DURATION_TYPE_PERMANENT, eLight, oLight);
nNth++;
oLight = GetNearestObjectByTag(sLight, oSwitch, nNth);
}
SetLocalInt(oSwitch, "nOn", 1);
return;
}
if (nOn == 1)//light is on
{
while (GetIsObjectValid(oLight))
{
effect eLoop = GetFirstEffect(oLight);
while (GetIsEffectValid(eLoop))
{
if (GetEffectType(eLoop) == EFFECT_TYPE_VISUALEFFECT)
DelayCommand(0.5, RemoveEffect(oLight, eLoop));
eLoop = GetNextEffect(oLight);
}
nNth++;
oLight = GetNearestObjectByTag(sLight, oSwitch, nNth);
}
SetLocalInt(oSwitch, "nOn", 0);
return;
}
}
Good luck.
Modifié par GhostOfGod, 10 janvier 2011 - 04:11 .