Jump to content
  • 0

NPC Sell All Items Script (Loot and Unequipped Items)


Alenovo

Question


  • Group:  Members
  • Topic Count:  1
  • Topics Per Day:  0.00
  • Content Count:  2
  • Reputation:   0
  • Joined:  12/21/16
  • Last Seen:  

Hello everyone,

I found this script by Punit and Emistry that allows loot and unequipped items to be sold easily. The NPC will ask if the player wants to sell all items in their inventory and pay for all of them when the player accepts. The purpose of this script is to make it easier for players to sell loot they find.

Problem:

The issue is when selling items that stack (e.g. ygg berries, potions, arrows, treasure boxes), it only treats the stack as though it's only one item and only pays for that item. For example, a treasure box sells for 150,000z. If you have 3 treasure boxes it should sell for 450,000z but the NPC only pays 150,000z.

This is not an issue for items that don't stack, especially equipment. Meaning if you have 2 broadswords in the inventory, the NPC would buy them correctly.

Script:

prontera,155,181,5	script	Sample	757,{
getinventorylist;
.@overcharge_lv = getskilllv( "MC_OVERCHARGE" );
if( .@overcharge_lv )
	.@overcharge_rate = 105 + ( 2  * .@overcharge_lv ) - ( ( .@overcharge_lv >= 10 )? 1:0 );
while( .@i < @inventorylist_count ){
	if( !@inventorylist_equip[.@i] ){
		.@item_sell_price = getiteminfo( @inventorylist_id[.@i],1 );
		if( .@overcharge_lv )
			.@item_sell_price = ( ( .@item_sell_price * .@overcharge_rate ) / 100 );
		mes " > "+getitemname( @inventorylist_id[.@i] )+" : "+.@item_sell_price+"z";
		.@cost += .@item_sell_price;
	}
	.@i++;
}
if( .@cost ){
	if( select( "Sell all items for "+.@cost+" zeny ?","Cancel" ) == 1 ){
		.@i = 0;
		while( .@i < @inventorylist_count ){
			if( !@inventorylist_equip[.@i] )
				delitem @inventorylist_id[.@i],@inventorylist_amount[.@i];
			.@i++;
		}
		Zeny += .@cost;
		mes "Gained "+.@cost+" zeny.";
	}
}else{
	mes "You dont have any items.";
}
close;
}

It would be greatly appreciated if anyone can help point out the issue with the script. I looked into the manuals and documentation but I couldn't really understand all of it because I'm new to this.

Thanks in advanced.

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 1

  • Group:  Members
  • Topic Count:  3
  • Topics Per Day:  0.00
  • Content Count:  50
  • Reputation:   9
  • Joined:  01/09/12
  • Last Seen:  

 .@cost += .@item_sell_price;

To

.@cost += .@item_sell_price * @inventorylist_amount[.@i];

 

Edited by Ehwaz
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  1
  • Topics Per Day:  0.00
  • Content Count:  2
  • Reputation:   0
  • Joined:  12/21/16
  • Last Seen:  

Thanks, Ehwaz. I'll try this out.

Update:

The fix Ehwaz provided works. It's working as intended now.

Here's the full NPC script below in case anyone wants it. I modified it tiny bit to show the total number of items that have stacks (e.g. 10x Red Potion, 5x Treasure Box):

prontera,155,181,5	script	Sell All Items	757,{
getinventorylist;
.@overcharge_lv = getskilllv( "MC_OVERCHARGE" );
if( .@overcharge_lv )
	.@overcharge_rate = 105 + ( 2  * .@overcharge_lv ) - ( ( .@overcharge_lv >= 10 )? 1:0 );
while( .@i < @inventorylist_count ){
	if( !@inventorylist_equip[.@i] ){
		.@item_sell_price = getiteminfo( @inventorylist_id[.@i],1 );
		if( .@overcharge_lv )
			.@item_sell_price = ( ( .@item_sell_price * .@overcharge_rate ) / 100 );
		mes " > "+@inventorylist_amount[.@i]+ "x " +getitemname( @inventorylist_id[.@i] )+" : "+.@item_sell_price+"z";
		.@cost += .@item_sell_price * @inventorylist_amount[.@i];
	}
	.@i++;
}
if( .@cost ){
	if( select( "Sell all items for "+.@cost+" zeny?","Cancel" ) == 1 ){
		.@i = 0;
		while( .@i < @inventorylist_count ){
			if( !@inventorylist_equip[.@i] )
				delitem @inventorylist_id[.@i],@inventorylist_amount[.@i];
			.@i++;
		}
		Zeny += .@cost;
		mes "Gained "+.@cost+" zeny.";
	}
}else{
	mes "You don't have any items to sell.";
}
close;
}

Thanks for the help.

Edited by Alenovo
Adding details to the fix.
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  6
  • Topics Per Day:  0.01
  • Content Count:  15
  • Reputation:   0
  • Joined:  04/23/21
  • Last Seen:  

sorry for digging subject but can anybody add option to this script to ignore item in FAV tab in equip ? because for now when i move items to FAV and click "NPC sale lock" it's work for normal shops but not for this NPC =/

@bump

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