Jump to content
  • 0

Universal Dynamic NPC Item Stock Limit?


Venomenon

Question


  • Group:  Members
  • Topic Count:  19
  • Topics Per Day:  0.00
  • Content Count:  50
  • Reputation:   0
  • Joined:  11/21/11
  • Last Seen:  

I was just wondering if it's possible to add a new feature on the Universal Dynamic NPC where in you can put a limited item in stock?

The code is here below:

-	shop	quest_shop1	-1,501:50

prontera,150,150,3	script	Free Equipments	917,{
set @i,0;
mes "[Donation Manager]";
mes "Please select the equipment you want";
callshop "quest_shop1",1;
npcshopattach "quest_shop1";
end;
OnBuyItem:
if(.BuildQuest) {
	for(set .e,0; !compare(getarg(.e+1),"Zeny"); set .e,.e+2) {}
	npcshopadditem "quest_shop27",getarg(.e+2),getarg(.e)*compare(getarg(.e+1),"SZeny");
	setarray .Shop[.i],getarg(.e+2);
	set .i,.i+1;
	goto Quest_Setup;
}
if(.Shop[@i]!=@bought_nameid) for(set @i,1; 1; set @i,@i+1) if(.Shop[@i]==@bought_nameid) { set .i,@i; callsub Quest_Setup; }
for(set @i,1; !@e; set @i,@i+1) if(.Shop[@i]==@bought_nameid) { set @e,1; set .i,@i; callsub Quest_Setup; }
mes "[shop Quest NPC]";
mes "I require the following:";
for(set @i,0; !compare(getarg(@i+1),"Zeny"); set @i,@i+2) mes "^FF0000" + ((countitem(getarg(@i))>=getarg(@i+1))? "^00FF00":"") + "" + getarg(@i+1) + " " + getitemname(getarg(@i)) + " [" + countitem(getarg(@i)) + "/" + getarg(@i+1) + "]";
if(getarg(@i)) mes "^FF0000" + ((Zeny>=getarg(@i))? "^00FF00":"") + "" + getarg(@i) + " Zeny";
mes "^000000In exchange, I will give you:^0000FF";
for(set @i,@i+2; getarg(@i+1,0); set @i,@i+2) mes getarg(@i+1) + " " + getitemname(getarg(@i));
switch(select("Exchange:" + (((((getiteminfo(@bought_nameid,5) & 1) || (getiteminfo(@bought_nameid,5) & 256) || (getiteminfo(@bought_nameid,5) & 512)) && @equip==0))? "Preview Item":"") + ":No thanks")) {
case 1:
	for(set @i,0; !compare(getarg(@i+1),"Zeny"); set @i,@i+2) if(countitem(getarg(@i)) < getarg(@i+1)) {
		next;
		mes "You have " + countitem(getarg(@i)) + " " + getitemname(getarg(@i)) + ", while I require " + getarg(@i+1) + ".";
		mes "Please obtain ^FF0000" + (getarg(@i+1)-countitem(getarg(@i))) + " more " + getitemname(getarg(@i)) + "^000000.";
		close;
	}
	if(Zeny < getarg(@i)) {
		next;
		mes "You do not have enough Zeny.";
		mes "Please obtain ^FF0000" + (getarg(@i)-Zeny) + " more Zeny^000000.";
		close;
	}
	for(set @i,0; !compare(getarg(@i+1),"Zeny"); set @i,@i+2) delitem getarg(@i),getarg(@i+1);
	set Zeny,Zeny-getarg(@i);
	for(set @i,@i+2; getarg(@i+1,0); set @i,@i+2) getitem getarg(@i),getarg(@i+1);
	if (compare(getarg(@i,0),"announce")) announce strcharinfo(0) + " has just obtained " + getitemname(@bought_nameid) + "!",bc_all;
	close;
case 2:
	set @bottomview, getlook(3);
	set @topview, getlook(4);
	set @midview, getlook(5);
	addtimer 1000, strnpcinfo(3)+"::On_Leave";
	set @equip,getiteminfo(@bought_nameid, 5);
	set @view, getiteminfo(@bought_nameid, 11);
	if(@equip != -1 && @view > 0) {
		if(@equip & 1) atcommand "@changelook 3 " + @view;
		if(@equip & 256) atcommand "@changelook 1 " + @view;
		if(@equip & 512) atcommand "@changelook 2 " + @view;
	}
	next;
	goto OnBuyItem;
case 3:
	close;
}
On_Leave:
atcommand "@changelook 1 " + @topview;
atcommand "@changelook 2 " + @midview;
atcommand "@changelook 3 " + @bottomview;
set @equip,0;
set @view,0;
set @topview,0;
set @midview,0;
set @bottomview,0;
end;
OnInit:
npcshopitem "quest_shop1",0,0;
set .BuildQuest,1;
set .i,1;
Quest_Setup:
switch(.i) {
	default: set .BuildQuest,0; set .e,0; set .i,0; end;
	case 1: callsub OnBuyItem,25095,600,600,"SZeny",2394,1;
}
}

