
I was looking through the code
and saw that there was some
earthquake code in the Id source but it seemed to be too
integrated with the world to just use their code, but it gave
me a great idea! So I took that code apart and put together
my own random earthquake generator! So, now you can add
random ground shaking and earthquake rumbling noises to your
mod and shake the bastards to their knees!!
How it works:
Simple! You put the generator
into the PutClientInServer()
function and the first time a player connects they'll activate
the earthquake generator (only gets activated once) and from that
point onward, the generator will randomly generate earthquakes
at intervals every 2..10 minutes and the duration of shaking
will last for between 10..20 seconds. COOL!! Neat Effect too!
Check it out!
Okay, enough rumbling, let's get
started!
Add in the blue code and take out any pink code.
NOTE: You'll need my
G_ClientInGame() helper functions which
I have not put into this tutorial. Please refer to many of
my previous tutorials for those helper functions..
Open up your p_client.c file and
add these new functions just
above your PutClientInServer() function...
![]()
//===================================================
//======= RANDOM EARTHQUAKE GENERATOR CODE ==========
//===================================================
//===================================================
void Earthquake_Think(edict_t *quake) {
int i;
edict_t *ent;
// Make rumbling
sounds..
if (quake->wait < level.time) {
gi.positioned_sound(quake->s.origin, quake, CHAN_AUTO,
gi.soundindex("world/quake.wav"), 1.0, ATTN_NONE, 0);
quake->wait = level.time + 0.5; }
// Shake around all
clients in game..
for(i=0;i < game.maxclients;i++) {
ent=g_edicts+i+1;
if (!G_ClientInGame(ent)) continue;
if (!ent->groundentity) continue; // Is ent currently airborne??
ent->groundentity = NULL; // If not, then keep'em on the ground..
ent->velocity[0] += crandom()*250;
ent->velocity[1] += crandom()*150;
ent->velocity[2] = 250*(100.0/ent->mass); }
// Time to stop
shaking yet..
if (level.time < quake->delay)
quake->nextthink = level.time + 0.1;
else {
quake->nextthink = level.time + (2*60) + (60*(rand()%8));
quake->delay=quake->nextthink + 10 + 10*(rand()%10); }
}
//===================================================
void Init_Earthquake_Generator(void) {
edict_t *quake;
static int i=0;
// First time thru
all init..
if (i!=0) return;
i=1; // Set so only
init ONCE!
quake = G_Spawn();
quake->classname = "EarthQuake";
VectorClear(quake->s.origin);
quake->svflags |= SVF_NOCLIENT;
quake->wait=0;
quake->think = Earthquake_Think;
// Random Earthquakes
every 2..10 minutes
quake->nextthink = level.time + (2*60) + (60*(rand()%8));
// Duration of
shaking 10..20 seconds..
quake->delay=quake->nextthink + 10 + 10*(rand()%10);
gi.linkentity(quake);
}
![]()
Don't worry about unlinking this
entity because we want it
active the entire level and the engine will unlink it
automatically anyway when the level changes...
Lastly, at the very top of your
PutClientInServer() function
add the following lines as shown..
![]()
void PutClientInServer(edict_t
*ent) {
---------- ADD THESE LINES RIGHT
HERE ---------------
// Start the
Earthquake Generator
Init_Earthquake_Generator();
---------------------------------------------------
rest of code continues on....
// find a spawn point
// do it before setting health back up, so farthest
// ranging doesn't count this client
SelectSpawnPoint(ent, spawn_origin, spawn_angles);
This will initialize the
generator when the first player
is put into the game!
That's it!! Now get out there
and SHAKE UP THE BASTARDS!!
Have Fun!!
philip