Bläddra i källkod

Implemented getequiptradability script command (#2750)

Thanks to @aleos89 @anacondaqq @Lemongrass3110
Jittapan Pluemsumran 7 år sedan
förälder
incheckning
bfb6972c59
2 ändrade filer med 38 tillägg och 0 borttagningar
  1. 7 0
      doc/script_commands.txt
  2. 31 0
      src/map/script.cpp

+ 7 - 0
doc/script_commands.txt

@@ -2935,6 +2935,13 @@ Merge all stackable items that separated by GUID flags
 (either by flag 4 item_flag.txt or GUID  in item_group).
 If no item ID/name given, all possible items in player's inventory will be merged.
 
+---------------------------------------
+
+*getequiptradability(<equipment slot>{,<char id>});
+
+Returns true if the item in <equipment slot> is tradable.
+Returns false otherwise.
+
 ---------------------------------------
 //
 2,1.- End of item-related commands.

+ 31 - 0
src/map/script.cpp

@@ -23698,6 +23698,36 @@ BUILDIN_FUNC(round) {
 	return SCRIPT_CMD_SUCCESS;
 }
 
+BUILDIN_FUNC(getequiptradability) {
+	int i, num;
+	TBL_PC *sd;
+
+	num = script_getnum(st, 2);
+
+	if (!script_charid2sd(3, sd)) {
+		return SCRIPT_CMD_FAILURE;
+	}
+
+	if (equip_index_check(num))
+		i = pc_checkequip(sd, equip_bitmask[num]);
+	else{
+		ShowError("buildin_getequiptradability: Unknown equip index '%d'\n",num);
+		return SCRIPT_CMD_FAILURE;
+	}
+
+	if (i >= 0) {
+		bool tradable = (sd->inventory.u.items_inventory[i].expire_time == 0 &&
+			(!sd->inventory.u.items_inventory[i].bound || pc_can_give_bounded_items(sd)) &&
+			itemdb_cantrade(&sd->inventory.u.items_inventory[i], pc_get_group_level(sd), pc_get_group_level(sd))
+			);
+		script_pushint(st, tradable);
+	}
+	else
+		script_pushint(st, false);
+
+	return SCRIPT_CMD_SUCCESS;
+}
+
 #include "../custom/script.inc"
 
 // declarations that were supposed to be exported from npc_chat.c
@@ -24345,6 +24375,7 @@ struct script_function buildin_func[] = {
 	BUILDIN_DEF2(round, "round", "i"),
 	BUILDIN_DEF2(round, "ceil", "i"),
 	BUILDIN_DEF2(round, "floor", "i"),
+	BUILDIN_DEF(getequiptradability, "i?"),
 #include "../custom/script_def.inc"
 
 	{NULL,NULL,NULL},