Frictional Games Forum (read-only)

Full Version: Random or Looping
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Ive just created lightning for my custom story, now all I need to do is get it to repeat randomly....which I do not know how to do. I'm guessing it could be "RandFloat" but I have not a clue how to implement it. here's the script to the lightning. How would you implement random OR EVEN Looping in this script?




void OnStart()
{
PreloadSound("general_thunder.snt");
SetSkyBoxActive(true);
SetSkyBoxColor(0.05, 0.05, 0.10, 1);
SetLightVisible("SpotLight_1", false);
SetLightVisible("SpotLight_2", false);
SetLightVisible("SpotLight_3", false);
SetLightVisible("SpotLight_4", false);
SetLightVisible("SpotLight_5", false);
SetLightVisible("SpotLight_6", false);
AddTimer("", 3.0f, "flashes");
}
//The many flashes that makes up the lightning. all triggered with "flashes"
void flashes(string &in asTimer)
{
AddTimer("", 0.01f, "flashesOn");
AddTimer("", 0.40f, "flashesOff");
AddTimer("", 0.45f, "flashesOn");
AddTimer("", 0.50f, "flashesOff");
AddTimer("", 0.63f, "flashesOn");
AddTimer("", 0.67f, "flashesOff");
AddTimer("", 0.70f, "flashesOn");
AddTimer("", 0.90f, "flashesOff");
AddTimer("", 1.10f, "Thunder");
}
void Thunder(string &in asTimer)
{
PlayGuiSound("general_thunder.snt" , 1.0f);
}
void flashesOn(string &in asTimer)
{
SetLightVisible("SpotLight_1", true);
SetLightVisible("SpotLight_2", true);
SetLightVisible("SpotLight_3", true);
SetLightVisible("SpotLight_4", true);
SetLightVisible("SpotLight_5", true);
SetLightVisible("SpotLight_6", true);
SetSkyBoxColor(0.5, 0.5, 0.6, 1);
}
void flashesOff(string &in asTimer)
{
SetLightVisible("SpotLight_1", false);
SetLightVisible("SpotLight_2", false);
SetLightVisible("SpotLight_3", false);
SetLightVisible("SpotLight_4", false);
SetLightVisible("SpotLight_5", false);
SetLightVisible("SpotLight_6", false);
SetSkyBoxColor(0.05, 0.05, 0.10, 1);
}
For RandomFloat I do not know... We should be able to put a name and then use GetLocalVarFloat.
But to use the loops, for all my scripts, I do like her :

Code:
void OnStart()
{
PreloadSound("general_thunder.snt");
SetSkyBoxActive(true);
SetSkyBoxColor(0.05, 0.05, 0.10, 1);
SetLightVisible("SpotLight_1", false);
SetLightVisible("SpotLight_2", false);
SetLightVisible("SpotLight_3", false);
SetLightVisible("SpotLight_4", false);
SetLightVisible("SpotLight_5", false);
SetLightVisible("SpotLight_6", false);
AddTimer("", 3.0f, "flashes");
}
//The many flashes that makes up the lightning. all triggered with "flashes"
void flashes(string &in asTimer)
{
AddTimer("", 0.01f, "flashesOn");
AddTimer("", 1.10f, "Thunder");
}
void Thunder(string &in asTimer)
{
PlayGuiSound("general_thunder.snt" , 1.0f);
}
void flashesOn(string &in asTimer)
{
SetLightVisible("SpotLight_1", true);
SetLightVisible("SpotLight_2", true);
SetLightVisible("SpotLight_3", true);
SetLightVisible("SpotLight_4", true);
SetLightVisible("SpotLight_5", true);
SetLightVisible("SpotLight_6", true);
SetSkyBoxColor(0.5, 0.5, 0.6, 1);
AddTimer("", 0.40f, "flashesOff");
}
void flashesOff(string &in asTimer)
{
SetLightVisible("SpotLight_1", false);
SetLightVisible("SpotLight_2", false);
SetLightVisible("SpotLight_3", false);
SetLightVisible("SpotLight_4", false);
SetLightVisible("SpotLight_5", false);
SetLightVisible("SpotLight_6", false);
SetSkyBoxColor(0.05, 0.05, 0.10, 1);
AddTimer("", 0.65f, "flashesOn2");
}
  void flashesOn2(string &in asTimer)
{
SetLightVisible("SpotLight_1", true);
SetLightVisible("SpotLight_2", true);
SetLightVisible("SpotLight_3", true);
SetLightVisible("SpotLight_4", true);
SetLightVisible("SpotLight_5", true);
SetLightVisible("SpotLight_6", true);
SetSkyBoxColor(0.5, 0.5, 0.6, 1);
AddTimer("", 0.40f, "flashesOff2");
}
  void flashesOff2(string &in asTimer)
{
SetLightVisible("SpotLight_1", false);
SetLightVisible("SpotLight_2", false);
SetLightVisible("SpotLight_3", false);
SetLightVisible("SpotLight_4", false);
SetLightVisible("SpotLight_5", false);
SetLightVisible("SpotLight_6", false);
SetSkyBoxColor(0.05, 0.05, 0.10, 1);
AddTimer("", 0.01f, "flashesOn");
}
In short: At start, he play FlashLightOn, after, FlashLightOff, after, FlashLightOn2, after, FlashLightOff2, And here, his back to the first FlashLightOn, Normally it will play forever Wink
Modifies or adds FlashLightOn / Off to vary the timer




Thanks narutohokager. I feel like an idiot. It never occurred to me that, in order to make the lightning loop, I would have to create a literal loop in the script itself. With that knowledge, I found a shorter way of doing it which would make it easier to create variations with just a single line of code.




AddTimer("", 0.1f, "flashSequence"); //loop start
}
void flashSequence(string &in asTimer)
{
AddTimer("", 5.0f, "flashes"); //I can add as many of these as I want Tongue
AddTimer("", 10.0f, "flashLoop");
}
void flashLoop(string &in asTimer)

{
AddTimer("", 0.1f, "flashSequence"); //loop end
}



Thanks again. Big Grin
No problem. Wink Dont hesitate to come back if you have another problem Big Grin