5v5 snipers

Ok so I'm a bit new to lua and need help figuring out if what I'm coding is correct. Im trying to make a game 5v5 snipers with the first to 50 kill the winner. is this a correct function to place in the addon_game_mode.lua directory? function CDOTAPlayer handle GetAssignedHero(sniper) end

Comments

  • edited February 2015 Posts: 1,670

    Hello @Keo are you using Barebones? If not, I recommend you to start your mod with them, you can use ModKit for that purpose (and have access to various useful features for modding).

    To make a "first to 50 kills wins" mechanic, just take a look at the barebones lua example under OnEntityKilled:

    function GameMode:OnEntityKilled( keys )
      
      -- The Unit that was Killed
      local killedUnit = EntIndexToHScript( keys.entindex_killed )
      -- The Killing entity
      local killerEntity = EntIndexToHScript( keys.entindex_attacker )
    
      if killedUnit:IsRealHero() then 
        print ("KILLEDKILLER: " .. killedUnit:GetName() .. " -- " .. killerEntity:GetName())
        if killedUnit:GetTeam() == DOTA_TEAM_BADGUYS and killerEntity:GetTeam() == DOTA_TEAM_GOODGUYS then
          self.nRadiantKills = self.nRadiantKills + 1
          if END_GAME_ON_KILLS and self.nRadiantKills >= KILLS_TO_END_GAME_FOR_TEAM then
            GameRules:SetSafeToLeave( true )
            GameRules:SetGameWinner( DOTA_TEAM_GOODGUYS )
          end
        elseif killedUnit:GetTeam() == DOTA_TEAM_GOODGUYS and killerEntity:GetTeam() == DOTA_TEAM_BADGUYS then
          self.nDireKills = self.nDireKills + 1
          if END_GAME_ON_KILLS and self.nDireKills >= KILLS_TO_END_GAME_FOR_TEAM then
            GameRules:SetSafeToLeave( true )
            GameRules:SetGameWinner( DOTA_TEAM_BADGUYS )
          end
        end
      end
    end
    

    END_GAME_ON_KILLS is just a global variable defined when the addon initializes, KILLS_TO_END_GAME_FOR_TEAM would be 50.

    This example however is for the first team to get to a particular amount of kills, if you want it to be the first player, just check for the killerEntity's kills with killerEntity:GetKills() instead of team.

    The concept of Modding Community doesn't go well together with Competitive Business
    My Project Page || My GitHub Profile ||