Jump to content
  • 0

Get item from storage


eko

Question


  • Group:  Members
  • Topic Count:  4
  • Topics Per Day:  0.00
  • Content Count:  16
  • Reputation:   0
  • Joined:  01/07/12
  • Last Seen:  

Hi !

I want to create a restock NPC, who take a #number of #item in the storage .

So I search a Source Edit which add this script command.

I've ever see SQl script for this, but it don't work very well.

Someone has a source edit like that ?

Thanks in advance

Eko

Ps : Sorry for my bad english --'

Link to comment
Share on other sites

14 answers to this question

Recommended Posts


  • Group:  Members
  • Topic Count:  16
  • Topics Per Day:  0.00
  • Content Count:  737
  • Reputation:   216
  • Joined:  11/29/11
  • Last Seen:  

From old forum and a bit of my own edit.


# This patch file was generated by NetBeans IDE
# It uses platform neutral UTF-8 encoding and n newlines.
Index: src/map/script.c
===================================================================
--- src/map/script.c (revision 15409)
+++ src/map/script.c (working copy)
@@ -16023,6 +16023,160 @@

return 0;
}
+
+/* =========================================
+* - GetStorageItem <item_id>,<amount>{,"<Nick Name>"};
+* Carlos H.
+* Max ammount = 30k
+* ----------------------------------------- */
+BUILDIN_FUNC(getstorageitem){
+ TBL_PC * sd = ((script_hasdata(st,4)) ? map_nick2sd(script_getstr(st,4)) : script_rid2sd(st));
+ struct item_data * item_data;
+ struct item item_tmp;
+ int amount = script_getnum(st,3);
+ int x;
+ if((item_data = itemdb_exists(script_getnum(st,2))) != NULL && sd != NULL){
+ if(amount <= 0 || (!itemdb_isstackable2(item_data)) || (itemdb_isstackable2(item_data) && amount > MAX_AMOUNT))
+ amount = 1;
+ memset(&item_tmp,0,sizeof(item_tmp));
+ item_tmp.nameid = item_data->nameid;
+ item_tmp.identify = 1;
+ if(!itemdb_isstackable2(item_data) && amount > 1){
+ for(x = 0; x < amount; x++)
+ storage_additem(sd,&item_tmp,amount);
+ }else {
+ storage_additem(sd,&item_tmp,amount);
+ clif_storageclose(sd);
+ sd->state.storage_flag = 0;
+ }
+
+ log_pick_pc(sd, LOG_TYPE_SCRIPT, item_tmp.nameid, amount, &item_tmp);
+ }
+ return 0;
+}
+
+/* =========================================
+* getStorageItem2 <item id>,<amount>,,<refine>,<attribut>,<c1>,<c2>,<c3>,<c3>{,<account ID>};
+* getStorageItem2 "<item name>",<amount>,,<refine>,<attribut>,<c1>,<c2>,<c3>,<c3>{,<account ID>};
+* [Lighta]
+* ----------------------------------------- */
+BUILDIN_FUNC(getstorageitem2){
+ TBL_PC * sd;
+ int nameid,amount,i;
+ int ref,attr,c1,c2,c3,c4;
+ struct script_data *data;
+ struct item_data * item_data;
+ struct item item_tmp;
+
+ data=script_getdata(st,2);
+ get_val(st,data);
+ if( data_isstring(data) )
+ {// "<item name>"
+ const char *name=conv_str(st,data);
+ struct item_data *item_data = itemdb_searchname(name);
+ if( item_data == NULL ){
+ ShowError("buildin_getstorageitem2: Nonexistant item %s requested.n", name);
+ return 1; //No item created.
+ }
+ nameid=item_data->nameid;
+ } else if( data_isint(data) )
+ {// <item id>
+ nameid=conv_num(st,data);
+ //Violet Box, Blue Box, etc - random item pick
+ if( nameid < 0 ) {
+ nameid=itemdb_searchrandomid(-nameid);
+ }
+ if( nameid <= 0 || !itemdb_exists(nameid) ){
+ ShowError("buildin getstorageitem2: Nonexistant item %d requested.n", nameid);
+ return 1; //No item created.
+ }
+ }
+ amount=script_getnum(st,3);
+ ref=script_getnum(st,4);
+ attr=script_getnum(st,5);
+ c1=(short)script_getnum(st,6);
+ c2=(short)script_getnum(st,7);
+ c3=(short)script_getnum(st,8);
+ c4=(short)script_getnum(st,9);
+
+ if( script_hasdata(st,10) )
+ sd=map_id2sd(script_getnum(st,10)); // <Account ID>
+ else
+ sd=script_rid2sd(st); // Attached player
+
+ if( sd == NULL ) // no target
+ return 0;
+
+ if((item_data = itemdb_exists(script_getnum(st,2))) != NULL && sd != NULL){
+ item_data=itemdb_exists(nameid);
+ if (item_data == NULL)
+ return -1;
+ if(item_data->type==IT_WEAPON || item_data->type==IT_ARMOR){
+ if(ref > MAX_REFINE) ref = MAX_REFINE;
+ }
+ else if(item_data->type==IT_PETEGG) {
+ ref = 0;
+ }
+ else {
+ ref = attr = 0;
+ }
+ memset(&item_tmp,0,sizeof(item_tmp));
+ item_tmp.nameid=nameid;
+ item_tmp.identify = 1;
+ item_tmp.refine=ref;
+ item_tmp.attribute=attr;
+ item_tmp.card[0]=(short)c1;
+ item_tmp.card[1]=(short)c2;
+ item_tmp.card[2]=(short)c3;
+ item_tmp.card[3]=(short)c4;
+
+ if(amount <= 0 || (!itemdb_isstackable2(item_data) && amount > 10) || (itemdb_isstackable2(item_data) && amount > MAX_AMOUNT))
+ amount = 1;
+ if(!itemdb_isstackable2(item_data) && amount > 1){
+ for(i = 0; i < amount; i++)
+ storage_additem(sd,&item_tmp,amount);
+ } else {
+ storage_additem(sd,&item_tmp,amount);
+ clif_storageclose(sd);
+ sd->state.storage_flag = 0;
+ }
+ log_pick_pc(sd, LOG_TYPE_SCRIPT, nameid, amount, &item_tmp);
+ }
+ return 0;
+}
+
+/*==========================================
+* delstorageitem [Lighta]
+* * - setStorageItem <item_id>,<amount>{,"<Nick Name>"};
+*------------------------------------------*/
+BUILDIN_FUNC(delstorageitem)
+{
+ TBL_PC * sd = ((script_hasdata(st,4)) ? map_nick2sd(script_getstr(st,4)) : script_rid2sd(st));
+ struct item_data * item_data;
+ int amount = script_getnum(st,3);
+ struct item item_tmp;
+ int i;
+
+ if((item_data = itemdb_exists(script_getnum(st,2))) != NULL && sd != NULL){
+ if(amount <= 0 || (!itemdb_isstackable2(item_data)) || (itemdb_isstackable2(item_data) && amount > MAX_AMOUNT))
+ amount = 1;
+
+ //search item in storage
+ ARR_FIND( 0, MAX_STORAGE, i, sd->status.storage.items[i].nameid == item_data->nameid);
+ if( i >= MAX_STORAGE )
+ return -1; //item not found
+
+ item_tmp=sd->status.storage.items[i]; //memo for log
+ storage_delitem(sd,i,amount);
+
+ clif_storageclose(sd);
+ sd->state.storage_flag = 0;
+
+ log_pick_pc(sd, LOG_TYPE_SCRIPT, item_tmp.nameid, -amount, &item_tmp);
+ }
+ return 0;
+}
+
// declarations that were supposed to be exported from npc_chat.c
#ifdef PCRE_SUPPORT
BUILDIN_FUNC(defpattern);
@@ -16458,5 +16612,10 @@
BUILDIN_DEF(checkquest, "i?"),
BUILDIN_DEF(changequest, "ii"),
BUILDIN_DEF(showevent, "ii"),
+
+ BUILDIN_DEF(getstorageitem,"ii*"),
+ BUILDIN_DEF(getstorageitem2,"viiiiiii?"),
+ BUILDIN_DEF(delstorageitem,"ii*"),
+
{NULL,NULL,NULL},
};

