Adding new Commands to EQ2Emu

Tutorials on setting up a server, configuring your client, and connecting to an EQ2Emulator server.
Only moderators can start new topics here
Forum rules
Most information about EQ2Emulator and Tutorials can be found at the Project Wiki. Look there for the most current information.
Locked
User avatar
John Adams
Retired
Posts: 9684
Joined: Thu Jul 26, 2007 6:27 am
EQ2Emu Server: EQ2Emulator Test Center
Characters: John
Location: Arizona
Contact:

Adding new Commands to EQ2Emu

Post by John Adams » Mon Feb 21, 2011 11:34 am

This involved editing the C++ code, and following our coding standards (should you choose to submit your work for integration into the base code). Please keep this in mind when submitting code changes.
Open Commands.h. Go through the code til you find the defines for COMMAND_*
Example:

Code: Select all

#define COMMAND_SPAWN				1
Note that our Command Handlers have a numerical, logical order to them. Let's keep it that way. If you are adding a command to an existing system, try and insert your command handler in an available ID grouped with other similar handlers. If no available (sequential) ID, then it's okay to add a new one to the bottom of the pile, using the next highest available ID.

We'll use adding a whole new ID as an example. At the end of the COMMAND_* defines, note what the last ID is. As of this writing, it was 279. We'll insert a new (bogus) command at the end.

Code: Select all

#define COMMAND_BOGUS 280
Save Commands.h

Open Commands.cpp, and search through the current switch for a logical place to insert your code - usually at the end for new commands. Since right now this is simply to get code in place to handle the right-click / create commands, the code is generic:

Code: Select all

		case COMMAND_BOGUS: {
			client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You just created a BOGUS command!");
			break;
Save Commands.cpp and compile! If you have no errors, your code is fine.
Next step is to create the `commands` entry in your world to handle the new slash command. Go to your `commands` table using your favorite MySQL editor and insert a new record for the command 'bogus'.

Code: Select all

INSERT INTO `commands`(`id`,`type`,`command`,`subcommand`,`handler`,`required_status`) VALUES ( NULL,'0','bogus','','280','0');
That should tell the world to allow you to type /bogus at a command line, and see the resulting message you created in code.
"You just created a BOGUS command!"

Locked

Who is online

Users browsing this forum: No registered users and 0 guests