How to get a LUA table of all units in game (DotA)?

This is a discussion on How to get a LUA table of all units in game (DotA)? within the Warcraft 3 Lua Scripts board part of the Warcraft 3 forum category; Hello, I saw that in the old version of the Lua Engine (1.0.4), there was this function: LuaTable GetAllUnits() // ...

Results 1 to 6 of 6
  1. #1
    seadoo14 is offline Newbie
    Array
    Join Date
    Apr 2009
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Rep Power
    0
    Reputation
    0

    How to get a LUA table of all units in game (DotA)?

    Hello,

    I saw that in the old version of the Lua Engine (1.0.4), there was this function: LuaTable GetAllUnits() // Returns a table of all units in game.

    In the updated version of Lua Engine, this function is no longer in the Game class. I'm wondering how exactly the function works, and how I could retrieve a table of all game units with Lua Engine 2.1.2.

    Thanks!

  2. #2
    Sosha is offline Banned User

    Array
    Join Date
    Oct 2011
    Location
    Iran
    Posts
    525
    Mentioned
    39 Post(s)
    Tagged
    0 Thread(s)
    Rep Power
    0
    Reputation
    1044
    You should hook "CreateUnit" native and store all the unit handles in a table.

    Something like this:

    Code:
    function CreateUnit_Pre(hUnit)    
        return nil -- or return hUnit (same behavior)
    end
    
    function Initialize(plugin)
        plugin:RegisterNativeHook("CreateUnit", "", "CreateUnit_Post")
    end

  3. #3
    seadoo14 is offline Newbie
    Array
    Join Date
    Apr 2009
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Rep Power
    0
    Reputation
    0
    The problem with that is that it doesn't work for summoned units (Remote mines). I'm trying to make a techies bot, and I saw in the source code of Absol's C++ bot that he uses the same "GetAllUnits()" function that was in the source code of Lua Engine 1.0.4, which is something like this:

    UINT GetMaxUnitForMap( )
    {
    UINT tmp = 0;
    DWORD tmpaddr = *( DWORD* ) ( GameDll + 0xAAE2FC );
    tmp += *( UINT* ) ( tmpaddr + 0x428 );
    tmp += 0x100000;
    if ( tmp == 0x100000 )
    return 0x3FFFFF;
    return tmp;
    }

    That list includes remote mines in it, and every other unit.
    So my question is how can I get that exact same list from Lua Engine 2.1.2?

    Currently my bot is hooking GetSummonedUnit() for detection of the creation of a remote mine, and GetIssuedOrderId() for the detection of a mine being detonated. This sort of works, but often causes fatal errors, and I much prefer the idea of just scanning every unit on the map rather than rely on native hooks.

    If you could help I would be grateful!
    Last edited by seadoo14; 09-13-2015 at 05:20 AM.

  4. #4
    Sosha is offline Banned User

    Array
    Join Date
    Oct 2011
    Location
    Iran
    Posts
    525
    Mentioned
    39 Post(s)
    Tagged
    0 Thread(s)
    Rep Power
    0
    Reputation
    1044
    The '"GetAllUnits()" can't be used in this version of lua engine because in this version we use unit jass handles while the "GetAllUnits()" return the unit pointers which is useless to us.

    I think there's a mistake in your code that causes fatal error.
    I may be able to fix your code if I have a close look at it.

  5. #5
    seadoo14 is offline Newbie
    Array
    Join Date
    Apr 2009
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Rep Power
    0
    Reputation
    0
    Hello, thanks so much for your replies so far. I have posted my Lua script here: https://repl.it/BHae/14 or here: [Lua] Techies Fatal Errors - Pastebin.com

    Whichever you prefer, although the code lines up better on the repl.it one.

    Right now I only have it coded for level 1 Remote Mines, although I will add the others and aghanim's later.

    Basically the collision detection for the mines works...it will say when a hero can be killed by the amount of mines placed, but sometimes there are weird Lua errors, and eventually game crashes. If you uncomment my Detonate() function, the game will crash right after mines explode.

    I hope it's something simple I have overlooked, because I have really tried every trick I could think of to get it working, and I want to eventually add math for auto-forcestaff and other things, so if you could find the problem that would be so great!

    Thank you.

    [EDIT]
    Now I'm thinking it's something to do with a threading issue. Because my native hooks are what gives me my unit list to run the math on, I think the hooks are firing and changing the unit list during my GameTick function's calculations, which causes errors.

    The best solution would be a function that I can call once per gametick that lists all units on the map, then loop through the list and pick out what I need. I thought about using GroupEnumUnitsInRect, with the rect returned from GetWorldBounds(), but apparently using CreateGroup() to do so causes a desync. I tried to hook DestroyGroup() to copy the group that was going to be destroyed and use it, but that didn't work either, my copied group was just null.
    Last edited by seadoo14; 09-13-2015 at 10:55 PM.

  6. #6
    WarnerTar is offline Newbie
    Array
    Join Date
    Dec 2018
    Location
    Panama
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Rep Power
    0
    Reputation
    0

    How to get a LUA table of all units in game DotA

    I want to change the settings programmatically:strNoteAddress,strNoteZip,strNote Phone,strNoteFax,strNoteEmail, strNoteMemohow to do it with language Lua?

Similar Threads

  1. Rangers - Regular's table
    By Jolinar in forum Guild Wars 2
    Replies: 2
    Last Post: 08-09-2014, 05:01 PM
  2. [Help] How to enum all units(HUNIT) in game? C++
    By i.raichu in forum Warcraft 3 Hacks, bots and tools
    Replies: 0
    Last Post: 02-27-2013, 03:11 PM
  3. 1.3.6 unit table?
    By beki in forum Starcraft 2 Coding
    Replies: 15
    Last Post: 10-13-2011, 09:51 PM
  4. Units frozed, not moving? can't build units at times?
    By adventweapon in forum Starcraft 2 Hacks, bots and tools
    Replies: 6
    Last Post: 09-22-2011, 07:44 PM
  5. Crash in Playercooldownitems Table! (Help)
    By DreZen in forum WoW Private Servers
    Replies: 3
    Last Post: 01-08-2008, 12:21 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •