Skip to content

Return of Reckoning

Wiki

RoR Wiki

API:ChangeTrade

From RoR Wiki

UI Lua API · Trade functions
Version: WAR 1.4.8

Changes the player's side of the current trade (items or money) and sends the update to the server.

ChangeTrade(tradeSlot, inventorySlot, backpackType, money)

Arguments

tradeSlot
number – What to change. 0 updates the money offer only. 1–9 adds or removes an item (see Details).
inventorySlot
number – Slot of the item to add, inside its backpack. 0 removes the item in trade slot tradeSlot instead.
backpackType
number – Backpack that inventorySlot belongs to (the EA_Window_Backpack.TYPE_* values: 1 quest, 2 inventory, 3 currency, 4 crafting).
money
number – Money offered. Only read when tradeSlot is 0.

Returns

Nothing.

Details

  • The client keeps a list of the items the player offers (up to 9) and the money amount. After changing that list it sends a trade update with the full list and money to the current trade partner.
  • tradeSlot = 0: stores money as the money offer and sends the update. The item list is unchanged.
  • tradeSlot 1–9 and inventorySlot = 0: removes the item in that trade slot. Later items move up one slot.
  • tradeSlot 1–9 and inventorySlot not 0: appends the item to the end of the list. The actual value of tradeSlot does not matter here; the stock UI always passes 1. inventorySlot and backpackType are turned into the item's absolute inventory slot before it is stored.
  • Any other tradeSlot value sends the update without changing anything.
  • The money value is only stored when tradeSlot is 0; in the other cases the last stored amount is sent again.
  • The stock UI calls ChangeTrade(0, 0, 0, money) to take back an acceptance (EA_Window_Trade.UnacceptTrade).
  • The client does not check for duplicate items or for more than 9 items, and removing an empty trade slot still shortens the list by one. Keep track of the offer in Lua, as the stock trade window does.
  • Does nothing if the player object does not exist yet.
  • The function needs at least four arguments and only reads the last four. All must be numbers.

Errors

None besides the generic Invalid Parameters message when an argument is not a number.

Example

From default/ea_tradewindow/source/tradewindow.lua:

-- which trade slot we're requesting doesn't matter so just hardcoding 1,
--   since server is just putting it in first available slot
ChangeTrade( 1, invSlotNum, backpackType, EA_Window_Trade.myOfferMoney )
-- tell server we're removing item from trade
ChangeTrade( slot, 0, 0, EA_Window_Trade.myOfferMoney )

See also