Random classes
Moderator: InsideQC Admins
10 posts
• Page 1 of 1
Random classes
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:
im not sure what the problem is :/?
- Code: Select all
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
- MeTcHsteekle
- Posts: 399
- Joined: Thu May 15, 2008 10:46 pm
- Location: its a secret
For starters:
Secondly... where are you calling it?
- Code: Select all
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?
Benjamin Darling
http://www.bendarling.net/
Reflex - In development competitive arena fps combining modern tech with the speed, precision and freedom of 90's shooters.
http://www.reflexfps.net/
http://www.bendarling.net/
Reflex - In development competitive arena fps combining modern tech with the speed, precision and freedom of 90's shooters.
http://www.reflexfps.net/
- Electro
- Posts: 312
- Joined: Wed Dec 29, 2004 11:25 pm
- Location: Brisbane, Australia
i got a call for it in playerprethink in client.qc
under
and that code i posted first is in weapons.qc underneath
...whats the diffrence between rint and ceil random :O?
under
- Code: Select all
makevectors (self.v_angle); // is this still used
CheckRules ();
WaterMove ();
and that code i posted first is in weapons.qc underneath
- Code: Select all
// 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
- MeTcHsteekle
- Posts: 399
- Joined: Thu May 15, 2008 10:46 pm
- Location: its a secret
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.)
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.)
-

Dr. Shadowborg - InsideQC Staff
- Posts: 1110
- Joined: Sat Oct 16, 2004 3:34 pm
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:
anyways thanks guys it works now
, now to have the classes actually do something...
also, that explanation is better then the one in the qcrm which was:
.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
bah
- MeTcHsteekle
- Posts: 399
- Joined: Thu May 15, 2008 10:46 pm
- Location: its a secret
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"
)
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"
-

Dr. Shadowborg - InsideQC Staff
- Posts: 1110
- Joined: Sat Oct 16, 2004 3:34 pm
Re: Random classes
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.
- FrikaC
- Site Admin
- Posts: 1026
- Joined: Fri Oct 08, 2004 11:19 pm
10 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 1 guest