TUTORIAL 1 - Creating Classes
by Fritz

This tutorial is intended to help you create a class based mod in which players can choose from a variety of classes, each with its own unique abilities/attributes. When this tutorial is completed you should be able to choose your class (by selecting a model) and recieve different weapons and attributes based on the class you chose.

there are only 4 simple steps to this tutorial, so let's get started.

Files you will need to modify:
g_local.h
g_client.c

1. Creating Variables (g_local.h)

First lets create some member variables to keep track of what class you are. We will need a playerclass variable to keep track of what class we are, and a newplayerclass variable to store the new class we will become when we respawn.
Go to about line 122
int			health;	
int			playerclass;	
int			newplayerclass;

I'm not sure if this is the most appropriate place to put this but it works.

2. Choosing Classes (g_client.c)

Ok, now we have to assign values to our newplayerclass variable when the player selects a model. The function we are about to edit is called when a client first connects to the server and whenever the player changes his user info.
Go to about line 621
	
// set model	Q_strncpyz( model, Info_ValueForKey (userinfo, "model"), sizeof( model ) );
	
if (!Q_stricmp (model, "biker/red")) 		ent->newplayerclass = 1;
	else if (!Q_stricmp (model, "anarki/blue"))		ent->newplayerclass = 2;
	else if (!Q_stricmp (model, "grunt/red"))		ent->newplayerclass = 3;
 	else {		ent->newplayerclass = 1;
 		Q_strncpyz( model, "biker/red", sizeof( model ) );
	} 	
  
So far there are only class values for a couple of models, but you could easily assign values to the rest of the models. You could also assign the same number to multiple models, which would be useful if you wanted to make all the biker models, or all the larger models, etc. the same class.

If the player chooses a model that has not been asigned a class variable then they will be set to the first class by default and be given the "biker/red" model.

3.Updating The Class(g_client.c)

Once a player has died we want to put the newplayerclass into playerclass when they respawn.
Go down to about line 935
	ent->flags = 0;	

	ent->playerclass = ent->newplayerclass;
  
You are finished creating your class system! You should see if your code compiles correctly at this point, but there will be absolutely no noticable changes if you run it.

2. Assigning stuff to the classes (g_client.c)

The final thing you have to do is give the players different stuff depending on what class they are.
Go to about line 945
	
if ( g_gametype.integer == GT_TEAM ) {		client->ps.ammo[WP_MACHINEGUN] = 50;
	} else {		client->ps.ammo[WP_MACHINEGUN] = 100;
	}	

//assign weapons according to class
	if(ent->playerclass==1){ 		client->ps.stats[STAT_WEAPONS] |= ( 1 << WP_BFG );
		client->ps.ammo[WP_BFG] = 20;
	}
	else if(ent->playerclass==2){
 		client->ps.stats[STAT_WEAPONS] |= ( 1 << WP_RAILGUN );
		client->ps.ammo[WP_RAILGUN] = 20;
	}
	else {
		client->ps.stats[STAT_WEAPONS] |= ( 1 << WP_LIGHTNING );
		client->ps.ammo[WP_LIGHTNING] = 20;
	}

You now have working classes! Right now the only thing that distinguishes the classes are the weapons they begin with but you could easily give them different speeds, health, armour, special abilities, etc. So now its your job to flesh out your classes and make your mod interesting.