PDA

View Full Version : NEW Gm command to find model Id's


Trackye
09-20-2015, 06:26 PM
I was trying to add weapons to my NPC's and was unable to use #npcedit Weapon (ID) command without searching in my database for the modelid...


So i created this GM command that returns the Model ID when you search for an item by itemid. For example.

I type #finditemmodel 14383 and it returns
Innoruuk's Curse - IT145.

Very simple.
The searching by item NAME and working as well but MUCH more reliable to search by item id.

I realize this is not a MAJOR improvement or feature but it made my life MUCH MUCH easier.

I did not provide a Diff because nothing is being removed. Just added.

Command.h
Line 157 I added

void command_finditemmodel(Client *c, const Seperator *sep);


and Command.cpp
Line 446 I added

command_add("finditemmodel", "- #finditemmodel searches for model of an item based on provided item ID", 0, command_finditemmodel) ||


Line 2841 I added

void command_finditemmodel(Client *c, const Seperator *sep)
{
if(sep->arg[1][0] == 0) {
c->Message(0, "Usage: #finditemmodel [search criteria]");
return;
}

std::string query;

int id = atoi((const char *)sep->arg[1]);
if (id == 0) // If id evaluates to 0, then search as if user entered a string.
query = StringFormat("SELECT name, idfile FROM items WHERE name LIKE '%%%s%%'", sep->arg[1]);
else // Otherwise, look for just that item id.
query = StringFormat("SELECT name, idfile FROM items WHERE id = %i", id);

auto results = database.QueryDatabase(query);
if (!results.Success()) {
c->Message (0, "Error querying database.");
c->Message (0, query.c_str());
}

if (results.RowCount() == 0) // No matches found.
c->Message (0, "No matches found for %s.", sep->arg[1]);

// If query runs successfully.
int count = 0;
const int maxrows = 20;

// Process each row returned.
for (auto row = results.begin(); row != results.end(); ++row) {
// Limit to returning maxrows rows.
if (++count > maxrows) {
c->Message (0, "%i modelid's shown. Too many results.", maxrows);
break;
}

c->Message (0, " %s: %s", row[0], row[1]);
}

// If we did not hit the maxrows limit.
if (count <= maxrows)
c->Message (0, "Query complete. %i rows shown.", count);

}


Thanks!

AdrianD
09-20-2015, 07:21 PM
/cheer

/10char