I started a bot from scratch. Once done, I would like to share it.
I would like to have a function to buy ectos until the player has less than 10k.
I'm unsure whether the functions are broken or I am using them wrong.
My function:
Code:
Func BuyEcto() Local Const $Ecto = 930 Local Const $mapid_<MaterialMap> = <ID> Local Const $mapid_<FarmingOutpost> = <ID> If GetMapID() <> $mapid_<MaterialMap> Then TravelTo($mapid_<MaterialMap>) WaitMapLoading($mapid_<MaterialMap>, 5000) EndIf Local $Trader = GetNearestNPCToCoords(X, Y) GoToNPC($Trader) Sleep(GetPing()+1000) While GetGoldCharacter() > 10000 TraderRequest($Ecto) Sleep(GetPing()+250) TraderBuy() WEnd TravelTo($mapid_<FarmingOutpost>) WaitMapLoading($mapid_<FarmingOutpost>, 5000) EndFunc
Code:
Func BuyEcto() Out("Declare Ecto with its ID.") Local Const $Ecto = 930 Out("Declared and set.") Out("Declare material map with its ID.") Local Const $mapid_<MaterialMap> = <ID> Out("Map declared1.") Out("Declare farming outpost with its ID.") Local Const $mapid_<FarmingOutpost> = <ID> Out("Map declared2.") If GetMapID() <> $mapid_<MaterialMap> Then Out("Going to MaterialMap.") TravelTo($mapid_<MaterialMap>) Out("At MaterialMap.") WaitMapLoading($mapid_<MaterialMap>, 5000) Out("MaterialMap loaded.") EndIf Out("Storing Rare Material Trader in $Trader.") Local $Trader = GetNearestNPCToCoords(X, Y) Out("Trader stored.") Out("Going to Trader.") GoToNPC($Trader) Out("At trader.") Sleep(GetPing()+1000) While GetGoldCharacter() > 10000 Out("Gold over 10k.") Out("Requesting Ecto.") TraderRequest($Ecto) Out("Ecto requested.") Sleep(GetPing()+250) Out("Buying Ecto x1.") TraderBuy() Out("Ecto bought.") WEnd Out("Going to FarmingOutpost.") TravelTo($mapid_<FarmingOutpost>) Out("At FarmingOutpost.") WaitMapLoading($mapid_<FarmingOutpost>, 5000) Out("FarmingOutpost Loaded.") EndFunc
Code:
Declare Ecto with its ID. Declared and set. Declare material map with its ID. Map declared1. Declare farming outpost with its ID. Map declared2. Going to MaterialMap. //Player is teleported as intended. At MaterialMap. MaterialMap loaded. Storing Rare Material Trader in $Trader. Trader stored. Going to Trader. //Player goes to trader as intended. At trader. //Trader window opens. Gold over 10k. Requesting Ecto. //Nothing happens, not sure if there should be anything. Buying Ecto x1. //Nothing happens. Ecto bought. //No ecto bought. Gold didn't decrease. Gold over 10k. //The loop starts again. Trader window still open. Nothing happens. Requesting Ecto. Buying Ecto x1. Ecto bought. Gold over 10k. //The loop goes on forever. ...etc...
Here are the functions:
Code:
;~ Description: Request a quote to buy an item from a trader. Returns true if successful. 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
Have a great day,
James.