help with a code I'm writing

goldboy

Vagabond
Good evening, I have a problem with a code I am writing. I want to create a store so that the bot can sell items. While it appears in the inventory, when you click to buy it, it says "the attempt to trade has failed". is there a solution



// ==================== SELL ====================
public static boolean startSell(Player phantom, List<ShopItem> items, String message) {
if (phantom == null || items == null || items.isEmpty())
return false;

stop(phantom);

try {
// clear package list to avoid package store
Object sellPkg = safeInvokeRet(phantom, "getSellPkgList");
if (sellPkg != null)
safeClearList(sellPkg);

Object sellList = safeInvokeRet(phantom, "getSellList");
if (sellList == null)
return false;

safeClearList(sellList);

for (ShopItem si : items) {
if (si == null || si.itemId <= 0 || si.count <= 0 || si.price <= 0)
return false;

ItemInstance invItem = phantom.getInventory().getItemByItemId(si.itemId);
if (invItem == null)
return false;
if (!invItem.canBeTraded(phantom))
return false;

long cnt = si.count;
if (cnt > invItem.getCount())
cnt = invItem.getCount();
if (cnt < 1)
return false;

int objId = invItem.getObjectId();

// primary: addItem(int objectId, long count, long price)
if (!tryInvoke(sellList, "addItem",
new Class[]{int.class, long.class, long.class},
new Object[]{objId, cnt, si.price})) {

// alt: addItem(ItemInstance,long,long)
if (!tryInvoke(sellList, "addItem",
new Class[]{invItem.getClass(), long.class, long.class},
new Object[]{invItem, cnt, si.price})) {

// fallback list.add(TradeItem)
TradeItem ti = new TradeItem(invItem);
ti.setObjectId(objId);
ti.setCount(cnt);
ti.setOwnersPrice(si.price);
tryInvoke(ti, "setStorePrice",
new Class[]{long.class}, new Object[]{si.price});

tryInvoke(sellList, "add",
new Class[]{Object.class}, new Object[]{ti});
}
}
}

setStoreMessage(phantom, message, true);
setPrivateStoreType(phantom, Player.STORE_PRIVATE_SELL);
safeSitDown(phantom);

phantom.broadcastPacket(new PrivateStoreMsgSell(phantom));
phantom.broadcastCharInfo();
phantom.saveTradeList();
return true;
} catch (Throwable t) {
return false;
}
}
 
Back
Top