• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Cheating the SetUnitUserData()

Status
Not open for further replies.
Level 10
Joined
Aug 19, 2008
Messages
491
Hey dudes, a quick question before I leave:
Is there any way I could 'go around' the Set Unit's Custom Value function?
I mean, by using variables and such to get the same result.

Why?
Well, I've solved a problem in my spell using this method, however I wanna make it 100% multi-instancable, and if a map uses this function for other features, it won't compile correctly.

Sorry for this quick question, but I'm in a hurry.
+Rep to the first dude who solves this!

Solved!
By a dude named grim001 in wc3c.net.

You can easily replace the Set/GetUnitUserData with an integer array, as long as the Index of the array is the 'id-number' of the unit. So a line like Set Footman's Custom Value to (Custom Value of (Footman)) + 1 will be Set Integer_Array[UnitId] = Set Integer_Array[UnitId] + 1
The "UnitId" can be obtained in this function: (only operational in vJass)

JASS:
//========================================
function H2I takes handle h returns integer
    return h
    return 0
endfunction

function GetUnitIndex takes unit u returns integer
    return H2I(u) - 0x100000
    //Note that the returned value is extremely large,
    //so you have to remove some of the numbers with "- 0x100000"
endfunction
//========================================
function Actions takes nothing returns nothing
    set UnitId = GetUnitIndex( f ) //Gets the unit's id
    set Integer_Array[UnitId] = Set Integer_Array[UnitId] + 1 //"Set unit's custom value to +1"
endfunction
//========================================
 
Last edited:
Level 12
Joined
Mar 23, 2008
Messages
942
Hey dudes, a quick question before I leave:
Is there any way I could 'go around' the Set Unit's Custom Value function?
I mean, by using variables and such to get the same result.

Why?
Well, I've solved a problem in my spell using this method, however I wanna make it 100% multi-instancable, and if a map uses this function for other features, it won't compile correctly.

Sorry for this quick question, but I'm in a hurry.
+Rep to the first dude who solves this!
Struct of Array
Array[x] = whatever
Unit custom value = x

I know there is something like that for timer (timerutil) and bufs (abuf), don't remember the one for units.
 
Level 10
Joined
Aug 19, 2008
Messages
491
Bump!

Is there no one else who has an idea?
I was thinking of something like "set Integer_Array["GetUnitIDNumber()"] = Integer_Array["GetUnitIDNumber"] + 1",
but I havn't found such a function :bored:

Note
"GetUnitIDNumber()" does not exists, what I meant was that I want a way to identify a unit on the map.
There must be some way because, if you think about it, when targeting multiple units of the same type they're always selected in the same order.
And they're always selected through the "ID Number" (hfoo_0001) with the smallest first.

Help me!
 
Level 12
Joined
Mar 23, 2008
Messages
942
Bump!

Is there no one else who has an idea?
I was thinking of something like "set Integer_Array["GetUnitIDNumber()"] = Integer_Array["GetUnitIDNumber"] + 1",
but I havn't found such a function :bored:

Note
"GetUnitIDNumber()" does not exists, what I meant was that I want a way to identify a unit on the map.
There must be some way because, if you think about it, when targeting multiple units of the same type they're always selected in the same order.
And they're always selected through the "ID Number" (hfoo_0001) with the smallest first.

Help me!

You are probably thinking of H2I.
Takes a handle (unit in your case) returns an integer.

Search for it.
 
I did it here. Its pretty simple, as long as you understand the jass loops

Ok, this answer actually makes sense:
  • Tower Build
    • Events
      • Unit - A unit Finishes construction
    • Conditions
      • (Unit-type of (Constructed structure)) Equal to Scout Tower
    • Actions
      • Set TempIntA = 0
      • Custom script: loop
      • Custom script: exitwhen udg_Tower_Used[udg_TempIntA] == 0
      • Set TempIntA = (TempIntA + 1)
      • Custom script: endloop
      • Set Tower_Unit[TempIntA] = (Constructed structure)
      • Special Effect - Create a special effect attached to the overhead of Tower_Unit[TempIntA] using Abilities\Spells\Other\TalkToMe\TalkToMe.mdl
      • Set Tower_SFX[TempIntA] = (Last created special effect)
      • Set Tower_Used[TempIntA] = 1
  • Tower Die
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Unit-type of (Dying unit)) Equal to Scout Tower
    • Actions
      • Set TempUnitA = (Dying unit)
      • Set TempIntA = 0
      • Custom script: loop
      • Custom script: exitwhen udg_TempUnitA == udg_Tower_Unit[udg_TempIntA]
      • Set TempIntA = (TempIntA + 1)
      • Custom script: endloop
      • Custom script: set udg_Tower_Unit[udg_TempIntA] = null
      • Special Effect - Destroy Tower_SFX[TempIntA]
      • Custom script: set udg_Tower_SFX[udg_TempIntA] = null
      • Custom script: set udg_TempUnitA = null
 
Level 10
Joined
Aug 19, 2008
Messages
491
In your case its the unit.
Just search the function lol.
I did, found nothing related to it.

I did it here. Its pretty simple, as long as you understand the jass loops
Wow now I'm really confused :bored:
Could you declare the variables? I'm not sure what udg_Tower_Used[Index] is for.
Mixing GUI with Jass just made things worse for me :xxd:
Don't worry about my Jass 1337 zk!llz, this problem was generated in a vJass spell I'm doing right now.
It looks really simple, but I'm not sure what yours does.

Your help is stil apreciated :thumbs_up:
Don't forget that if you solve my problem you'll get +Rep, and I'm a man of my word.
 
Ok, I'll try and explain this.
The important part is:
  • Set TempIntA = 0
  • Custom script: loop
  • Custom script: exitwhen udg_Tower_Used[udg_TempIntA] == 0
  • Set TempIntA = (TempIntA + 1)
  • Custom script: endloop
TempIntA isn't all that important, it is just an integer variable that takes the place of a local, and is just set to one higher each time the loop runs. Now, the loop is set to exit when the integer value (it could just as easily be boolean) is 0, which signifies that that slot in the unit variable is open. After the unit variable Tower_Unit is set to the constructed structure, Tower_Used is set to 1, so that that slot is now filled, and another unit will not be set to that same Tower_Unit
 
Level 10
Joined
Aug 19, 2008
Messages
491
Ok, I'll try and explain this.
The important part is:
  • Set TempIntA = 0
  • Custom script: loop
  • Custom script: exitwhen udg_Tower_Used[udg_TempIntA] == 0
  • Set TempIntA = (TempIntA + 1)
  • Custom script: endloop
TempIntA isn't all that important, it is just an integer variable that takes the place of a local, and is just set to one higher each time the loop runs. Now, the loop is set to exit when the integer value (it could just as easily be boolean) is 0, which signifies that that slot in the unit variable is open. After the unit variable Tower_Unit is set to the constructed structure, Tower_Used is set to 1, so that that slot is now filled, and another unit will not be set to that same Tower_Unit

I see, thank you. Makes more sence now :wink:
Unfortunatly, I was looking for a solution in vJass :grin: and it should set those values you decribed to around 200 units simulatieously. I found the solution in wc3c.net.
I will post the solution here aswell, and then a moderator can tag this as solved.

Don't worry, I'll givey you rep for your help :thumbs_up:
You deserve something for your work

SOLVED!
 
Status
Not open for further replies.
Top