<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.returnofreckoning.com/index.php?action=history&amp;feed=atom&amp;title=API%3AInitiateTrade</id>
	<title>API:InitiateTrade - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.returnofreckoning.com/index.php?action=history&amp;feed=atom&amp;title=API%3AInitiateTrade"/>
	<link rel="alternate" type="text/html" href="https://wiki.returnofreckoning.com/index.php?title=API:InitiateTrade&amp;action=history"/>
	<updated>2026-10-17T07:42:49Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.11</generator>
	<entry>
		<id>https://wiki.returnofreckoning.com/index.php?title=API:InitiateTrade&amp;diff=30510&amp;oldid=prev</id>
		<title>Maintenance script: UI Lua API import (WAR 1.4.8)</title>
		<link rel="alternate" type="text/html" href="https://wiki.returnofreckoning.com/index.php?title=API:InitiateTrade&amp;diff=30510&amp;oldid=prev"/>
		<updated>2026-10-16T19:45:42Z</updated>

		<summary type="html">&lt;p&gt;UI Lua API import (WAR 1.4.8)&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{LuaApi|group=Trade}}&lt;br /&gt;
Asks the server to open a trade with the current target or with a given player.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
InitiateTrade(useCurrentTarget, targetId)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Arguments ==&lt;br /&gt;
;useCurrentTarget : &amp;lt;code&amp;gt;number&amp;lt;/code&amp;gt; – &amp;lt;code&amp;gt;1&amp;lt;/code&amp;gt; to trade with the player&amp;#039;s current target. Any other value uses &amp;lt;code&amp;gt;targetId&amp;lt;/code&amp;gt;.&lt;br /&gt;
;targetId : &amp;lt;code&amp;gt;number&amp;lt;/code&amp;gt; – Object ID of the player to trade with. Ignored when &amp;lt;code&amp;gt;useCurrentTarget&amp;lt;/code&amp;gt; is &amp;lt;code&amp;gt;1&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Returns ==&lt;br /&gt;
Nothing.&lt;br /&gt;
&lt;br /&gt;
== Details ==&lt;br /&gt;
* With &amp;lt;code&amp;gt;useCurrentTarget = 1&amp;lt;/code&amp;gt;:&lt;br /&gt;
** If there is no current target, nothing happens.&lt;br /&gt;
** If the target&amp;#039;s ID is not valid, nothing happens.&lt;br /&gt;
** Otherwise the target&amp;#039;s name is written to &amp;lt;code&amp;gt;GameData.Player.TradeTarget.Name&amp;lt;/code&amp;gt; and the target&amp;#039;s ID is used.&lt;br /&gt;
* The chosen ID is stored as the current trade partner, and a &amp;quot;start trade&amp;quot; status is sent to the server. [[API:ChangeTrade|ChangeTrade]], [[API:AcceptTrade|AcceptTrade]] and [[API:CancelTrade|CancelTrade]] all use this stored partner.&lt;br /&gt;
* With &amp;lt;code&amp;gt;useCurrentTarget&amp;lt;/code&amp;gt; other than &amp;lt;code&amp;gt;1&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;targetId&amp;lt;/code&amp;gt; is used as given (cut to a 16-bit value) and &amp;lt;code&amp;gt;GameData.Player.TradeTarget.Name&amp;lt;/code&amp;gt; is not changed.&lt;br /&gt;
* The client does not check what kind of object the target is. The server decides whether the trade can start.&lt;br /&gt;
* Does nothing if the player object does not exist yet.&lt;br /&gt;
* The function needs at least two arguments and only reads the last two.&lt;br /&gt;
&lt;br /&gt;
== Errors ==&lt;br /&gt;
None besides the generic &amp;#039;&amp;#039;Invalid Parameters&amp;#039;&amp;#039; message when an argument is not a number.&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
From &amp;lt;code&amp;gt;default/ea_tradewindow/source/tradewindow.lua&amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if not EA_Window_Trade.TradeOpen() then&lt;br /&gt;
	InitiateTrade( 1, 0 )&lt;br /&gt;
	EA_Window_Trade.RefreshItemData (REFRESH_BOTH)&lt;br /&gt;
	EA_Window_Trade.Show()&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[API:ChangeTrade|ChangeTrade]]&lt;br /&gt;
* [[API:AcceptTrade|AcceptTrade]]&lt;br /&gt;
* [[API:CancelTrade|CancelTrade]]&lt;/div&gt;</summary>
		<author><name>Maintenance script</name></author>
	</entry>
</feed>