unit attachment possibilities (need to be multiinstanceable)

Level 3
Joined
Jun 19, 2010
Messages
49
im in a situation where i need to refer to a unit which i cant refer normally through any event responses. i want to know of ways how i can refer to it on a multiplayer map, so the solution must be multiinstanceable. gamecache isnt liked, because it is quite slow & do the natives "StoreUnit" & "RestoreUnit" even work in multiplayer? hashtables are limited to 256(?), so what can i use instead of them? in the following example i already show a possible solution, but unfortunately i already use the UnitUserData for another system...

JASS:
    scope BuildTower initializer onInit
     
     
            private function GridSimBuild takes nothing returns nothing
                    // HERE I NEED TO REFER TO ORIGINAL BUILDER UNIT "u_builder"
                    // BUT HOW???
     
                    // I COULD USE A STRUCT LIKE:
                    //      private struct Data
                    //              unit u
                    //      endstruct
                    // & IN FUNC "Ability2Unit":
                    //      local Data d = d.create()
                    //      set d.u = u_builder
                    //      call SetUnitUserData(u_dummyBuilder, d)
                    // & IN THIS FUNC ("GridSimBuild"):
                    //      local Data d = Data(GetUnitUserData(GetTriggerUnit()))
                    //      local unit u_YAY = d.u
                    // !!! BUT !!!
                    // I ALREADY USE THE UNITUSERDATA FOR ANOTHER SYSTEM,
                    // SO WHAT ELSE CAN I USE?
            endfunction
     
     
            private function Ability2Unit takes nothing returns nothing
                    local trigger tri
                    local unit u_builder = GetTriggerUnit()
                    local unit u_dummyBuilder
                    local player p = GetOwningPlayer(u_builder)
     
                    set u_dummyBuilder = CreateUnit( p, 'hpea', 0, 0, 0 )
     
                    set tri = CreateTrigger()
                    call TriggerRegisterUnitEvent( tri, u_dummyBuilder, EVENT_UNIT_ISSUED_POINT_ORDER )
                    call TriggerAddAction( tri, function GridSimBuild )
     
                    set tri = null
                    set p = null
                    set u_builder = null
                    set u_dummyBuilder = null
            endfunction
     
     
            private function onInit takes nothing returns nothing
                    local trigger t = CreateTrigger()
                    local integer i_player
                   
                    set i_player = 0
                    loop
                            exitwhen i_player > 11
                            call TriggerRegisterPlayerUnitEvent(t, Player(i_player), EVENT_PLAYER_UNIT_SPELL_CHANNEL, null)
                            set i_player = i_player+1
                    endloop
                   
                    call TriggerAddAction(t, function Ability2Unit)
                   
                    set t = null
            endfunction
           
    endscope

here's also a never expiring link to pastebin where i originally wrote the code example.
 
Level 29
Joined
Oct 24, 2012
Messages
6,545
What are you trying to accomplish with this code ?
Also hashtables are limited to 256 hashtables but you can use bribes table library to make use of one hashtable for many many systems.

You should never use the unit user data for a system. Use a unit indexer. Then you can retrieve and never change the unit user data of a unit and do stuff with that.

You should also not use TriggerAddAction. Use TriggerAddCondition and run everything from there.
 
Level 3
Joined
Jun 19, 2010
Messages
49
@ deathismyfriend
thanks for that quick answer!
repped because i never had that idea:
You should never use the unit user data for a system. Use a unit indexer. Then you can retrieve and never change the unit user data of a unit and do stuff with that.
regarding "table": at the moment im using table 3.0 (and the moment im searching for the link i see that table 3.1 is out & that it is the table version from Vexorian not from bribe... have to compare the differences...).
& thx for pointing to "TriggerAddCondition", i will use it when everything else works...

edit:
just a question popping up:
if i never touch the unit user data of units, are they always unique?
 
Level 29
Joined
Oct 24, 2012
Messages
6,545
If you use a unit indexer (I use Bribe's unit indexer) then the user data will always be unique. Here is the link to Unit indexer. http://www.hiveworkshop.com/forums/spells-569/gui-unit-indexer-1-2-0-2-a-197329/
It is in GUI but it is coded as if it was in JASS. It will keep the custom values of the units unique. (Never change the custom values of the units)

Here is the link to bribes table. You can see the difference. http://www.hiveworkshop.com/forums/jass-resources-412/snippet-new-table-188084/
 
Level 29
Joined
Mar 10, 2009
Messages
5,016
you dont need hastables nor UnitIndexer for that, what is the 'POINT' order you talking about?...to 'know' the order you can use the native 'GetUnitCurrentOrder', use a timer if needed...

EDIT:
Ok if you want to know the original unit 'HERE I NEED TO REFER TO ORIGINAL BUILDER UNIT' use hashtables...
 
Top