Page 4 of 9 FirstFirst ... 2 3 4 5 6 ... LastLast
Results 31 to 40 of 89

Thread: Newbie has problems.

  1. #31
    Basic Member
    Join Date
    Oct 2016
    Posts
    247
    testing now, but it looks like you were right, even though it produced no errors, the missing check in the first section may have been the cause.

  2. #32
    Basic Member
    Join Date
    Oct 2016
    Posts
    247
    Thanks for the help.

    Have a basic working Troll Warlord.

    Code:
    local utils = require(GetScriptDirectory() ..  "/util")
    local inspect = require(GetScriptDirectory() ..  "/inspect")
    local enemyStatus = require(GetScriptDirectory() .. "/enemy_status" )
    
    function AbilityLevelUpThink()  
    	
    	local npcBot = GetBot();
    	local build = "NOT IMPLEMENTED";
    	
    	if string.find(npcBot:GetUnitName(), "hero") then
    		build = require(GetScriptDirectory() .. "/builds/item_build_" .. string.gsub(npcBot:GetUnitName(), "npc_dota_hero_", ""))
    	end
    	
    	if build == "NOT IMPLEMENTED" then 
    		return 
    	end
    
        local BotAbilityPriority = build["skills"];
    	
    	if npcBot:GetAbilityPoints()<1 or #BotAbilityPriority==0 or  (GetGameState()~=GAME_STATE_PRE_GAME and GetGameState()~= GAME_STATE_GAME_IN_PROGRESS) then
    		return;
    	end
    	
    	if (npcBot:GetAbilityPoints() > 0) then 
    	if BotAbilityPriority[1] ~= "-1" and BotAbilityPriority[1] ~= nil then
    		local sNextAbility = npcBot:GetAbilityByName(BotAbilityPriority[1])
    		if (sNextAbility~=nil and sNextAbility:CanAbilityBeUpgraded() and sNextAbility:GetLevel() < sNextAbility:GetMaxLevel() and not sNextAbility:IsHidden()) then
    			--npcBot:Action_Chat(BotAbilityPriority[1],true);
    			npcBot:Action_LevelAbility(BotAbilityPriority[1])
    			table.remove( BotAbilityPriority, 1 )
    		end	
    	else
    		table.remove( BotAbilityPriority, 1 )
    	end	
    	end
    end
    
    
    ----------------------------------------------------------------------------------------------------------------------------------
    
    castLDDesire = 0;
    castNWDesire = 0;
    castNBDesire = 0;
    castDDesire = 0;
    
    function AbilityUsageThink()
    
    	local npcBot = GetBot();
    
    
    		if npcBot:IsChanneling() then
    		return;
    	end
    
    	-- Check if we're already using an ability
    	if ( npcBot:IsUsingAbility() ) then return end;
    
    
    abilityBR = npcBot:GetAbilityByName( "troll_warlord_berserkers_rage" );
    
    abilityWR = npcBot:GetAbilityByName( "troll_warlord_whirling_axes_ranged" );
    
    abilityWM = npcBot:GetAbilityByName( "troll_warlord_whirling_axes_melee" );
    
    abilityBT = npcBot:GetAbilityByName( "troll_warlord_battle_trance" );
    
    
    
    	-- Consider using each ability
    	castBRDesire = ConsiderBeserkRage();
    	castWRDesire, castWRTarget = ConsiderWhirlingRanged();   
    	castWMDesire = ConsiderWhirlingMelee();
    	castBTDesire = ConsiderBattleTrance();    
    
    	if ( castBTDesire > castWRDesire and castBTDesire > castWMDesire and castBTDesire > castBRDesire ) 
    	then
    		npcBot:Action_UseAbility( abilityBT );
    		return;
    	end
    
    	if ( castWRDesire > 0 ) 
    	then
    		npcBot:Action_UseAbilityOnEntity( abilityWR, castWRTarget );
    		return;
    	end
    	
    	
    	if ( castWMDesire > 0 ) 
    	then
    		npcBot:Action_UseAbility( abilityWM);
    		return;
    	end
    
    
    		if ( castBRDesire > 0 ) 
    	then
    		npcBot:Action_UseAbility( abilityBR);
    		return;
    	end
    
    
    	
    end
    
    ----------------------------------------------------------------------------------------------------------------------------------
    
    function CanCastWhirlingRangedOnTarget( npcTarget )
    	return npcTarget:CanBeSeen() and npcTarget:IsHero() or not npcTarget:IsMagicImmune() and not npcTarget:IsInvulnerable();
    end
    
    ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    
    
    
    
    function ConsiderBeserkRage()
    
    	local npcBot = GetBot();
    
    	-- Make sure it's castable
    	if ( not abilityBR:IsFullyCastable() ) 
    	then 
    		return BOT_ACTION_DESIRE_NONE, 0;
    	end;
    
    
    
    -------------if in fountain - go ranged--------------
    
    if GetBot():DistanceFromFountain() == 0 and abilityBR:GetToggleState() == true then
    return BOT_ACTION_DESIRE_LOW, 0;
    end
    
    
    --------- toggle to melee if enemy too close ----------------------
    local tableNearbyEnemyHeroes = npcBot:GetNearbyHeroes( 600, true, BOT_MODE_NONE);
    if(tableNearbyEnemyHeroes[1] ~= nil) then
    
    if ( npcBot:GetActiveMode() == BOT_MODE_RETREAT and abilityBR:GetToggleState() == false) or (GetUnitToUnitDistance( tableNearbyEnemyHeroes[1], npcBot ) < 225  and  abilityBR:GetToggleState() == false) then
    
    	return BOT_ACTION_DESIRE_HIGH, 0;
    	end
    
    end
    
    ---------- toggle to ranged if no enemies ----------------------
    local tableNearbyEnemyHeroes = npcBot:GetNearbyHeroes( 600, true, BOT_MODE_NONE);
    
    
    if abilityBR:GetToggleState() == true and  tableNearbyEnemyHeroes[1] == nil then
    	return BOT_ACTION_DESIRE_LOW, 0;
    	end
    
    --------- toggle to ranged near heros only if far away ---------------------------
    local tableNearbyEnemyHeroes = npcBot:GetNearbyHeroes( 600, true, BOT_MODE_NONE);
    if(tableNearbyEnemyHeroes[1] ~= nil) then
    
    
    local npcMostDangerousEnemy = nil;
    local nMostDangerousDamage = 0;
    
    	for _,npcEnemy in pairs( tableNearbyEnemyHeroes )
    	do
    			
    	local nDamage = npcEnemy:GetEstimatedDamageToTarget( false, npcBot, 3.0, DAMAGE_TYPE_ALL );
    		if ( nDamage > nMostDangerousDamage )
    		then
    		nMostDangerousDamage = nDamage;
    		npcMostDangerousEnemy = npcEnemy;
    		end
    	end
    		
    end
    	if ( npcMostDangerousEnemy ~= nil )
    		then
    		if (GetUnitToUnitDistance( npcEnemy, npcBot ) > 225 and  abilityBR:GetToggleState() == true) then
    			return BOT_ACTION_DESIRE_HIGH,0;
    		end
    
    
    
    	end
    
    
    
    return BOT_ACTION_DESIRE_NONE, 0;
    end
    
    
    ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    
    ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    
    
    
    function ConsiderWhirlingRanged()
    
    	local npcBot = GetBot();
    
    	-- Make sure it's castable
    	if ( not abilityWR:IsFullyCastable() ) 
    	then 
    		return BOT_ACTION_DESIRE_NONE, 0;
    	end;
    
    	
    	-- Get some of its values
    	local nCastRange = abilityWR:GetCastRange();
    	local nRadius = 100;
    
    
    -----	---------------------------------------------
    	-- Mode based usage
    --------------------------------------------------
    
    
    ------------ LANING ------------- 
    
    	if ( npcBot:GetActiveMode() == BOT_MODE_LANING and npcBot:GetMana()/npcBot:GetMaxMana() >= 0.2  ) then
    		local tableNearbyEnemyCreeps = npcBot:GetNearbyCreeps( 1000, true);
    		local tableNearbyEnemyHeroes = npcBot:GetNearbyHeroes( 1000, true, BOT_MODE_NONE);
    			if ((tableNearbyEnemyHeroes[1] ~= nil) and (tableNearbyEnemyCreeps[1] ~= nil)) then
    			for _,npcTarget in pairs( tableNearbyEnemyHeroes )
    			do
    				if ( CanCastWhirlingRangedOnTarget( npcTarget ) ) 
    				then
    				return BOT_ACTION_DESIRE_LOW, npcTarget; 
    				end
    			end
    			end
    
    	end
    ---------- RETREATING -----------------------  
    
    if ( npcBot:GetActiveMode() == BOT_MODE_RETREAT and npcBot:GetActiveModeDesire() >= BOT_MODE_DESIRE_HIGH ) 
    	then
    		local tableNearbyEnemyHeroes = npcBot:GetNearbyHeroes( nCastRange + 200, true, BOT_MODE_NONE );
    		for _,npcTarget in pairs( tableNearbyEnemyHeroes )
    		do
    			if ( npcBot:WasRecentlyDamagedByHero( npcEnemy, 2.0 ) ) 
    			then
    				if ( CanCastWhirlingRangedOnTarget( npcTarget ) ) 
    				then
    					return BOT_ACTION_DESIRE_HIGH, npcTarget; 
    				end
    			end
    		end
    	end
    
    
    
    
    -------- If we're in a teamfight, use it on the scariest enemy---------
    
    	local tableNearbyAttackingAlliedHeroes = npcBot:GetNearbyHeroes( 1000, false, BOT_MODE_ATTACK );
    	if ( #tableNearbyAttackingAlliedHeroes >= 2 ) 
    	then
    
    		local npcMostDangerousEnemy = nil;
    		local nMostDangerousDamage = 0;
    
    		local tableNearbyEnemyHeroes = npcBot:GetNearbyHeroes( nCastRange, true, BOT_MODE_NONE );
    		for _,npcTarget in pairs( tableNearbyEnemyHeroes )
    		do
    			if ( CanCastWhirlingRangedOnTarget( npcTarget ) )
    			then
    				local nDamage = npcTarget:GetEstimatedDamageToTarget( false, npcBot, 3.0, DAMAGE_TYPE_ALL );
    				if ( nDamage > nMostDangerousDamage )
    				then
    					nMostDangerousDamage = nDamage;
    					npcMostDangerousEnemy = nnpcTarget;
    				end
    			end
    		end
    
    		if ( npcMostDangerousEnemy ~= nil )
    		then
    			return BOT_ACTION_DESIRE_HIGH, npcTarget;
    		end
    	end
    
    
    
    ----------- If a mode has set a target, do it------------
    
    	local npcTarget = npcBot:GetTarget();
    	if ( npcTarget ~= nil and CanCastWhirlingRangedOnTarget( npcTarget ) )
    	then
    		if ( GetUnitToUnitDistance( npcTarget, npcBot ) < ( nCastRange + 200 ) )
    		then
    			return BOT_ACTION_DESIRE_HIGH, npcTarget;
    		end
    	end
    
    
    
    
    ----------- DEFEND TOWER - from heroes ----------------------- 
    
    	if ( 	 npcBot:GetActiveMode() == BOT_MODE_DEFEND_TOWER_TOP or
    		 npcBot:GetActiveMode() == BOT_MODE_DEFEND_TOWER_MID or
    		 npcBot:GetActiveMode() == BOT_MODE_DEFEND_TOWER_BOT ) 
    	then
    		local tableNearbyEnemyHeroes = npcBot:GetNearbyHeroes( 1000, true, BOT_MODE_NONE);
    			if(tableNearbyEnemyHeroes[1] ~= nil) then
    			return BOT_ACTION_DESIRE_LOW, npcTarget; 
    			end
    		end
    
    
    
    
    	return BOT_ACTION_DESIRE_NONE, 0;
    
    end
    
    
    
    
    ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    
    ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    
    function ConsiderWhirlingMelee()
    
    	local npcBot = GetBot();
    
    	-- Make sure it's castable
    	if ( not abilityWM:IsFullyCastable() ) then 
    		return BOT_ACTION_DESIRE_NONE, 0;
    	end
    
    
    	-- Get some of its values
    	local nRadius = 450;
    	local nCastRange = 0;
    	local nDamage = abilityWM:GetAbilityDamage();
    
    --------------------------------------------------------
    	-- Mode based usage
    -------------------------------------------------------
    
    
    
    ------- RETREATING -----------------------------------
    
    	if ( npcBot:GetActiveMode() == BOT_MODE_RETREAT and npcBot:GetActiveModeDesire() >= BOT_MODE_DESIRE_HIGH ) 
    	then
    		local tableNearbyEnemyHeroes = npcBot:GetNearbyHeroes( nCastRange + nRadius, true, BOT_MODE_NONE );
    		for _,npcEnemy in pairs( tableNearbyEnemyHeroes )
    		do
    			if ( npcBot:WasRecentlyDamagedByHero( npcEnemy, 2.0 ) ) 
    			then
    				
    					return BOT_ACTION_DESIRE_MODERATE;
    				end
    			end
    	end
    
    ------ CHASING -------------------------------
    	if ( npcBot:GetActiveMode() == BOT_MODE_ROAM or
    		 npcBot:GetActiveMode() == BOT_MODE_TEAM_ROAM or
    		 npcBot:GetActiveMode() == BOT_MODE_GANK or
    		 npcBot:GetActiveMode() == BOT_MODE_DEFEND_ALLY ) 
    	then
    		local npcTarget = npcBot:GetTarget();
    
    		if ( npcTarget ~= nil ) 
    		then
    			if ( GetUnitToUnitDistance( npcBot, npcTarget ) < nRadius)
    			then
    				return BOT_ACTION_DESIRE_HIGH;
    			end
    		end
    	end
    
    -------- if we're in creep wave and in range of enemy hero -----
    
    	if ( npcBot:GetActiveMode() == BOT_MODE_LANING) 
    	then
    		local tableNearbyEnemyHeroes = npcBot:GetNearbyHeroes( 1300, true, BOT_MODE_NONE );
    		local npcTarget = tableNearbyEnemyHeroes[1];
    
    		if ( npcTarget ~= nil ) 
    		then
    			if ( GetUnitToUnitDistance( npcBot, npcTarget ) < nRadius)
    			then
    				local locationAoE = npcBot:FindAoELocation( true, false, npcBot:GetLocation(), 0, nRadius, 0.0, 100000 );
    				if ( locationAoE.count >= 3 ) then
    					return BOT_ACTION_DESIRE_MODERATE;
    				end
    			end
    		end
    	end
    
    
    
    
    
    	return BOT_ACTION_DESIRE_NONE, 0;
    
    end
    
    
    
    ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    
    ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    
    
    
    
    function ConsiderBattleTrance()
    
    	local npcBot = GetBot();
    
    	-- Make sure it's castable
    	if ( not abilityBT:IsFullyCastable() ) then 
    		return BOT_ACTION_DESIRE_NONE, 0;
    	end
    
    
    	-- If we're in a teamfight, use it on the scariest enemy
    	local tableNearbyAttackingAlliedHeroes = npcBot:GetNearbyHeroes( 1000, false, BOT_MODE_ATTACK );
    	if ( #tableNearbyAttackingAlliedHeroes >= 2 ) 
    	then
    		return BOT_ACTION_DESIRE_HIGH, 0;
    		
    	end
    
    	return BOT_ACTION_DESIRE_NONE, 0;
    
    end

    His skill up is within his script, so no other files are needed, still uses build framework that EXP uses.
    Axes doesnt seem to skill up straight away all of the time, but does work.

    please review before use, very basic script, probably needs more conditions for skill use.

    Edit: he doesnt toggle melee on for extra run speed during retreat like i wanted.
    Last edited by Yavimaya; 02-09-2017 at 12:48 AM.

  3. #33
    Basic Member
    Join Date
    Oct 2016
    Posts
    247
    yet another problem.

    im trying to get clinkz to turn his searing arrows on and off at different times, but he either doesnt change anything or he turns it on and off.
    ive been through a few changes in code and had it mostly working at one point, but it broke and once it broke, even clicking undo and resaving, then reloading didnt unbreak it, which is weird.

    this is what i have narrowed it down to to try and troubleshoot why its turning on and off, i cant see wtf is going on.

    Code:
    if ( not abilitySA:IsActivated() )then	
    		return BOT_ACTION_DESIRE_LOW, 0;
    	end
    even that small chunk turns it on and off which is from the code below:


    Code:
    function ConsiderSearingArrows()
    
    	local npcBot = GetBot();
    	--local WWMana = abilityWW:GetManaCost()
    
    
    
    -------------if in fountain turn off--------------
    
    --	if GetBot():DistanceFromFountain() < 1 and ( abilitySA:GetToggleState() ) then
    --		return BOT_ACTION_DESIRE_LOW, 0;
    --	end
    
    
    
    ---------- turn on when mana over 70% -----------------------
    	--if abilitySA:IsActivated() and npcBot:GetMana()/npcBot:GetMaxMana() >= 0.8 then return end
    	
    	if ( not abilitySA:IsActivated() )then -- and npcBot:GetMana()/npcBot:GetMaxMana() >= 0.5 ) then
    	--if abilitySA:IsActivated() and npcBot:GetMana()/npcBot:GetMaxMana() >= 0.8 then return end
    		return BOT_ACTION_DESIRE_LOW, 0;
    	end
    
    
    --------- turn off before not enough mana for wind walk -------------------
    
    --	if  (abilitySA:GetToggleState() and npcBot:GetMana()/npcBot:GetMaxMana() < 0.5)  then 
    --		return BOT_ACTION_DESIRE_LOW, 0;
    --	end
    
    
    ----------------if ganking make sure arrows are on-------------------
    
    --if npcBot:GetActiveMode() == BOT_MODE_ATTACK or npcBot:GetActiveMode() == BOT_MODE_GANK then
    --	if (not abilitySA:GetToggleState() ) and (npcBot:GetMana()/npcBot:GetMaxMana() >= 0.25)  then
    --		return BOT_ACTION_DESIRE_MODERATE, 0;
    --	end
    --
    --end
    
    
    	return BOT_ACTION_DESIRE_NONE, 0;
    
    end

    i have also tried this in the past, which also half worked, but not properly.
    Code:
    function ConsiderSearingArrows()
    
    	local npcBot = GetBot();
    	--local WWMana = abilityWW:GetManaCost()
    
    
    
    -------------if in fountain turn off--------------
    
    	if GetBot():DistanceFromFountain() == 0 and ( SEARING_ARROWS_STATUS ) then
    		abilitySA:ToggleAutoCast();
    		SEARING_ARROWS_STATUS = false
    	end
    
    
    
    ---------- turn on when mana over 70% -----------------------
    	
    	
    	if ( not SEARING_ARROWS_STATUS ) and npcBot:GetMana()/npcBot:GetMaxMana() >= 0.55  then
    		abilitySA:ToggleAutoCast();
    		SEARING_ARROWS_STATUS = true
    	end
    
    
    --------- turn off before not enough mana for wind walk -------------------
    local WWMana = abilityWW:GetManaCost()
    	if ( SEARING_ARROWS_STATUS ) and (npcBot:GetMana()/npcBot:GetMaxMana() < 0.55)  then 
    		abilitySA:ToggleAutoCast();
    		SEARING_ARROWS_STATUS = false
    	end
    
    
    
    ----------------if ganking make sure arrows are on-------------------
    
    if npcBot:GetActiveMode() == BOT_MODE_ATTACK or npcBot:GetActiveMode() == BOT_MODE_GANK then
    	if ( not SEARING_ARROWS_STATUS ) and (npcBot:GetMana()/npcBot:GetMaxMana() >= 0.25)  then
    		abilitySA:ToggleAutoCast();
    		SEARING_ARROWS_STATUS = true
    	end
    
    end
    
    
    	return BOT_ACTION_DESIRE_NONE, 0;
    
    end
    i just cant see why he is turning on and off, and when i settle him down, he just gets out of whack sometimes (at fountain code is there to reset it on death or it stays on all the time and searing arrows var gets thrown out)
    Last edited by Yavimaya; 02-11-2017 at 06:02 AM.

  4. #34
    Basic Member
    Join Date
    May 2014
    Posts
    270
    @Yavimaya
    Why don't you just make it UseAbilityOnEntity rather than make it toggle the auto cast. I think that's the easier way to do.

    Question :
    How can I get which lane the bot currently at? If I'm using GetAssignedLane, will it change every time the bot move to the other lane?
    Last edited by arz_on4dt; 02-11-2017 at 06:00 PM.

  5. #35
    Basic Member
    Join Date
    Oct 2016
    Posts
    247
    i dont use it because its easier to call times to turn it on and off (turn off before no mana for stealth, make sure its on for gank, etc) than him running around with it off when pushing, farming, etc and having to put it all in manually.

    how does IsToggle() work? as you can see ive used the other options, and they are ok as far as actually turning the skill on and off goes, but its so easy to make conflicts etc that its hardly worth using those functions.
    one example is the fact that the code i put in first here, one simple line to check "if its not on, turn it on" turns it on and off constantly and the same thing happened with GetToggleStatus() and simply by using a variable (searing_arrows_status) and then toggling the skill.
    all exactly the same result.

    not sure about lanes.

  6. #36
    Basic Member
    Join Date
    May 2014
    Posts
    270
    Quote Originally Posted by Yavimaya View Post
    i dont use it because its easier to call times to turn it on and off (turn off before no mana for stealth, make sure its on for gank, etc) than him running around with it off when pushing, farming, etc and having to put it all in manually.

    how does IsToggle() work? as you can see ive used the other options, and they are ok as far as actually turning the skill on and off goes, but its so easy to make conflicts etc that its hardly worth using those functions.
    one example is the fact that the code i put in first here, one simple line to check "if its not on, turn it on" turns it on and off constantly and the same thing happened with GetToggleStatus() and simply by using a variable (searing_arrows_status) and then toggling the skill.
    all exactly the same result.

    not sure about lanes.
    Can I look at your clinkz full code? Maybe I can help.

  7. #37
    Basic Member
    Join Date
    Oct 2016
    Posts
    247
    This version is the best working, but i dont like it, it uses variables and relies on the state and variable remaining aligned.

    Code:
    require(GetScriptDirectory() ..  "/ability_item_usage_generic")
    local utils = require(GetScriptDirectory() ..  "/util")
    local inspect = require(GetScriptDirectory() ..  "/inspect")
    local enemyStatus = require(GetScriptDirectory() .. "/enemy_status" )
    
    function AbilityLevelUpThink()  
    	ability_item_usage_generic.AbilityLevelUpThink(); 
    end
    
    
    ----------------------------------------------------------------------------------------------------------------------------------
    
    castSDesire = 0;
    castSADesire = 0;
    castWWDesire = 0;
    castDPDesire = 0;
    SEARING_ARROWS__STATUS = false;
    
    
    function AbilityUsageThink()
    
    	local npcBot = GetBot();
    
    
    		if npcBot:IsChanneling() then
    		return;
    	end
    
    	-- Check if we're already using an ability
    	if ( npcBot:IsUsingAbility() ) then return end;
    
    
    abilityS = npcBot:GetAbilityByName( "clinkz_strafe" );
    
    abilitySA = npcBot:GetAbilityByName( "clinkz_searing_arrows" );
    
    abilityWW = npcBot:GetAbilityByName( "clinkz_wind_walk" );
    
    abilityDP = npcBot:GetAbilityByName( "clinkz_death_pact" );
    
    	-- Consider using each ability
    	castSDesire = ConsiderStrafe();
    	castSADesire = ConsiderSearingArrows();   
    	castWWDesire = ConsiderWindWalk();
    	castDPDesire, castDPTarget = ConsiderDeathPact();    
    
    	if ( castDPDesire > 0 ) 
    	then
    		npcBot:Action_UseAbilityOnEntity( abilityDP, castDPTarget );
    		return;
    	end
    
    	if ( castWWDesire > 0 ) 
    	then
    		npcBot:Action_UseAbility( abilityWW );
    		return;
    	end
    	
    	
    	if ( castSADesire > 0 ) 
    	then
    		npcBot:Action_UseAbility( abilitySA );
    		return;
    	end
    
    
    		if ( castSDesire > 0 ) 
    	then
    		npcBot:Action_UseAbility( abilityS );
    		return;
    	end
    
    
    	
    end
    
    ----------------------------------------------------------------------------------------------------------------------------------
    
    function CanCastDeathPactOnTarget( npcTarget )
    	return npcTarget:CanBeSeen() and not npcTarget:IsMagicImmune() and not npcTarget:IsInvulnerable();
    end
    
    
    ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    
    
    
    
    
    
    
    
    
    
    
    function ConsiderStrafe()
    
    	local npcBot = GetBot();
    
    	-- Make sure it's castable
    	if ( not abilityS:IsFullyCastable() ) 
    	then 
    		return BOT_ACTION_DESIRE_NONE, 0;
    	end;
    
    
    	local nAttackRange = npcBot:GetAttackRange();
    	local tableNearbyEnemyHeroes = npcBot:GetNearbyHeroes( nAttackRange, true, BOT_MODE_NONE );
    
    ------ If we're in a teamfight, use it--------------------------
    
    	local tableNearbyAttackingAlliedHeroes = npcBot:GetNearbyHeroes( 1000, false, BOT_MODE_ATTACK );
    --	local tableNearbyEnemyHeroes = npcBot:GetNearbyHeroes( nAttackRange, true, BOT_MODE_NONE );
    		if ( #tableNearbyAttackingAlliedHeroes >= 2 )  and (tableNearbyEnemyHeroes[1] ~= nil) and npcBot:GetActiveMode() == BOT_MODE_ATTACK then
    		return BOT_ACTION_DESIRE_MODERATE, 0;
    		
    		end
    
    
    ----- if has death pact modifer and is invisble and enemy hero near and npcbot:bot_mode_attack / has target, then use -------------------
    
    
    
    if ( npcBot:HasModifier("modifier_clinkz_death_pact") and (npcBot:IsInvisble() == true) and (tableNearbyEnemyHeroes[1] ~= nil)) and (npcBot:GetTarget() ~= nil or npcBot:GetActiveMode() == BOT_MODE_ATTACK) then     ---- ISINVIS NOT WORKING
    --local tableNearbyEnemyHeroes = npcBot:GetNearbyHeroes( nAttackRange, true, BOT_MODE_NONE );
    
    return BOT_ACTION_DESIRE_LOW, 0;
    		
    		end
    
    
    	return BOT_ACTION_DESIRE_NONE, 0;
    end
    
    
    
    
    
    
    
    ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    
    ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    
    
    
    
    function ConsiderSearingArrows()
    
    	local npcBot = GetBot();
    	--local WWMana = abilityWW:GetManaCost()
    
    
    
    -------------if in fountain turn off--------------
    
    	if GetBot():DistanceFromFountain() == 0 and ( SEARING_ARROWS_STATUS ) then
    		abilitySA:ToggleAutoCast();
    		SEARING_ARROWS_STATUS = false
    	end
    
    
    
    ---------- turn on when mana over 70% -----------------------
    	if ( not SEARING_ARROWS_STATUS ) and (npcBot:GetMana()/npcBot:GetMaxMana() >= 0.55)  then
    	
    	--if ( not abilitySA:GetToggleState() then -- and npcBot:GetMana()/npcBot:GetMaxMana() >= 0.55)  then
    		abilitySA:ToggleAutoCast();
    		SEARING_ARROWS_STATUS = true
    	end
    
    
    --------- turn off before not enough mana for wind walk -------------------
    local WWMana = abilityWW:GetManaCost()
    	if ( SEARING_ARROWS_STATUS ) and (npcBot:GetMana()/npcBot:GetMaxMana() < 0.55)  then 
    		abilitySA:ToggleAutoCast();
    		SEARING_ARROWS_STATUS = false
    	end
    
    
    
    ----------------if ganking make sure arrows are on-------------------
    
    if npcBot:GetActiveMode() == BOT_MODE_ATTACK or npcBot:GetActiveMode() == BOT_MODE_GANK then
    	if ( not SEARING_ARROWS_STATUS ) and (npcBot:GetMana()/npcBot:GetMaxMana() >= 0.25)  then
    		abilitySA:ToggleAutoCast();
    		SEARING_ARROWS_STATUS = true
    	end
    
    end
    
    
    	return BOT_ACTION_DESIRE_NONE, 0;
    
    end
    
    ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    
    ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    
    function ConsiderWindWalk()
    
    	local npcBot = GetBot();
    
    	-- Make sure it's castable
    	if ( not abilityWW:IsFullyCastable() ) then 
    		return BOT_ACTION_DESIRE_NONE, 0;
    	end
    
    
    ----- if has deathpact modifer and (? and is bot_mode gank / roam)  then use ---------------------
    
    if  npcBot:HasModifier("modifier_clinkz_death_pact") and npcBot:GetActiveMode() == BOT_MODE_ATTACK or npcBot:GetActiveMode() == BOT_MODE_GANK then
    return BOT_ACTION_DESIRE_LOW, 0;
    end
    
    
    
    ------- RETREATING -----------------------------------
    
    	if ( npcBot:GetActiveMode() == BOT_MODE_RETREAT and npcBot:GetActiveModeDesire() >= BOT_MODE_DESIRE_HIGH ) 
    	then
    	return BOT_ACTION_DESIRE_HIGH;
    			
    	end
    	
    
    
    
    	return BOT_ACTION_DESIRE_NONE, 0;
    
    end
    
    
    
    ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    
    ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    
    
    
    
    function ConsiderDeathPact()
    
    	local npcBot = GetBot();
    
    	-- Make sure it's castable
    	if ( not abilityDP:IsFullyCastable() ) then 
    		return BOT_ACTION_DESIRE_NONE, 0;
    	end
    
    
    	local nCastRange = abilityDP:GetCastRange();
    
    
    ------------ check for and consume highest health creep -------------------------
    
    
    	local maxHP = 0;
    	local NCreep = nil;
    	local tableNearbyNeutrals = npcBot:GetNearbyNeutralCreeps( 1000 );
    	for _,neutral in pairs(tableNearbyNeutrals)
    	do
    		local NeutralHP = neutral:GetHealth();
    		if NeutralHP > maxHP
    		then
    			NCreep = neutral;
    			maxHP = NeutralHP;
    		end
    	end
    	
    	if NCreep ~= nil then
    		return BOT_ACTION_DESIRE_HIGH, NCreep;
    	end	
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    --	local npcMostDangerousEnemy = nil;
    --	local nMostDangerousDamage = 0;
    
    --	local tableNearbyEnemyCreeps = npcBot:GetNearbyCreeps( 3 * nCastRange, true );
    
    --	if ( not npcBot:HasModifier("modifier_clinkz_death_pact") ) 
    --	then
    
    --		for _,npcEnemy in pairs( tableNearbyEnemyCreeps )
    --		do
    			
    --				local nDamage = npcEnemy:GetHealth();
    --				if ( nDamage > nMostDangerousDamage )
    --				then
    --					nMostDangerousDamage = nDamage;
    --					npcMostDangerousEnemy = npcEnemy;
    --				end
    			
    --		end
    
    --		if ( npcMostDangerousEnemy ~= nil )
    --		then
    --			return BOT_ACTION_DESIRE_MODERATE, npcMostDangerousEnemy;
    --		end
    	
    --	end
    
    
    
    	return BOT_ACTION_DESIRE_NONE, 0;
    
    end

  8. #38
    Basic Member
    Join Date
    May 2014
    Posts
    270
    @Yavimaya
    Maybe try to change how you cast the searing arrow with ToggleBurningSpear function. And no need to return castConsider value.
    Code:
    require(GetScriptDirectory() ..  "/ability_item_usage_generic")
    local utils = require(GetScriptDirectory() ..  "/util")
    local inspect = require(GetScriptDirectory() ..  "/inspect")
    local enemyStatus = require(GetScriptDirectory() .. "/enemy_status" )
    
    function AbilityLevelUpThink()  
    	ability_item_usage_generic.AbilityLevelUpThink(); 
    end
    
    
    castBSDesire = 0;
    
    
    function AbilityUsageThink()
    
    	local npcBot = GetBot();
    	
    	-- Check if we're already using an ability
    	if ( npcBot:IsUsingAbility() ) then return end
    
    	abilityBS = npcBot:GetAbilityByName( "clinkz_searing_arrows" );
    	-- Consider using each ability
    	ToggleBurningSpear();
    	
    end
    
    function CanCastBurningSpearOnTarget( npcTarget )
    	return npcTarget:CanBeSeen() and not npcTarget:IsInvulnerable();
    end
    
    function ToggleBurningSpear()
    
    	local npcBot = GetBot();
    	
    	local currManaP = npcBot:GetMana() / npcBot:GetMaxMana();
    	local npcTarget = npcBot:GetTarget();
    	
    	if ( npcTarget ~= nil and 
    		( npcTarget:IsHero() or npcTarget:IsTower() or npcTarget:GetUnitName() == "npc_dota_roshan" ) and 
    		CanCastBurningSpearOnTarget( npcTarget ) and 
    		currManaP > .25 
    		) 
    	then
    		if not abilityBS:GetAutoCastState( ) then
    			abilityBS:ToggleAutoCast()
    		end
    	else 
    		if  abilityBS:GetAutoCastState( ) then
    			abilityBS:ToggleAutoCast()
    		
    		end
    	end
    	
    end
    This Code will only make clinkz auto cast when he is at team fight, hitting tower when pushing, and doing roshan. I hope this will help.
    Edit : Sorry for the function name, I'm just copy paste it from my huskar burning spear.
    Last edited by arz_on4dt; 02-12-2017 at 07:44 AM.

  9. #39
    Basic Member
    Join Date
    May 2014
    Posts
    270
    This is my Clinkz full code
    Code:
    require(GetScriptDirectory() ..  "/ability_item_usage_generic")
    local utils = require(GetScriptDirectory() ..  "/util")
    local inspect = require(GetScriptDirectory() ..  "/inspect")
    local enemyStatus = require(GetScriptDirectory() .. "/enemy_status" )
    
    function AbilityLevelUpThink()  
    	ability_item_usage_generic.AbilityLevelUpThink(); 
    end
    
    
    castSTDesire = 0;
    castSADesire = 0;
    castWWDesire = 0;
    castDPDesire = 0;
    
    
    function AbilityUsageThink()
    
    	local npcBot = GetBot();
    	
    	-- Check if we're already using an ability
    	if ( npcBot:IsUsingAbility() ) then return end
    
    	abilityST = npcBot:GetAbilityByName( "clinkz_strafe" );
    	abilitySA = npcBot:GetAbilityByName( "clinkz_searing_arrows" );
    	abilityWW = npcBot:GetAbilityByName( "clinkz_wind_walk" );
    	abilityDP = npcBot:GetAbilityByName( "clinkz_death_pact" );
    	-- Consider using each ability
    	if abilitySA:IsTrained() then
    		ToggleSearingArrow();
    	end
    	
    	castSTDesire, castSTTarget = ConsiderStarfe()
    	castSADesire, castSATarget = ConsiderSearingArrows()
    	castWWDesire               = ConsiderWindWalk()
    	castDPDesire, castDPTarget = ConsiderDeathPack()
    	
    	if castSTDesire > 0
    	then
    		npcBot:Action_UseAbility(abilityST);
    	end
    	
    	if castSADesire > 0 
    	then
    		npcBot:Action_UseAbilityOnEntity(abilitySA, castSATarget);
    	end
    	
    	if castWWDesire > 0
    	then
    		npcBot:Action_UseAbility(abilityWW);
    	end
    	
    	if castDPDesire > 0
    	then
    		npcBot:Action_UseAbilityOnEntity(abilityDP, castDPTarget);
    	end
    	
    end
    
    function CanCastSearingArrowOnTarget( npcTarget )
    	return npcTarget:CanBeSeen() and not npcTarget:IsInvulnerable();
    end
    function CanCastDeathPactOnTarget( npcTarget )
    	return npcTarget:CanBeSeen() and not npcTarget:IsMagicImmune() and not npcTarget:IsInvulnerable();
    end
    
    function ToggleSearingArrow()
    
    	local npcBot = GetBot();
    	
    	local currManaP = npcBot:GetMana() / npcBot:GetMaxMana();
    	local npcTarget = npcBot:GetTarget();
    	
    	if ( npcTarget ~= nil and 
    		( npcTarget:IsHero() or npcTarget:IsTower() or npcTarget:GetUnitName() == "npc_dota_roshan" ) and 
    		CanCastSearingArrowOnTarget( npcTarget ) and 
    		currManaP > .25 
    		) 
    	then
    		if not abilitySA:GetAutoCastState( ) then
    			abilitySA:ToggleAutoCast()
    		end
    	else 
    		if  abilitySA:GetAutoCastState( ) then
    			abilitySA:ToggleAutoCast()
    		end
    	end
    	
    end
    
    function ConsiderStarfe()
    
    	local npcBot = GetBot();
    	
    	if ( not abilityST:IsFullyCastable() ) then 
    		return BOT_ACTION_DESIRE_NONE;
    	end
    	
    	local attackRange = npcBot:GetAttackRange()
    	
    	if ( npcBot:GetActiveMode() == BOT_MODE_PUSH_TOWER_TOP or
    		 npcBot:GetActiveMode() == BOT_MODE_PUSH_TOWER_MID or
    		 npcBot:GetActiveMode() == BOT_MODE_PUSH_TOWER_BOTTOM ) 
    	then
    		local tableNearbyEnemyTowers = npcBot:GetNearbyTowers( attackRange, true );
    		if tableNearbyEnemyTowers[1] ~= nil 
    			and not tableNearbyEnemyTowers[1]:IsInvulnerable() 
    			and GetUnitToUnitDistance(  tableNearbyEnemyTowers[1], npcBot  ) < attackRange
    		then	
    			return BOT_ACTION_DESIRE_MODERATE;
    		end
    	end
    	
    	if ( npcBot:GetActiveMode() == BOT_MODE_ROSHAN ) 
    	then
    		local npcTarget = npcBot:GetTarget();
    		if ( npcTarget ~= nil and GetUnitToUnitDistance(  npcTarget, npcBot  ) < attackRange  )
    		then
    			return BOT_ACTION_DESIRE_MODERATE;
    		end
    	end
    	
    	if ( npcBot:GetActiveMode() == BOT_MODE_ROAM or
    		 npcBot:GetActiveMode() == BOT_MODE_TEAM_ROAM or
    		 npcBot:GetActiveMode() == BOT_MODE_GANK or
    		 npcBot:GetActiveMode() == BOT_MODE_ATTACK or
    		 npcBot:GetActiveMode() == BOT_MODE_DEFEND_ALLY ) 
    	then
    		local npcTarget = npcBot:GetTarget();
    		if ( npcTarget ~= nil and GetUnitToUnitDistance( npcTarget, npcBot ) < attackRange ) 
    		then
    			return BOT_ACTION_DESIRE_MODERATE;
    		end
    	end
    
    	return BOT_ACTION_DESIRE_NONE;
    	
    end
    
    
    
    function ConsiderSearingArrows()
    
    	local npcBot = GetBot();
    	
    	if ( not abilitySA:IsFullyCastable() ) then 
    		return BOT_ACTION_DESIRE_NONE, 0;
    	end
    
    	if abilitySA:GetAutoCastState( ) then
    		return BOT_ACTION_DESIRE_NONE, 0;
    	end
    
    	local nDamage = npcBot:GetAttackDamage() + abilitySA:GetSpecialValueInt( "damage_bonus" );
    	local currManaP = npcBot:GetMana() / npcBot:GetMaxMana();
    	local attackRange = npcBot:GetAttackRange()
    	
    	if npcBot:GetActiveMode() == BOT_MODE_LANING then
    		local laneCreeps = npcBot:GetNearbyLaneCreeps(attackRange, true);
    		for _,creep in pairs(laneCreeps)
    		do
    			if creep:GetHealth() <= nDamage then
    				return BOT_ACTION_DESIRE_LOW, creep;
    			end
    		end
    	end
    	
    	if npcBot:GetActiveMode() == BOT_MODE_LANING then
    		local NearbyEnemyHeroes = npcBot:GetNearbyHeroes(attackRange, true, BOT_MODE_NONE);
    		if NearbyEnemyHeroes[1] ~=  nil and CanCastSearingArrowOnTarget(NearbyEnemyHeroes[1]) and currManaP > 0.65  then
    			return BOT_ACTION_DESIRE_LOW, NearbyEnemyHeroes[1];
    		end
    	end
    	
    	
    	return BOT_ACTION_DESIRE_NONE, 0;
    	
    end
    
    function ConsiderWindWalk()
    	local npcBot = GetBot();
    
    	if ( not abilityWW:IsFullyCastable() ) then 
    		return BOT_ACTION_DESIRE_NONE;
    	end
    	
    	local attackRange = npcBot:GetAttackRange()
    	
    	if ( npcBot:GetActiveMode() == BOT_MODE_RETREAT and npcBot:GetActiveModeDesire() >= BOT_MODE_DESIRE_HIGH ) 
    	then
    		local tableNearbyEnemyHeroes = npcBot:GetNearbyHeroes( 1000, true, BOT_MODE_NONE );
    		if tableNearbyEnemyHeroes ~= nil and #tableNearbyEnemyHeroes >= 1 then
    			return BOT_ACTION_DESIRE_HIGH;
    		end
    	end
    
    	if ( npcBot:GetActiveMode() == BOT_MODE_ROAM or
    		 npcBot:GetActiveMode() == BOT_MODE_TEAM_ROAM or
    		 npcBot:GetActiveMode() == BOT_MODE_GANK  ) 
    	then
    		local npcTarget = npcBot:GetTarget();
    		if ( npcTarget ~= nil ) 
    		then
    			local dist = GetUnitToUnitDistance( npcBot, npcTarget );
    			if ( dist > 2 * attackRange and dist <= 3000 )
    			then
    				return BOT_ACTION_DESIRE_MODERATE;
    			end
    		end
    	end
    	
    	return BOT_ACTION_DESIRE_NONE;
    	
    end
    
    function ConsiderDeathPack()
    	local npcBot = GetBot();
    	if ( not abilityDP:IsFullyCastable() ) then 
    		return BOT_ACTION_DESIRE_NONE, 0;
    	end
    	
    	local maxHP = 0;
    	local NCreep = nil;
    	local tableNearbyCreeps = npcBot:GetNearbyCreeps( 800, true );
    	if #tableNearbyCreeps >= 2 then
    		for _,creeps in pairs(tableNearbyCreeps)
    		do
    			local CreepHP = creeps:GetHealth();
    			if CreepHP > maxHP and ( creeps:GetHealth() / creeps:GetMaxHealth() > .75 )
    			then
    				NCreep = creeps;
    				maxHP = CreepHP;
    			end
    		end
    	end
    
    	if NCreep ~= nil then
    		return BOT_ACTION_DESIRE_LOW, NCreep;
    	end	
    
    	return BOT_ACTION_DESIRE_NONE, 0;
    
    end

  10. #40
    Basic Member
    Join Date
    Oct 2016
    Posts
    247
    lol ive noticed you are getting lazy with changing function names. :P
    you not using a good text editor?

    ill check out your clinkz code, im still looking for a way to toggle properly though as he has enough mana to use his fire arrows when farming / general use later in the game, so why turn it off until he must? :wink:
    the code i pasted that works fairly well is based on the shutnik outworlds orb, but for him he just turns it on and leaves it, which is why it worked for the programmer i guess.
    in any "toggle" situation, if you only have the one toggle function is becomes very easy to create conflicts, i wish game programmers would think about that and make actual toggle on and toggle off functions.

    edit: reading through that script, it seems pretty good, ill give it a run and see how it works.
    if your toggle function works better, i might just use that with my own conditions.... or maybe its my conditions that are doing me over.
    Last edited by Yavimaya; 02-12-2017 at 04:00 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
  •