I was just going to post on the old eAthena forums but I found out that you guys transferred here and the Universal Dynamic NPC topic has not been made yet so I seek help here in the scripting support if possible. If I'm still wrong, forgive me if I post in the wrong section

Link to comment
Share on other sites

9 answers to this question

Recommended Posts

  • 0

  • Group:  Members
  • Topic Count:  39
  • Topics Per Day:  0.01
  • Content Count:  615
  • Reputation:   201
  • Joined:  11/09/11
  • Last Seen:  

set the array OnInit: you are resetting the array on every npc click...

prontera,153,153,3 script Free Equipments 917,{
setarray .setlimit[0],3,5;

change to

prontera,153,153,3 script Free Equipments 917,{

find the OnInit: section add

OnInit:
setarray .setlimit[0],3,5;

I'll look into more options later, because you ill also need to the shop dynamic so on each click of the shop, it's updated with the amount of stock, aka, if .setlimit[.@a] == 0, the item should not display... and the index should be skipped...

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  39
  • Topics Per Day:  0.01
  • Content Count:  615
  • Reputation:   201
  • Joined:  11/09/11
  • Last Seen:  

This is considered more of a request, because you are not attempting to do this on your own, but asking for someone to do it for you. (Topic Moved)

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  19
  • Topics Per Day:  0.00
  • Content Count:  50
  • Reputation:   0
  • Joined:  11/21/11
  • Last Seen:  

Oh well thanks for pointing that out sir! Basically, I still really want to do this on my own but I have no idea how so I thought I should post it there. Anyways, thanks. Hope someone can help me out here :)

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  24
  • Topics Per Day:  0.01
  • Content Count:  201
  • Reputation:   47
  • Joined:  11/17/11
  • Last Seen:  

Maybe you could try adding an npc variable to keep count for each item. So in the following:

Quest_Setup:
switch(.i) {
 default: set .BuildQuest,0; set .e,0; set .i,0; end;

 case 1: callsub OnBuyItem,25095,600,600,"SZeny",2394,1;
 }
}

Change it to something like this:

Quest_Setup:
switch(.i) {
 default: set .BuildQuest,0; set .e,0; set .i,0; end;

 case 1:
	if(.ThisItemLimit <= 10) {
		callsub OnBuyItem,25095,600,600,"SZeny",2394,1;
		set .ThisItemLimit,.ThisItemLimit+1;
	}
 }
}

I have not tested this, but it should work o: (Note, you will have to add a menu for GMs to clear it or some other means otherwise it will remain unaccessable)

+Edit: Damn this copy paste ! haha, sorry but this edit should appear properly now!

Edited by Truly
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  19
  • Topics Per Day:  0.00
  • Content Count:  50
  • Reputation:   0
  • Joined:  11/21/11
  • Last Seen:  

Thank you sir! I'd try it when I get home. I only got one question more, what if I have like multiple items, something like this, will it still work just by following the pattern of the code you posted sir for each case?

