After realizing that the original tutorial by Raz0r on JACoders is now dead, I have decided to rewrite this one with a better focus on OpenJK.
Note that this tutorial is written with OpenJK in mind.
The Command itself
Each command has a basic signature that looks something like this:
void Cmd_God_f(gentity_t* ent) { // ... }
This signature is important and you'll need to use it for your Undying command, otherwise it won't work.
Somewhere in game/g_cmds.c we will be adding the function:
void Cmd_Undying_f(gentity_t* ent) { // ... }
The rest of the function is very simple. When you enter Undying mode, it displays a message stating that you are in Undying mode and sets your health and max health to 999.
#define UNDYING_HEALTH 999 void Cmd_Undying_f(gentity_t* ent) { // author: eezstreet if(!ent->client) { return; // don't do anything if they aren't a player } ent->client->ps.stats[STAT_HEALTH] = ent->health = UNDYING_HEALTH; // set our health to 999 ent->client->ps.stats[STAT_HEALTH_MAX] = UNDYING_HEALTH; // set our max health to 999 trap->SendServerCommand(ent-g_entities, "print \"Undying mode: ON\n\""); }
It's simple, yet effective. But we also need to add the toggle functionality. Simply checking the player's max health ought to do.
#define UNDYING_HEALTH 999 void Cmd_Undying_f(gentity_t* ent) { // author: eezstreet if(!ent->client) { return; // don't do anything if they aren't a player } if(ent->client->ps.stats[STAT_HEALTH_MAX] == UNDYING_HEALTH) { ent->client->ps.stats[STAT_HEALTH_MAX] = 100; // set our max health to 999. if we are over 100 health, it will count down trap->SendServerCommand(ent-g_entities, "print \"Undying mode: OFF\n\""); } else { ent->client->ps.stats[STAT_HEALTH] = ent->health = UNDYING_HEALTH; // set our health to 999 ent->client->ps.stats[STAT_HEALTH_MAX] = UNDYING_HEALTH; // set our max health to 999 trap->SendServerCommand(ent-g_entities, "print \"Undying mode: ON\n\""); } }
Linking the command - Multiplayer OpenJK
Lastly, we need to link the command. This is very simple and easy to do. Look for this table in g_cmds.c. You will need to add your own entry in this table, in alphabetical order. Since the command starts with a "u", it will appear between "t_use" and "voicecmd". The entry should look something like this:
{ "undying", Cmd_Undying_f, CMD_CHEAT|CMD_NOINTERMISSION|CMD_ALIVE },
The first column in this entry specifies what the command will be if you enter it via the console - /undying in this case.
The second column is the function which is called by the command.
The third column is flags. I'm only aware of three: CMD_CHEAT (which specifies that it's a cheat), CMD_NOINTERMISSION (which specifies that it can't be used during intermission) and CMD_ALIVE (which specifies that it can't be used while dead).
Linking the command - Singleplayer (or not OpenJK)
You'll need to add new cases to a large if/elseif block at the end of g_cmds.c/pp. See here. Otherwise, it's largely identical. Your new block will probably look like this:
else if(Q_stricmp(cmd, "undying") == 0) { Cmd_Undying_f(ent); }
Note that SP and the SDK code don't use the flag system that OpenJK does, so you'll need to check for cheat mode, being alive and not intermission on your own, within Cmd_Undying_f.
Recommended Comments
There are no comments to display.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now