QuakeZone
MOD Coding Tutorials
Quake II Coding Tutorials!

Introduction
Code
Notes
Exercises
Quake II Coding Tutorials

10 Thunderbolt Pick-up

Introduction Introduction

This tutorial explains how to create thunderbolts as pick-ups. It is based on the Lightning gun tutorial on the Quakestyle Tutorials page (see links) and requires that this tutorial has already been implemented.

This tutorial explains how to fire thunderbolts once in a player's possession. It does not explain how to spawn them - I will leave this as a task for the reader, although I may create a tutorial on this in the future.

Code Code


g_items.c

Find the list of items added to itemlist, and add the following entry:


	// PJT - thunderbolt
	{
		"item_thunderbolt",
		NULL,
		NULL,
		NULL,
		NULL,
		"items/pkup.wav",
		NULL,
	    0,
		NULL,
		"w_blaster",
		"Thunderbolt",
		0,
		1,
		NULL,
		NULL,
		0,
		NULL,
		0,
		"models/proj/lightning/tris.md2"	},
	// PJT
		


g_weapon.c

The changes to procedure fire_lightning are documented in tutorial 09, lightning rockets:


p_weapon.c

Replace the entire procedure Weapon_Thunderbolt_Fire with the following:

// PJT - lightning bolt

//======================================================================

//OM-LGUN
void Weapon_Thunderbolt_Fire (edict_t *ent)
{	vec3_t	offset, start;
	vec3_t	forward, right;
	int 	ammo;
	int 	damage;
	int 	toasty;

	/* PJT - not weapon
	if (!(ent->client->buttons & BUTTON_ATTACK))
	{
		ent->client->ps.gunframe++;
	}
	else
	*/
	{
		/* 	PJT - check for pick up
		if (! ent->client->pers.inventory[ent->client->ammo_index] )
		{
			if (level.time >= ent->pain_debounce_time)
			{
				gi.sound(ent, CHAN_VOICE, gi.soundindex("weapons/noammo.wav"), 1, ATTN_NORM, 0);
				ent->pain_debounce_time = level.time + 1;
			}
			NoAmmoWeaponChange (ent);
		}
		else
		*/
		{
			damage = TBOLT_DAMAGE;
			if (is_quad)
			{
				toasty = 8000;
				damage *= 4;
			}
			else
				toasty = 2000;

			// PJT	if (ent->client->ps.gunframe == 6) // if its starting. do the initial bolt sound
				gi.sound(ent, CHAN_WEAPON, gi.soundindex("weapons/lfire.wav"), 1, ATTN_NORM, 0);
			gi.sound(ent, CHAN_AUTO, gi.soundindex("weapons/tesla.wav"), .5, ATTN_NORM, 0);
			if (ent->waterlevel == 3) //ZZZZZZZZZAAAAAAAAAAAAAAAPPPPPPP!!!!!!
			{
				/* PJT - no ammo
				ent->client->pers.inventory[ent->client->ammo_index] = 0;
				*/
				T_RadiusDamage(ent, ent, toasty, NULL, toasty, MOD_TBOLT_DISCHARGE);
				return;
			}
			AngleVectors (ent->client->v_angle, forward, right, NULL);
			VectorScale (forward, -2, ent->client->kick_origin);
			VectorSet(offset, 8, 8, ent->viewheight - 8);
			P_ProjectSource (ent->client, ent->s.origin, offset, forward, right, start);
			fire_lightning (ent, start, forward, NULL, 0, damage);  // PJT - new parameters
			PlayerNoise(ent, start, PNOISE_WEAPON);
			/* PJT - no ammo
			if (! ( (int)dmflags->value & DF_INFINITE_AMMO ) )
				ent->client->pers.inventory[ent->client->ammo_index] -= TBOLT_CELLS;
			*/
			ent->client->pers.inventory[ITEM_INDEX(FindItem("Thunderbolt"))] -= 1;
		}
	}
	/* PJT - no weapon frame
	ent->client->ps.gunframe++;
	if (ent->client->ps.gunframe == 12 && ent->client->pers.inventory[ent->client->ammo_index])
		ent->client->ps.gunframe = 7;
	*/
}

// PJT
		

g_cmds.c

To the top of the file, add the following prototype:

void Weapon_Thunderbolt_Fire (edict_t *ent);		
		
Then, in procedure ClientCommand, add the following lines at the indicated position:
// PJT - thunderbolt
   	else if (Q_stricmp (cmd, "tbolt") == 0)
		Cmd_Thunder_f (ent);
// PJT

 	else if (Q_stricmp (cmd, "gameversion") == 0)
 		gi.cprintf (ent, PRINT_HIGH, "%s : %s\n", GAMEVERSION, __DATE__);
		
Finally, at the end of the file, add the following procedure:
// PJT - thunderbolt
void Cmd_Thunder_f (edict_t *ent)
{
	if (ent->client->pers.inventory[ITEM_INDEX(FindItem("Thunderbolt"))] > 0 )
		Weapon_Thunderbolt_Fire (ent);
	else
		gi.cprintf (ent, PRINT_HIGH, "You are fresh out of thunderbolts.\n");
}
// PJT
		


cmds.cfg

To your config file, add the following bind key command:

		bind t "tbolt"
		
Notes Notes to code


g_items.c
  • Thunderbolt is added as an item to the game's list of items
  • the file name of the lightning model is included so that it is pre-loaded when a game starts

p_weapon.c
  • Weapon_Thunderbolt_Fire is the procedure added by the Quakestyle Lightning Gun tutorial when a lightning bolt is fired:
    • all references to ammunition have been removed - instead the cost is to reduce the number of thunderbolts in possession
    • the changes to the gun frame are removed as these are not relevant to the use of a picked-up object
    • the parameters to fire_lightning have now changed - see tutorial 09, lightning rockets

g_cmds.c
  • the prototype is required by Cmd_Thunder_f for calling the procedure to fire thunderbolts
  • ClientCommand processes ...um... client commands entered in the console:
    • Cmd_Thunder_f is called when the key for thunderbolts is pressed
  • Cmd_Thunder_f calls Weapon_Thunderbolt_Fire above to unleash a thunderbolt if the player holds one, otherwise a message is displayed.
Exercises Exercises

  • create code for spawning and collection of thunderbolts


Page last updated 25th November 2000