summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/script_commands.txt4
-rw-r--r--src/map/script.c75
-rw-r--r--src/map/script.h3
3 files changed, 60 insertions, 22 deletions
diff --git a/doc/script_commands.txt b/doc/script_commands.txt
index cb0314ac5..66dd96463 100644
--- a/doc/script_commands.txt
+++ b/doc/script_commands.txt
@@ -3277,6 +3277,7 @@ Example:
---------------------------------------
*getiteminfo(<item ID>, <type>)
+*getiteminfo("<item name>", <type>)
*setiteminfo(<item ID>, <type>, <value>)
This function will look up the item with the specified ID number in the
@@ -3285,6 +3286,9 @@ It will return -1 if there is no such item.
Valid types are:
+ ITEMINFO_ID - Item ID (getiteminfo() only!)
+ ITEMINFO_AEGISNAME - Unique name to reference the item (getiteminfo() only!)
+ ITEMINFO_NAME - Display name (getiteminfo() only!)
ITEMINFO_BUYPRICE - Buy Price
ITEMINFO_SELLPRICE - Sell Price
ITEMINFO_TYPE - Item Type
diff --git a/src/map/script.c b/src/map/script.c
index 0cfd6da73..73bfca5b9 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -14780,24 +14780,34 @@ static BUILDIN(getitemslots)
return true;
}
-// TODO: add matk here if needed
-
-/*==========================================
- * Returns some values of an item [Lupus]
- * Price, Weight, etc...
- *------------------------------------------*/
+/**
+ * Returns various information about an item.
+ *
+ * @code{.herc}
+ * getiteminfo(<item ID>, <type>);
+ * getiteminfo("<item name>", <type>);
+ * @endcode
+ *
+ **/
static BUILDIN(getiteminfo)
{
- int item_id = script_getnum(st, 2);
- int n = script_getnum(st, 3);
- struct item_data *it = itemdb->exists(item_id);
+ struct item_data *it;
+
+ if (script_isstringtype(st, 2)) { /// Item name.
+ const char *name = script_getstr(st, 2);
+ it = itemdb->search_name(name);
+ } else { /// Item ID.
+ it = itemdb->exists(script_getnum(st, 2));
+ }
if (it == NULL) {
script_pushint(st, -1);
return true;
}
- switch (n) {
+ int type = script_getnum(st, 3);
+
+ switch (type) {
case ITEMINFO_BUYPRICE:
script_pushint(st, it->value_buy);
break;
@@ -14909,16 +14919,24 @@ static BUILDIN(getiteminfo)
case ITEMINFO_STACK_AMOUNT:
script_pushint(st, it->stack.amount);
break;
- case ITEMINFO_STACK_FLAG:
- {
- int stack_flag = 0;
- if (it->stack.inventory != 0) stack_flag |= 1;
- if (it->stack.cart != 0) stack_flag |= 2;
- if (it->stack.storage != 0) stack_flag |= 4;
- if (it->stack.guildstorage != 0) stack_flag |= 8;
- script_pushint(st, stack_flag);
- }
+ case ITEMINFO_STACK_FLAG: {
+ int stack_flag = 0;
+
+ if (it->stack.inventory != 0)
+ stack_flag |= 1;
+
+ if (it->stack.cart != 0)
+ stack_flag |= 2;
+
+ if (it->stack.storage != 0)
+ stack_flag |= 4;
+
+ if (it->stack.guildstorage != 0)
+ stack_flag |= 8;
+
+ script_pushint(st, stack_flag);
break;
+ }
case ITEMINFO_ITEM_USAGE_FLAG:
script_pushint(st, it->item_usage.flag);
break;
@@ -14928,11 +14946,21 @@ static BUILDIN(getiteminfo)
case ITEMINFO_GM_LV_TRADE_OVERRIDE:
script_pushint(st, it->gm_lv_trade_override);
break;
+ case ITEMINFO_ID:
+ script_pushint(st, it->nameid);
+ break;
+ case ITEMINFO_AEGISNAME:
+ script_pushstr(st, it->name);
+ break;
+ case ITEMINFO_NAME:
+ script_pushstr(st, it->jname);
+ break;
default:
- ShowError("buildin_getiteminfo: Invalid item type %d.\n", n);
- script_pushint(st,-1);
+ ShowError("buildin_getiteminfo: Invalid item info type %d.\n", type);
+ script_pushint(st, -1);
return false;
}
+
return true;
}
@@ -27005,7 +27033,7 @@ static void script_parse_builtin(void)
BUILDIN_DEF(setnpcdisplay,"sv??"),
BUILDIN_DEF(compare,"ss"), // Lordalfa - To bring strstr to scripting Engine.
BUILDIN_DEF(strcmp,"ss"),
- BUILDIN_DEF(getiteminfo,"ii"), //[Lupus] returns Items Buy / sell Price, etc info
+ BUILDIN_DEF(getiteminfo,"vi"), //[Lupus] returns Items Buy / sell Price, etc info
BUILDIN_DEF(setiteminfo,"iii"), //[Lupus] set Items Buy / sell Price, etc info
BUILDIN_DEF(getequipcardid,"ii"), //[Lupus] returns CARD ID or other info from CARD slot N of equipped item
BUILDIN_DEF(getequippedoptioninfo, "i"),
@@ -27651,6 +27679,9 @@ static void script_hardcoded_constants(void)
script->set_constant("ITEMINFO_ITEM_USAGE_FLAG", ITEMINFO_ITEM_USAGE_FLAG, false, false);
script->set_constant("ITEMINFO_ITEM_USAGE_OVERRIDE", ITEMINFO_ITEM_USAGE_OVERRIDE, false, false);
script->set_constant("ITEMINFO_GM_LV_TRADE_OVERRIDE", ITEMINFO_GM_LV_TRADE_OVERRIDE, false, false);
+ script->set_constant("ITEMINFO_ID", ITEMINFO_ID, false, false);
+ script->set_constant("ITEMINFO_AEGISNAME", ITEMINFO_AEGISNAME, false, false);
+ script->set_constant("ITEMINFO_NAME", ITEMINFO_NAME, false, false);
script->constdb_comment("getmercinfo options");
script->set_constant("MERCINFO_ID,", MERCINFO_ID, false, false);
diff --git a/src/map/script.h b/src/map/script.h
index 857d22c61..ed860368c 100644
--- a/src/map/script.h
+++ b/src/map/script.h
@@ -484,6 +484,9 @@ enum script_iteminfo_types {
ITEMINFO_ITEM_USAGE_FLAG,
ITEMINFO_ITEM_USAGE_OVERRIDE,
ITEMINFO_GM_LV_TRADE_OVERRIDE,
+ ITEMINFO_ID,
+ ITEMINFO_AEGISNAME,
+ ITEMINFO_NAME,
ITEMINFO_MAX
};