Results 1 to 4 of 4

Thread: weird item purchase action in late game

  1. #1
    Basic Member
    Join Date
    Dec 2016
    Posts
    123

    weird item purchase action in late game

    So I have rewrite the item build list in "item_purchase_alchemist.lua" for bot_alchemist, and it works fine before late game.
    But after purchase manta, alchemist just keeping buy "item_vitality_booster" as soon as he get enough gold.
    I printed the table in console, and next item should be "item_mystic_staff" for shivas_guard, but instead alchemist just buy "item_vitality_booster" multiple times.
    if I give bot enough gold at beginning of the game, it will buy all the items on my list correctly, so I assume there's some issue with the late game that default item_purchase_generic or item_purchase_alchemist.lua kicks in.

    edit: have another test where I give bot enough gold at beginning of the game, bot managed to get to moonshard( which is at the end of my list), but before buying moonshard, it still purchase 2-3 item_vitality_booster randomly.



    Code:
    local tableItemsToBuy = { 
    				"item_tango",
    				"item_quelling_blade",
    				"item_stout_shield",
    				"item_flask",
    				"item_ring_of_regen",
    				"item_sobi_mask",
    				"item_recipe_soul_ring",
    				"item_boots",
    				"item_ring_of_health",
    				"item_vitality_booster",
    				"item_relic",
    				"item_recipe_radiance",
    				"item_blades_of_attack",
    				"item_blades_of_attack",
    				"item_platemail",
    				"item_vitality_booster",
    				"item_point_booster",
    				"item_energy_booster",
    				"item_mystic_staff",
    				"item_blade_of_alacrity",
    				"item_boots_of_elves",
    				"item_recipe_yasha",
    				"item_ultimate_orb",
    				"item_recipe_manta",
    				"item_mystic_staff",
    				"item_recipe_shivas_guard",
    				"item_javelin",
    				"item_belt_of_strength",
    				"item_recipe_basher",
    				"item_recipe_abyssal_blade",
    				"item_hyperstone",
    				"item_hyperstone",
    			};
    
    function ItemPurchaseThink()
    	local npcBot = GetBot();
            buyitem();
    
    
    end
    
    function buyitem()
    	local npcBot = GetBot();
    	if ( #tableItemsToBuy == 0 )
    	then
    		npcBot:SetNextItemPurchaseValue( 0 );
    		return;
    	end
    
    	local sNextItem = tableItemsToBuy[1];
    
    	npcBot:SetNextItemPurchaseValue( GetItemCost( sNextItem ) );
    
    	if ( npcBot:GetGold() >= GetItemCost( sNextItem ) )	then
    		if  (not IsItemPurchasedFromSecretShop(sNextItem)) then
    			npcBot:Action_PurchaseItem( sNextItem );
    			table.remove( tableItemsToBuy, 1 );	
    		elseif( IsItemPurchasedFromSecretShop(sNextItem) and GetUnitToLocationDistance( npcBot , SECRETSHOP) > 300) then
    			local courier = GetCourier(0);
    			npcBot:Action_Courier(courier , COURIER_ACTION_SECRET_SHOP); 
    			if (courier:DistanceFromSecretShop( ) <= 300) then
    			courier:Action_PurchaseItem(sNextItem);
    			table.remove( tableItemsToBuy, 1 );
    			
    				for item_k, item in pairs(tableItemsToBuy) do  ----print table of item to buy
    					print(item);
    				end
    			
    			end
    		elseif( IsItemPurchasedFromSecretShop(sNextItem) and GetUnitToLocationDistance( npcBot , SECRETSHOP) <= 300) then
    			npcBot:Action_PurchaseItem( sNextItem );
    			table.remove( tableItemsToBuy, 1 );
    		end
    	end
    end
    Last edited by lunarbreez; 02-04-2017 at 08:38 PM.

  2. #2
    Basic Member
    Join Date
    Mar 2012
    Posts
    2,014
    My guess is, the distance you use to check how close (or far) you are from the shop is the issue.
    Instead of saying "buy this", try asking the game if you could buy it, then remove and skip to the next ONLY IF you could buy it.

    i.e.
    Code:
    local result = whicheverEntityCourOrHero:Action_PurchaseItem(sNextItem );
    
    if (result == PURCHASE_ITEM_SUCCESS) then
        npcBot:Action_Chat("I bought " .. sNextItem  .. " , I am carry or I feed", false);
        table.remove( tableItemsToBuy, 1 );
    else
        npcBot:Action_Chat("awww, plz guys, tell me how to buy items from the Secret Shop, I am new to the game, plz! no report plz!!", false);
    end
    Try that! (sorry, not at home so no chance to test it, but even as best practice, if a function returns the result of a process, you should ALWAYS check it before going to the next step instead of assuming that it just works).

    These are the enums for the result:
    Code:
    	PURCHASE_ITEM_SUCCESS				= -1,
    	PURCHASE_ITEM_OUT_OF_STOCK			= 82,
    	PURCHASE_ITEM_DISALLOWED_ITEM		= 78,
    	PURCHASE_ITEM_INSUFFICIENT_GOLD		= 63,
    	PURCHASE_ITEM_NOT_AT_HOME_SHOP		= 67,
    	PURCHASE_ITEM_NOT_AT_SIDE_SHOP		= 66,
    	PURCHASE_ITEM_NOT_AT_SECRET_SHOP	= 62,
    	PURCHASE_ITEM_INVALID_ITEM_NAME		= 33
    Explanations on the normal, high and very high brackets in replays: here, here & here
    Why maphacks won't work in D2: here

  3. #3
    Basic Member
    Join Date
    Jun 2013
    Posts
    274
    A thing to note is some shops have weird trigger areas. For example, if you're going to the Radiant secret shop from the Radiant top tower, you can be within 300 units of the shop, but not be in the trigger area.

  4. #4
    Basic Member
    Join Date
    Dec 2016
    Posts
    123
    Quote Originally Posted by The Nomad View Post
    My guess is, the distance you use to check how close (or far) you are from the shop is the issue.
    Instead of saying "buy this", try asking the game if you could buy it, then remove and skip to the next ONLY IF you could buy it.

    i.e.
    Code:
    local result = whicheverEntityCourOrHero:Action_PurchaseItem(sNextItem );
    
    if (result == PURCHASE_ITEM_SUCCESS) then
        npcBot:Action_Chat("I bought " .. sNextItem  .. " , I am carry or I feed", false);
        table.remove( tableItemsToBuy, 1 );
    else
        npcBot:Action_Chat("awww, plz guys, tell me how to buy items from the Secret Shop, I am new to the game, plz! no report plz!!", false);
    end
    Try that! (sorry, not at home so no chance to test it, but even as best practice, if a function returns the result of a process, you should ALWAYS check it before going to the next step instead of assuming that it just works).

    These are the enums for the result:
    Code:
    	PURCHASE_ITEM_SUCCESS				= -1,
    	PURCHASE_ITEM_OUT_OF_STOCK			= 82,
    	PURCHASE_ITEM_DISALLOWED_ITEM		= 78,
    	PURCHASE_ITEM_INSUFFICIENT_GOLD		= 63,
    	PURCHASE_ITEM_NOT_AT_HOME_SHOP		= 67,
    	PURCHASE_ITEM_NOT_AT_SIDE_SHOP		= 66,
    	PURCHASE_ITEM_NOT_AT_SECRET_SHOP	= 62,
    	PURCHASE_ITEM_INVALID_ITEM_NAME		= 33
    I tried result check and it's the same in late game, still keep buying vitality_booster, the edited code are below:
    Code:
    	if ( npcBot:GetGold() >= GetItemCost( sNextItem ) )	then
    		if  (not IsItemPurchasedFromSecretShop(sNextItem)) then
    			local result = npcBot:Action_PurchaseItem(sNextItem);
    			if (result == PURCHASE_ITEM_SUCCESS) then
    				npcBot:Action_PurchaseItem( sNextItem );
    				table.remove( tableItemsToBuy, 1 );
    			end
    		elseif( IsItemPurchasedFromSecretShop(sNextItem) and npcBot:DistanceFromSecretShop( ) > 300) then
    			local courier = GetCourier(0);
    			local result = courier:Action_PurchaseItem(sNextItem);
    			npcBot:Action_Courier(courier , COURIER_ACTION_SECRET_SHOP); 
    			if (result == PURCHASE_ITEM_SUCCESS) then
    			courier:Action_PurchaseItem(sNextItem);
    			table.remove( tableItemsToBuy, 1 );
    			npcBot:Action_Courier(courier , COURIER_ACTION_TRANSFER_ITEMS); 		
    				for item_k, item in pairs(tableItemsToBuy) do  ----print table of item to buy
    					print(item);
    				end
    			
    			end
    		elseif( IsItemPurchasedFromSecretShop(sNextItem) and  npcBot:DistanceFromSecretShop( ) <= 300) then
    			local result = npcBot:Action_PurchaseItem(sNextItem);
    			if (result == PURCHASE_ITEM_SUCCESS) then
    				npcBot:Action_PurchaseItem( sNextItem );
    				table.remove( tableItemsToBuy, 1 );
    			end
    		end
    	end
    Last edited by lunarbreez; 02-07-2017 at 11:28 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •