diff options
author | cookiecrumbs <cookiecrumbs@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2012-07-22 05:15:32 +0000 |
---|---|---|
committer | cookiecrumbs <cookiecrumbs@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2012-07-22 05:15:32 +0000 |
commit | 52ed37bd877a4f462171a1501ec1ab2c4fd19eea (patch) | |
tree | ef42647de9b19016dac41e1a6899891a8d69074c /src/map/atcommand.c | |
parent | 04ce57ecc743ec95e79fedab7e00bc650e386d23 (diff) | |
download | hercules-52ed37bd877a4f462171a1501ec1ab2c4fd19eea.tar.gz hercules-52ed37bd877a4f462171a1501ec1ab2c4fd19eea.tar.bz2 hercules-52ed37bd877a4f462171a1501ec1ab2c4fd19eea.tar.xz hercules-52ed37bd877a4f462171a1501ec1ab2c4fd19eea.zip |
Added the ability to bind atcommands to NPC events (ex: NPCNAME::OnEvent); original version by ToastOfDoom however heavily modified by I enabling command level at the invoking/character (@/#) level and fixes to prevent console errors as well as fixes aimed to ensure compatibility with rAthena.
Updated the script_commands.txt documentation with the following script commands: bindatcmd, unbindatcmd and useatcmd.
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@16471 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/map/atcommand.c')
-rw-r--r-- | src/map/atcommand.c | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/src/map/atcommand.c b/src/map/atcommand.c index afa22b392..15f75d55a 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -85,6 +85,17 @@ static AtCommandInfo* get_atcommandinfo_byname(const char *name); // @help static const char* atcommand_checkalias(const char *aliasname); // @help static void atcommand_get_suggestions(struct map_session_data* sd, const char *name, bool atcommand); // @help +// @commands (script-based) +struct Atcmd_Binding* get_atcommandbind_byname(const char* name) +{ + int i = 0; + if( *name == atcommand_symbol || *name == charcommand_symbol ) + name++; // for backwards compatibility + ARR_FIND( 0, ARRAYLENGTH(atcmd_binding), i, strcmp(atcmd_binding[i].command, name) == 0 ); + return ( i < ARRAYLENGTH(atcmd_binding) ) ? &atcmd_binding[i] : NULL; + return NULL; +} + //----------------------------------------------------------- // Return the message string of the specified number by [Yor] //----------------------------------------------------------- @@ -8987,6 +8998,9 @@ bool is_atcommand(const int fd, struct map_session_data* sd, const char* message TBL_PC * ssd = NULL; //sd for target AtCommandInfo * info; + // @commands (script based) + Atcmd_Binding * binding; + nullpo_retr(false, sd); //Shouldn't happen @@ -9063,7 +9077,33 @@ bool is_atcommand(const int fd, struct map_session_data* sd, const char* message //check to see if any params exist within this command if( sscanf(atcmd_msg, "%99s %99[^\n]", command, params) < 2 ) params[0] = '\0'; - + + // @commands (script based) + if(type == 1) { + // Check if the command initiated is a character command + if (*message == charcommand_symbol && + (ssd = map_nick2sd(charname)) == NULL && (ssd = map_nick2sd(charname2)) == NULL ) + { + sprintf(output, "%s failed. Player not found.", command); + clif_displaymessage(fd, output); + return true; + } + + // Get atcommand binding + binding = get_atcommandbind_byname(command); + + // Check if the binding isn't NULL and there is a NPC event, level of usage met, et cetera + if( binding != NULL && binding->npc_event[0] && + ((*atcmd_msg == atcommand_symbol && pc_get_group_level(sd) >= binding->level) || + (*atcmd_msg == charcommand_symbol && pc_get_group_level(sd) >= binding->level2))) + { + // Check if self or character invoking; if self == character invoked, then self invoke. + bool invokeFlag = ((*atcmd_msg == atcommand_symbol) ? 1 : 0); + npc_do_atcmd_event((invokeFlag ? sd : ssd), command, params, binding->npc_event); + return true; + } + } + //Grab the command information and check for the proper GM level required to use it or if the command exists info = get_atcommandinfo_byname(atcommand_checkalias(command + 1)); if (info == NULL) { |