Script order problems, hard to solve.

edited July 2015 in Questions
function GameMode:FilterExecuteOrder(filterTable)
  if filterTable["order_type"] == 6 then
    local units_table = filterTable["units"]
    for n,v in pairs(units_table) do
      local Hcaster = EntIndexToHScript(v)
      local ability = filterTable["entindex_ability"]
      local target = filterTable["entindex_target"]
      local Htarget = EntIndexToHScript(target)
      local Hability = EntIndexToHScript(ability)
      local FindAbility = Htarget:FindAbilityByName("antimage_magick_dodge")
      local TargetPos = Htarget:GetAbsOrigin()
      local CasterPos = Hcaster:GetAbsOrigin()
      local difference = TargetPos - CasterPos
      local Lenght2D = difference:Length2D()
      if Htarget:FindAbilityByName("antimage_magick_dodge") ~= nil then
        if Lenght2D < 300 then
          return true
        else
          return false
        end
      end
    end
  else
    return true
  end
end

We have Antimage which have this passive skill.

This passive skill prevent use any targeted spells on Antimage if unit will be close than 300 range.

Our problem is, when other hero casts spell on Antimage and his range > 300, that hero must run towards Antimage and then when he will be near in 300 range cast his spell.

Can you help us to solve this?

Comments

  • Posts: 12

    1). Easy way: Lua class abilities can return any cast range dictated by the script. Make the script that checks if the target has "antimage_magick_dodge" and returns 300 in that case.

    2). Hard way: Give the order to move on position of Anti-mage and then compare the range in every time interval. Once you get in range start casting.

  • Posts: 67

    Problem not solved.

    Second question: how to give an order to cast targeted ability?

    and immediate, and others)

  • Posts: 12

    CastAbilityOnTarget(handle target, handle ability, int playerIndex) ?

    If you already have a lot of complex abilities you better switch to lua class.

  • edited July 2015 Posts: 1,670

    In Filter Orders you better you use ExecuteOrderFromTable.

    ExecuteOrderFromTable({ UnitIndex = entityIndex, OrderType = DOTA_UNIT_ORDER_CAST_TARGET, TargetIndex = entindex_target, AbilityIndex = entindex_ability, Queue = false})
    

    There's no need to change all your skills to ability_lua for doing this.

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

  • Posts: 12

    He means he want the ability to be castable only in 300 range from Anti-mage.

  • Posts: 67

    thanks a lot.

  • Posts: 67

    https://www.youtube.com/watch?v=hY0L1VL_6KA

    here video on youtube, show how out passive works. But there is a big mistake.

    This skill as I said before decreases cast range abilities to 300, if it casted on antimage. So when you give order to axe, to cast. He went and casts it from 300 range. It's ok. But there is a new problem that we occured. It's if we order to cast on antimage spell, and then do something else, it will be bugged. So when we gave another order, when distance between axe and antimage becomes <300 Axe will be ordered to cast his targeted spell.

    Script:

    function GameMode:FilterExecuteOrder(filterTable)
      if filterTable["order_type"] == 6 then
        local units_table = filterTable["units"]
        for n,v in pairs(units_table) do
          local Hcaster = EntIndexToHScript(v)
          local ability = filterTable["entindex_ability"]
          local target = filterTable["entindex_target"]
          local Htarget = EntIndexToHScript(target)
          local Hability = EntIndexToHScript(ability)
          local FindAbility = Htarget:FindAbilityByName("antimage_magick_dodge")
          local TargetPos = Htarget:GetAbsOrigin()
          local CasterPos = Hcaster:GetAbsOrigin()
          local difference = TargetPos - CasterPos
          local Lenght2D = difference:Length2D()
          if Htarget:FindAbilityByName("antimage_magick_dodge") ~= nil then
            if Lenght2D < 300 then
              return true
            else
              ExecuteOrderFromTable({ UnitIndex = Hcaster:GetEntityIndex(), 
                      OrderType = DOTA_UNIT_ORDER_MOVE_TO_TARGET, 
                      TargetIndex = Htarget:GetEntityIndex(), 
                      Position = Htarget:GetAbsOrigin(), 
                      Queue = false
                    })
              Timers:CreateTimer(0.03, function()
                local TargetPos2 = Htarget:GetAbsOrigin()
                local CasterPos2 = Hcaster:GetAbsOrigin()
                local difference2 = TargetPos2 - CasterPos2
                local Lenght2D2 = difference2:Length2D()
                  if Lenght2D2 < 300 then
                      ExecuteOrderFromTable({ UnitIndex = Hcaster:GetEntityIndex(), OrderType = DOTA_UNIT_ORDER_CAST_TARGET, TargetIndex = Htarget:GetEntityIndex(), AbilityIndex = ability, Queue = false})
                      return nil
                  end
                  return 0.03
              end)
              return false
            end
          end
        end
        return true
      else
        return true
      end
    end
    

    What you can advice to do? We want to make this passive)

  • Posts: 12

    Make abilities lua class. Save your self a lot of work.

    Or if you really want to keep this you need to add a way to disengage from your timer if the unit got another order. Like this:

    function GameMode:FilterExecuteOrder(filterTable)
      if filterTable["order_type"] == 6 then
        local units_table = filterTable["units"]
        for n,v in pairs(units_table) do
          local Hcaster = EntIndexToHScript(v)
          local ability = filterTable["entindex_ability"]
          local target = filterTable["entindex_target"]
          local Htarget = EntIndexToHScript(target)
          local Hability = EntIndexToHScript(ability)
          local FindAbility = Htarget:FindAbilityByName("antimage_magick_dodge")
          local TargetPos = Htarget:GetAbsOrigin()
          local CasterPos = Hcaster:GetAbsOrigin()
          local difference = TargetPos - CasterPos
          local Lenght2D = difference:Length2D()
          Htarget.order_flag = nil
          if Htarget:FindAbilityByName("antimage_magick_dodge") ~= nil then
            if Lenght2D < 300 then
              return true
            else
    
              ExecuteOrderFromTable({ UnitIndex = Hcaster:GetEntityIndex(), 
                      OrderType = DOTA_UNIT_ORDER_MOVE_TO_TARGET, 
                      TargetIndex = Htarget:GetEntityIndex(), 
                      Position = Htarget:GetAbsOrigin(), 
                      Queue = false
                    })
              Hcaster.order_flag = true
              Timers:CreateTimer(0.03, function()
                local TargetPos2 = Htarget:GetAbsOrigin()
                local CasterPos2 = Hcaster:GetAbsOrigin()
                local difference2 = TargetPos2 - CasterPos2
                local Lenght2D2 = difference2:Length2D()
                  if Lenght2D2 < 300 then
                      ExecuteOrderFromTable({ UnitIndex = Hcaster:GetEntityIndex(), OrderType = DOTA_UNIT_ORDER_CAST_TARGET, TargetIndex = Htarget:GetEntityIndex(), AbilityIndex = ability, Queue = false})
                      return nil
                  elseif Hcaster.order_flag ~= true then
                       return nil
                  end
                  return 0.03
              end)
              return false
            end
          end
        end
        return true
      else
        return true
      end
    end
    

    Haven't tested it though

  • Posts: 67

    Understood your idea, but it not works.

    Noya help us)

  • Posts: 1,670

    You'll have to be a bit more descriptive than "it not works" :laughing:

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

  • Posts: 3

    Has the same problem too, many thanks if you'll help me :smirk:

  • Posts: 12
    function GameMode:FilterExecuteOrder(filterTable)
      if filterTable["order_type"] == 6 then
        local units_table = filterTable["units"]
        for n,v in pairs(units_table) do
          local Hcaster = EntIndexToHScript(v)
          local ability = filterTable["entindex_ability"]
          local target = filterTable["entindex_target"]
          local Htarget = EntIndexToHScript(target)
          local Hability = EntIndexToHScript(ability)
          local FindAbility = Htarget:FindAbilityByName("antimage_magick_dodge")
          local TargetPos = Htarget:GetAbsOrigin()
          local CasterPos = Hcaster:GetAbsOrigin()
          local difference = TargetPos - CasterPos
          local Lenght2D = difference:Length2D()
          Hcaster.order_flag = nil
          if Htarget:FindAbilityByName("antimage_magick_dodge") ~= nil then
            if Lenght2D < 300 then
              return true
            else
    
              ExecuteOrderFromTable({ UnitIndex = Hcaster:GetEntityIndex(), 
                      OrderType = DOTA_UNIT_ORDER_MOVE_TO_TARGET, 
                      TargetIndex = Htarget:GetEntityIndex(), 
                      Position = Htarget:GetAbsOrigin(), 
                      Queue = false
                    })
              Hcaster.order_flag = true
              Timers:CreateTimer(0.03, function()
                local TargetPos2 = Htarget:GetAbsOrigin()
                local CasterPos2 = Hcaster:GetAbsOrigin()
                local difference2 = TargetPos2 - CasterPos2
                local Lenght2D2 = difference2:Length2D()
                  if Lenght2D2 < 300 then
                      ExecuteOrderFromTable({ UnitIndex = Hcaster:GetEntityIndex(), OrderType = DOTA_UNIT_ORDER_CAST_TARGET, TargetIndex = Htarget:GetEntityIndex(), AbilityIndex = ability, Queue = false})
                      return nil
                  elseif Hcaster.order_flag ~= true then
                       return nil
                  end
                  return 0.03
              end)
              return false
            end
          end
        end
        return true
      else
        return true
      end
    end
    

    Here fixed it. Wrote it last second and was a bit confused in all the variables you have in the script.

    However, you should still consider switching to lua class. You will run in to many more problems that will require even more work arounds. Porting data driven abilities is really easy especially if data driven part only consists of RunScript