Difference between revisions of "Hercules Plugin Manager"

From Hercules Wiki
Jump to: navigation, search
(Created page with "Often referred to as the HPM, the '''Hercules Plugin Manager''' is yet another Hercules Original = Building a plugin = While the C code for the plugin normally won...")
 
(Updated malformed links and file references)
Line 20: Line 20:
 
Support for Hooks will be enabled within the next [[HPM]] release.
 
Support for Hooks will be enabled within the next [[HPM]] release.
 
== HPM @commands ==
 
== HPM @commands ==
The [[HPM]] makes it very simple to provide [[@command|@commands]] through plugins.<br/>
+
The [[HPM]] makes it very simple to provide [[Atcommand|atcommands]] through plugins.<br/>
You define a new [[@command]] exactly as it'd normally be done in [[src/map/atcommand.c]].<br/>
+
You define a new atcommand exactly as it'd normally be done in {{git|src/map/atcommand.c}}<br/>
 
'''Example:'''
 
'''Example:'''
 
  ACMD(sample) {//@sample command - 5 params: const int fd, struct map_session_data* sd, const char* command, const char* message, struct AtCommandInfo *info
 
  ACMD(sample) {//@sample command - 5 params: const int fd, struct map_session_data* sd, const char* command, const char* message, struct AtCommandInfo *info
Line 33: Line 33:
 
A full usage of this is demonstrated in the [[HPM]]'s sample {{git|src/plugins/sample.c}}
 
A full usage of this is demonstrated in the [[HPM]]'s sample {{git|src/plugins/sample.c}}
 
== HPM Script Commands ==
 
== HPM Script Commands ==
The [[HPM]] makes it very simple to provide [[Script_Commands|script commands]] through plugins.<br/>
+
The [[HPM]] makes it very simple to provide [[Category:Script_Command|script commands]] through plugins.<br/>
You define a new [[Script_Commands|script command]] exactly as it'd normally be done in [[src/map/script.c]].<br/>
+
You define a new script command exactly as it'd normally be done in {{git|src/map/script.c}}<br/>
 
'''Example:'''
 
'''Example:'''
 
  BUILDIN(sample) {//script command 'sample(num);' - 1 param: struct script_state* st
 
  BUILDIN(sample) {//script command 'sample(num);' - 1 param: struct script_state* st
Line 46: Line 46:
 
A full usage of this is demonstrated in the [[HPM]]'s sample {{git|src/plugins/sample.c}}
 
A full usage of this is demonstrated in the [[HPM]]'s sample {{git|src/plugins/sample.c}}
 
== HPM Console Commands ==
 
== HPM Console Commands ==
The [[HPM]] makes it very simple to provide [[Console_Commands|console commands]] through plugins.<br/>
+
The [[HPM]] makes it very simple to provide [[Category:Console_Command|console commands]] through plugins.<br/>
You define a new [[Console_Commands|console command]] exactly as it'd normally be done in [[src/common/console.c]].<br/>
+
You define a new console command exactly as it'd normally be done in {{git|src/common/console.c}}<br/>
 
'''Example:'''
 
'''Example:'''
 
  CPCMD(sample) {//console command 'sample' - 1 param: char *line
 
  CPCMD(sample) {//console command 'sample' - 1 param: char *line

Revision as of 23:10, 10 June 2013

Often referred to as the HPM, the Hercules Plugin Manager is yet another Hercules Original

Contents

Building a plugin

While the C code for the plugin normally won't have discrepancies, in order to compile the plugin certain criteria must be met depending on your Operating System, there are 2 guides below, one for windows and other for everything else (which should work on any *nix distro, as well as on OSX).

Windows
Building HPM Plugin for MSVC
All Others
Building HPM Plugin for gcc

Creating a plugin

After following the building a plugin guide, all thats left is for your plugin's code to be made, the following will guide you through the basics of how a HPM plugin works.

HPM Events

Events are functions in a plugin that are triggered by the Hercules Plugin Mananger when they meet certain criteria.

  • void plugin_init (void)
    • Triggered when the server starts
  • void plugin_final (void)
    • Triggered when the server starts to shut itself down
  • void server_ready (void)
    • Triggered after the server is done starting, and is online.

With the HPM you only need to code the events your plugin will use.

HPM Hooks

Support for Hooks will be enabled within the next HPM release.

HPM @commands

The HPM makes it very simple to provide atcommands through plugins.
You define a new atcommand exactly as it'd normally be done in src/map/atcommand.c
Example:

ACMD(sample) {//@sample command - 5 params: const int fd, struct map_session_data* sd, const char* command, const char* message, struct AtCommandInfo *info
	clif->message(fd,"You used the @sample command!");
	ShowDebug("I'm being run! message -> '%s' by '%s'\n",message,sd->status.name);
	return true;
}

After that you just have to link your new command, to do that you use the void plugin_init (void) event.

HPMi->addCommand("sample",ACMD_A(sample));

and voila, your plugin now adds the @sample command. A full usage of this is demonstrated in the HPM's sample src/plugins/sample.c

HPM Script Commands

The HPM makes it very simple to provide through plugins.
You define a new script command exactly as it'd normally be done in src/map/script.c
Example:

BUILDIN(sample) {//script command 'sample(num);' - 1 param: struct script_state* st
	int arg = script_getnum(st,2);
	ShowInfo("I'm being run! arg -> '%d'\n",arg);
	return true;
}

After that you just have to link your new script command, to do that you use the void plugin_init (void) event.

HPMi->addScript("sample","i",BUILDIN_A(sample)); //note the 2nd param is this commands' arg-types (in this case, a number)

and voila, your plugin now adds the sample script command. A full usage of this is demonstrated in the HPM's sample src/plugins/sample.c

HPM Console Commands

The HPM makes it very simple to provide through plugins.
You define a new console command exactly as it'd normally be done in src/common/console.c
Example:

CPCMD(sample) {//console command 'sample' - 1 param: char *line
	ShowInfo("I'm being run! arg -> '%s'\n",line?line:"NONE");
}

After that you just have to link your new script command, to do that you use the void plugin_init (void) event.

addCPCommand("this:is:a:sample",CPCMD_A(sample)); // note the first param is the path to this command, in this case it translates to 'this is a sample' and everything afterwards is the commands' params

and voila, your plugin now adds the sample console command. A full usage of this is demonstrated in the HPM's sample src/plugins/sample.c

HPM Function Overloading

Thanks to Hercules Renewal Phase One, you're capable of overloading all functions covered by the Hercules Renewal Phase One interfaces, with your plugin.
Example:

int my_custom_check_target_function( struct block_list *src, struct block_list *target,int flag) {
	//<...> code
}
struct battle_interface *battle;
void server_ready(void) {
	battle = GET_SYMBOL("battle");
	battle->check_target = &my_custom_check_target_function;
}

and voila, your plugin just overloaded the game server's battle_check_target function with your plugin's own, this is greatly handy to ensure your customs do not create conflicts when updating your Hercules Repository

Other Features

Is there something you'd like to do with your plugin that requires modifications to HPM's core? let we know, and we'll do our best to make it happen.
Post your suggestions here

Support

Need help writing your plugin? post your question on our support forum