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.0updates the money offer only.1–9adds or removes an item (see Details).- inventorySlot
number– Slot of the item to add, inside its backpack.0removes the item in trade slottradeSlotinstead.- backpackType
number– Backpack thatinventorySlotbelongs to (theEA_Window_Backpack.TYPE_*values: 1 quest, 2 inventory, 3 currency, 4 crafting).- money
number– Money offered. Only read whentradeSlotis0.
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: storesmoneyas the money offer and sends the update. The item list is unchanged.tradeSlot1–9 andinventorySlot = 0: removes the item in that trade slot. Later items move up one slot.tradeSlot1–9 andinventorySlotnot 0: appends the item to the end of the list. The actual value oftradeSlotdoes not matter here; the stock UI always passes1.inventorySlotandbackpackTypeare turned into the item's absolute inventory slot before it is stored.- Any other
tradeSlotvalue sends the update without changing anything. - The money value is only stored when
tradeSlotis0; 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 )
