TheGreatCthulhu
Member
Posts: 213
Threads: 10
Joined: Oct 2010
Reputation:
32
|
RE: Sounds don't play
OK. Using your original script as a starting point, it would look something like this:
funcdef void WindFunc(); WindFunc@[] functions(3);
void OnEnter() { AddTimer("", 1, "Wind");
// Note that the indices start from 0, not 1! @functions[0] = @windysound_1; @functions[1] = @windysound_2; @functions[2] = @windysound_3;
}
void Wind (string &in asTimer) { AddTimer("", 0.1, "Windy"); PlaySoundAtEntity("wind_amb", "wind_amb.snt", "", 1.f, false); }
void Windy (string &in asTimer) { CreateParticleSystemAtEntity("", "ps_dust_whirl", "Windy_"+RandInt(1, 7), false);
int index = RandInt(0, functions.length() - 1); // in this case same as RandInt(0, 2) WindFunc@ f = functions[index]; f();
AddTimer("", RandInt(1.0, 7.0), "Windy"); }
void windysound_1() { PlaySoundAtEntity("", "scare_wind.snt", "Windy_"+RandInt(1, 7), 0.f, false); }
void windysound_2() { PlaySoundAtEntity("", "scare_wind_reverse.snt","Windy_"+RandInt(1, 7), 0.f, false); }
void windysound_3() { PlaySoundAtEntity("", "general_wind_whirl_rand.snt", "Windy_"+RandInt(1, 7), 0.f, false); }
The only difference to your original code is that here I declared the funcdef at the top, and the function pointer array right after it. Then all the function pointers inside the array are set to point to windysound_#() functions.
And then, in place of your
"windysound_"+RandInt(1, 3);
line, there's this instead:
int index = RandInt(0, functions.length() - 1); // in this case same as RandInt(0, 2)
WindFunc@ f = functions[index];
f();
P.S. I just noticed I made an accidental mistake in my previous post; wherever it says Action it should say WindFunc instead. In my test code I named it Action, but then decided to change it to WindFunc in order for it to make more sense in your map. Gonna edit the post to correct.
The timer based alternative would go like this:
void OnEnter() { AddTimer("", 1, "Wind"); }
void Wind (string &in asTimer) { AddTimer("", 0.1, "Windy"); PlaySoundAtEntity("wind_amb", "wind_amb.snt", "", 1.f, false); }
void Windy (string &in asTimer) { CreateParticleSystemAtEntity("", "ps_dust_whirl", "Windy_"+RandInt(1, 7), false); AddTimer("", 0.0f, "windysound_" + RandInt(1, 3)); // <--------- here
AddTimer("", RandInt(1.0, 7.0), "Windy"); // <--- BTW, you probably wanted RandFloat() here? }
void windysound_1(string &in asTimer) { AddDebugMessage("wnd_1", false); PlaySoundAtEntity("", "scare_wind.snt", "Windy_"+RandInt(1, 7), 0.f, false); }
void windysound_2(string &in asTimer) { AddDebugMessage("wnd_2", false); PlaySoundAtEntity("", "scare_wind_reverse.snt","Windy_"+RandInt(1, 7), 0.f, false); }
If using timers, make sure that you change the parameter lists for windysound_#() functions to match those required for timer callbacks.
With funcdefs you don't need to do that - funcdef can be defined to point to a function with arbitrary parameter list and return type (see the tutorial from a few posts above), so they offer more flexibility.
|
|