Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to make lightning go off randomly?
Viperdream Offline
Member

Posts: 124
Threads: 16
Joined: Jan 2011
Reputation: 0
#1
How to make lightning go off randomly?

So I have this room where I want lightning to go off randomly.

This is what I've found in the Rainy Halls map. As this is the onliest one I know that has random events.
/*Random lightning and thunder at start of level
*/
void TimerThunder(string &in asTimer)
{
    AddLocalVarInt("ThunderStep", 1);                //What step to play in the event
    float fEventSpeed = RandFloat(0.05f, 0.15f);    //The default time between steps in an event

    switch(GetLocalVarInt("ThunderStep")) {
        case 1:
            ThunderLights(2,0.05f);
        break;
        case 2:
            ThunderLights(1,0.05f);
        break;
        case 3:
            ThunderLights(3,0.05f);
        break;
        case 4:
            ThunderLights(1,0.05f);
        break;
        case 5:
            ThunderLights(2,0.05f);
        break;
        case 6:
            ThunderLights(3,0.05f);
        break;
        case 7:
            ThunderLights(1,0.3f);
            PlaySoundAtEntity("Thunder", "general_thunder.snt", "AreaThunder", 0.0f, false);
        break;
    }
    
    if(GetLocalVarInt("ThunderStep") < 8)  AddTimer("thunder", fEventSpeed, "TimerThunder");
    else {
        SetLocalVarInt("ThunderStep", 0);
        
        AddTimer("thunder", RandFloat(10.0f, 30.0f), "TimerThunder");
    }
}
void ThunderLights(int alIntensity, float afFade)
{
    /*Skip parts of a flash everynow and then but not the first strong light
    **and not the last "back to normal" light
     */
    if(RandFloat(1, 3) == 1 && (GetLocalVarInt("ThunderStep") != 3 or GetLocalVarInt("ThunderStep") != 7)) return;
    
    float fF = 0.2f;
    
    switch(alIntensity) {
        case 1:
            for(int i=0;i<=5;i++) FadeLightTo("spotthunder_"+i,0.52f,0.55f,0.6f,0.45f,-1,afFade-0.04f);
            for(int i=0;i<=7;i++) FadeLightTo("pointthunder_"+i,0.32f,0.35f,0.4f,0.2f,-1,afFade-0.025f);
            for(int i=0;i<=3;i++) FadeLightTo("ambthunder_"+i,0.2f,0.25f,0.35f,-1,-1,afFade);
        break;
        case 2:
            for(int i=0;i<=5;i++) FadeLightTo("spotthunder_"+i,0.82f+fF,0.85f+fF,0.9f+fF,0.9f+fF,-1,afFade-0.04f);
            for(int i=0;i<=7;i++) FadeLightTo("pointthunder_"+i,0.72f+fF,0.75f+fF,0.8f+fF,0.4f+fF,-1,afFade-0.025f);
            for(int i=0;i<=3;i++) FadeLightTo("ambthunder_"+i,0.25f+fF,0.3f+fF,0.4f+fF,-1,-1,afFade);
        break;
        case 3:
            for(int i=0;i<=5;i++) FadeLightTo("spotthunder_"+i,0.92f+fF,0.95f+fF,1+fF,1+fF,-1,afFade-0.04f);
            for(int i=0;i<=7;i++) FadeLightTo("pointthunder_"+i,0.82f+fF,0.85f+fF,0.9f+fF,0.5f+fF,-1,afFade-0.025f);
            for(int i=0;i<=3;i++) FadeLightTo("ambthunder_"+i,0.3f+fF,0.35f+fF,0.45f+fF,-1,-1,afFade);
        break;
    }
}


Onliest thing that I could understand were the game scripts. But I'm completely lost at the Break and Case. And what is
void ThunderLights(int alIntensity, float afFade)
I didn't even find a callback function for it.

I'm not asking you to write a script. I merely want an explanation for these things. Google didn't really make it clear for me.
So I was hoping I could get a push in the right direction here Smile

03-27-2011, 06:54 PM
Find
Pandemoneus Offline
Senior Member

Posts: 328
Threads: 2
Joined: Sep 2010
Reputation: 0
#2
RE: How to make lightning go off randomly?

It's a custom function.
The devs could have named it
void ThunderLights(int a, float b)
aswell.

And to make "random" timers, use RandInt or RandFloat.
If you use RandInt(0, 10); for example it will choose a random whole number between (and including) 0 and 10.

(This post was last modified: 03-27-2011, 07:04 PM by Pandemoneus.)
03-27-2011, 07:03 PM
Find
Viperdream Offline
Member

Posts: 124
Threads: 16
Joined: Jan 2011
Reputation: 0
#3
RE: How to make lightning go off randomly?

And what is the time between those then?

03-27-2011, 07:25 PM
Find
Pandemoneus Offline
Senior Member

Posts: 328
Threads: 2
Joined: Sep 2010
Reputation: 0
#4
RE: How to make lightning go off randomly?

AddTimer("thunder", RandFloat(10.0f, 30.0f), "TimerThunder");

Make the timer function call itself...

03-27-2011, 07:38 PM
Find




Users browsing this thread: 1 Guest(s)