• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Trying to understand hashtables

Status
Not open for further replies.
Level 14
Joined
Nov 17, 2010
Messages
1,265
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 40
Joined
Jun 9, 2011
Messages
13,183
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,265
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,265
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,265
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,265
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