diff --git a/doc/script_commands.txt b/doc/script_commands.txt index 5a98c0f6e9..df2e094406 100644 --- a/doc/script_commands.txt +++ b/doc/script_commands.txt @@ -3108,12 +3108,17 @@ If is false the command only returns the count of unidentified items. --------------------------------------- -*getenchantgrade() +*getenchantgrade({,}) This function will return the enchantgrade of the equipment from which the -function is called. +function is called or the specified equipment slot. If nothing is +equipped there, it returns -1. -This function is intended for use in item scripts. +Valid equipment slots are: + +EQI_COMPOUND_ON - Item slot that calls this script (In context of item script) (default) + +For a list of others equipment slots see 'getequipid'. --------------------------------------- // diff --git a/src/map/script.cpp b/src/map/script.cpp index 90f5241962..3fb0ce159a 100644 --- a/src/map/script.cpp +++ b/src/map/script.cpp @@ -25458,15 +25458,32 @@ BUILDIN_FUNC(refineui){ BUILDIN_FUNC(getenchantgrade){ struct map_session_data *sd; - if( !script_rid2sd( sd ) ){ + if (!script_charid2sd(3, sd)) { + script_pushint(st,-1); return SCRIPT_CMD_FAILURE; } - if( current_equip_item_index == -1 ){ + int index, position; + + if (script_hasdata(st, 2)) + position = script_getnum(st, 2); + else + position = EQI_COMPOUND_ON; + + if (position == EQI_COMPOUND_ON) + index = current_equip_item_index; + else if (equip_index_check(position)) + index = pc_checkequip(sd, equip_bitmask[position]); + else { + ShowError( "buildin_getenchantgrade: Unknown equip index '%d'\n", position ); + script_pushint(st,-1); return SCRIPT_CMD_FAILURE; } - script_pushint( st, sd->inventory.u.items_inventory[current_equip_item_index].enchantgrade ); + if (index < 0 || index >= MAX_INVENTORY || sd->inventory.u.items_inventory[index].nameid == 0) + script_pushint(st, -1); + else + script_pushint(st, sd->inventory.u.items_inventory[index].enchantgrade); return SCRIPT_CMD_SUCCESS; } @@ -26194,7 +26211,7 @@ struct script_function buildin_func[] = { BUILDIN_DEF2(rentalcountitem, "rentalcountitem2", "viiiiiii?"), BUILDIN_DEF2(rentalcountitem, "rentalcountitem3", "viiiiiiirrr?"), - BUILDIN_DEF(getenchantgrade, ""), + BUILDIN_DEF(getenchantgrade, "??"), BUILDIN_DEF(mob_setidleevent, "is"),