Index: src/map/storage.c
===================================================================
--- src/map/storage.c (revision 15409)
+++ src/map/storage.c (working copy)
@@ -127,7 +127,7 @@
/*==========================================
* Internal add-item function.
*------------------------------------------*/
-static int storage_additem(struct map_session_data* sd, struct item* item_data, int amount)
+int storage_additem(struct map_session_data* sd, struct item* item_data, int amount)
{
struct storage_data* stor = &sd->status.storage;
struct item_data *data;

Index: src/map/storage.h
===================================================================
--- src/map/storage.h (revision 15409)
+++ src/map/storage.h (working copy)
@@ -37,4 +37,5 @@
int storage_guild_storagesave(int account_id, int guild_id, int flag);
int storage_guild_storagesaved(int guild_id); //Ack from char server that guild store was saved.

+int storage_additem(struct map_session_data* sd, struct item* item_data, int amount);
#endif /* _STORAGE_H_ */
[/codeBOX]

Edited by Lighta
Please use CODEBOX if your Script is Long
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  4
  • Topics Per Day:  0.00
  • Content Count:  16
  • Reputation:   0
  • Joined:  01/07/12
  • Last Seen:  

Thanks a lot, but it return compile error =/

source edit for additem2 is missing

Edited by eko
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  16
  • Topics Per Day:  0.00
  • Content Count:  737
  • Reputation:   216
  • Joined:  11/29/11
  • Last Seen:  

Oh right there some eamod in that i'm sorry.

I change the 1st post to put the proper patch.

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  4
  • Topics Per Day:  0.00
  • Content Count:  16
  • Reputation:   0
  • Joined:  01/07/12
  • Last Seen:  

I've specified the file name in the script to apply this patch, but it don't work..

1 out of 1 hunk FAILED -- saving rejects to file src/map/script.c.rej

1 out of 1 hunk FAILED -- saving rejects to file src/map/storage.c.rej

patching file src/map/storage.h

patch unexpectedly ends in middle of line

Hunk #1 FAILED at 37.

1 out of 1 hunk FAILED -- saving rejects to file src/map/storage.h.rej

Edited by eko
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  16
  • Topics Per Day:  0.00
  • Content Count:  737
  • Reputation:   216
  • Joined:  11/29/11
  • Last Seen:  

I add the index manually, the 2 other one are in storage.h and storage.c

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  4
  • Topics Per Day:  0.00
  • Content Count:  16
  • Reputation:   0
  • Joined:  01/07/12
  • Last Seen:  

Well it's work !

But that's not what I need ! x)

I need a command which move item from storage to inventory =/

This command create item on storage, or delete it.

Else if i can have a command who countstorageitem, it can works too.

Can you help me again ?

Thanks for all !

Edited by eko
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  16
  • Topics Per Day:  0.00
  • Content Count:  737
  • Reputation:   216
  • Joined:  11/29/11
  • Last Seen:  

Ah sorry for mistunderstanding then.

Hopefully I already did what u asked but I found my script quite lame here, so do as you want.

Here the patch for countstorageitem. (how to use it is in description)

# This patch file was generated by NetBeans IDE
# It uses platform neutral UTF-8 encoding and n newlines.
Index: src/map/script.c
--- Base (BASE)
+++ Locally Modified (Based On LOCAL)
@@ -15982,6 +15982,84 @@

    return 0;
}
+
+/*==========================================
+ * Countstorageitem,type,item{,"<Nick Name>"} [Lighta]
+ * type : 0 inventory, 1 guildinventory
+ * item : itemid or itemname
+ *------------------------------------------*/
+BUILDIN_FUNC(countstorageitem)
+{
+    int i, type;
+    short int nameid;
+    int count = 0;
+    struct script_data* data;
+    struct item_data* item_data;
+    struct guild_storage *gstor;
+	    struct storage_data *stor;
+
+    TBL_PC * sd = ((script_hasdata(st,4)) ? map_nick2sd(script_getstr(st,4)) : script_rid2sd(st));
+    if (!sd) {
+        script_pushint(st,0);
+        return 0;
+    }
+
+    type = script_getnum(st,2);
+    data = script_getdata(st,3);
+    get_val(st,data);
+    if( data_isstring(data) ) {
+        const char* name = conv_str(st,data);
+        if((item_data = itemdb_searchname(name)) != NULL) {
+            nameid = item_data->nameid;
+        }
+        else {
+            nameid = 0;
+        }
+    } else
+        nameid = conv_num(st,data);
+	    
+	    if(nameid<=0){
+		    ShowError("Invalid item specified in countstorageitem");
+		    script_pushint(st,-1);
+		    return -1;
+	    }
+
+	    switch(type){
+			    case 0 :
+					    stor=&sd->status.storage;
+					    for(i = 0; i < MAX_STORAGE; i++) {
+							    if(&stor->items[i] != NULL && stor->items[i].nameid  > 0 &&
+									    stor->items[i].amount > 0 && stor->items[i].nameid == nameid
+							    )
+							    count += stor->items[i].amount;
+					    }
+					    break;
+
+			    case 1:
+					    if (sd->status.guild_id && (gstor=guild2storage2(sd->status.guild_id))) {
+						    for(i = 0; i < MAX_GUILD_STORAGE; i++) {
+								    if(&gstor->items[i] != NULL && gstor->items[i].nameid  > 0 &&
+										    gstor->items[i].amount > 0 && gstor->items[i].nameid == nameid
+								    )
+								    count += gstor->items[i].amount;
+						    }
+					    }
+					    else {
+						    script_pushint(st,-1); //ShowInfo("Charactere not related to a guild");
+						    return -1;
+					    }
+					    break;
+
+			    default :
+					    ShowError("Invalid type specified in countstorageitem");
+					    script_pushint(st,-1);
+					    return -1;
+	    }
+    
+    script_pushint(st,count);
+    return 0;
+}
+
// declarations that were supposed to be exported from npc_chat.c
#ifdef PCRE_SUPPORT
BUILDIN_FUNC(defpattern);
@@ -16417,5 +16495,7 @@
    BUILDIN_DEF(checkquest, "i?"),
    BUILDIN_DEF(changequest, "ii"),
    BUILDIN_DEF(showevent, "ii"),
