ThePlasticBling wrote:would this work:
so would this work:
Code: Select all
void () mystery_box =
{
if ( (random () = 0.1) )
{
self.weapon = IT_ROCKET_LAUNCHER;
}
else
{
if ( (random () = 0.200001) )
{
self.weapon = IT_NAILGUN;
}
else
{
if ( (random () = 0.3) )
{
self.weapon = IT_SUPER_SHOTGUN;
}
else
{
if ( (random () = 0.4) )
{
self.weapon = IT_SUPER_NAILGUN;
}
}
}
}
};
First things first.
a) I strongly suggest you to read at least a bit about QuakeC syntax before trying to write any code:
This won't work as you expect. "=" means attribution in QuakeC, and
you can't assign a value to a function. So this is illegal code, and won't even compile (have you at least tried ?). For comparisons between values, you should be using "==";
b) as Spike said, random() is a function that returns a non-integer value between 0.00 and 1.00. As you may suspect, the chances to random() return
exactly 0.10 or 0.20 are slim, so you should instead test if the returned value falls in a range (0.90 to 0.99, 0.80 to 0.89, etc):
Code: Select all
if (random () >= 0.9) {// do something... }
else if (random () >= 0.8) {// do something else...}
c) finally, if you call random () in every test it will return a different value, and you actually want to test only the first value, otherwise you may end passing by all the tests and never give a weapon to the player. So, you should do this instead:
Code: Select all
local float r;
r = random ();
if (r > 0.9) {// do something}
else if (r > 0.8) {// do something else}
(...)