
Ok! This tutorial will add in some infrared goggles into your Q2 mod. These goggles and their functionality are effectively copied from the Rogue Mission Pack source code, and modified by me not to function like a powerup.
First things first, we're going to set up the command to switch on the goggles. Open up G_CMDS.C and scroll down to right above the function ClientCommand. Insert the following:
void Cmd_Infrared_f (edict_t *ent) // PSY: IR Goggles
{ if (ent->client->goggles) // we're on { ent->client->goggles = 0; ent->client->ps.rdflags &= ~RDF_IRGOGGLES; } else // we're off { ent->client->goggles = 1; ent->client->ps.rdflags |= RDF_IRGOGGLES; }}
This sets up the command for the goggles, toggle-ing the ent->client->goggles variable and setting the RDF_IRGOGGLES flag as necessary.
Now we need to set up the drain of cells on the goggles. Open up the P_CLIENT.C file and go down into ClientThink. Right before the line "gi.linkentity(ent);" add the following:
// PSY: GOGGLES DRAIN if (ent->client->goggles) {if (ent->client->pers.inventory[ITEM_INDEX(FindItem("Cells"))] >= 1)
{ent->client->goggledrain ++;
if (ent->client->goggledrain == 10)
{ent->client->pers.inventory[ITEM_INDEX(FindItem("Cells"))] -= 1;
ent->client->goggledrain = 0;
}}
else
{
ent->client->ps.rdflags &= ~RDF_IRGOGGLES;ent->client->goggles = 0;
}
}
This handles the goggle drain. You need one more block of code, to make the players visible to the Infrared scanning. Go into P_VIEW.C and find G_SetClientEffects(). Go down right before the line "if (ent->powerarmor_time > level.time)":
if (!(ent->s.renderfx & RF_IR_VISIBLE)) ent->s.renderfx |= RF_IR_VISIBLE;
This ensures that the player is always visible (even dead) to IR. The final thing you need to do is go into G_LOCAL.H and add in two new client variables into the gclient_s structure, after the line "qboolean update_chase;" insert the following:
int goggles; int goggledrain;
And that's it! IR goggles! Enjoy!
Tutorial by Psykotik