QuakeZone
MOD Coding Tutorials
Quake II Coding Tutorials!

Introduction
Pre-requisites
Code
Notes
Exercises
Quake II Coding Tutorials

13 Creating Random Spawn Points

Introduction Introduction

This tutorial describe show to generate a table of random spawn points, useful when spawning pick-up items, such as Tech pick-ups (cf).

These spawn points are not strictly random as they are merely the spawn points of already existing items. In the case of this tutorial, they are those items that are not allowed to spawn (in Team Rocket, no weapons or ammo items are spawned, so their spawn points are used to build our table).

Pre-requisites Pre-requisites

  • None.
Code Code


g_local.h

At the end of structure level_locals_t, add the following 2 lines:

	vec3_t		spawn_points[50];	// random spawn points
	int		num_spawn_points;	// number of spawn points	
		

g_spawn.c

In procedure InitGame, add the following line at the indicated position:

	skill = gi.cvar ("skill", "1", CVAR_LATCH);
	maxentities = gi.cvar ("maxentities", "1024", CVAR_LATCH);

	level.num_spawn_points = 0;		// PJT - spawn points	
		

g_items.c

In procedure SpawnItem, add the following lines at the start of the procedure:

	// PJT - spawn points
	// create spawn points for disallowed items
	// only spawn armour and health (but may still get disallowed by dm flags)
	if (!(item->pickup == Pickup_Health || item->pickup == Pickup_Adrenaline ||
		  item->pickup == Pickup_AncientHead || item->pickup == Pickup_Armor ||
	  	  item->pickup == Pickup_PowerArmor))
	{
		// PJT - spawn rockets
		if (level.num_spawn_points < 51)
		{
			level.num_spawn_points++;
			VectorCopy(ent->s.origin, level.spawn_points[level.num_spawn_points - 1]);
		}
		// PJT
		G_FreeEdict (ent);
		return;
	}
	// PJT
		
Notes Notes to code


g_local.h
  • the level structure is amended to hold a table for the spawn points, and a counter for the number of used spawn points

g_spawn.c
  • InitGame has been amended so that, at the start of every game, the spawn point count is reset

g_items.c
  • SpawnItem has been amended to store the spawn co-ordinates of any item that is not spawned in the mod. This was particularly suited to Team Rocket as all weapons and ammo items are disallowed.
Exercises Exercises

Nope, can't think of any. If I come up with a method for truly random spawn points that don't end up in lava I will post it on this site.


Page last updated 3rd December 2001