Page 1 of 2 1 2 LastLast
Results 1 to 10 of 14

Thread: BUG: GetTower(..,..) Will return nil if tower has fallen

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

    BUG: GetTower(..,..) Will return nil if tower has fallen

    Using GetTower() when the tower is alive works fine but when tower has fallen. GetTower will return nil and IsAlive() function wont work.

    using operator == to check nil if you encounter with this issue.

  2. #2
    Basic Member
    Join Date
    Mar 2012
    Posts
    1,713
    That's normal behavior. The handle is gone once the unit is destroyed.
    Also, if a unit is destroyed, it's absolutely logical to not "find" it anymore
    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
    Dec 2016
    Posts
    134
    I though that the handle wouldnt be removed if the tower destroyed.

    Its better to save handle and access the last position of tower during the game. it would be good for pushing and lane defending...
    thanks for your reply

  4. #4
    Basic Member
    Join Date
    Mar 2012
    Posts
    1,713
    Just cache the location. Local variables are faster anyway performance-wise.
    Explanations on the normal, high and very high brackets in replays: here, here & here
    Why maphacks won't work in D2: here

  5. #5
    Basic Member
    Join Date
    Dec 2016
    Posts
    121
    I have problem because of tower handle not destroyed when fallen.
    Code like
    Code:
    	local tower = GetTower(GetOpposingTeam( ), building);	
    		if (tower ~= nil and tower:IsAlive() ) then
    will crash my dota2 because I still get the handle of tower when it fall, so tower~= nil is passed and then 'tower:IsAlive()' will crash my dota2 since tower no longer exist.

    I had 'tower~= nil' check for nil value in every code related with towers, which didn't work.
    Code:
    local tablebuildings = { 
    TOWER_BASE_1,
    TOWER_BASE_2,
    TOWER_MID_3,
    TOWER_BOT_3,
    TOWER_TOP_3,
    TOWER_MID_2,
    TOWER_MID_1,
    TOWER_TOP_2,
    TOWER_BOT_2,
    TOWER_TOP_1,
    TOWER_BOT_1,
    			};
    Code:
    function FindEnemyNearestTower(location)
    	local min_distance = 99999;
    	local nearest_tower = nil;
    	local nearest_tower_name = nil;
    	for building_k, building in pairs(tablebuildings) do
    		local current_tower = GetTower(GetOpposingTeam( ), building);
    		if (current_tower~= nil and current_tower:IsAlive() and (not current_tower:IsInvulnerable( )) and GetUnitToLocationDistance(current_tower, location) < min_distance) then
    			min_distance = GetUnitToLocationDistance(current_tower, location);
    			nearest_tower = current_tower;
    			nearest_tower_name = building;
    		end
    	end
    	return nearest_tower , nearest_tower_name; ---some times can't get the handle of the enemy tower
    end
    Last edited by lunarbreez; 03-17-2017 at 05:41 PM.

  6. #6
    Basic Member
    Join Date
    Nov 2015
    Posts
    108
    Have you tried tower:IsNull() in that case?

  7. #7
    Basic Member
    Join Date
    Dec 2016
    Posts
    121
    where is function IsNull() come from? can't find it on wiki or ModDota API Documentation.

  8. #8
    Basic Member
    Join Date
    Mar 2012
    Posts
    1,713
    I think if this is a bug, IsNull() should not be the fix, but rather a native patch should be the fix.
    Chris, can you double check this use-case?
    Explanations on the normal, high and very high brackets in replays: here, here & here
    Why maphacks won't work in D2: here

  9. #9
    Basic Member
    Join Date
    May 2014
    Posts
    238
    Try to use GetHealth() > 0 instead of IsAlive().

  10. #10
    Basic Member
    Join Date
    Mar 2012
    Posts
    1,713
    That would be the same thing, since the handle is the problem.

    I've been looking at it and I don't see an issue in your code. Are you sure the problem is in FindEnemyNearestTower() ? And not before/after ? It could be after if you don't check the return values and just execute code.
    What do the logs say if you enable condebug?
    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
  •