How to detect when a hero is killed by another hero (hero killed and hero that killed)

I am new to lua and dota 2 custom games still trying to figure things out does anyone know how to detect when a hero is killed and the hero that killed them? Example code snippet would really help since im still getting used to the syntax

Comments

  • edited January 2017 Posts: 149
    function GameMode:_InitGameMode()
       ListenToGameEvent('entity_killed', Dynamic_Wrap(GameMode, 'OnEntityKilled'), self)
    end
    
    function GameMode:OnEntityKilled( keys )
    
      local killedUnit = EntIndexToHScript( keys.entindex_killed )
      local killerEntity = nil
      local xpBounty = killedUnit:GetDeathXP()
      if keys.entindex_attacker ~= nil then
        killerEntity = EntIndexToHScript( keys.entindex_attacker )
      end
    
      if killerEntity:IsHero() and killedUnit:IsHero() then
       -- your code
      end
    end
    
  • Posts: 14

    wow this is a perfect example thank you