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

[General] How to find the primary attribute from triggering unit

Status
Not open for further replies.
Level 6
Joined
Jan 17, 2014
Messages
166
Hi,

Is there a trigger on how to know what the primary attribute of a centain unit is.

Thx in advance
 
You can't directly read the main attribute. But you can save the type into hashtable with HeroType as parent key. (You need to understand hashtable for my example)

There are the correct integers:

JASS:
bj_HEROSTAT_STR    // Strength
bj_HEROSTAT_AGI    // Agility
bj_HEROSTAT_INT    // Intelligence

For example, paladin's (human) main attribute is Strength. Let's go.

Init:

call SaveInteger(hash, 'Hpal', 0, bj_HEROSTAT_STR)

And for check:
JASS:
local integer stat = LoadInteger(hash, GetUnitTypeId(GetTriggerUnit()), 0)

if (stat == bj_HEROSTAT_STR) then
    BJDebugMsg("Main attribute is strength.")
elseif (stat == bj_HEROSTAT_AGI) then
    BJDebugMsg("Main attribute is agility.")
elseif (stat == bj_HEROSTAT_Int) then
    BJDebugMsg("Main attribute is intelligence.")
endif

This seems as a bit work, but I think it's acceptable if you need it. It's doable. :)
 
Level 6
Joined
Jan 17, 2014
Messages
166
Ah ok. The thing is. For my map, i have map custom herospells with gui triggers. For example, an int nuke hero has some spells based on int.
There is an option in my map to create custom hero's. You choose 3skills and an ultimate from the skillpool of not chosen hero's (this is after the picking fase). My solution now is:
Create a variable namd: "player1(/2/3/4)heroprimaryattribute" wich is integer. If a hero is chosen thats agi the variable will be 1, if int then 2 and if str then 3.
And then when a spelltrigger is activated, i use if/then/else to check for variable 1/2/3.
What do you think? Is hashtables better?
 
How do you want to check if it's an str/agi/int hero? You still need some kind of SetUp where you define it for each hero type. (if you want avoid countless If/Then/Else blocks)

With saving the correct attribute into hashtable you will need only 1 line for 1 hero type in the SetUp.

And yes, you could abstract str/agi/int constant integers into 1/2/3. The question is if you need it.
 
Level 6
Joined
Jan 17, 2014
Messages
166
I don't check what its primary attribute is. You can chose for the custom hero out a few specific hero's. So i do a check when the hero is bought. Like:
Event- a unit sells a unit
If/then/else : dwarf/ tauren ->set variable to str hero
If/then/else : arc mage/ far seer -> set to int
If/then/else : blademaster/ demon hunter -> set to agi.
I don't know anything about hashtables. But i think when using hashtables im still going to use if/then/else for the spell set-up.
For example: Unit deal dmg to target equal 4x primary attibute.
How can a hashtable safe the if/thrn/else lines?
Love to heard from ya and thx for replies so far
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
You can also give them an ability based on attribute bonus and call it Strength, Agility, Intelligence. (3 abilities with all 1 level)
If a unit has the ability Strength, it is a Strength unit. etc etc

I prefer the hashtable/array solution but this is a bit easier to make.
 
Level 12
Joined
Nov 3, 2013
Messages
989
I don't know anything about hashtables. But i think when using hashtables im still going to use if/then/else for the spell set-up.

You won't be using any else if like that if you're using hashtable.

With the hashtable you'll first save what stat is the primary stat for each unit type. Then afterwards each time you'd be checking which it is instead it would load the value directly from the unit type instead.

Basically the game won't have to "think" what's the primary attribute, it will "know" instead and make no more fuss about it.
 
Status
Not open for further replies.
Top