Jump to content
  • 0
eKoh

How can I detect every item I sell to this NPC?

Question

I am using a dynamic shop from trunk>doc>sample>npc_dynamic_shop.txt.

 

// Dummy shop to insert items into:- shop dyn_shop1 -1,501:50.prontera,181,200,4 script Dynamic Shop 2_F_MAGICMASTER,{callshop "dyn_shop1",0;npcshopattach "dyn_shop1";end;OnSellItem:for (.@i = 0; .@i < getarraysize(@sold_nameid); ++.@i) {if(countitem(@sold_nameid[.@i]) < @sold_quantity[.@i] || @sold_quantity[.@i] <= 0) {mes "omgh4x!";close;} else if (@sold_nameid[.@i] == Red_Potion) {delitem Red_Potion, @sold_quantity[.@i];$@rpotsleft += @sold_quantity[.@i];Zeny += @sold_quantity[.@i]*20;} else if (@sold_nameid[.@i] == Orange_Potion){delitem Orange_Potion, @sold_quantity[.@i];$@opotsleft += @sold_quantity[.@i];Zeny += @sold_quantity[.@i]*100;} else {mes "Sorry, I don't need your items.";close;}}deletearray @sold_quantity, getarraysize(@sold_quantity);deletearray @sold_nameid, getarraysize(@sold_nameid);mes "Deal completed.";close;

 

But I don't want to sell items, what I want to do is to detect for example:

 

200 White Potions

20 Awakening Potions

 

The player will put 200 white potions and 20 awakening potions, and what the script should do is to store these numbers and names into vars, but I am failing at this last step (my mind is about to blow X_x).

 

The bad thing about the script is that it compares @sold_nameid with a white potion and a orange potion, but it does not save it into a var.

 

I would be REALLY GRATEFUL, for any help, srsly lol.

 

 

My badass script /heh


 

-	shop	dyn_shop1	-1,501:50-	script	Test	-1,{    callshop "dyn_shop1",2;	npcshopattach "dyn_shop1";	end;OnSellItem:	for (.@i = 0; .@i < getarraysize(@sold_nameid); .@i++) {		if (countitem(@sold_nameid[.@i]) < @sold_quantity[.@i] || @sold_quantity[.@i] <= 0) {			mes "omgh4x!";			close;		} else if ( @sold_nameid[.@i] > 1 )			set .@item1,@sold_nameid[.@i];			else if ( @sold_nameid[.@i] > 2 )				set .@item2,@sold_nameid[.@i];				else if ( @sold_nameid[.@i] > 3 )					set .@item3,@sold_nameid[.@i];										mes ""+.@item1+","+.@item2+","+.@item3+"";					close;				deletearray @sold_quantity, getarraysize(@sold_quantity);	deletearray @sold_nameid, getarraysize(@sold_nameid);	mes "Deal completed.";	close;	}}prontera,154,182,5	duplicate(Test)	Test#1	117

I get this:

 

oac5du.jpg

Edited by eKoh

Share this post


Link to post
Share on other sites

5 answers to this question

Recommended Posts

  • 0

Well, yours will only work for 3 items, this one should go for any amount:

-	shop	dyn_shop1	-1,501:50-	script	Test	-1,{        callshop "dyn_shop1",2;	npcshopattach "dyn_shop1";	end;OnSellItem:	for (.@i = 0; .@i < getarraysize(@sold_nameid); .@i++) {		if (countitem(@sold_nameid[.@i]) < @sold_quantity[.@i] || @sold_quantity[.@i] <= 0) {			mes "omgh4x!";			close;		} else if (@sold_nameid[.@i] > 1){			setd ".@item" + .@i, @sold_nameid[.@i];			setd ".@itemqty" + .@i, @sold_quantity[.@i];			mes "You want " + getd(".@itemqty" + .@i) + " " + getitemname(getd(".@item" + .@i)) + (getd(".@itemqty" + .@i)>1?"s":"") + ", right?";		}	}	mes "That totals " +  getarraysize(@sold_nameid) + " items.";	deletearray @sold_quantity, getarraysize(@sold_quantity);	deletearray @sold_nameid, getarraysize(@sold_nameid);	close;}prontera,154,182,5	duplicate(Test)	Test#1	117


An it's strange, for me arrays with char variables went fine.

Share this post


Link to post
Share on other sites
  • 0

But you already have IDs and amount sold in variables O_o

@sold_nameid[index] <- array with ID of item;

@sold_quantity[index] <- array with sold amounts.

 

If you want to keep these variables in char-based ones following should work:

-    shop    dyn_shop1    -1,501:50-    script    Test    -1,{callshop "dyn_shop1",2;npcshopattach "dyn_shop1";end;    OnSellItem:    for (.@i = 0; .@i < getarraysize(@sold_nameid); .@i++) {        if (countitem(@sold_nameid[.@i]) < @sold_quantity[.@i] || @sold_quantity[.@i] <= 0) {            mes "omgh4x!";            close;        }    item[getarraysize(item)] = @sold_nameid[.@i];    amount[getarraysize(amount)] = @sold_quantity[.@i];    }            deletearray @sold_quantity, getarraysize(@sold_quantity);    deletearray @sold_nameid, getarraysize(@sold_nameid);    mes "Stored item sellings:";    for (.@i = 0; .@i < getarraysize(item); .@i++) {        mes "ItemID: " + item[.@i] + "; Amount: " + amount[.@i];    }    mes "These will not disappear anywhere until you clean up these arrays yourself.";    close;}prontera,154,182,5    duplicate(Test)    Test#1    117

Share this post


Link to post
Share on other sites
  • 0

