Localized "Random()"?
Moderator: InsideQC Admins
12 posts
• Page 1 of 1
Localized "Random()"?
I have an observation followed by a question. My friend had made me some zombie sounds, a few for each action, sight, idle, attack, etc. And i thought it would be really simple to make it random for each sound to be played. so i did the correct random code an stuff and it worked great. Until i tested it with a horde, turns out that "random()" is global? Is that correct? If 3 or 4 zombies attacked at the same, it played the same sound. If there was a group and they saw you ALL of them played the same sight sound.
If (random() == global) (lol)
{
How do i make it per enitity? Is it possible? Or at least what can i do to make it different enough to that any sound initiated at the same time wont be the same?
};
If (random() == global) (lol)
{
How do i make it per enitity? Is it possible? Or at least what can i do to make it different enough to that any sound initiated at the same time wont be the same?
};
- Ghost_Fang
- Posts: 336
- Joined: Thu Nov 12, 2009 4:37 am
GLOBAL as in attenuation?
example:
ATTN_NORM makes it not a global sound
example:
- Code: Select all
rs = rint((random() * 5) + 1);
self.noise = "";
if (rs == 1)
self.noise = "player/pain1.wav";
else if (rs == 2)
self.noise = "player/pain2.wav";
else if (rs == 3)
self.noise = "player/pain3.wav";
else if (rs == 4)
self.noise = "player/pain4.wav";
else if (rs == 5)
self.noise = "player/pain5.wav";
else
self.noise = "player/pain6.wav";
sound (self, CHAN_VOICE, self.noise, 1, ATTN_NORM);
ATTN_NORM makes it not a global sound
- r00k
- Posts: 1110
- Joined: Sat Nov 13, 2004 10:39 pm
random will return a different value each time its called. it has nothing to do with the entity that is currently set to self.
You're just being unlucky, or you're swamping the client with too many sounds for it to play them all at once, or something. Or maybe the one that you do hear is just a little louder.
You're just being unlucky, or you're swamping the client with too many sounds for it to play them all at once, or something. Or maybe the one that you do hear is just a little louder.
- Spike
- Posts: 2892
- Joined: Fri Nov 05, 2004 3:12 am
- Location: UK
Oops! Late night->morning post i misread his situation.
Though, if the channel is GLOBAL then only one sound will be heard.
A method to possibly hear each zombie "moan" individually,
without overlapping could be to stagger the time when they make
the noise. This way as one sound is ending another sound can use that channel.
Yet this may sound like a "left-to-right" crowd cheering
His problem is not unlike the start of e1m3, with a high skill value,
when there are 3 or more zombies, moan same sound, and when u gib them with the GL, they make the same noise at the same time...
Though, if the channel is GLOBAL then only one sound will be heard.
A method to possibly hear each zombie "moan" individually,
without overlapping could be to stagger the time when they make
the noise. This way as one sound is ending another sound can use that channel.
Yet this may sound like a "left-to-right" crowd cheering
His problem is not unlike the start of e1m3, with a high skill value,
when there are 3 or more zombies, moan same sound, and when u gib them with the GL, they make the same noise at the same time...
- r00k
- Posts: 1110
- Joined: Sat Nov 13, 2004 10:39 pm
If you want to ensure every zombie plays a different sound from the other, don't use random(). Keep the last played sight sound index as a global var and refer to it, updating when using the value:
- Code: Select all
float sight_sound;
string () nextZombieSightSound =
{
sight_sound = sight_sound + 1;
if ((sight_sound > MAX_SIGHT_SOUNDS) || (!sight_sound))
{
sight_sound = 1;
}
if (sight_sound == 1)
{
return ("zombie/sight1.wav");
}
else if (sight_sound == 2)
{
return ("zombie/sight2.wav");
}
// (...)
else
{
return ("zombie/sightN.wav");
}
};
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC
(LordHavoc)
-

frag.machine - Posts: 2090
- Joined: Sat Nov 25, 2006 1:49 pm
This is basically what I was doing to try to randomize sounds:
It worked well with one zombie, but in hordes, some zombies attacked at the same time playing the same sound, and it gets kind of annoying when 3 or 4 zombies are making the same exact sounds 90% of the time.
But I used frag.machine's method and it seemed to randomize it a bit more. I only did it to sight and attack. Those were the only 2 real problems.
- Code: Select all
void() knight_runatk1 =[ $runattack1, knight_runatk2 ]
{
if (random() < 0.4)
sound (self, CHAN_WEAPON, "knight/attack1.wav", 1, ATTN_NORM);
else if (random() > 0.7)
sound (self, CHAN_WEAPON, "knight/attack3.wav", 1, ATTN_NORM);
else
sound (self, CHAN_WEAPON, "knight/attack2.wav", 1, ATTN_NORM);
ai_charge(20);
};
It worked well with one zombie, but in hordes, some zombies attacked at the same time playing the same sound, and it gets kind of annoying when 3 or 4 zombies are making the same exact sounds 90% of the time.
But I used frag.machine's method and it seemed to randomize it a bit more. I only did it to sight and attack. Those were the only 2 real problems.
- Ghost_Fang
- Posts: 336
- Joined: Thu Nov 12, 2009 4:37 am
how many digits does random() do? i thought it was only to the tenth decimal (0.X) it does it to the hundredth? If i would have known i would have done that.
This is what i was thinking:
< 0.4 would be 0.1, 0.2, and 0.3.
> 0.7 would be 0.8, 0.9, and 1.0
else would be 0.4, 0.5, and 0.6
This was when i thought random() only did tenth decimal.
This is what i was thinking:
< 0.4 would be 0.1, 0.2, and 0.3.
> 0.7 would be 0.8, 0.9, and 1.0
else would be 0.4, 0.5, and 0.6
This was when i thought random() only did tenth decimal.
- Ghost_Fang
- Posts: 336
- Joined: Thu Nov 12, 2009 4:37 am
the 'spec' doesn't mention a precision anywhere. Which can change depending on platform anyway..
Its a number between 0 and 1.
There's generally more than 1k graduations.
Its a number between 0 and 1.
There's generally more than 1k graduations.
- Spike
- Posts: 2892
- Joined: Fri Nov 05, 2004 3:12 am
- Location: UK
Ghost_Fang wrote:This is basically what I was doing to try to randomize sounds:
- Code: Select all
void() knight_runatk1 =[ $runattack1, knight_runatk2 ]
{
if (random() < 0.4)
sound (self, CHAN_WEAPON, "knight/attack1.wav", 1, ATTN_NORM);
else if (random() > 0.7)
sound (self, CHAN_WEAPON, "knight/attack3.wav", 1, ATTN_NORM);
else
sound (self, CHAN_WEAPON, "knight/attack2.wav", 1, ATTN_NORM);
ai_charge(20);
};
It worked well with one zombie, but in hordes, some zombies attacked at the same time playing the same sound, and it gets kind of annoying when 3 or 4 zombies are making the same exact sounds 90% of the time.
But I used frag.machine's method and it seemed to randomize it a bit more. I only did it to sight and attack. Those were the only 2 real problems.
you will get better results the more sounds you have to choose from. also maybe some sounds are louder than others? this will affect your perception of what sounds are being used
- hondobondo
- Posts: 207
- Joined: Tue Sep 26, 2006 2:48 am
Yea, the more the better would make it even more random, and they are all about the same volume. And they are very distinctive between each other so i would be able to tell regardless.
- Ghost_Fang
- Posts: 336
- Joined: Thu Nov 12, 2009 4:37 am
12 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 1 guest
