1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. The Lich King demands your service! We've reached the 19th edition of the Icon Contest. Come along and make some chilling servants for the one true king.
    Dismiss Notice
  4. The 4th SFX Contest has started. Be sure to participate and have a fun factor in it.
    Dismiss Notice
  5. The poll for the 21st Terraining Contest is LIVE. Be sure to check out the entries and vote for one.
    Dismiss Notice
  6. The results are out! Check them out.
    Dismiss Notice
  7. Don’t forget to sign up for the Hive Cup. There’s a 555 EUR prize pool. Sign up now!
    Dismiss Notice
  8. The Hive Workshop Cup contest results have been announced! See the maps that'll be featured in the Hive Workshop Cup tournament!
    Dismiss Notice
  9. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

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

Discussion in 'World Editor Help Zone' started by Paulus, Jan 3, 2015.

  1. Paulus

    Paulus

    Joined:
    Jan 17, 2014
    Messages:
    155
    Resources:
    0
    Resources:
    0
    Hi,

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

    Thx in advance
     
  2. IcemanBo

    IcemanBo

    Joined:
    Sep 6, 2013
    Messages:
    6,182
    Resources:
    22
    Maps:
    3
    Spells:
    11
    Template:
    1
    Tutorials:
    4
    JASS:
    3
    Resources:
    22
    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:

    Code (vJASS):

    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:
    Code (vJASS):

    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. :)
     
  3. ukn0wnD3str0y3r

    ukn0wnD3str0y3r

    Joined:
    Feb 15, 2013
    Messages:
    372
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    Do this work if i check the str is higher/agi is higher exclude bonuses?
     
  4. Maker

    Maker

    Joined:
    Mar 6, 2006
    Messages:
    9,190
    Resources:
    17
    Maps:
    2
    Spells:
    14
    Tutorials:
    1
    Resources:
    17
    Most of the time checking the highest attribute would be a working solution but it is in no way guaranteed. I would not rely on that.
     
  5. Paulus

    Paulus

    Joined:
    Jan 17, 2014
    Messages:
    155
    Resources:
    0
    Resources:
    0
    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?
     
  6. IcemanBo

    IcemanBo

    Joined:
    Sep 6, 2013
    Messages:
    6,182
    Resources:
    22
    Maps:
    3
    Spells:
    11
    Template:
    1
    Tutorials:
    4
    JASS:
    3
    Resources:
    22
    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.
     
  7. Paulus

    Paulus

    Joined:
    Jan 17, 2014
    Messages:
    155
    Resources:
    0
    Resources:
    0
    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
     
  8. IcemanBo

    IcemanBo

    Joined:
    Sep 6, 2013
    Messages:
    6,182
    Resources:
    22
    Maps:
    3
    Spells:
    11
    Template:
    1
    Tutorials:
    4
    JASS:
    3
    Resources:
    22
    As I showed and explained you onyl need 1 line per HeroType in SetUp if use hashtable.

    But yes making many If/Then/Else checks would also work, but it's not an elegant way.

    How ever you should or learn about hashtables or just try your method, and then see how it goes. :)
     
  9. Wietlol

    Wietlol

    Joined:
    Aug 1, 2013
    Messages:
    4,653
    Resources:
    3
    Spells:
    3
    Resources:
    3
    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.
     
  10. Death Adder

    Death Adder

    Joined:
    Nov 3, 2013
    Messages:
    884
    Resources:
    0
    Resources:
    0
    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.