|
QuakeZone MOD Coding Tutorials
|
|
|
Introduction Pre-requisites Code Notes Exercises |
|
| Introduction |
|
|
This tutorial describes enhancements made to QDevel's original teamplay tutorial, to add team names and team switching (via console). The players can then use "switch 1|2" on the console to switch teams, provided
the host has enabled team switching with the sv_allowswitch variable.
|
| Pre-requisites |
|
|
| Code |
|
|
g_local.h Add the following cvar references as indicated: // PJT - team play extern cvar_t *sv_teamname1; // team names extern cvar_t *sv_teamname2; extern cvar_t *sv_allowswitch; // allow team switching // PJT <-- end of insert #define world (&g_edicts[0])Then add the following to the end of the file:
// PJT - team play
typedef struct
{
char *name; // team name
int score; // team score
} team_data;
extern team_data team_table[];
// PJT
p_client.c Add to the top of the file, just after the include statements: cvar_t *sv_teamname1; // PJT - team names cvar_t *sv_teamname2; cvar_t *sv_allowswitch; // PJT - teams - allow switchingAdd the following to the top of the code as indicated:
void SP_misc_teleporter_dest (edict_t *ent); // <-- insert after this line
// PJT - team play
team_data team_table[] =
{
{"", 0},
{"RedNasties", 0},
{"BlueMeanies", 0}
}
;
Then, in procedure AssignTeam (new procedure added by the QDevels tutorial) amend
the following line as indicated:
// if (current > 4)
if (current > maxteams) // PJT - "maxteams" was "4"
At the end of the same procedure add the following lines:
// PJT - team names gi.bprintf (PRINT_MEDIUM, "%s has joined team %s.\n", self->client->pers.netname, team_table[self->client->resp.team].name); g_save.c At the end of procedure InitGame add the following lines:
// PJT - team play
sv_teamname1 = gi.cvar("sv_teamname1","Red_Team", CVAR_SERVERINFO); // team names
sv_teamname2 = gi.cvar("sv_teamname2","Blue_Team", CVAR_SERVERINFO); // team names
team_table[1].name = sv_teamname1->string;
team_table[2].name = sv_teamname2->string;
sv_allowswitch = gi.cvar("sv_allowswitch","0", CVAR_SERVERINFO); // allow team switching
// PJT
g_cmds.c Add the following lines into procedure ClientCommand as indicated: // PJT - team play - switch teams else if (Q_stricmp (cmd, "switch") == 0) Cmd_Switch_f (ent); // PJT <-- end of insert else if (Q_stricmp (cmd, "gameversion") == 0) gi.cprintf (ent, PRINT_HIGH, "%s : %s\n", GAMEVERSION, __DATE__);Then add the following procedure at the end of the file:
// PJT - team play
/* allows players to switch between teams */
void Cmd_Switch_f (edict_t *ent)
{
int i, maxteams;
maxteams = 2;
// check switch allowed
if (!(sv_allowswitch->value))
{
gi.cprintf (ent, PRINT_HIGH, "Team switching is not enabled.\n");
return;
}
// check valid team number entered
i = atoi (gi.argv(1));
if ((i < 1) || (i > maxteams))
{
gi.cprintf (ent, PRINT_HIGH, "Invalid team number entered.\n");
return;
}
// check not same team
if (i == ent->client->resp.team)
{
gi.cprintf (ent, PRINT_HIGH, "You are already on team %i.\n", i);
return;
}
// switch to that team (and set score to zero - cannot carry frags to new team)
ent->client->resp.score = 0;
ent->client->resp.team = i;
gi.bprintf (PRINT_MEDIUM, "%s has joined team %s.\n",
ent->client->pers.netname,
team_table[ent->client->resp.team].name);
AssignSkin(ent, Info_ValueForKey (ent->client->pers.userinfo, "skin"));
}
// PJT
cmds.cfg Add the following lines to your game config file: set sv_teamname1 Red_Nasties set sv_teamname2 Blue_Meanies set sv_allowswitch 1 |
| Notes |
|
|
g_local.h
p_client.c
g_save.c
g_cmds.c
cmds.cfg
|
| Exercises |
|
|