Index | FAQ | Search | Memberlist | Usergroups | Profile | Log in to check your private messages | Log in | Register

Random classes

| 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 |

Posted: Fri Sep 04, 2009 1:20 am Post subject: 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:

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 |

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

Posted: Fri Sep 04, 2009 12:49 pm Post subject: |

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 |

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

Posted: Fri Sep 04, 2009 6:15 pm Post subject: |

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 |

Dr. Shadowborg Inside3D Staff Joined: 16 Oct 2004 Posts: 726 |

Posted: Fri Sep 04, 2009 10:17 pm Post subject: |

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 |

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

Posted: Sat Sep 05, 2009 2:13 am Post subject: |

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 , now to have the classes actually do something...
_________________
bah

Back to top |

Dr. Shadowborg Inside3D Staff Joined: 16 Oct 2004 Posts: 726 |

Posted: Sat Sep 05, 2009 3:43 am Post subject: |

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" )
_________________
"Roboto suggests Plasma Bazooka."

Back to top |

FrikaC Site Admin Joined: 08 Oct 2004 Posts: 947 |

Posted: Tue Sep 08, 2009 2:09 pm Post subject: 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.

Back to top |

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

Posted: Wed Sep 09, 2009 12:54 am Post subject: |

ah thanks for the info guys, greatly appreciated :} _________________ bah

Back to top |

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

Posted: Tue Sep 15, 2009 1:40 am Post subject: |

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 |

Orion Joined: 12 Jan 2007 Posts: 414 Location: Brazil |

Posted: Tue Sep 15, 2009 3:35 am Post subject: |

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.

Back to top |

Display posts from previous:

| 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