Jump to content

Utility: @restock - get items from storage with a command


Mastagoon

Recommended Posts


  • Group:  Members
  • Topic Count:  8
  • Topics Per Day:  0.00
  • Content Count:  63
  • Reputation:   35
  • Joined:  07/04/19
  • Last Seen:  

@restock - get items from storage with a command


My take on the @restock command. 

This script allows you to set a list of item to restock from your storage, for example 100 blue gemstones and 300 white potions.

When using the command, a ticket item will be consumed to get the specified items from storage.

This script is so that you'll always have the needed quantity of items in the list. for example, if you have 22 gemstones in your inventory and you use @restock, you'll get the 78 gemstones missing to the full 100

any feedback is appreciated.


  • Submitter
  • Submitted
    01/21/2021
  • Category
  • Video
  • Content Author
    Mastagoon

 

  • Love 1
  • MVP 1
Link to comment
Share on other sites

  • 3 months later...

  • Group:  Members
  • Topic Count:  2
  • Topics Per Day:  0.00
  • Content Count:  6
  • Reputation:   0
  • Joined:  06/11/20
  • Last Seen:  

i did a clean up of the script however i have experienced an issue when the item in your inventory is greater than what you have from your restock list. what happens is that a negative amount of item is dropped from the player. 
this version does not need the ticket however it only works whenever you are in town.
EDIT:
v1.2 with the function to prevent the error when the items in your inventory is greater than that of your re-stock list.
 




 

//===== rAthena Script ======================================= 
//= @restock command
//===== By: ==================================================
//= Mastagoon
//===== Description: =========================================
//= @restock command to get certain items from your storage
//===== Current Version: =====================================
//= 1.0
//= 1.1 added town only and clean up on some of the code.
//= 1.2 added an if function when your items in your inventory is greater than the items from your stock list<hannahhaven621>
//===== TODO: ================================================
//=	@restock SNAPSHOT
//============================================================
-	script	restock_atcmd	-1,{	
function	addSpace	{
	set .@space$, "";
	for(.@i = 1; .@i <= getarg(0); .@i++) {
		set .@space$, .@space$+" ";
	}
	return .@space$;
}

function	showRestockHelp	{
	dispbottom "Command Usage : ";
	dispbottom "@restock add <itemid> <quantity> : add item to restock list";
	dispbottom "@restock remove <itemid> : remove item from restock list";
	dispbottom "@restock list : show current restock list";
	dispbottom "@restock reset : reset restock list";
	dispbottom "@restock help/h : show this help menu";
	dispbottom "@restock : get restock items from the storage.";
}

OnInit:
	.TicketID = -1;
	setarray .allowedtypes[0],0,1,2,3,7,8,9,10,11,12; //healing,usable,etc,delayed usable
	bindatcmd "restock",strnpcinfo(3)+"::OnAtcommand";
	end;

OnAtcommand:
	switch(.@atcmd_numparameters) {
		case 0:	// @restock command
			if(getarraysize(RestockList) == 0) {
				dispbottom "Your restock list is empty.";
				end;
			} 
			if(!getmapflag(strcharinfo(3),mf_town,0)) {
				dispbottom "You can only use this command inside Towns.";
				end;			
			}	
			for(.@i = 0; .@i < getarraysize(RestockList); .@i++) {
				.@amount = RestockAmountList[.@i] - countitem(RestockList[.@i]);
				if(!storagecountitem(RestockList[.@i])  > .@amount)  {
					dispbottom "@restocking "+getitemname(RestockList[.@i])+" failed, your item in your inventory is greater than your restock list.";
				close;
				}
				if(storagecountitem(RestockList[.@i])  >= .@amount) {
					getitem RestockList[.@i],.@amount;
					storagedelitem RestockList[.@i],.@amount; // successful @restock
				}
					else {
					dispbottom "@restocking "+getitemname(RestockList[.@i])+" failed, not enough in storage.";
				}
			}
			break;
		case 1:
			if(strtolower(.@atcmd_parameters$[0]) == "list") { // get restock list
				if(getarraysize(RestockList) == 0) {
					dispbottom "Your restock list is empty.";
					end;
				}
				dispbottom "ID"+addSpace(32)+"Name"+addSpace(32)+"Quantity";
				dispbottom "============================================";
				for(.@i = 0; .@i < getarraysize(RestockList); .@i++) {
					.@item_name$ = getitemname(RestockList[.@i]);
					dispbottom RestockList[.@i]+addSpace(30-getstrlen(.@i+""))+.@item_name$+addSpace(36-
					getstrlen(.@item_name$))+RestockAmountList[.@i];
				}
			} else if(strtolower(.@atcmd_parameters$[0]) == "reset") {	// reset restock list
				deletearray RestockList[0],getarraysize(RestockList);
				deletearray RestockAmountList[0],getarraysize(RestockAmountList);
				dispbottom "Your restock list have been reset.";
			} else if(strtolower(.@atcmd_parameters$[0]) == "help" || strtolower(.@atcmd_parameters$[0]) == "h") {
				showRestockHelp();
			}
			break;
		case 2:
			if(strtolower(.@atcmd_parameters$[0]) != "remove") {
				showRestockHelp();
				end;
			}
			.@item = atoi(.@atcmd_parameters$[1]);
			if(getitemname(.@item) == "null") {
				dispbottom "@restock : This item dones not exist. (id "+.@item+")";
				end;
			}
			.@index = inarray(RestockList, .@item);
			if(.@index == -1) {	//item is not in the list
				dispbottom "@restock : This item is not on your restock list.";
				end;
			}
			deletearray RestockList[.@index],1;
			deletearray RestockAmountList[.@index],1;
			dispbottom "@restock: item "+getitemname(.@item)+" deleted succesfully!";
			break;
		case 3:
			.@item = atoi(.@atcmd_parameters$[1]);
			.@quantity = atoi(.@atcmd_parameters$[2]);
			if(strtolower(.@atcmd_parameters$[0]) != "add" || !.@item || !.@quantity) {
				dispbottom "@restock : Invaild parameters.";
				showRestockHelp();
				end;
			}
			if(getitemname(.@item) == "null"){
				dispbottom "@restock : This item does not exist. (id "+.@item+")";
				end;
			} else if(inarray(.allowedtypes[0],getiteminfo(.@item,2)) == -1) {
				dispbottom "@restock : You cannot restock this type of items.";
				end;
			} else if(inarray(RestockList[0],.@item) >= 0) {
				dispbottom "@restock : Item '"+getitemname(.@item)+"' (id:"+.@item+") already in list.";
				end;
			} else if(.@quantity < 1 || .@quantity > 500) {
				dispbottom "@restock : Please enter valid quantity value (1 - 500)";
				end;
			}
			//passed all checks
			setarray RestockList[getarraysize(RestockList)],.@item;
			setarray RestockAmountList[getarraysize(RestockAmountList)],.@quantity;
			dispbottom "@restock : Item '"+getitemname(.@item)+"' (id:"+.@item+") amount "+.@quantity+" successfully added!";
			break;
		default:
			showRestockHelp();
			break;
	}
	end;
}

 

