Jump to content

Jedi Academy turned 20 this year! We celebrated in a ton of different ways: mod contest, server event, podcast, etc. Thank you to all who have been a part of this game for the last two decades. Check out the anniversary content!

Read more

Welcome to JKHub

This community is dedicated to the games Star Wars: Jedi Outcast (2002) and Jedi Academy (2003). We host over 3,000 mods created by passionate fans around the world, and thousands of threads of people showcasing their works in progress and asking for assistance. From mods to art to troubleshooting help, we probably have it. If we don't, request or contribute!

Get started

This game turned 20 years old this year, and it is still one of the greatest Star Wars games of all time. If you're new or returning from a long hiatus, here are the basics of getting started with Star Wars Jedi Knight Jedi Academy in 2023.

Read more

Making a Command - Serverside


eezstreet

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.


User Feedback

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...