Results 1 to 6 of 6

Thread: Secret (Side) Mode and Item Purchase

  1. #1
    Basic Member
    Join Date
    Aug 2016
    Posts
    13

    Secret (Side) Mode and Item Purchase

    Hi, I've found a method that finally is able to tell bot to go to secret (or side shop) without using ugly hardcoded coordinates and action move to point. Here is what I do :

    1. Detect whether an item is from a secret shop or not and set flag. It seems we can also define a new attribute of a bot (I don't know if this is a bad practice or there is a better way) :
    Code:
    ...
    if ( IsItemPurchasedFromSecretShop( sNextItem ) and npcBot:DistanceFromSecretShop() <= secretShopThreshold ) then
          -- this item is from secret shop
          npcBot.secretShopMode = true;
    
          if ( npcBot:DistanceFromSecretShop() <= distanceBuyShop ) then
            ItemPurchaseBot( npcBot, sNextItem, tableItemsToBuy );
            npcBot.secretShopMode = false;
          end
        end
    ...
    2. Create mode_secret_shop_xxx.lua and implement GetDesire reading this flag :
    Code:
    function GetDesire()
      local npcBot = GetBot();
      local desire = 0.0;
      if ( npcBot.secretShopMode == true ) then
        desire = 0.5;
      end
      
      return Clamp( desire, BOT_MODE_DESIRE_NONE, BOT_MODE_DESIRE_ABSOLUTE );
    end
    This should get your bot having 0.5 desire of going to secret shop. The value can be customised to your needs.
    Hopefully this helps!

    Thanks

  2. #2
    Basic Member
    Join Date
    Apr 2015
    Posts
    5
    You sir might just be a lifesaver.

    The ItemPurchaseThink() in the item_purchase_lina.lua causes very strange behavior, so with this it might just become workable.
    Last edited by RamonNZ; 01-26-2017 at 12:54 AM.

  3. #3
    Basic Member
    Join Date
    Apr 2015
    Posts
    5
    Hmm, the secret shop works like a dream, the side shop code has 2 problems:

    1) If you create more than .25 desire when you first spawn, the whole game crashes. It doesn't crash after the game starts at 0 seconds. This isn't really a problem since he should really be buying from the fountain before the game starts.
    2) Once you amp up his desire to go to the side shop he stops exactly where he is and stops moving completely. That functionality doesn't seem to be implimented yet =/
    Last edited by RamonNZ; 01-26-2017 at 12:49 AM.

  4. #4
    Basic Member
    Join Date
    Jun 2013
    Posts
    259
    Yeah you just need to implement the Think() function to do the actions. When the mode becomes active, the default literally just makes the bot walk towards the shop until in range to purchase (when working), so you can do the same.

    Code:
    function Think()
    
        local npcBot = GetBot();
    
        local shop_top = Vector(-7232, 4480);
        local shop_bot = Vector(7360, -4160);
    
        local dist_top = GetUnitToLocationDistance( npcBot, shop_top );
        local dist_bot = GetUnitToLocationDistance( npcBot, shop_bot );
    
        if (dist_top < dist_bot) then
            npcBot:Action_MoveToLocation(shop_top);
        else
            npcBot:Action_MoveToLocation(shop_bot);
        end
    
    end
    Last edited by Cornbane; 01-26-2017 at 09:35 AM.

  5. #5
    Basic Member
    Join Date
    Apr 2017
    Posts
    1
    hi guys, according to your discuss I write this and it seem work

    Code:
    
    local tableItemsToBuy = { 
    				--"item_tango",
    				--"item_clarity",
    				--"item_flask",
    				"item_reaver",
    				----------------------
    				"item_blink",
    				---------------------
    				"item_boots", 
    				"item_blades_of_attack",
    				"item_blades_of_attack",
    				----------------------
    				"item_ogre_axe",
    				"item_quarterstaff",
    				"item_sobi_mask",
    				"item_robe",
    				---------------------- 
    				"item_ogre_axe",
    				"item_mithril_hammer",
    				"item_recipe_black_king_bar",
    				-----------------------
    				"item_lifesteal",
    				"item_mithril_hammer",
    				"item_reaver",
    				----------------------
    				"item_reaver",
    				"item_vitality_booster",
    				"item_recipe_heart",
    			};
    
    
    ----------------------------------------------------------------------------------------------------
    
    local secretShopThreshold = 100000;
    local distanceBuyShop = 500;
    
    function ItemPurchaseThink()
    
    	local npcBot = GetBot();
    
    	if ( #tableItemsToBuy == 0 )
    	then
    		npcBot:SetNextItemPurchaseValue( 0 );
    		return;
    	end
    
    	local sNextItem = tableItemsToBuy[1];
    	--print("Money is enough,Will buy: ",sNextItem," cost is:",tostring(GetItemCost(sNextItem)),"location ",npcBot:GetLocation());
    
    	npcBot:SetNextItemPurchaseValue( GetItemCost( sNextItem ) );
    
    	if ( npcBot:GetGold() >= GetItemCost( sNextItem ) )
    	then
    		if ( IsItemPurchasedFromSecretShop(sNextItem) and npcBot:DistanceFromSecretShop() <= secretShopThreshold )
    		then
    			--print("Money is enough,Will Move to secret shop for: ",sNextItem);
    			npcBot.secretShopMode = true;
    
    			local shop_top = Vector(-4600, 1100);
    			local shop_bot = Vector(4600,  -1160);
    
    			local dist_top = GetUnitToLocationDistance( npcBot, shop_top );
    			local dist_bot = GetUnitToLocationDistance( npcBot, shop_bot );
    
    			if (dist_top < dist_bot) then
    				npcBot:Action_MoveToLocation(shop_top);
    			else
    				npcBot:Action_MoveToLocation(shop_bot);
    			end
    
    			if ( npcBot:DistanceFromSecretShop() <= distanceBuyShop ) 
    			then
    				print("Will buy at secret shop : ",sNextItem," cost is:",tostring(GetItemCost(sNextItem)));
    				npcBot:ActionImmediate_PurchaseItem( sNextItem );
    				table.remove( tableItemsToBuy, 1 );
    				npcBot.secretShopMode = false;
    			end
    		else
    			print("Money is enough,Will buy: ",sNextItem," cost is:",tostring(GetItemCost(sNextItem)));
    			npcBot:ActionImmediate_PurchaseItem( sNextItem );
    			table.remove( tableItemsToBuy, 1 );
    		end
    	end
    
    end
    
    ----------------------------------------------------------------------------------------------------
    But it's also something wrong, when the bot need to purchase, he just walk and ignore anything. i just wondering how to make it better.
    Last edited by fansongy; 04-16-2017 at 04:12 AM.

  6. #6
    Basic Member
    Join Date
    Mar 2012
    Posts
    1,565
    First off, I just wanted too comment on this
    Quote Originally Posted by RamonNZ View Post
    You sir might just be a lifesaver.

    The ItemPurchaseThink() in the item_purchase_lina.lua causes very strange behavior, so with this it might just become workable.
    The bots_example project is just that: an example. Something akin to a proof of concept that should show what MIGHT be done, not something that you use "as is" and it's good to go out of the box
    Having said that, it needs A LOT of modifications (which is why I prefer a full takeover rather than the mode-approach )

    As for this.

    Quote Originally Posted by fansongy View Post
    hi guys, according to your discuss I write this and it seem work

    But it's also something wrong, when the bot need to purchase, he just walk and ignore anything. i just wondering how to make it better.
    Let's see about the code design. They are not necessarily the problem, but writing more readable and cleaner code can indirectly help to either find the problem OR an involuntary rewrite might fix it So let's start.

    1. You use SetNextItemPurchaseValue() twice in that code. Why? Do you use GetNextItemPurchaseValue() anywhere in your code? Please keep in mind that nay extra code just adds overhead. It's true that these functions in particular don't affect performance that drastically, but that is how optimizations work: a small reduction here, anothere one there, and before you know it you gained 20 FPS (as I said, not the case here, but clean code helps you see what you are actually doing)
    2. You set secretShopMode to true then to false. Is that used anywhere?
    3. You are using shop_top and shop_bot when you can just as well use GetShopLocation() (signature is: GetShopLocation( nTeamID, nShopID ) : vector and see the SHOPS constants); also, why are you setting them every frame? They never change; just use local variables, near distanceBuyShop and secretShopThreshold instead; it helps performance (since you create 2 new variables AND a new Vector structure AND you assign them each frame) and it is a LOT more readable
    4. Are you sure distanceBuyShop should be 500? Try 200 and see if it works.
    5. If purchases fail, debug why! ActionImmediate_PurchaseItem() returns a result Use as so:
    Code:
    local result = npcBot:ActionImmediate_PurchaseItem(sNextItem);
    print("Testing purchase result: " .. result);
    Where result should return one of these constants. Then you can see the reason why it fails.

    Try the above and see if you can find the issue (I am mostly thinking of the distance and the result check)
    But the clean-up suggestions are good too
    Explanations on the normal, high and very high brackets in replays: here, here & here
    Why maphacks won't work in D2: here

Posting Permissions

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