+	    
+	    BUILDIN_DEF(countstorageitem,"iv"),
    {NULL,NULL,NULL},
};

</nick>

Edited by Lighta
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  4
  • Topics Per Day:  0.00
  • Content Count:  16
  • Reputation:   0
  • Joined:  01/07/12
  • Last Seen:  

It works but there isn't countitemstorage x)

I've tested and :

Countitemstorage 0 : Count item in inventory

Countitemstorage 1 : Count item in gStorage

Edited by eko
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  16
  • Topics Per Day:  0.00
  • Content Count:  737
  • Reputation:   216
  • Joined:  11/29/11
  • Last Seen:  

? you mean, countstorageitem, cause ofc if it's coutitemstorage that won't work.

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  4
  • Topics Per Day:  0.00
  • Content Count:  16
  • Reputation:   0
  • Joined:  01/07/12
  • Last Seen:  

Yup sorry,

(countstorageitem(0,1025) return the number of item in the inventory, not in the storage

and (countstorageitem(1,1025) return the number of item in the guild storage.

But i need a countitem for storage x)

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  16
  • Topics Per Day:  0.00
  • Content Count:  737
  • Reputation:   216
  • Joined:  11/29/11
  • Last Seen:  

Ah right indeed, I'll change this later, you just need to point on storage instead inventory. I'll sending after class.

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  4
  • Topics Per Day:  0.00
  • Content Count:  16
  • Reputation:   0
  • Joined:  01/07/12
  • Last Seen:  

That's right!

I need to countitem on storage, not on inventory.

To giev you an example

The restock script is approximately like this :

if countstorageitem(#item) > #number

destorageitem #item #number

getitem #item #number

So i need the countitem to check if the player have the item in the storage before creating them in his inventory

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  4
  • Topics Per Day:  0.00
  • Content Count:  16
  • Reputation:   0
  • Joined:  01/07/12
  • Last Seen:  

Bump ? :)

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  16
  • Topics Per Day:  0.00
  • Content Count:  737
  • Reputation:   216
  • Joined:  11/29/11
  • Last Seen:  

ok I edited the second codebox so you should be fine now. perhaps I'll resume all on 1st one

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...