Quest_Setup:
switch(.i) {
default: set .BuildQuest,0; set .e,0; set .i,0; end;
case 1: callsub OnBuyItem,25095,600,600,"SZeny",2394,1;


case 2: callsub OnBuyItem,25095,600,600,"SZeny",2395,1;


case 3: callsub OnBuyItem,25095,600,600,"SZeny",2396,1;

Edited by Venomenon
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  24
  • Topics Per Day:  0.01
  • Content Count:  201
  • Reputation:   47
  • Joined:  11/17/11
  • Last Seen:  

It should work fine as long as you change the npc variable name, so like .ThisItemLimit1 then .ThisItemLimit2 etc.

Btw i didnt mention it, but i should now. If the case is not sending data back up, and all cases are empty, you will probably get some empty menus or something later on. You can easily solve this by adding an if statement on the end basically seeing if there is data in the shop, if not the goto some L_noitem menu.

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  19
  • Topics Per Day:  0.00
  • Content Count:  50
  • Reputation:   0
  • Joined:  11/21/11
  • Last Seen:  

Hi, good day sir. I just tried the script revision and I still can buy the items over and over again even when I set it to <=2.

Then I tried to put a variable checker for .ThisItemLimit and found out that the variable does not change even when I buy the item from the NPC.

Edited by Venomenon
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  24
  • Topics Per Day:  0.01
  • Content Count:  201
  • Reputation:   47
  • Joined:  11/17/11
  • Last Seen:  

Alright i have made a little progress with this, i have been debugging it for over an hour ~.~ seems it isnt as simple as i thought.

I got it to recognize that you bought an item, and it updates an array for that item, but im having trouble removing that item from the shop. Hopefully we can get another brain in here to help with this o:

Thus far:



-	shop	quest_shop1	-1,501:50

prontera,153,153,3	script	Free Equipments	917,{
setarray .setlimit[0],3,5;			// Set the item limit here. *Note, make them match the Case/Callsub at the end of this script.
if(getgmlevel() == 99) {
	mes "[Donation Manager]";
	mes "^FF0000~Admin Menu~^000000";
	mes "Would you like to reset";
	mes "the item limit sir?";
	switch(select("No, don't:Yes, reset it")) {
		case 1:
			next;
			mes "[Donation Manager]";
			mes "It's alright, no rush.";
			next;
			break;
		case 2:
			next;
			mes "[Donation Manager]";
			mes "Are you sure you want";
			mes "the item limit to be ^FF0000reset^000000?";
			switch(select("No, don't:Yes, reset it")) {
				case 1:
					next;
					mes "[Donation Manager]";
					mes "It's alright, no rush.";
					next;
					break;
				case 2:
					next;
					set .itemlimit1,0;
					mes "[Donation Manager]";
					mes "It has been done!";
					close;
			}
		break;
	}
}
set .@temp,0;
set @i,0;
mes "[Donation Manager]";
mes "Please select the equipment you want";
callshop "quest_shop1",1;
npcshopattach "quest_shop1";
end;
OnBuyItem:
if(.BuildQuest) {
	for(set .e,0; !compare(getarg(.e+1) + "","Zeny"); set .e,.e+2) {}
	for (set .@t,0; .@t < getarraysize(.itemlimit)+1; set .@t,.@t + 1) {
		if(.setlimit[.@t] < .itemlimit[.@t]) {
			npcshopdelitem "quest_shop1",914,1;
			set .@temp,.@temp+1;
		} else npcshopadditem "quest_shop1",getarg(.e+2),getarg(.e)*compare(getarg(.e+1) + "","SZeny");
	}
	setarray .Shop[.i],getarg(.e+2);
	set .i,.i+1;
	goto Quest_Setup;
}
if(.@temp > getarraysize(.itemlimit)) goto L_none;
if(.Shop[@i]!=@bought_nameid) for(set @i,1; 1; set @i,@i+1) if(.Shop[@i]==@bought_nameid) { set .i,@i; callsub Quest_Setup; }
for(set @i,1; !@e; set @i,@i+1) if(.Shop[@i]==@bought_nameid) { set @e,1; set .i,@i; callsub Quest_Setup; }
mes "[shop Quest NPC]";
mes "I require the following:";
for(set @i,0; !compare(getarg(@i+1) + "","Zeny"); set @i,@i+2) mes "^FF0000" + ((countitem(getarg(@i))>=getarg(@i+1))? "^00FF00":"") + "" + getarg(@i+1) + " " + getitemname(getarg(@i)) + " [" + countitem(getarg(@i)) + "/" + getarg(@i+1) + "]";
if(getarg(@i)) mes "^FF0000" + ((Zeny>=getarg(@i))? "^00FF00":"") + "" + getarg(@i) + " Zeny";
mes "^000000In exchange, I will give you:^0000FF";
for(set @i,@i+2; getarg(@i+1,0); set @i,@i+2) mes getarg(@i+1) + " " + getitemname(getarg(@i));
switch(select("Exchange:" + (((((getiteminfo(@bought_nameid,5) & 1) || (getiteminfo(@bought_nameid,5) & 256) || (getiteminfo(@bought_nameid,5) & 512)) && @equip==0))? "Preview Item":"") + ":No thanks")) {
	case 1:
		for(set @i,0; !compare(getarg(@i+1) + "","Zeny"); set @i,@i+2) if(countitem(getarg(@i)) < getarg(@i+1)) {
			next;
			mes "You have " + countitem(getarg(@i)) + " " + getitemname(getarg(@i)) + ", while I require " + getarg(@i+1) + ".";
			mes "Please obtain ^FF0000" + (getarg(@i+1)-countitem(getarg(@i))) + " more " + getitemname(getarg(@i)) + "^000000.";
			close;
		}
		if(Zeny < getarg(@i)) {
			next;
			mes "You do not have enough Zeny.";
			mes "Please obtain ^FF0000" + (getarg(@i)-Zeny) + " more Zeny^000000.";
			close;
		}
		for(set @i,0; !compare(getarg(@i+1) + "","Zeny"); set @i,@i+2) delitem getarg(@i),getarg(@i+1);
		set Zeny,Zeny-getarg(@i);
		for(set @i,@i+2; getarg(@i+1,0); set @i,@i+2) getitem getarg(@i),getarg(@i+1);
		set .itemlimit[getarg(6)],.itemlimit[getarg(6)] + 1;
		if (compare(getarg(@i,0) + "","announce")) announce strcharinfo(0) + " has just obtained " + getitemname(@bought_nameid) + "!",bc_all;
		close;
	case 2:
		set @bottomview, getlook(3);
		set @topview, getlook(4);
		set @midview, getlook(5);
		addtimer 1000, strnpcinfo(3)+"::On_Leave";
		set @equip,getiteminfo(@bought_nameid, 5);
		set @view, getiteminfo(@bought_nameid, 11);
		if(@equip != -1 && @view > 0) {
			if(@equip & 1) atcommand "@changelook 3 " + @view;
			if(@equip & 256) atcommand "@changelook 1 " + @view;
			if(@equip & 512) atcommand "@changelook 2 " + @view;
		}
		next;
		goto OnBuyItem;
	case 3:
		close;
}
On_Leave:
atcommand "@changelook 1 " + @topview;
atcommand "@changelook 2 " + @midview;
atcommand "@changelook 3 " + @bottomview;
set @equip,0;
set @view,0;
set @topview,0;
set @midview,0;
set @bottomview,0;
end;
L_none:
next;
mes "[Donation Manager]";
mes "Oh I am sorry... ";
mes "There seems to be a";
mes "shortage of items currently.";
next;
mes "[Donation Manager]";
mes "Please try again later!";
close;
end;
OnInit:
npcshopitem "quest_shop1",0,0;
npcshopdelitem "quest_shop1",0,0;
set .BuildQuest,1;
set .i,1;
Quest_Setup:
switch(.i) {
	case 1: callsub OnBuyItem,914,600,600,"SZeny",678,1,0;		// Little modification here. Add a final argument being the item number.
	case 2: callsub OnBuyItem,915,600,600,"SZeny",679,1,1;		// Notice how it increases by 1 every time.
	case 3: set .BuildQuest,0; set .e,0; set .i,0;				// This line prevents that Warning on your Console about item id 0.
}
}

There were some minor errors with the script before such as an incorrect shop name and some others. This one has pretty much what it should, and 1/2 of the item limit edit.

Edited by Truly
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  19
  • Topics Per Day:  0.00
  • Content Count:  50
  • Reputation:   0
  • Joined:  11/21/11
  • Last Seen:  

Thank you sir. I'll try this soon as I get home! More power!

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...