Browse Source

Updates of getenchantgrade() script command (#6420)

* Updates getenchantgrade() script command adding <equipement slot> as optional argument to retrieve the grade of a specific equipment slot.

Thanks to @Lemongrass3110 and @aleos89 !
Atemo 3 years ago
parent
commit
543e658aae
2 changed files with 29 additions and 7 deletions
  1. 8 3
      doc/script_commands.txt
  2. 21 4
      src/map/script.cpp

+ 8 - 3
doc/script_commands.txt

@@ -3108,12 +3108,17 @@ If <type> is false the command only returns the count of unidentified items.
 
 ---------------------------------------
 
-*getenchantgrade()
+*getenchantgrade({<equipment slot>,<char_id>})
 
 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'.
 
 ---------------------------------------
 //

+ 21 - 4
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"),