Selling to a Material Trading by Scripting in 2024

05/06/2024 16:25 fury90723#1
Ok I will be brief, I want to "request a quote" to a Material Trader Merchant (for example to know the price of bones, the non rare one) to sell an item to them.

I found a way to do that, but doing so crashes the game at the moment.

The latest GWA2.au3 offers the function
Func TraderRequestSell($aItem)

but using it as below crashes the game

PHP Code:
Local $Item_ExtraID_Bones 921

Do
           
Local $quote TraderRequestSell($Item_ExtraID_Bones)
           If 
TraderSell() Then $lHowMany += 1
Until $lHowMany 

Do you guys have any suggestions or experience with this
and how did you make it work?
05/06/2024 18:55 Restia Ashdoll#2
Quote:
Originally Posted by fury90723 View Post
Ok I will be brief, I want to "request a quote" to a Material Trader Merchant (for example to know the price of bones, the non rare one) to sell an item to them.

I found a way to do that, but doing so crashes the game at the moment.

The latest GWA2.au3 offers the function
Func TraderRequestSell($aItem)

but using it as below crashes the game

PHP Code:
Local $Item_ExtraID_Bones 921

Do
           
Local $quote TraderRequestSell($Item_ExtraID_Bones)
           If 
TraderSell() Then $lHowMany += 1
Until $lHowMany 

Do you guys have any suggestions or experience with this
and how did you make it work?
You should need 2 Func for that

Here is an Example how it could look in script:
Code:
	While GetGoldCharacter() > 20*1000
		TraderRequest(930)
		Sleep(500 + 3 * GetPing())
		TraderBuy()
	WEnd
Code:
Func TraderRequest($aModelID, $aExtraID = -1)
	Local $lItemStruct = DllStructCreate('long Id;long AgentId;byte Unknown1[4];ptr Bag;ptr ModStruct;long ModStructSize;ptr Customized;byte unknown2[4];byte Type;byte unknown4;short ExtraId;short Value;byte unknown4[2];short Interaction;long ModelId;ptr ModString;byte unknown5[4];ptr NameString;ptr SingleItemName;byte Unknown4[10];byte IsSalvageable;byte Unknown6;byte Quantity;byte Equiped;byte Profession;byte Type2;byte Slot')

	Local $lOffset[4] = [0, 0x18, 0x40, 0xC0]
	Local $lItemArraySize = MemoryReadPtr($mBasePointer, $lOffset)
	Local $lOffset[5] = [0, 0x18, 0x40, 0xB8, 0]
	Local $lItemPtr, $lItemID
	Local $lFound = False
	Local $lQuoteID = MemoryRead($mTraderQuoteID)

	For $lItemID = 1 To $lItemArraySize[1]
		$lOffset[4] = 0x4 * $lItemID
		$lItemPtr = MemoryReadPtr($mBasePointer, $lOffset)
		If $lItemPtr[1] = 0 Then ContinueLoop

		DllCall($mKernelHandle, 'int', 'ReadProcessMemory', 'int', $mGWProcHandle, 'int', $lItemPtr[1], 'ptr', DllStructGetPtr($lItemStruct), 'int', DllStructGetSize($lItemStruct), 'int', '')
		If DllStructGetData($lItemStruct, 'ModelID') = $aModelID And DllStructGetData($lItemStruct, 'bag') = 0 And DllStructGetData($lItemStruct, 'AgentID') == 0 Then
			If $aExtraID = -1 Or DllStructGetData($lItemStruct, 'ExtraID') = $aExtraID Then
				$lFound = True
				ExitLoop
			EndIf
		EndIf
	Next
	If Not $lFound Then Return False

	DllStructSetData($mRequestQuote, 2, DllStructGetData($lItemStruct, 'ID'))
	Enqueue($mRequestQuotePtr, 8)

	Local $lDeadlock = TimerInit()
	$lFound = False
	Do
		Sleep(20)
		$lFound = MemoryRead($mTraderQuoteID) <> $lQuoteID
	Until $lFound Or TimerDiff($lDeadlock) > GetPing() + 5000
	Return $lFound
EndFunc   ;==>TraderRequest

Func TraderBuy()
	If Not GetTraderCostID() Or Not GetTraderCostValue() Then Return False
	Enqueue($mTraderBuyPtr, 4)
	Return True
EndFunc   ;==>TraderBuy

idk if these gwa2 func still work i didnt use that for years but at least you see how it should work
05/06/2024 22:10 Lumi#3
#moved
05/07/2024 02:14 fury90723#4
Thank you for answering Restia Ashdoll!

Yeah you suggested me the 2 functions to buy,
there are 2 to buy and 2 to sell
allegedly:
-> buy
TraderRequest()
TraderBuy()
-> sell
TraderRequestSell()
TraderSell()

The trader request functions crash the game.
Do we know any workarounds for this?

I'd be willing to add a new implementation to GWA2, but I am not sure how would I go and do that, are there any docs that help with the GW API?

Maybe my gwa2 is not the latest one? Does anybody have one that works? (headers are the latest ones)

GWA2.au3

;~ Description: Request a quote to sell an item to the trader.
Func TraderRequestSell($aItem)
Local $lItemID
Local $lFound = False
Local $lQuoteID = MemoryRead($mTraderQuoteID)

If IsDllStruct($aItem) = 0 Then
$lItemID = $aItem
Else
$lItemID = DllStructGetData($aItem, 'ID')
EndIf

DllStructSetData($mRequestQuoteSell, 2, $lItemID)
Enqueue($mRequestQuoteSellPtr, 8)

Local $lDeadlock = TimerInit()
Do
Sleep(20)
$lFound = MemoryRead($mTraderQuoteID) <> $lQuoteID
Until $lFound Or TimerDiff($lDeadlock) > GetPing() + 155000
Return $lFound
EndFunc ;==>TraderRequestSell

;~ Description: ID of the item item being sold.
Func TraderSell()
#If Not GetTraderCostID() Or Not GetTraderCostValue() Then Return False
Enqueue($mTraderSellPtr, 4)
Return True
EndFunc ;==>TraderSell