Theres a lot of little things we code which seem redundant as someone has likely done it before. You can spend a lot of time reinventing the wheel and less time working on the new fun things.
I will make a page on DP Wiki and update it with these if we see fit.
I'll start it off:
This method will play a random sound. I find I have to do this alot so why not make a method for this.
Code: Select all
// Spike:
string(string fmt, string sub1) format_s =
{
float p;
p = strstrofs(fmt, "%s", 0);
if (p == -1)
return fmt;
return strcat(substring(fmt, 0, p), sub1, substring(fmt, p+2, -1));
};
/* randomSound
Same as sound() except takes a float cnt.
plays a random variant of the sound. for example:
randomSound(self,CHAN_BODY,"Sounds/Player/pl_step%s.wav",0.3,ATTN_IDLE,3);
plays randomly Sounds/Player/pl_step1.wav,
Sounds/Player/pl_step2.wav, or
Sounds/Player/pl_step3.wav
EXT used:
FRIK_FILE
FTE_STRINGS
*/
void(entity e, float chan, string samp, float vol, float atten, float cnt) randomSound = {
float r;
r = floor(random() * cnt) + 1;
sound(e, chan, format_s(samp,ftos(r)), vol, atten);
};
FRIK_FILE, FTE_STRING