Inside3D!
     

Random classes

 
Post new topic   Reply to topic    Inside3d Forums Forum Index -> QuakeC Programming
View previous topic :: View next topic  
Author Message
MeTcHsteekle



Joined: 15 May 2008
Posts: 397
Location: its a secret

PostPosted: Fri Sep 04, 2009 1:20 am    Post subject: Random classes Reply with quote

so I'm having an issue [big surprise there eh?] with having random classes for players when they enter the game, it seems to just run through them really really fast instead of just having one until you die [then you get a hopefully different class] this is what i got so far:

Code:
void() getclass =
{
   local float   c;
   
   c = rint ((random()*3) + 1);
   
   if (c == 1)
   {
      //self.classtype = 0;
      centerprint(self, "light");
      self.effects = self.effects + EF_BRIGHTLIGHT;
   }
   if (c == 2)
   {
      //self.classtype = 1;
      centerprint(self, "health");
   }
   if (c == 3)
   {
      //self.classtype = 2;
      centerprint(self, "armor");
   }
   if (c == 4)
   {
      //self.classtype = 3;
      centerprint(self, "speed");
   }
};   

im not sure what the problem is :/?
_________________
bah
Back to top
View user's profile Send private message AIM Address
Electro



Joined: 29 Dec 2004
Posts: 241
Location: Brisbane, Australia

PostPosted: Fri Sep 04, 2009 12:49 pm    Post subject: Reply with quote

For starters:

Code:

void() getclass =
{
   local float   c;
   
   c = ceil(random() * 3);
   
   if (c == 1)
   {
      //self.classtype = 0;
      centerprint(self, "light");
      self.effects = self.effects + EF_BRIGHTLIGHT;
   }
   else if (c == 2)
   {
      //self.classtype = 1;
      centerprint(self, "health");
   }
   else if (c == 3)
   {
      //self.classtype = 2;
      centerprint(self, "armor");
   }
   else if (c == 4)
   {
      //self.classtype = 3;
      centerprint(self, "speed");
   }
};


Secondly... where are you calling it?
_________________
Unit reporting!
http://www.bendarling.net/
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
MeTcHsteekle



Joined: 15 May 2008
Posts: 397
Location: its a secret

PostPosted: Fri Sep 04, 2009 6:15 pm    Post subject: Reply with quote

i got a call for it in playerprethink in client.qc

under
Code:
makevectors (self.v_angle);      // is this still used

   CheckRules ();
   WaterMove ();


and that code i posted first is in weapons.qc underneath
Code:
// called by worldspawn
void() W_Precache =
{
   precache_sound ("weapons/r_exp3.wav");   // new rocket explosion
   precache_sound ("weapons/rocket1i.wav");   // spike gun
   precache_sound ("weapons/sgun1.wav");
   precache_sound ("weapons/guncock.wav");   // player shotgun
   precache_sound ("weapons/ric1.wav");   // ricochet (used in c code)
   precache_sound ("weapons/ric2.wav");   // ricochet (used in c code)
   precache_sound ("weapons/ric3.wav");   // ricochet (used in c code)
   precache_sound ("weapons/spike2.wav");   // super spikes
   precache_sound ("weapons/tink1.wav");   // spikes tink (used in c code)
   precache_sound ("weapons/grenade.wav");   // grenade launcher
   precache_sound ("weapons/bounce.wav");      // grenade bounce
   precache_sound ("weapons/shotgn2.wav");   // super shotgun
};

float() crandom =
{
   return 2*(random() - 0.5);
};


...whats the diffrence between rint and ceil random :O?
_________________
bah
Back to top
View user's profile Send private message AIM Address
Dr. Shadowborg
Inside3D Staff


Joined: 16 Oct 2004
Posts: 726

PostPosted: Fri Sep 04, 2009 10:17 pm    Post subject: Reply with quote

