Inside3D tutorials.
Created By: Drywall
eMail: drywall@telefragged.com
Difficulty Scale: Easy


Step 1
In this tutorial, you will learn all you'll ever need to know about lighting of objects by testing them on various guns. There are 4 simple things that you can with the lighting effects that are hard-coded into quake.exe, and I'll demonstrate all of them.

As always, add the code in blue, delete the code in red, and leave the rest of the code alone.
Step 2
Alright, he first thing you have to do, is fire up whatever text editor you have, and open the weapons.qc file. Now, scroll to the launch_spike void.

/*
===============
launch_spike
Used for both the player and the ogre
===============
*/
void(vector org, vector dir) launch_spike =
{
    newmis = spawn ();
    newmis.owner = self;
    newmis.movetype = MOVETYPE_FLYMISSILE;
    newmis.solid = SOLID_BBOX;

    newmis.angles = vectoangles(dir);

    newmis.touch = spike_touchl;
    newmis.classname = "spike";
    newmis.think = SUB_Remove;
    newmis.nextthink = time + 6;
    setmodel (newmis, "progs/spike.mdl");
    setsize (newmis, VEC_ORIGIN, VEC_ORIGIN);
    setorigin (newmis, org);
    newmis.velocity = dir * 1000;
    newmis.effects = newmis.effects | EF_BRIGHTFIELD // Spikes will now
                                                     // have a glowing field around it
};
Now you may be wondering what you just did. Well, I won't tell you. Hehe just kidding. What you just did was add a 'brightfield' effect to the spike. The EF_BRIGHTFIELD effect puts a bunch of yellow spots around the object. No, I don't believe the color can be changed. The 'brightfield's are useful for creating weapons that are supposed to have a poisonous or hallucinogenic effect. And yes, I can't spell :) If you like this effect, compile and run. If not, scrap it and go on to Step 3.

Step 3
Alrighty, now I'll teach you about what's probably the two most useful of the effects. EF_BRIGHTLIGHT and EF_DIMLIGHT. You may recall these from my flaregun tutorial. Well, that's how you'd use these. Again in weapons.qc, scroll to the void W_FireRocket. Examine the code below.
/*
================
W_FireRocket
================
*/
void() W_FireRocket =
{
    local   entity missile, mpuff;
    self.currentammo = self.ammo_rockets = self.ammo_rockets - 1;
    sound (self, CHAN_WEAPON, "weapons/sgun1.wav", 1, ATTN_NORM);
    self.punchangle_x = -2;
    missile = spawn ();
    missile.owner = self;
    missile.movetype = MOVETYPE_FLYMISSILE;
    missile.solid = SOLID_BBOX;
    missile.classname = "missile";
// set missile speed
    makevectors (self.v_angle);
    missile.velocity = aim(self, 1000);
    missile.velocity = missile.velocity * 1000;
    missile.angles = vectoangles(missile.velocity);
    missile.touch = T_MissileTouch;
// set missile duration
    missile.nextthink = time + 5;
    missile.think = SUB_Remove;
    missile.effects = missile.effects | EF_BRIGHTLIGHT // Makes the rocket shiny (or use EF_DIMLIGHT)
    setmodel (missile, "progs/missile.mdl");
    setsize (missile, '0 0 0', '0 0 0');
    setorigin (missile, self.origin + v_forward*8 + '0 0 16');
};
Alright, what did you do? Well, this is another simple lighting effect, that causes, obvioulsy, a bright light. This is great for flares, but that's honestly just about it. If you like nice shiny rockets, save & comiple. Otherwise, um I dunno, if you don't like this, why did you bother programming it ? :)
Step 4
Now for the final lighting effect, EF_MUZZLEFLASH, which when the room lights up upon the firing of the object. Now remember, effects can only be applied to entities. In weapons, the entities are projectiles. Because the shotguns and lightining gun don't fire projectiles (they pretend to, but they don't actually launch an entity), it's much harder to add effects to anything shot from them. So, we'll use the nailgun once again. This time, I'll show you how to combine effects as well.
/*
===============
launch_spike
Used for both the player and the ogre
===============
*/
void(vector org, vector dir) launch_spike =
{
    newmis = spawn ();
    newmis.owner = self;
    newmis.movetype = MOVETYPE_FLYMISSILE;
    newmis.solid = SOLID_BBOX;
    
    newmis.angles = vectoangles(dir);
    
    newmis.touch = spike_touch;
    newmis.classname = "spike";
    newmis.think = SUB_Remove;
    newmis.nextthink = time + 6;
    setmodel (newmis, "progs/spike.mdl");
    setsize (newmis, VEC_ORIGIN, VEC_ORIGIN);
    setorigin (newmis, org);
    newmis.velocity = dir * 1000;
    newmis.effects = newmis.effects | EF_BRIGHTFIELD | EF_MUZZLEFLASH // Spikes will now have 
//a glowing field around it, and briefly make a light in the room.
};
Alright, here's what you just did. The " | "s mean 'and', and so you said 'make the effects what they were, plus the bright lights, plus the muzzle flash. Now the nailgun will light up when shooting nails, and the nails will be all funky lookin :)


Step 5
So. We've now gone over every single effect that you can easily use to light an entity. You can now make flares, poison, lighting guns, and all sorts of things. To run any of these, simply save, compile, and run as usual.