Forum

Localized "Random()"?

Discuss programming in the QuakeC language.

Moderator: InsideQC Admins

Localized "Random()"?

Postby Ghost_Fang » Thu Sep 02, 2010 3:57 am

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?
};
Ghost_Fang
 
Posts: 336
Joined: Thu Nov 12, 2009 4:37 am

Postby Urre » Thu Sep 02, 2010 6:07 am

I've never experienced the problem you're describing. If you show us some code, we might be able to help track down the problem more easily!

Yours sincerely

Bananas
I was once a Quake modder
User avatar
Urre
 
Posts: 1109
Joined: Fri Nov 05, 2004 2:36 am
Location: Moon

Postby r00k » Thu Sep 02, 2010 8:14 am

GLOBAL as in attenuation?

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

Postby Spike » Thu Sep 02, 2010 8:25 am

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.
Spike
 
Posts: 2892
Joined: Fri Nov 05, 2004 3:12 am
Location: UK

Postby r00k » Thu Sep 02, 2010 5:47 pm

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...
r00k
 
Posts: 1110
Joined: Sat Nov 13, 2004 10:39 pm

Postby frag.machine » Thu Sep 02, 2010 6:47 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)
User avatar
frag.machine
 
Posts: 2090
Joined: Sat Nov 25, 2006 1:49 pm

Postby Ghost_Fang » Thu Sep 02, 2010 7:53 pm

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.
Ghost_Fang
 
Posts: 336
Joined: Thu Nov 12, 2009 4:37 am

Postby r00k » Fri Sep 03, 2010 4:02 am

It might be a bit confusing since you are using knight animation frames with the zombie?

Also you only have 0.2 chance of playing one of 3 sounds.
Try, < 0.33 >0.66 else...
r00k
 
Posts: 1110
Joined: Sat Nov 13, 2004 10:39 pm

Postby Ghost_Fang » Fri Sep 03, 2010 4:54 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.
Ghost_Fang
 
Posts: 336
Joined: Thu Nov 12, 2009 4:37 am

Postby Spike » Fri Sep 03, 2010 7:06 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.
Spike
 
Posts: 2892
Joined: Fri Nov 05, 2004 3:12 am
Location: UK

Postby hondobondo » Fri Sep 03, 2010 7:46 am

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

Postby Ghost_Fang » Fri Sep 03, 2010 8:16 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


Return to QuakeC Programming

Who is online

Users browsing this forum: No registered users and 1 guest