فهرست منبع

Added script command "consumeitem" which is used in some official scripts.
Documentation will follow.

git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@17137 54d463be-8e91-2dee-dedb-b68131a5f0ec

lemongrass3110 12 سال پیش
والد
کامیت
8d3d8e0e1b
1فایلهای تغییر یافته به همراه42 افزوده شده و 0 حذف شده
  1. 42 0
      src/map/script.c

+ 42 - 0
src/map/script.c

@@ -17332,6 +17332,47 @@ BUILDIN_FUNC(npcskill)
 	return 0;
 	return 0;
 }
 }
 
 
+/* Consumes a item
+ * consumeitem <item id>
+ * consumeitem "<item name>"
+*/
+BUILDIN_FUNC(consumeitem)
+{
+	TBL_NPC *nd;
+	TBL_PC *sd;
+	struct script_data *data;
+	struct item_data *item_data;
+
+	nullpo_retr( 1, ( sd = script_rid2sd( st ) ) );
+	nullpo_retr( 1, ( nd = (TBL_NPC *)map_id2bl( sd->npc_id ) ) );
+
+	data = script_getdata( st, 2 );
+	get_val( st, data );
+
+	if( data_isstring( data ) ){
+		const char *name = conv_str( st, data );
+
+		if( ( item_data = itemdb_searchname( name ) ) == NULL ){
+			ShowError( "buildin_consumeitem: Nonexistant item %s requested.\n", name );
+			return 1;
+		}
+	}else if( data_isint( data ) ){
+		int nameid = conv_num( st, data );
+
+		if( ( item_data = itemdb_exists( nameid ) ) == NULL ){
+			ShowError("buildin_consumeitem: Nonexistant item %d requested.\n", nameid );
+			return 1;
+		}
+	}else{
+		ShowError("buildin_consumeitem: invalid data type for argument #1 (%d).", data->type );
+		return 1;
+	}
+
+	run_script( item_data->script, 0, sd->bl.id, nd->bl.id );
+
+	return 0;
+}
+
 // declarations that were supposed to be exported from npc_chat.c
 // declarations that were supposed to be exported from npc_chat.c
 #ifdef PCRE_SUPPORT
 #ifdef PCRE_SUPPORT
 BUILDIN_FUNC(defpattern);
 BUILDIN_FUNC(defpattern);
@@ -17776,6 +17817,7 @@ struct script_function buildin_func[] = {
 	BUILDIN_DEF(cleanmap,"s"),
 	BUILDIN_DEF(cleanmap,"s"),
 	BUILDIN_DEF2(cleanmap,"cleanarea","siiii"),
 	BUILDIN_DEF2(cleanmap,"cleanarea","siiii"),
 	BUILDIN_DEF(npcskill,"viii"),
 	BUILDIN_DEF(npcskill,"viii"),
+	BUILDIN_DEF(consumeitem,"vi?"),
 	/**
 	/**
 	 * @commands (script based)
 	 * @commands (script based)
 	 **/
 	 **/