• 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.
  • Create a faction for Warcraft 3 and enter Hive's 19th Techtree Contest: Co-Op Commanders! Click here to enter!
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 21st Texturing Contest: Upgrade is now concluded, time to vote for your favourite set of icons! Click here to vote!

Trying to understand hashtables

Status
Not open for further replies.
Level 14
Joined
Nov 17, 2010
Messages
1,266
I'm trying to figure out a better way to use armor. I basically want it to act as a number that can be referenced so I can reduce the damage taken by that number.

For example:

Damage = 50
Armor = 10
Damage Taken = (50-10) = 40

This can easily be done with a DDS, but what I cannot do is detect the armor of a unit. So basically I want to assign an armor value to each unit-type so I can just reference that. (For my heroes I can adjust their armor by detecting when they pick up items, level up, etc.)

I was thinking a hashtable would be the best way to save armor values for individual unit-types, but I have no idea where to start. I have a very basic idea of how hashtables work, but I need a small example of where to start.

If someone could help me out I would be very grateful!
 

Chaosy

Tutorial Reviewer
Level 41
Joined
Jun 9, 2011
Messages
13,248
Simply put an hashtable is a 2D array.
If you don't know what an 2D array is, let's start with 1D arrays.

Here's a 1D array:
set variable[number] = something

Which means this is a 2D array:
set variable[oneNumber][anotherNumber] = something

It can also be explained as an array of arrays.

Anyway, for your puposes:
save armor [Handle id of your unit] [any number you want, just remember it] in your hashtable

the handle id of a unit is a unique number for that unit.
 
Level 14
Joined
Nov 17, 2010
Messages
1,266
How do I know the Handle ID of a unit. And can I set a Handle ID for a unit-type? (so all units of type footmen have the same handle id for example)

When you say save armor [Handle id of your unit] does this mean I want to use the Hashtable - Save Integer function?
 
Last edited:
Level 14
Joined
Nov 17, 2010
Messages
1,266
But how do I assign an integer (or real) to each unit type and then call on it later. I basically want an on damage trigger that will set damage to the amount - armor = new amount.

For instance I want brown wolves to have 5 armor and black wolves to have 8 armor. How can I call the armor value depending on the unit type taking damage?
 
Level 14
Joined
Nov 17, 2010
Messages
1,266
So is armor the integer value I want to put in for each unit?

Would this be right

At Map Init do this for each unit type
  • Set ArmorUnit = |cffeecc00Black Wolf|r (Level 2) (Respawn) 0374 <gen>
  • Custom script: set udg_Armor_Int = GetUnitTypeId(udg_ArmorUnit)
  • Hashtable - Save 8.00 as Armor_Int of 0 in ArmorHash
And then on damage
  • Custom script: set udg_Armor_Int = GetUnitTypeId(udg_ArmorUnit)
  • Set DeadlySlash_Damage = (amount - (Load Armor_Int of 0 from ArmorHash))
 
Level 14
Joined
Nov 17, 2010
Messages
1,266
It's working just like I want. Thanks for the help.

Now I just have to adjust some old triggers and add a bunch of new ones to capture when a hero gains more armor through items, levels, etc.
 
Status
Not open for further replies.
Top