RECENT NEWS
📢 𝟑𝟎% Discount for all ads only this month ❄️

667 items disappearing in trade fix ✅

Adam
power_settings_new
Seen 3 years ago
Steel Warrior (11/15)
Steel Warrior
0
0
0
11 Posts
Posts
0
Warning level
0
Likes
0
Dislikes
Joined: 2022-04-24

Upon trading another player who's got less inventory space than the items offered, they disappear,
I couldn't find fix for this as it usually happens, just posting mine here in case someone needs it, maybe not perfect, but works as it should.

1. Add variables in Trade.java:

Code:
	private int invspaceTrader1 = 0;
	private int invspacePartner1 = 0;
	private int invspaceTrader2 = 0;
	private int invspacePartner2 = 0;
	private int cancelTrade1 = 0;
	private int cancelTrade2 = 0;

2. Place this somewhere:

Code:
	public void invspaceCall1() {
		invspaceTrader1 = trader.getInventory().getFreeSlots();
		invspacePartner1 = partner.getInventory().getFreeSlots();
	}
	public void invspaceCall2() {
		invspaceTrader2 = trader.getInventory().getFreeSlots();
		invspacePartner2 = partner.getInventory().getFreeSlots();
	}
	public void cancelTrade() {
		cancelTrade1 = (invspaceTrader2-invspaceTrader1)+(invspacePartner1-invspacePartner2);
		cancelTrade2 = (invspacePartner2-invspacePartner1)+(invspaceTrader1-invspaceTrader2);
	}

3. under:

Code:
public void openFirstTradeScreen(Player p) {

add this:

Code:
invspaceCall1();

and under

Code:
public void openSecondTradeScreen(Player p) {

add:

Code:
invspaceCall2();

Search for:

Code:
private void giveItems() {

replace the whole thing with:

Spoiler for code:
Code:
	private void giveItems() {
		try {
	cancelTrade();
			if (trader.getInventory().getFreeSlots()+cancelTrade1 < 0) {
				
				partner.getPackets()
						.sendGameMessage(
								"Other player does not have enough space in their inventory.");
				trader.getPackets().sendGameMessage(
						"You do not have enough space in your inventory.");
				tradeFailed();
				return;
			} else if (partner.getInventory().getFreeSlots()+cancelTrade2 < 0) {
				trader.getPackets()
						.sendGameMessage(
								"Other player does not have enough space in their inventory.");
				partner.getPackets().sendGameMessage(
						"You do not have enough space in your inventory.");
				tradeFailed();
				return;
			}
			for (Item itemAtIndex : traderItemsOffered.toArray()) {
				if (itemAtIndex != null) {
					partner.getInventory().addItem(itemAtIndex.getId(),
							itemAtIndex.getAmount());
				}
			}
			for (Item itemAtIndex : partnerItemsOffered.toArray()) {
				if (itemAtIndex != null) {
					trader.getInventory().addItem(itemAtIndex.getId(),
							itemAtIndex.getAmount());
				}
			}
			endSession();
			partner.getInventory().refresh();
            partner.getPackets().sendGameMessage("Accepted trade.");
			trader.getInventory().refresh();
			trader.getPackets().sendGameMessage("Accepted trade.");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
00
  • Like
Reactions: