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

Percent Damage based on primary attribute

Status
Not open for further replies.
Level 9
Joined
Apr 23, 2011
Messages
527
i believe this is how you do it

  • Actions
    • Set att = (Strength of caster (Exclude bonuses))
    • Unit - Cause caster to damage target, dealing (100 + (Real(att) x 0.05)) damage of attack type Spells and damage type Normal
this should deal 100 + 5% of strength damage to the target

if multiple heroes with different primary attributes can cast the same spell then probably use an ITE check, don't know how to check the primary attribute though
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
Also, next to that, the value may be inaccurate, there may be many more things that you want to change to the damage, there may be more things that you want to have multiple levels for and most of all, you are setting the level of an ability... Lets imagine hero abilities... or rather, just dont.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
In GUI...
  • Unit - Cause (Triggering unit) to damage (Triggering unit), dealing ((Real((Strength of (Triggering unit) (Include bonuses)))) x 0.10) damage of attack type Spells and damage type Normal
There is no way to detect primary attribute, you will need to hardcode that. Replace the "Triggering unit" with appropriate unit value. Obviously choose appropriate attack and damage types. Hero attributes is an integer function so you will need a conversion from integer to real to do the arithmetic statement.

I assume you know how to work out percentages already from highschool so I will not explain the maths behind it.
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
There are a few workarounds to get the primary attribute... in the first place you could just make a script of it that loads the primary attribute from the object editor and generates the code when you save the map, but you could also give all heroes an ability.
DummyAbilityStrength
DummyAbilityIntelligence
DummyAbilityAgility
With this, you can check what ability the hero has instead of checking for each unit type.
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
The fastest approach would be having an integer array which uses the custom value of a unit as index for each individual unit (Unit Indexer) which is filled when a unit is created loading the data from a hashtable made by the Object Data Extractor.

It is faster than hashtables (arrays over hashtables) it is easier to use (except for GUI) and you can implement it for every single map without having to change anything to it's JASS code (which fills the arrays and loads the data) when you use it in different maps (ODE).
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
Catalog natives?
In SC2 you can look up all data with triggers using the Catalog natives. One of the many convenient features SC2 has.

myArray[GetUnitUserData(u)] vs LoadInteger(myHashtable, GetHandleId(u), 0)
I always thought the first one was faster.
Wrong comparison...

myArray[GetUnitUserData(u)] vs LoadInteger(myHashtable, GetUnitTypeId(u), CONST_KEY)

It might be faster, but the speed difference is minimal and the data efficiency is more efficient with the hashtable since it is per unit type as opposed to per unit.
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
Yea true, however that native is accessible kind of.
However it is not exactly a native and you have to install a small thingy to make it work.

The problem is that the value is written as string in the editor instead of an integer so you will have to either use an array or use three checks again to check what the string is.

function GetUnitTypePrimaryAttribute takes integer unitTypeId returns string

But in any case, there are now enough examples of how to find the primary attribute :D
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
In the Object Editor, you select primary attribute by a checkbox, the view strings of that checkbox are Agility, Intelligence and Strength.
The raw data of that checkbox are AGI, INT and STR respectively.
That means that the data stored in the hashtable from the ODE stores a string as well.
So you would need a special function to get the right integer out of it:

JASS:
function GetUnitTypePrimaryAttibuteEx takes integer unitTypeId returns integer
    local string data = GetUnitTypePrimaryAttribute(unitTypeId)
    if data == "AGI" then
        return bj_HEROSTAT_AGI
    elseif data == "INT" then
        return bj_HEROSTAT_INT
    elseif data == "STR" then
        return bj_HEROSTAT_STR
    endif
    return 3
endfunction

At least this would be your function if you use ODE.
If you want to create a hashtable by yourself and add the data to it manually (which takes quite some time and is extremely boring), you can indeed save the attribute as an integer instead.
 
Status
Not open for further replies.
Top