From a525f09528eb6d6df9a21aff5c01e5e1ca36b936 Mon Sep 17 00:00:00 2001 From: Wolfie Date: Wed, 23 Jan 2019 19:09:49 +1300 Subject: [PATCH] Changes equip() to return 0 or 1 if item successfully equipped. --- doc/script_commands.txt | 3 +++ src/map/script.c | 25 ++++++++++++++++--------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/doc/script_commands.txt b/doc/script_commands.txt index 88f1000df14..a094c661d1b 100644 --- a/doc/script_commands.txt +++ b/doc/script_commands.txt @@ -5603,6 +5603,9 @@ item in his/her inventory, while the autoequip function will equip the given item ID when this is looted. The option parameter of the autoequip is 1 or 0, 1 to turn it on, and 0 to turn it off. +equip() returns 1 if the item was successfully equipped and 0 if the +item failed to equip. + Examples: //This will equip a 1104 (falchion) on the character if this is in the diff --git a/src/map/script.c b/src/map/script.c index 897fd5bf1b0..7d236c2ee44 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -16473,21 +16473,28 @@ static BUILDIN(unequip) static BUILDIN(equip) { - int nameid=0,i; + int nameid = 0, i; struct item_data *item_data; struct map_session_data *sd = script->rid2sd(st); - if (sd == NULL) - return false; - nameid=script_getnum(st,2); - if((item_data = itemdb->exists(nameid)) == NULL) - { - ShowError("wrong item ID : equipitem(%d)\n",nameid); - return false; + if (sd == NULL) { + script_pushint(st, 0); + return true; } + + nameid = script_getnum(st, 2); + if ((item_data = itemdb->exists(nameid)) == NULL) { + ShowError("buildin_equip: Invalid Item ID (%d).\n",nameid); + script_pushint(st, 0); + return true; + } + ARR_FIND(0, sd->status.inventorySize, i, sd->status.inventory[i].nameid == nameid && sd->status.inventory[i].equip == 0); + if (i < sd->status.inventorySize) - pc->equipitem(sd, i, item_data->equip); + script_pushint(st, pc->equipitem(sd, i, item_data->equip)); + else + script_pushint(st, 0); return true; }