Func TraderRequest + TraderBuy

10/09/2022 14:00 BigBoyEnergy#1
Hello everybody,

I have been trying to get the Function TraderRequest work.
But it doesn't work.

Code:
While GetGoldCharacter() > 20*1000
		TraderRequest(930)
		TraderBuy()
		Sleep(500 + 3 * GetPing())
	WEnd
The problem is, it goes to the trader, talks to it, but it doesn't buy anything.

Here is the TraderRequest and TraderBuy code.

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

;~ Description: Buy the requested item.
Func TraderBuy()
	If Not GetTraderCostID() Or Not GetTraderCostValue() Then Return False
	Enqueue($mTraderBuyPtr, 4)
	Return True
EndFunc   ;==>TraderBuy
Does anyone have a working function? Or updated one?
11/14/2022 08:57 jrad99#2
I am running into this also. Did you ever figure it out?
In my testing it seems GETTRADERCOSTVALUE() is coming back as 0, which I believe is causing TraderRequest() and TraderBuy() to return false, which is why it isn't buying anything.
12/19/2022 21:42 BigBoyEnergy#3
I managed to get a gwa2 file that contained way more code. I replaced some stuff and that one is working. No idea what is different :')
01/30/2023 12:58 SneakyJoe#4
Quote:
Originally Posted by BigBoyEnergy View Post
I managed to get a gwa2 file that contained way more code. I replaced some stuff and that one is working. No idea what is different :')
Can you please share the gwa2 file you found?
01/30/2023 13:03 BigBoyEnergy#5
Quote:
Originally Posted by SneakyJoe View Post
Can you please share the gwa2 file you found?
https://github.com/Greg-76/Gwa2_by_Greg76


Here you go

Some things are renamed, but I'm sure you can work with it
03/15/2023 21:39 xnx#6
hey mates, still having trouble to fix my gwa2 for traderrequest and traderbuy function for material.

can anyone help me get around or offer me a function gwa2 for that?

the greg-76 gwa2 is broken


might be an adressing issue? fix via cheat engine but i cant figure out how to get the right hex adressing

any help is appreciated!
08/09/2023 16:26 BigBoyEnergy#7
Quote:
Originally Posted by xnx View Post
hey mates, still having trouble to fix my gwa2 for traderrequest and traderbuy function for material.

can anyone help me get around or offer me a function gwa2 for that?

the greg-76 gwa2 is broken


might be an adressing issue? fix via cheat engine but i cant figure out how to get the right hex adressing

any help is appreciated!
I can send you my GWA2 File, and the code to make it buy ecto's.


Code:
Func BUYECTOS()

	Do
        RndSleep(Random(250,500))
		Local $Me = GetAgentByID(-2)
        Local $guy = GetNearestNPCToCoords(DllStructGetData($Me, 'X'), DllStructGetData($Me, 'Y'))
    Until DllStructGetData($guy, 'Id') <> 0
    ChangeTarget($guy)
    RndSleep(Random(250,500))
    GoToNPC($guy)
    RndSleep(Random(250,500))
    Do
        MoveTo(DllStructGetData($guy, 'X'), DllStructGetData($guy, 'Y'), 40)
        RndSleep(Random(500,750))
        GoToNPC($guy)
        RndSleep(Random(250,500))
        Local $Me = GetAgentByID(-2)
    Until ComputeDistance(DllStructGetData($Me, 'X'), DllStructGetData($Me, 'Y'), DllStructGetData($guy, 'X'), DllStructGetData($guy, 'Y')) < 250
    RndSleep(Random(1000,1500))
	;~This section does the buying
    While GetGoldCharacter() > 20 * 1000
	If GetGoldStorage() > 10000 Then
	WithdrawGold(10000)
	CheckGold()
	EndIf
        TraderRequest(930)
        Sleep(500 + 3 * GetPing())
        TraderBuy()
    WEnd
 EndFunc   ;~ Rare Material trader
05/07/2024 08:06 fury90723#8
Bump 2024, what's the latest known gwa2 and headers?

TraderRequestSell() crashes my game
05/07/2024 19:07 apoguita#9
look in the "working bots thread" most recently gwa2 is posted there , also most recently headers, but not all, i managed to gather almost complete.headers with those and merging other recently working bots (vaettir, follower)
05/07/2024 20:37 DarkOPM#10
#closed

Please use the other thread.