Tutorial: My First Quake III Arena Mod
So, we've loaded our mod as qvm files. That's good, but it's not really exciting. Right now we've made no actual changes to the source code, so what you're playing now is just plain old vanilla Quake 3. So let's dig in and make our first changes to the game.
So lets see, what are the things that our mod needs. I'll list them here:
- There are no weapon or ammo pickups in the map.
- Players hold only one weapon at any given moment.
- Players that die are spawned again with the initial weapon.
- When a player makes a frag, he moves on to the next weapon.
- Ammo is unlimited.
- When a player scores a frag with the last weapon, he scores a large number of bonus points.
- Players must not drop weapons when they die.
- Ammo must not be displayed on the hud since it's always unlimited
- We want server admins to be able to determine the order in which players progress through the weapons.
- We want to display a message on all player's screens when a player gets the last weapon.
Taking a closer look at the code
So far we've seen that there are 3 relevant projects in here: cgame, game and q3_ui. The cgame project deals with all things that are related to the client. In other words: it contains code that is specific for one player in the match and this is executed on the player's own computer.
The game project is code that runs on the server. It contains code for tracking and updating gamestate.
Finally there's the q3_ui project which contains code related to the in-game menus. In this tutorial, we won't be doing anything with the q3_ui project, but cgame and game are edited.
Last but not least, it helps a bit to get a general idea of what the filename prefixes are for. Most obvious one are these prefixes:
- ai_ files are related to bot AI
- g_ files are related to serverside game code
- cg_ files are related to clientside game code
- bg_ files are files that are shared between the cgame and game projects and are related to shared client/server functions, such as network prediction
Removing weapons from the playing field
Our first task is to remove all weapons and ammo from the levels. We don't want players to pick up any ammo or weapons because they should stick strictly to the weapon the are currently using. Stopping ammo and weapons from spawning is rather easy. Check out the file g_items.c in the game project. You'll find the G_SpawnItem function here. It takes an (empty) as input and an item definition. It applies the correct properties to the entity based on the item definition that's passed and spawns it. What we can simply do here is check if the item definition defines a weapon or ammo box and simply skip the entire function if this is the case. This is done by simply adding the following line right at the top of the function:
if (item->giType != IT_WEAPON && item->giType != IT_AMMO)
IT_WEAPON and IT_AMMO are enum values defined in bg_public.h. Ofcourse the rest of the code must be closed within curly brackets: { and }. The result is that whenever the game tries to spawn a weapon or an ammo box, this code makes sure it doesn't happen. Obviously this is not the ideal way to do this, because right now, we have an entity in the server's memory that holds up space while it's not visible or used in the game. In other words: it's a waste of resources. It's not as bad as I make it sound though: in a normal game of Q3A these enitites are there as well, so it doens't degrade performance. In a future update of the mod, we might be looking more closely at this to optimize things like this. Compile the game again (either as dll's or qvm's. Remember to use the right vm_ settings in q3config.cfg). Check out the map and see how all weapon and ammo pickups are gone.