Edited by hannahhaven621
udpated code
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  8
  • Topics Per Day:  0.00
  • Content Count:  63
  • Reputation:   35
  • Joined:  07/04/19
  • Last Seen:  

9 hours ago, hannahhaven621 said:

i did a clean up of the script however i have experienced an issue when the item in your inventory is greater than what you have from your restock list. what happens is that a negative amount of item is dropped from the player. 
this version does not need the ticket however it only works whenever you are in town.
EDIT:
v1.2 with the function to prevent the error when the items in your inventory is greater than that of your re-stock list.
 




 


//===== rAthena Script ======================================= 
//= @restock command
//===== By: ==================================================
//= Mastagoon
//===== Description: =========================================
//= @restock command to get certain items from your storage
//===== Current Version: =====================================
//= 1.0
//= 1.1 added town only and clean up on some of the code.
//= 1.2 added an if function when your items in your inventory is greater than the items from your stock list<hannahhaven621>
//===== TODO: ================================================
//=	@restock SNAPSHOT
//============================================================
-	script	restock_atcmd	-1,{	
function	addSpace	{
	set .@space$, "";
	for(.@i = 1; .@i <= getarg(0); .@i++) {
		set .@space$, .@space$+" ";
	}
	return .@space$;
}

function	showRestockHelp	{
	dispbottom "Command Usage : ";
	dispbottom "@restock add <itemid> <quantity> : add item to restock list";
	dispbottom "@restock remove <itemid> : remove item from restock list";
	dispbottom "@restock list : show current restock list";
	dispbottom "@restock reset : reset restock list";
	dispbottom "@restock help/h : show this help menu";
	dispbottom "@restock : get restock items from the storage.";
}

OnInit:
	.TicketID = -1;
	setarray .allowedtypes[0],0,1,2,3,7,8,9,10,11,12; //healing,usable,etc,delayed usable
	bindatcmd "restock",strnpcinfo(3)+"::OnAtcommand";
	end;

OnAtcommand:
	switch(.@atcmd_numparameters) {
		case 0:	// @restock command
			if(getarraysize(RestockList) == 0) {
				dispbottom "Your restock list is empty.";
				end;
			} 
			if(!getmapflag(strcharinfo(3),mf_town,0)) {
				dispbottom "You can only use this command inside Towns.";
				end;			
			}	
			for(.@i = 0; .@i < getarraysize(RestockList); .@i++) {
				.@amount = RestockAmountList[.@i] - countitem(RestockList[.@i]);
				if(!storagecountitem(RestockList[.@i])  > .@amount)  {
					dispbottom "@restocking "+getitemname(RestockList[.@i])+" failed, your item in your inventory is greater than your restock list.";
				close;
				}
				if(storagecountitem(RestockList[.@i])  >= .@amount) {
					getitem RestockList[.@i],.@amount;
					storagedelitem RestockList[.@i],.@amount; // successful @restock
				}
					else {
					dispbottom "@restocking "+getitemname(RestockList[.@i])+" failed, not enough in storage.";
				}
			}
			break;
		case 1:
			if(strtolower(.@atcmd_parameters$[0]) == "list") { // get restock list
				if(getarraysize(RestockList) == 0) {
					dispbottom "Your restock list is empty.";
					end;
				}
				dispbottom "ID"+addSpace(32)+"Name"+addSpace(32)+"Quantity";
				dispbottom "============================================";
				for(.@i = 0; .@i < getarraysize(RestockList); .@i++) {
					.@item_name$ = getitemname(RestockList[.@i]);
					dispbottom RestockList[.@i]+addSpace(30-getstrlen(.@i+""))+.@item_name$+addSpace(36-
					getstrlen(.@item_name$))+RestockAmountList[.@i];
				}
			} else if(strtolower(.@atcmd_parameters$[0]) == "reset") {	// reset restock list
				deletearray RestockList[0],getarraysize(RestockList);
				deletearray RestockAmountList[0],getarraysize(RestockAmountList);
				dispbottom "Your restock list have been reset.";
			} else if(strtolower(.@atcmd_parameters$[0]) == "help" || strtolower(.@atcmd_parameters$[0]) == "h") {
				showRestockHelp();
			}
			break;
		case 2:
			if(strtolower(.@atcmd_parameters$[0]) != "remove") {
				showRestockHelp();
				end;
			}
			.@item = atoi(.@atcmd_parameters$[1]);
			if(getitemname(.@item) == "null") {
				dispbottom "@restock : This item dones not exist. (id "+.@item+")";
				end;
			}
			.@index = inarray(RestockList, .@item);
			if(.@index == -1) {	//item is not in the list
				dispbottom "@restock : This item is not on your restock list.";
				end;
			}
			deletearray RestockList[.@index],1;
			deletearray RestockAmountList[.@index],1;
			dispbottom "@restock: item "+getitemname(.@item)+" deleted succesfully!";
			break;
		case 3:
			.@item = atoi(.@atcmd_parameters$[1]);
			.@quantity = atoi(.@atcmd_parameters$[2]);
			if(strtolower(.@atcmd_parameters$[0]) != "add" || !.@item || !.@quantity) {
				dispbottom "@restock : Invaild parameters.";
				showRestockHelp();
				end;
			}
			if(getitemname(.@item) == "null"){
				dispbottom "@restock : This item does not exist. (id "+.@item+")";
				end;
			} else if(inarray(.allowedtypes[0],getiteminfo(.@item,2)) == -1) {
				dispbottom "@restock : You cannot restock this type of items.";
				end;
			} else if(inarray(RestockList[0],.@item) >= 0) {
				dispbottom "@restock : Item '"+getitemname(.@item)+"' (id:"+.@item+") already in list.";
				end;
			} else if(.@quantity < 1 || .@quantity > 500) {
				dispbottom "@restock : Please enter valid quantity value (1 - 500)";
				end;
			}
			//passed all checks
			setarray RestockList[getarraysize(RestockList)],.@item;
			setarray RestockAmountList[getarraysize(RestockAmountList)],.@quantity;
			dispbottom "@restock : Item '"+getitemname(.@item)+"' (id:"+.@item+") amount "+.@quantity+" successfully added!";
			break;
		default:
			showRestockHelp();
			break;
	}
	end;
}

 

Thank you for your contribution ❤️ . I have updated the file and added a few options.

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
Reply to this topic...

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