This tutorial is for adding server side variables for now. I may add client side variables (and how to move them between the games) later.
Ok the first thing you should decide is where you want the variable. Do you want it to be available for all objects in the world, or just the players, or do you want it to be global (not attached to any object in particular, but available for every file and function)
Next, you should decide the type of variable you want to add. Look at this list (It's possible to create your own, but thats a different tutorial)
Finally you need a name for the variable. I'd suggest making this meaningful, rather than something like x. One good idea is to preface all your variables with a small code (like your initials) i.e. instead of calling something newpostion, I would call it sma_newposition. it make your additions easy to find, and prevents conflicting variable names.
Decided all that? Good.
I'll get to the positioning of the variable in a moment, first off I'll show you how to declare it
Fairly simple, you put the type of variable first, and then the name, followed by a semi-colon
Examples:
int sma_mytimer; vec3_t sma_mypostion; char[20] sma_myname;
Ok now we come to positioning the variable. If you want it available for every object, then you want to place it in the gentity_t structure.
Search for qboolean botDelayBegin in g_local.h (game directory).
Place the variable declaration between that and the };
i.e.
gitem_t *item; // for bonus items qboolean botDelayBegin; int sma_mytimer; // new variable is here };
Placing it just for the players is similar. search for int timeResidual; in g_local.h (game directory)
This puts you at the end of the gclient_t structure definiton. put the variable between that and the };
i.e.
gentity_t *hook; // grapple hook if out // timeResidual is used to handle events that happen every second // like health / armor countdowns and regeneration int timeResidual; int sma_mytimer; // new variable is here };
Got it? Good.
Ok, declaring it globaly is slightly different. You actualy have to declare it twice. one in a specific file, and once in g_local.h as an extern. (Extern is a key word that tells the compiler that the actual definition is in another file)
At the end of g_local.h add a declaration like the one below
extern int sma_mytimer;
The pick a file (g_main.c is a good one) and add the defintion just after all the #include lines at the top.
Bit different depending on the type of variable you've added.