This script randomly creates flashing tile colours anywhere the placeable TAG "light" is found on a specific tileset grid. It's a lot more complex.
// Declarations
void SetFloatArray(object oObject, string sVarName, int nComponent, float fValue);
float GetFloatArray(object oObject, string sVarName, int nComponent);
void SetIntArray(object oObject, string sVarName, int nComponent, int nValue);
int GetIntArray(object oObject, string sVarName, int nComponent);
void SetLocationArray(object oObject, string sVarName, int nComponent, location lValue);
location GetLocationArray(object oObject, string sVarName, int nComponent);
void SetObjectArray(object oObject, string sVarName, int nComponent, object oValue);
object GetObjectArray(object oObject, string sVarName, int nComponent);
void SetStringArray(object oObject, string sVarName, int nComponent, string sValue);
string GetStringArray(object oObject, string sVarName, int nComponent);
void SetFloat2DArray(object oObject, string sVarName, int nxComponent, int nyComponent, float fValue);
float GetFloat2DArray(object oObject, string sVarName, int nxComponent, int nyComponent);
void SetInt2DArray(object oObject, string sVarName, int nxComponent, int nyComponent, int nValue);
int GetInt2DArray(object oObject, string sVarName, int nxComponent, int nyComponent);
void SetLocation2DArray(object oObject, string sVarName, int nxComponent, int nyComponent, location lValue);
location GetLocation2DArray(object oObject, string sVarName, int nxComponent, int nyComponent);
void SetObject2DArray(object oObject, string sVarName, int nxComponent, int nyComponent, object oValue);
object GetObject2DArray(object oObject, string sVarName, int nxComponent, int nyComponent);
void SetString2DArray(object oObject, string sVarName, int nxComponent, int nyComponent, string sValue);
string GetString2DArray(object oObject, string sVarName, int nxComponent, int nyComponent);
string PadString(string sVarName, int nxComponent, int nyComponent);
// Implementations
void SetFloatArray(object oObject, string sVarName, int nComponent, float fValue)
{
SetLocalFloat(oObject, sVarName+IntToString(nComponent), fValue);
return;
}
float GetFloatArray(object oObject, string sVarName, int nComponent)
{
return GetLocalFloat(oObject, sVarName+IntToString(nComponent));
}
void SetIntArray(object oObject, string sVarName, int nComponent, int nValue)
{
SetLocalInt(oObject, sVarName+IntToString(nComponent), nValue);
return;
}
int GetIntArray(object oObject, string sVarName, int nComponent)
{
return GetLocalInt(oObject, sVarName+IntToString(nComponent));
}
void SetLocationArray(object oObject, string sVarName, int nComponent, location lValue)
{
SetLocalLocation(oObject, sVarName+IntToString(nComponent), lValue);
return;
}
location GetLocationArray(object oObject, string sVarName, int nComponent)
{
return GetLocalLocation(oObject, sVarName+IntToString(nComponent));
}
void SetObjectArray(object oObject, string sVarName, int nComponent, object oValue)
{
SetLocalObject(oObject, sVarName+IntToString(nComponent), oValue);
return;
}
object GetObjectArray(object oObject, string sVarName, int nComponent)
{
return GetLocalObject(oObject, sVarName+IntToString(nComponent));
}
void SetStringArray(object oObject, string sVarName, int nComponent, string sValue)
{
SetLocalString(oObject, sVarName+IntToString(nComponent), sValue);
return;
}
string GetStringArray(object oObject, string sVarName, int nComponent)
{
return GetLocalString(oObject, sVarName+IntToString(nComponent));
}
void SetFloat2DArray(object oObject, string sVarName, int nxComponent, int nyComponent, float fValue)
{
SetLocalFloat(oObject, PadString(sVarName, nxComponent, nyComponent), fValue);
return;
}
float GetFloat2DArray(object oObject, string sVarName, int nxComponent, int nyComponent)
{
return GetLocalFloat(oObject, PadString(sVarName, nxComponent, nyComponent));
}
void SetInt2DArray(object oObject, string sVarName, int nxComponent, int nyComponent, int nValue)
{
SetLocalInt(oObject, PadString(sVarName, nxComponent, nyComponent), nValue);
return;
}
int GetInt2DArray(object oObject, string sVarName, int nxComponent, int nyComponent)
{
return GetLocalInt(oObject, PadString(sVarName, nxComponent, nyComponent));
}
void SetLocation2DArray(object oObject, string sVarName, int nxComponent, int nyComponent, location lValue)
{
SetLocalLocation(oObject, PadString(sVarName, nxComponent, nyComponent), lValue);
return;
}
location GetLocation2DArray(object oObject, string sVarName, int nxComponent, int nyComponent)
{
return GetLocalLocation(oObject, PadString(sVarName, nxComponent, nyComponent));
}
void SetObject2DArray(object oObject, string sVarName, int nxComponent, int nyComponent, object oValue)
{
SetLocalObject(oObject, PadString(sVarName, nxComponent, nyComponent), oValue);
return;
}
object GetObject2DArray(object oObject, string sVarName, int nxComponent, int nyComponent)
{
return GetLocalObject(oObject, PadString(sVarName, nxComponent, nyComponent));
}
void SetString2DArray(object oObject, string sVarName, int nxComponent, int nyComponent, string sValue)
{
SetLocalString(oObject, PadString(sVarName, nxComponent, nyComponent), sValue);
return;
}
string GetString2DArray(object oObject, string sVarName, int nxComponent, int nyComponent)
{
return GetLocalString(oObject, PadString(sVarName, nxComponent, nyComponent));
}
string PadString(string sVarName, int nxComponent, int nyComponent)
{
string sTemp;
sTemp = IntToString(nxComponent);
while (GetStringLength(sTemp) < 4)
{
sTemp = "0" + sTemp;
}
sVarName += sTemp;
sTemp = IntToString(nyComponent);
while (GetStringLength(sTemp) < 4)
{
sTemp = "0" + sTemp;
}
sVarName += sTemp;
return sVarName;
}
This goes on a placeable in your area with the TAG light_control. The below script goes on the placeables OnUserDefined.
#include "array4"
void RemoveEffects(object oObject);
int TurnOffLights();
float LIGHT_DURATION = 1.0;
float LIGHT_INTERVAL = 0.8;
void main()
{
int nEvent = GetUserDefinedEventNumber();
object oLight;
int i,j,nRandom,x,nNumLights;
effect e;
//AssignCommand(GetObjectByTag("light_control"), SendMessageToPC(GetFirstPC(), "DEBUG: FIRED!"));
// Continue light flashing
if(nEvent==1)
{
//AssignCommand(GetObjectByTag("light_control"), SendMessageToPC(GetFirstPC(), "DEBUG: EVENT == 1"));
if(GetLocalInt(OBJECT_SELF, "STOP")) SetLocalInt(OBJECT_SELF, "STOP", 0);
else
{
//AssignCommand(GetObjectByTag("light_control"), SendMessageToPC(GetFirstPC(), "DEBUG: LOOP!"));
nNumLights = GetLocalInt(OBJECT_SELF, "nNumLights");
for(i=4;i<7;i++)
{
nRandom=Random(nNumLights);
//AssignCommand(GetObjectByTag("light_control"), SendMessageToPC(GetFirstPC(), "DEBUG: LOOP: RANDOM!"));
do
{
//AssignCommand(GetObjectByTag("light_control"), SendMessageToPC(GetFirstPC(), "DEBUG: LOOP: DO!"));
x=0;
for(j=1;j<i;j++)
{
if(nRandom==GetIntArray(OBJECT_SELF, "lights", j))
{
nRandom++;
if(nRandom==nNumLights) nRandom=0;
x=1;
}
}
} while (x==1);
SetIntArray(OBJECT_SELF, "lights", i, nRandom);
}
for(i=1;i<4;i++)
{
//AssignCommand(GetObjectByTag("light_control"), SendMessageToPC(GetFirstPC(), "DEBUG: FOR SWITCH RANDOM"));
x=GetIntArray(OBJECT_SELF, "lights", i+3);
SetIntArray(OBJECT_SELF, "lights", i, x);
oLight=GetObjectByTag("light", x);
nRandom = Random(7);
switch(nRandom)
{
case 0: e=EffectVisualEffect(VFX_DUR_LIGHT_BLUE_5); break;
case 1: e=EffectVisualEffect(VFX_DUR_LIGHT_GREY_5); break;
case 2: e=EffectVisualEffect(VFX_DUR_LIGHT_ORANGE_5); break;
case 3: e=EffectVisualEffect(VFX_DUR_LIGHT_PURPLE_5); break;
case 4: e=EffectVisualEffect(VFX_DUR_LIGHT_RED_5); break;
case 5: e=EffectVisualEffect(VFX_DUR_LIGHT_WHITE_5); break;
case 6: e=EffectVisualEffect(VFX_DUR_LIGHT_YELLOW_5); break;
}
ApplyEffectToObject(DURATION_TYPE_TEMPORARY, e, oLight, LIGHT_DURATION);
}
DelayCommand(LIGHT_INTERVAL, SignalEvent(OBJECT_SELF, EventUserDefined(1)));
}
}
// Turn off light flashing
if(nEvent==2)
{
//AssignCommand(GetObjectByTag("light_control"), SendMessageToPC(GetFirstPC(), "DEBUG: EVT#2 TURN OFF LIGHT!"));
SetLocalInt(OBJECT_SELF, "STOP", 1);
TurnOffLights();
SetLocalInt(OBJECT_SELF, "lights_on", FALSE);
}
// Start light flashing
if(nEvent==3)
{
//AssignCommand(GetObjectByTag("light_control"), SendMessageToPC(GetFirstPC(), "DEBUG: EVT#3 TURN ON LIGHT!"));
if(!GetLocalInt(OBJECT_SELF, "lights_on"))
{
nNumLights=TurnOffLights();
SetLocalInt(OBJECT_SELF, "nNumLights", nNumLights);
for(i=1;i<4;i++) SetIntArray(OBJECT_SELF, "lights", i, i);
SetLocalInt(OBJECT_SELF, "lights_on", TRUE);
SignalEvent(OBJECT_SELF, EventUserDefined(1));
}
}
}
void RemoveEffects(object oObject)
{
effect e = GetFirstEffect(oObject);
while(GetIsEffectValid(e))
{
RemoveEffect(oObject, e);
e = GetNextEffect(oObject);
}
return;
}
int TurnOffLights()
{
int i=0;
object oLight = GetObjectByTag("light", i);
while(GetIsObjectValid(oLight))
{
RemoveEffects(oLight);
i++;
oLight = GetObjectByTag("light", i);
}
return i;
}
Event to fire when entering the area in question.