How to force each team to have a different hero.

I have little to none experience with lua and I was wondering how to force each team to have a single hero. Like radiant team spawns as a io, and dire spawns with a sf.

Comments

  • Thanks for the links, but im running into the problem that except for the last link, the code they have sets both teams equal to one hero and it makes a double of the hero when you spawn. The third link i don't know how to implement, probably me just being a noob.

  • Posts: 273
    function your_gamemode:InitGameMode()
    
       ListenToGameEvent('player_connect_full', Dynamic_Wrap(your_gamemode, 'OnConnectFull'), self)
       ListenToGameEvent('npc_spawned', Dynamic_Wrap(your_gamemode, 'OnNPCSpawned'), self)
    
    end
    
    function your_gamemode:OnConnectFull(keys)
       local io = "npc_dota_hero_wisp"
       local gamemode = GameRules:GetGameModeEntity()
       gamemode:SetCustomGameForceHero(io)
    end
    
    function your_gamemode:OnNPCSpawned(keys)
       local sf = "npc_dota_hero_nevermore" 
       local npc = EntIndexToHScript(keys.entindex)
    
       if npc:IsRealHero() and npc.bFirstSpawned == nil then
          npc.bFirstSpawned = true
    
          if npc:GetTeam() == DOTA_TEAM_BADGUYS then
             local playerID = npc:GetPlayerID()
             PlayerResource:ReplaceHeroWith(playerID, sf, 625, 0)
          end
       end
    end
    
  • So i implemented the code in my game mode folder and it is giving me a parameter type mismatch error saying that the EntEndexToHscript is returning void. What should I change to fix this?

  • Posts: 96

    try add condition

    if npc and npc:IsRealHero() and not npc.bFirstSpawned then
    

    i'm not sure why it was failing on trying to return entity but give that a try

  • edited January 2017 Posts: 273

    Functions I wrote should be in your addon_game_mode.lua beside functions Precache(context) and Activate() unless you are using BMD's barebones (then they should go in events.lua). Make sure its EntIndexToHScript and not EntEndexToHscript.

    Edit: I mislead you. My bad. Read this

  • edited January 2017 Posts: 6
    function GameMode:InitGameMode()
       ListenToGameEvent('player_connect_full', Dynamic_Wrap(GameMode, 'OnConnectFull'), self)
       ListenToGameEvent('npc_spawned', Dynamic_Wrap(GameMode, 'OnNPCSpawned'), self)
    
    end
    
    
    function GameMode:OnConnectFull(keys)
       local io = "npc_dota_hero_wisp"
       local gamemode = GameRules:GetGameModeEntity()
       gamemode:SetCustomGameForceHero(io)
       local sf = "npc_dota_hero_nevermore" 
       local npc = EntIndexToHScript(keys.entindex)
    
       if npc:IsRealHero() and npc.bFirstSpawned == nil then
          npc.bFirstSpawned = true
    
          if npc:GetTeam() == DOTA_TEAM_BADGUYS then
             local playerID = npc:GetPlayerID()
             PlayerResource:ReplaceHeroWith(playerID, sf, 625, 0)
          end
       end
    end
    
    

    I am using BMD's barebones so this is what I put in the events folder now. For the your_gamemode part I thought that since it is barebones I just change it to GameMode. Do I need to change it to the map name?

  • Posts: 273

    No, it should be GameMode, but nvm that, you messed up. You need to only modify some things not just copy-paste. Please do the following.

    1) Delete all the stuff you did previously because it will mess up everything.

    2) Find settings.lua; inside it find FORCE_PICKED_HERO = nil and replace with: FORCE_PICKED_HERO = "npc_dota_hero_wisp"

    3) Find inside gamemode.lua this line: function GameMode:OnHeroInGame(hero). Inside that function put this code (PUT IT HERE FOR EXAMPLE):

    Timers:CreateTimer(0.5, function()
       if hero:GetTeam() == DOTA_TEAM_BADGUYS then
          local playerID = hero:GetPlayerID()
          local sf = "npc_dota_hero_nevermore"
          PlayerResource:ReplaceHeroWith(playerID, sf, STARTING_GOLD, 0)
       end
    end)
    

    4) in your addon_game_mode.lua inside Precache( context ) put this:

    PrecacheUnitByNameSync("npc_dota_hero_wisp", context)
    PrecacheUnitByNameSync("npc_dota_hero_nevermore", context)
    

    And you are done.

  • That worked. Thank you guys for the help, and sorry I needed a lot of hand holding for this.