Well, first playerprethink is a horrible place to put it. Put it somewhere where it will work properly, like somewhere in putclientinserver() or some such.

Also, crandom isn't short for ceil random. (I have no idea what it's short for actually) What it does is flip at random, from either a positive or a negative value. i.e. crandom()*1 will result in either regular 1 or -1. (Yes, I know this explanation sucks.)
_________________
"Roboto suggests Plasma Bazooka."
Back to top
View user's profile Send private message
MeTcHsteekle



Joined: 15 May 2008
Posts: 397
Location: its a secret

PostPosted: Sat Sep 05, 2009 2:13 am    Post subject: Reply with quote

ah okay, i had a feeling that prethink wasn't gonna work for some reason, but i didn't know where i should have put it.

also, that explanation is better then the one in the qcrm which was:
Quote:
10.1.2. ceil
float ceil(float val)
Returns val, rounded up to the integer above (like the equivalent function in C).
.

anyways thanks guys it works now Very Happy, now to have the classes actually do something...
_________________
bah
Back to top
View user's profile Send private message AIM Address
Dr. Shadowborg
Inside3D Staff


Joined: 16 Oct 2004
Posts: 726

PostPosted: Sat Sep 05, 2009 3:43 am    Post subject: Reply with quote

Extra tip:

rint will return whatever you feed it rounded to whatever integer is closest. i.e. 0.1 will return 0 whereas 0.9 will return 1.

ceil will always round up whatever you feed it, meaning regardless of whether it's 0.1 or 0.9 it will always return 1.

floor does the exact opposite of ceil. (Always rounding down, meaning regardless of whether you feed it 0.1 or 0.9 it will always return 0.)

These are actually pretty useful functions when you don't want fractional figures and whatnot. (i.e. wierd stuff like "you got 1.5 shells" Wink )
_________________
"Roboto suggests Plasma Bazooka."
Back to top
View user's profile Send private message
FrikaC
Site Admin


Joined: 08 Oct 2004
Posts: 947

PostPosted: Tue Sep 08, 2009 2:09 pm    Post subject: Re: Random classes Reply with quote

MeTcHsteekle wrote:

self.effects = self.effects + EF_BRIGHTLIGHT;


Use the | symbol, not +. Plus means to add the value of EF_BRIGHTFIELD (1) in. If it's already got this bit set it will clear it, and flip the next highest bit and so on up, ie addition. Meaning if its 1, it will become 2 which is EF_MUZZLEFLASH. If 2, it will become 3, if 3 it will become 4. As it ever increases all the bits, since we're adding 1, will be toggled. Each of those values are combinations of completely unrelated bit flags.

The | symbol "if bit is set on the left side OR on the right side, the bit is set in the result". This is the typical operation used in setting bitflags.
Back to top
View user's profile Send private message Send e-mail
MeTcHsteekle



Joined: 15 May 2008
Posts: 397
Location: its a secret

PostPosted: Wed Sep 09, 2009 12:54 am    Post subject: Reply with quote

ah thanks for the info guys, greatly appreciated :}
_________________
bah
Back to top
View user's profile Send private message AIM Address
Lardarse



Joined: 05 Nov 2005
Posts: 243
Location: Bristol, UK

PostPosted: Tue Sep 15, 2009 1:40 am    Post subject: Reply with quote

Dr. Shadowborg wrote:
Also, crandom isn't short for ceil random. (I have no idea what it's short for actually)

Centered random?
_________________
<ekiM> Son, you're writing data structures your CPU can't cache.
Back to top
View user's profile Send private message
Orion



Joined: 12 Jan 2007
Posts: 413
Location: Brazil

PostPosted: Tue Sep 15, 2009 3:35 am    Post subject: Reply with quote

The difference between random() and crandom() is that random() returns a decimal between 0 and 1. crandom() will return a decimal between -1 and 1. Smile
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Inside3d Forums Forum Index -> QuakeC Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2004 phpBB Group