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