summaryrefslogtreecommitdiff
path: root/src/map
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2019-06-02 15:26:57 +0200
committerGitHub <noreply@github.com>2019-06-02 15:26:57 +0200
commitdb4a29905f97016a4945db2670b15452e4e8ad20 (patch)
treed30966cf77043637c64a5e8ec7fe5424463a5518 /src/map
parent1e1942ccc51b7a4b27bb3d8deea5e5a1178b8531 (diff)
parent858e732e15c495f3073c8037b9612c6c20390f76 (diff)
downloadhercules-db4a29905f97016a4945db2670b15452e4e8ad20.tar.gz
hercules-db4a29905f97016a4945db2670b15452e4e8ad20.tar.bz2
hercules-db4a29905f97016a4945db2670b15452e4e8ad20.tar.xz
hercules-db4a29905f97016a4945db2670b15452e4e8ad20.zip
Merge pull request #2394 from bWolfie/buildin_delitemidx
Adds BUILDIN(delitemidx), which deletes an item at the given index.
Diffstat (limited to 'src/map')
-rw-r--r--src/map/script.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/map/script.c b/src/map/script.c
index d9c3660d0..86674be25 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -8631,6 +8631,48 @@ static BUILDIN(delitem2)
return false;
}
+/**
+ * Deletes item at given index.
+ * delitem(<index>{, <amount{, <account id>}});
+ */
+static BUILDIN(delitemidx)
+{
+ struct map_session_data *sd;
+
+ if (script_hasdata(st, 4)) {
+ if ((sd = script->id2sd(st, script_getnum(st, 4))) == NULL) {
+ st->state = END;
+ return true;
+ }
+ } else {
+ if ((sd = script->rid2sd(st)) == NULL)
+ return true;
+ }
+
+ int i = script_getnum(st, 2);
+ if (i < 0 || i >= sd->status.inventorySize) {
+ ShowError("buildin_delitemidx: Index (%d) should be from 0-%d.\n", i, sd->status.inventorySize - 1);
+ st->state = END;
+ return false;
+ }
+
+ if (itemdb->exists(sd->status.inventory[i].nameid) == NULL)
+ ShowWarning("buildin_delitemidx: Deleting invalid Item ID (%d).\n", sd->status.inventory[i].nameid);
+
+ int amount = 0;
+ if (script_hasdata(st, 3)) {
+ if ((amount = script_getnum(st, 3)) > sd->status.inventory[i].amount)
+ amount = sd->status.inventory[i].amount;
+ } else {
+ amount = sd->status.inventory[i].amount;
+ }
+
+ if (amount > 0)
+ script->buildin_delitem_delete(sd, i, &amount, true);
+
+ return true;
+}
+
/*==========================================
* Enables/Disables use of items while in an NPC [Skotlex]
*------------------------------------------*/
@@ -25558,6 +25600,7 @@ static void script_parse_builtin(void)
BUILDIN_DEF(makeitem2,"viiiiiiii????"),
BUILDIN_DEF(delitem,"vi?"),
BUILDIN_DEF(delitem2,"viiiiiiii?"),
+ BUILDIN_DEF(delitemidx, "i??"),
BUILDIN_DEF2(enableitemuse,"enable_items",""),
BUILDIN_DEF2(disableitemuse,"disable_items",""),
BUILDIN_DEF(cutin,"si"),