Page 1 of 3 1 2 3 LastLast
Results 1 to 10 of 25

Thread: Help Me With Captain Mode

  1. #1
    Basic Member
    Join Date
    May 2014
    Posts
    270

    Question Help Me With Captain Mode

    I've implemented a dummy Captains Mode on hero selection. Here is the code
    Code:
    function Think()
    	if GetGameMode() == GAMEMODE_AP then
    		AllPickLogic();
    	elseif GetGameMode() == GAMEMODE_CM then
    		CaptainModeLogic();
    	end
    end
    
    local ListPickedHeroes = {};
    local AllHeroesSelected = false;
    
    function CaptainModeLogic()
    	if (GetGameState() ~= GAME_STATE_HERO_SELECTION) then
            return
        end
    	
    	if GetHeroPickState() == HEROPICK_STATE_CM_CAPTAINPICK then	
    		PickCaptain();
    	elseif GetHeroPickState() == HEROPICK_STATE_CM_BAN1 then
    		BansHero();
    	elseif GetHeroPickState() == HEROPICK_STATE_CM_BAN2 then
    		BansHero();	
    	elseif GetHeroPickState() == HEROPICK_STATE_CM_BAN3 then
    		BansHero();	
    	elseif GetHeroPickState() == HEROPICK_STATE_CM_BAN4 then
    		BansHero();	
    	elseif GetHeroPickState() == HEROPICK_STATE_CM_SELECT1 then
    		PicksHero();	
    	elseif GetHeroPickState() == HEROPICK_STATE_CM_SELECT2 then
    		PicksHero();	
    	elseif GetHeroPickState() == HEROPICK_STATE_CM_SELECT3 then
    		PicksHero();		
    	elseif GetHeroPickState() == HEROPICK_STATE_CM_SELECT4 then
    		PicksHero();	
    	elseif GetHeroPickState() == HEROPICK_STATE_CM_BAN5 then
    		BansHero();
    	elseif GetHeroPickState() == HEROPICK_STATE_CM_BAN6 then
    		BansHero();	
    	elseif GetHeroPickState() == HEROPICK_STATE_CM_BAN7 then
    		BansHero();	
    	elseif GetHeroPickState() == HEROPICK_STATE_CM_BAN8 then
    		BansHero();	
    	elseif GetHeroPickState() == HEROPICK_STATE_CM_SELECT5 then
    		PicksHero();	
    	elseif GetHeroPickState() == HEROPICK_STATE_CM_SELECT6 then
    		PicksHero();	
    	elseif GetHeroPickState() == HEROPICK_STATE_CM_SELECT7 then
    		PicksHero();		
    	elseif GetHeroPickState() == HEROPICK_STATE_CM_SELECT8 then
    		PicksHero();	
    	elseif GetHeroPickState() == HEROPICK_STATE_CM_BAN9 then
    		BansHero();
    	elseif GetHeroPickState() == HEROPICK_STATE_CM_BAN10 then
    		BansHero();	
    	elseif GetHeroPickState() == HEROPICK_STATE_CM_SELECT9 then
    		PicksHero();		
    	elseif GetHeroPickState() == HEROPICK_STATE_CM_SELECT10 then
    		PicksHero();	
    	elseif GetHeroPickState() == HEROPICK_STATE_CM_PICK then
    		SelectsHero();	
    	end
    	
    end
    
    function PickCaptain()
    	if not IsHumanPlayerExist() or DotaTime() > -1 then
    		if GetCMCaptain() == -1 then
    			local CaptBot = GetFirstBot();
    			if CaptBot ~= nil then
    				SetCMCaptain(CaptBot)
    			end
    		end
    	end
    end
    
    function IsHumanPlayerExist()
        local Players = GetTeamPlayers(GetTeam())
        for _,id in pairs(Players) do
            if not IsPlayerBot(id) then
    			return true;
            end
        end
        return false;
    end
    
    function GetFirstBot()
    	local BotId = nil;
    	local Players = GetTeamPlayers(GetTeam())
        for _,id in pairs(Players) do
            if IsPlayerBot(id) then
    			BotId = id;
    			return BotId;
            end
        end
    	return BotId;
    end
    
    
    function RandomHero()
    	
    	local hero = "";
    	while ( hero == "" or IsCMPickedHero(GetTeam(), hero) or IsCMPickedHero(GetOpposingTeam(), hero) or IsCMBannedHero(hero) ) 
    	do
            hero = allBotHeroes[RandomInt(1, #allBotHeroes)];
        end
    	return hero;
    end
    
    function BansHero()
    	if not IsPlayerBot(GetCMCaptain()) or not IsPlayerInHeroSelectionControl(GetCMCaptain()) then
    		return
    	end	
    	
    	local BannedHero = RandomHero();
    	print(BannedHero.." is Banned")
    	CMBanHero(BannedHero);
    end
    
    function PicksHero()
    	if not IsPlayerBot(GetCMCaptain()) or not IsPlayerInHeroSelectionControl(GetCMCaptain()) then
    		return
    	end	
    	
    	local PickedHero = RandomHero();
    	print(PickedHero.." is Picked")
    	table.insert(ListPickedHeroes, PickedHero);
    	CMPickHero(PickedHero);
    end
    
    function WasHumansDonePicking()
    	local Players = GetTeamPlayers(GetTeam())
        for _,id in pairs(Players) 
    	do
            if not IsPlayerBot(id) then
    			if GetSelectedHeroName(id) == nil or GetSelectedHeroName(id) == "" then
    				return false;
    			end	
            end
        end
    	return true;
    end
    
    function SelectsHero()
    	if not AllHeroesSelected and ( WasHumansDonePicking() or GetCMPhaseTimeRemaining() < 1 ) then
    		local Players = GetTeamPlayers(GetTeam())
    		local RestBotPlayers = {};
    		for _,id in pairs(Players) 
    		do
    			local hero_name =  GetSelectedHeroName(id);
    			if hero_name ~= nil and hero_name ~= "" then
    				print(hero_name.." removed")
    				UpdateSelectedHeroes(hero_name)
    			else
    				table.insert(RestBotPlayers, id)
    			end	
    		end
    		for i = 1, #RestBotPlayers
    		do
    			print("ID "..RestBotPlayers[i].." picked "..ListPickedHeroes[i])
    			SelectHero(RestBotPlayers[i], ListPickedHeroes[i])
    		end
    		AllHeroesSelected = true;
    	end
    end
    
    function UpdateSelectedHeroes(selected)
    	for i=1, #ListPickedHeroes
    	do
    		if ListPickedHeroes[i] == selected then
    			table.remove(ListPickedHeroes, i);
    			return;
    		end
    	end
    end
    The questions is, Why did everytime I tried to disconnecting before the game ends and then try to make a new game, my dota 2 always crashes no matter what game mode I'm in? And why it's picking so fast? I'm as a Captain can't pick or ban the hero I wanted to. Is there anything wrong with code? Help me please.....

    Edit : Edit the code to the fixed version, but still I need to add some picking and baning logic, and some timer to mimic the thinking bot
    Last edited by arz_on4dt; 03-22-2017 at 04:48 PM.

  2. #2
    Basic Member
    Join Date
    Oct 2016
    Posts
    248
    Just use Draft Bot code as i am or at least look at his code if you want to rewrite.

  3. #3
    Basic Member
    Join Date
    May 2014
    Posts
    270
    Quote Originally Posted by Yavimaya View Post
    Just use Draft Bot code as i am or at least look at his code if you want to rewrite.
    No, it's just too confusing to see another people's code. If there is an error I don't know where to fixed it. So it's better to writing my own code, so I can clearly see where are my mistakes at. .

  4. #4
    Basic Member
    Join Date
    Nov 2015
    Posts
    108
    You do realize you just asked us to read your code and find your mistakes then refused to look at another persons code cause its too hard to read another's code and find mistakes?

    Sorry, I have nothing more useful to contribute cause I don't know squat about hero selection process really.

  5. #5
    Basic Member
    Join Date
    Oct 2016
    Posts
    248
    LOL iron!
    yea i find reading others code pretty easy, i find writing my own code from scratch almost impossible.

    just reading the start of your code, i tried similar.... took your AP code and added the elseif gamemode == AP..... to add AP to the CM code, but at character load it crashed every time... for no reason.

    so i dont know, i havent read through yours yet, but so far simply adding the different game modes the easiest way possible may just be crashy.
    Last edited by Yavimaya; 03-22-2017 at 02:12 PM.

  6. #6
    Basic Member
    Join Date
    Oct 2016
    Posts
    248
    btw, adamQ got breakers charge working by overtaking the roam and attack desires if you havent seen and want to get SB working (he only works 90% - still cancels charge sometimes, but when he locks in he locks in properly, but will tower dive too)

  7. #7
    Basic Member
    Join Date
    May 2014
    Posts
    270
    OK.. Thanks for the replay . Found the mistakes already. I almost finished it .
    Last edited by arz_on4dt; 03-22-2017 at 02:28 PM.

  8. #8
    I'd love to see bots playing this mode, similar to the HOTS bots playing Draft mode; those bots pick and ban heroes at an average pace.

  9. #9
    Basic Member
    Join Date
    May 2014
    Posts
    270
    I've finished it . But still though. I can only play one game. If I continuously play the game (whatever the game mode I'm in) the game will crash. I have to exit Dota 2 first, open it again then start to play. The same thing happen with Draft Bot. Any Idea? Or is it only me that experiencing that issue?
    Last edited by arz_on4dt; 03-22-2017 at 04:39 PM.

  10. #10
    Basic Member
    Join Date
    Oct 2016
    Posts
    248
    Quote Originally Posted by arz_on4dt View Post
    I've finished it . But still though. I can only play one game. If I continuously play the game (whatever the game mode I'm in) the game will crash. I have to exit Dota 2 first, open it again then start to play. The same thing happen with Draft Bot. Any Idea? Or is it only me that experiencing that issue?
    No, i have experienced this since the start of january or so.
    i never associated it with the draft bot script, i havent played much else since i started compiling them, but im pretty sure it happens every single time i host any game with any script.

    edit: just tested, only happening with captains mode.
    interesting that it isnt just a bug in the draft bot script - unless you both did the same thing wrong.
    Last edited by Yavimaya; 03-22-2017 at 05:20 PM.

Posting Permissions

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