summaryrefslogtreecommitdiff
path: root/src/emap/script_buildins.c
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2017-04-19 22:50:55 +0300
committerAndrei Karas <akaras@inbox.ru>2017-04-19 22:50:55 +0300
commit1e1398a0c731dab75d5ca5d7077af68cc6104769 (patch)
tree87fafbcd6a086f4586b53e1c46d680e684521779 /src/emap/script_buildins.c
parent095588880ef3c2577fc9e6a81da20479c56f5bf7 (diff)
downloadplugin-1e1398a0c731dab75d5ca5d7077af68cc6104769.tar.gz
plugin-1e1398a0c731dab75d5ca5d7077af68cc6104769.tar.bz2
plugin-1e1398a0c731dab75d5ca5d7077af68cc6104769.tar.xz
plugin-1e1398a0c731dab75d5ca5d7077af68cc6104769.zip
Add script functions for manipulate item options.
New functions: getitemoptionidbyindex getitemoptionvaluebyindex getitemoptionparambyindex setitemoptionbyindex
Diffstat (limited to 'src/emap/script_buildins.c')
-rw-r--r--src/emap/script_buildins.c124
1 files changed, 124 insertions, 0 deletions
diff --git a/src/emap/script_buildins.c b/src/emap/script_buildins.c
index a50caf7..2e47c77 100644
--- a/src/emap/script_buildins.c
+++ b/src/emap/script_buildins.c
@@ -2267,3 +2267,127 @@ BUILDIN(slide)
unit->movepos(&sd->bl, x, y, 1, 0);
return true;
}
+
+BUILDIN(getItemOptionIdByIndex)
+{
+ getSD()
+ getInventoryIndex(2)
+
+ if (sd->status.inventory[n].nameid <= 0 || sd->status.inventory[n].amount <= 0)
+ {
+ script_pushint(st, 0);
+ return false;
+ }
+
+ const int optIndex = script_getnum(st, 3);
+ if (optIndex < 0 || optIndex >= MAX_ITEM_OPTIONS)
+ {
+ script_pushint(st, 0);
+ return false;
+ }
+
+ const int optType = sd->status.inventory[n].option[optIndex].index;
+ script_pushint(st, optType);
+
+ return true;
+}
+
+BUILDIN(getItemOptionValueByIndex)
+{
+ getSD()
+ getInventoryIndex(2)
+
+ if (sd->status.inventory[n].nameid <= 0 || sd->status.inventory[n].amount <= 0)
+ {
+ script_pushint(st, 0);
+ return false;
+ }
+
+ const int optIndex = script_getnum(st, 3);
+ if (optIndex < 0 || optIndex >= MAX_ITEM_OPTIONS)
+ {
+ script_pushint(st, 0);
+ return false;
+ }
+
+ const int optValue = sd->status.inventory[n].option[optIndex].value;
+ script_pushint(st, optValue);
+
+ return true;
+}
+
+BUILDIN(getItemOptionParamByIndex)
+{
+ getSD()
+ getInventoryIndex(2)
+
+ if (sd->status.inventory[n].nameid <= 0 || sd->status.inventory[n].amount <= 0)
+ {
+ script_pushint(st, 0);
+ return false;
+ }
+
+ const int optIndex = script_getnum(st, 3);
+ if (optIndex < 0 || optIndex >= MAX_ITEM_OPTIONS)
+ {
+ script_pushint(st, 0);
+ return false;
+ }
+
+ const int optParam = sd->status.inventory[n].option[optIndex].param;
+ script_pushint(st, optParam);
+
+ return true;
+}
+
+BUILDIN(setItemOptionByIndex)
+{
+ getSD()
+ getInventoryIndex(2)
+
+ if (sd->status.inventory[n].nameid <= 0 || sd->status.inventory[n].amount <= 0)
+ return false;
+
+ if (itemdb->isstackable2(sd->inventory_data[n]))
+ return false;
+
+ // not allow change equipped items
+ if (sd->status.inventory[n].equip != 0)
+ return false;
+
+ const int optIndex = script_getnum(st, 3);
+ if (optIndex < 0 || optIndex >= MAX_ITEM_OPTIONS)
+ {
+ ShowError("Wrong optIndex in setitemoptionbyindex\n");
+ return false;
+ }
+ int optType = 0;
+ int optValue = 0;
+ if (script_hasdata(st, 5))
+ {
+ optType = script_getnum(st, 4);
+ optValue = script_getnum(st, 5);
+ }
+ else
+ {
+ optType = sd->status.inventory[n].option[optIndex].index;
+ optValue = script_getnum(st, 4);
+ }
+
+ if (optType != 0 && itemdb->option_exists(optType) == NULL)
+ {
+ ShowError("Wrong optType in setitemoptionbyindex\n");
+ return false;
+ }
+
+ clif->delitem(sd, n, 1, DELITEM_MATERIALCHANGE);
+ logs->pick_pc(sd, LOG_TYPE_SCRIPT, -1, &sd->status.inventory[n], sd->inventory_data[n]);
+
+ sd->status.inventory[n].option[optIndex].index = optType;
+ sd->status.inventory[n].option[optIndex].value = optValue;
+
+ clif->additem(sd, n, 1, 0);
+ logs->pick_pc(sd, LOG_TYPE_SCRIPT, 1, &sd->status.inventory[n], sd->inventory_data[n]);
+
+ return true;
+}