diff options
author | shennetsind <ind@henn.et> | 2013-02-16 22:33:13 -0200 |
---|---|---|
committer | shennetsind <ind@henn.et> | 2013-02-16 22:33:13 -0200 |
commit | b8379d2dc56197dc970db8bf1c0ba60ae4835819 (patch) | |
tree | aca11affcf4392479304800ab56bd0281cd29ab5 /src/map/atcommand.c | |
parent | 4ce4adceac3bde1e778c2b9e53b4a4954049f349 (diff) | |
download | hercules-b8379d2dc56197dc970db8bf1c0ba60ae4835819.tar.gz hercules-b8379d2dc56197dc970db8bf1c0ba60ae4835819.tar.bz2 hercules-b8379d2dc56197dc970db8bf1c0ba60ae4835819.tar.xz hercules-b8379d2dc56197dc970db8bf1c0ba60ae4835819.zip |
@skillid Improvement
As suggested by Streusel and backed by the development team, @skillid now supports partial search.
Signed-off-by: shennetsind <ind@henn.et>
Diffstat (limited to 'src/map/atcommand.c')
-rw-r--r-- | src/map/atcommand.c | 42 |
1 files changed, 31 insertions, 11 deletions
diff --git a/src/map/atcommand.c b/src/map/atcommand.c index e54166019..320ca83ff 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -5379,27 +5379,47 @@ ACMD_FUNC(clearcart) * @skillid by [MouseJstr] * lookup a skill by name *------------------------------------------*/ -ACMD_FUNC(skillid) -{ - int skillen, idx; +#define MAX_SKILLID_PARTIAL_RESULTS 5 +#define MAX_SKILLID_PARTIAL_RESULTS_LEN 74 /* "skill " (6) + "%d:" (up to 5) + "%s" (up to 30) + " (%s)" (up to 33) */ +ACMD_FUNC(skillid) { + int skillen, idx, i, found = 0; + DBIterator* iter; + DBKey key; + DBData *data; + char partials[MAX_SKILLID_PARTIAL_RESULTS][MAX_SKILLID_PARTIAL_RESULTS_LEN]; + nullpo_retr(-1, sd); - if (!message || !*message) - { + if (!message || !*message) { clif_displaymessage(fd, msg_txt(1163)); // Please enter a skill name to look up (usage: @skillid <skill name>). return -1; } skillen = strlen(message); - - for (idx = 0; idx < MAX_SKILL_DB; idx++) { - if (strnicmp(skill_db[idx].name, message, skillen) == 0 || strnicmp(skill_db[idx].desc, message, skillen) == 0) - { - sprintf(atcmd_output, msg_txt(1164), idx, skill_db[idx].desc); // skill %d: %s + + iter = db_iterator(skilldb_name2id); + + for( data = iter->first(iter,&key); iter->exists(iter); data = iter->next(iter,&key) ) { + idx = skill_get_index(db_data2i(data)); + if (strnicmp(key.str, message, skillen) == 0 || strnicmp(skill_db[idx].desc, message, skillen) == 0) { + sprintf(atcmd_output, msg_txt(1164), db_data2i(data), skill_db[idx].desc, key.str); // skill %d: %s (%s) clif_displaymessage(fd, atcmd_output); + } else if ( found < MAX_SKILLID_PARTIAL_RESULTS && ( stristr(key.str,message) || stristr(skill_db[idx].desc,message) ) ) { + snprintf(partials[found++], MAX_SKILLID_PARTIAL_RESULTS_LEN, msg_txt(1164), db_data2i(data), skill_db[idx].desc, key.str); } } - + + dbi_destroy(iter); + + if( found ) { + sprintf(atcmd_output, msg_txt(1398), found); // -- Displaying first %d partial matches + clif_displaymessage(fd, atcmd_output); + } + + for(i = 0; i < found; i++) { /* partials */ + clif_displaymessage(fd, partials[i]); + } + return 0; } |