Title: Random Earthquake Generator Difficulty: Easy By: Philip (aka Maj.Bitch) Email: peblair@gv.net Date: 11-24-98 Note: Please give credit where credit is due. ====================================================== 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, so I took it apart and decided to 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 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 EFFECTS TOO! Check it out! Okay, enough rumbling, let's get started! //=========================================================== Open up your p_client.c file and add these new functions just above your PutClientInServer() function... ------------------ START HERE -------------------- //=================================================== //======= 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; 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); } ------------------- END HERE --------------------- 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(); --------------------------------------------------- // 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