Hello, I kind of made it work! ;D

 

 

 

nwzbs0.jpg

 

 

 

 

 

2qa0qqb.jpg

 

 

 

here is the code:

 

 

-	shop	dyn_shop1	-1,501:50-	script	Test	-1,{        callshop "dyn_shop1",2;	npcshopattach "dyn_shop1";	end;OnSellItem:	for (.@i = 0; .@i < getarraysize(@sold_nameid); .@i++) {		if (countitem(@sold_nameid[.@i]) < @sold_quantity[.@i] || @sold_quantity[.@i] <= 0) {			mes "omgh4x!";			close;		} else if (@sold_nameid[.@i] > 1){			set .@items,getarraysize(@sold_nameid);			set .@item1,getelementofarray(@sold_nameid,0); set .@itemqty1,getelementofarray(@sold_quantity,0);			set .@item2,getelementofarray(@sold_nameid,1); set .@itemqty2,getelementofarray(@sold_quantity,1);			set .@item3,getelementofarray(@sold_nameid,2); set .@itemqty3,getelementofarray(@sold_quantity,2);						mes "You want " + .@items + " items, right?";			mes "You want " + .@itemqty1 + " " + getitemname(.@item1) + "s, right?";			mes "You want " + .@itemqty2 + " " + getitemname(.@item2) + "s, right?";			mes "You want " + .@itemqty3 + " " + getitemname(.@item3) + "s, right?";			close;		}			deletearray @sold_quantity, getarraysize(@sold_quantity);	deletearray @sold_nameid, getarraysize(@sold_nameid);	mes "Deal completed.";	close;	}}prontera,154,182,5	duplicate(Test)	Test#1	117

 

 

 

Is there a way to make this code simplier?

 

Update.

 

I kind of simplify it:

 

 

 

-	shop	dyn_shop1	-1,501:50-	script	Test	-1,{	callshop "dyn_shop1",2;	npcshopattach "dyn_shop1";	end;OnSellItem:	for (.@i = 0; .@i < getarraysize(@sold_nameid); .@i++) {		if (countitem(@sold_nameid[.@i]) < @sold_quantity[.@i] || @sold_quantity[.@i] <= 0) {			mes "omgh4x!";			close;		} else if (@sold_nameid[.@i] > 1){			set @items,getarraysize(@sold_nameid);			setarray @itemsname[0],getelementofarray(@sold_nameid,0),getelementofarray(@sold_nameid,1),getelementofarray(@sold_nameid,2),getelementofarray(@sold_nameid,3),getelementofarray(@sold_nameid,4),getelementofarray(@sold_nameid,5),getelementofarray(@sold_nameid,6),getelementofarray(@sold_nameid,7),getelementofarray(@sold_nameid,8),getelementofarray(@sold_nameid,9),getelementofarray(@sold_nameid,10),getelementofarray(@sold_nameid,11);			setarray @itemsqty[0],getelementofarray(@sold_quantity,0),getelementofarray(@sold_quantity,1),getelementofarray(@sold_quantity,2),getelementofarray(@sold_quantity,3),getelementofarray(@sold_quantity,4),getelementofarray(@sold_quantity,5),getelementofarray(@sold_quantity,6),getelementofarray(@sold_quantity,7),getelementofarray(@sold_quantity,8),getelementofarray(@sold_quantity,9),getelementofarray(@sold_quantity,10),getelementofarray(@sold_quantity,11);						if ( getelementofarray(@sold_nameid,0) > 1) mes "" + @itemsqty[0] + " "+ getitemname(@itemsname[0])+"";			if ( getelementofarray(@sold_nameid,1) > 1) mes "" + @itemsqty[1] + " "+ getitemname(@itemsname[1])+"";			if ( getelementofarray(@sold_nameid,2) > 1) mes "" + @itemsqty[2] + " "+ getitemname(@itemsname[2])+"";			if ( getelementofarray(@sold_nameid,3) > 1) mes "" + @itemsqty[3] + " "+ getitemname(@itemsname[3])+"";			if ( getelementofarray(@sold_nameid,4) > 1) mes "" + @itemsqty[4] + " "+ getitemname(@itemsname[4])+"";			if ( getelementofarray(@sold_nameid,5) > 1) mes "" + @itemsqty[5] + " "+ getitemname(@itemsname[5])+"";			if ( getelementofarray(@sold_nameid,6) > 1) mes "" + @itemsqty[6] + " "+ getitemname(@itemsname[6])+"";			if ( getelementofarray(@sold_nameid,7) > 1) mes "" + @itemsqty[7] + " "+ getitemname(@itemsname[7])+"";			if ( getelementofarray(@sold_nameid,8) > 1) mes "" + @itemsqty[8] + " "+ getitemname(@itemsname[8])+"";			if ( getelementofarray(@sold_nameid,9) > 1) mes "" + @itemsqty[9] + " "+ getitemname(@itemsname[9])+"";			if ( getelementofarray(@sold_nameid,10) > 1) mes "" + @itemsqty[10] + " "+ getitemname(@itemsname[10])+"";			if ( getelementofarray(@sold_nameid,11) > 1) mes "" + @itemsqty[11] + " "+ getitemname(@itemsname[11])+"";					}			deletearray @sold_quantity, getarraysize(@sold_quantity);	deletearray @sold_nameid, getarraysize(@sold_nameid);	mes "Deal completed.";	close;	}}prontera,154,182,5	duplicate(Test)	Test#1	117

 

 

 

Btw, it is finally working ;D!

 

34sfqqh.jpg

 

29qjpd2.jpg

Edited by eKoh

Share this post


Link to post
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.   Restore formatting

  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.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.