• 🏆 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!

Best way to store stats for large amounts of units

Status
Not open for further replies.
Level 4
Joined
May 2, 2009
Messages
69
Hello Hive,

I'm a novice mapmaker who is now trying to study up on things and learn to use the Map Editor for what it's really worth.

I've taken a few cracks at trying to use a triggered combat system, (abilities that deal damage based on stats, using stats for attacks and defense), but there's one single problem that I keep facing, and that is how to store stats for a large amount of units. A large amount being somewhere around 80+.

It was easy when I planned on only using stats for the players' heroes, I just used array variables and got the player number to retrieve the stored data. But I KNOW there is a more efficient way than making a variable with an array size of 80+.

I want the triggers to look something like:
"Casting Unit deals damage to Target Unit equal to Casting Unit's Strength * Target Unit's Armor Reduction Value"

I've heard a little bit of information about hash tables. Is that the sort of thing I'm looking for, to store and save information based on the unit type?
 
Level 4
Joined
May 2, 2009
Messages
69
I suppose you have a point with that, but I guess what my REAL problem is lies with the fact that I don't know how to get the data based on the unit type. I can set Armor/Str/Int values to every unit, one by one, but how do I retrieve those stats in a trigger? For example, if the Armor value of a Ghoul is set in the variable "Armor[45]", and "Armor[45] = .31", how do I plug that into the trigger like the one in my first post?

Like I said, I'm quite a newbie here, and the only option I can see is very impractical. And that is to have 80+ triggers saying
"If Unit Type (target of ability being cast) = Ghoul --> Run Trigger (Hero attack Ghoul)"
For each unit type

And vice-versa for when it is a unit attacking the player. And I would have to do this for every attack and spell.

Is there a way to just preset the stats when the game starts and easily retrieve them mid-trigger?
 
Level 37
Joined
Mar 6, 2006
Messages
9,240
Hashtable is perfect for unit type related data.

This will save value "5" for the unit type with key 0.
call SaveInteger(hastable, unitTypeId, 0, 5)

This will load the value stored for the unit type at key 0.
Set armor = LoadInteger(hastable, GetUnitTypeId(unit), 0)

Look for a hashtable tutorial.
 
Level 4
Joined
May 2, 2009
Messages
69
Okay, perfect. I think I saw a tutorial on hashtables somewhere, I'll dig it up and figure it out. Thanks for the help, guys.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,199
Global variables have no defined size. For integer and real you can get away with setting the GUI size field to 1 as long as you initialize the indices you want to use somewhere else (otherwise they will just be 0). It is dangerous to use many globals with large sizes as the initialization routine might hit the op limit and cause the initialization thread to crash so trigger events are not set up.
 
Status
Not open for further replies.
Top