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

How to get a units Buff level

Status
Not open for further replies.
Level 9
Joined
Aug 2, 2008
Messages
219
I have some problems with buffs, i need to get the level of of buff but there is no such native or function which returns the level of a buff. I have tried to use GetUnitAbilityLevel but it only returns 1 if a unit has the specific buff, even if the level is 2 or 3 and returns 0 if the unit does not have the buff. If someone knows a solution then please tell.

Well and i have another question which does not fit to headline but maybe someone can help me there too. People always say it´s a bad idea to use UnitUserData and i understand why it´s bad to use it. But does this apply to Dummy units ? I mean those kind of dummy units which just are used as enhanced special effects.

There well be rep for anyone who tries to be helpful !
 
Level 9
Joined
Aug 2, 2008
Messages
219
You mean creating a new rawcode for every level ? That would be a big hassle and it´s not very userfriendly. But thank you for helping so far and no problem because of the waiting time. I guess i have to write a lame function which solves the problem... I i just thought there is a native or a trick or what ever which easily detects a units buff level.
 
You mean creating a new rawcode for every level ? That would be a big hassle and it´s not very userfriendly. But thank you for helping so far and no problem because of the waiting time. I guess i have to write a lame function which solves the problem... I i just thought there is a native or a trick or what ever which easily detects a units buff level.

just create a new buff for every level of your spell for example if you have 3 levels then make 3 buffs maybe you can them Buff -Level 1 and so on

then at the object editor you can set a buff for each level of the spell so just change the Effect->Buff of the spell for every level into its corresponding buff.....
 
Level 12
Joined
Aug 22, 2008
Messages
911
Buff levels are given by default to levels of spells, for example if my paladin has a level 2 devotion aura my footman near him will be granted a level 2 devotion aura buff.
You could do, as the people before me recommend, a buff for each level, and it would be more recommended because you want to get the buff level.
 
Level 9
Joined
Aug 2, 2008
Messages
219
I don´t really like the idea of creating a new buff for every level of the spell, because it´s not userfriendly IMO. Or just think about a who user wants my ability to have about 100 levels and then create about 100 buffs ? Thats not very effiecient.
I was a bit to impatient to wait for a suitable answer solved the problem by myself.
Nevertheless i have to say thank you to all who tried to be of help !

~thread can be closed
 
Level 9
Joined
Aug 2, 2008
Messages
219
You could try to get the level of the ability that the buff is coming from.
This is what the function does i wrote =).
[updated]
JASS:
library GetAuraBuffLevel initializer Init
//****==============================================================****//
//***                                                                ***//
//**                             How to use                           **//
//*                                                                    *//

//    All you need to do to get a the level of an aura buff is calling
//            my function and filling the right parameters.
//     Lets assume we have a Dreadlord ingame and we want to get the 
//             buff level of Vampire Aure from a near ghoul.
//Parameter List:
//¯¯¯¯¯¯¯¯¯¯¯¯¯¯
// -abil    : The rawcode of the main ability which provides the buff. In
//            our case this would be the rawcode of Vampire aura.
//
// -x/y     : The x/y coordinates of the ghoul.
//   
// -r       : The range of the aura. If a unit has a buff provided by an
//            aura it is indeed in range of the aura.
//
// -p       : The player who is the owner of the unit which has the main
//            ability. In our case that´s the Dreadlords owner.
//
// -pos/neg : You can set these values to true or false, the returned
//            value depends on the combination.
//            true,false  = Will return the highest ability level of an
//                          allied unit.
//            false,true  = Will return the highest ability level of an
//                          enemy unit.
//            true,true   = Will return the hightst ability level of an
//                          allied OR enemy unit.
//            false,false = Returns zero, because an aura which does
//                          neither affect allies nor enemys does not
//                          really exists and therefore it can´t be
//                          detected.

//Note:
//¯¯¯¯
// If there is no unit in range of the x/y coordinates who has the main
// ability the function will return zero. If there is more than one unit
// near the coordinates with the matching conditions the function will
// return the level of the highest ability.

//*                                                                    *//
//**                  End of manual and begin of script               **//
//***                                                                ***//
//****==============================================================****//

    //Do not edit here
    globals
        private integer TempLevel
        private integer TempAbil
        private boolean Negative
        private boolean Positive
        private player  Owner
        private filterfunc BuffSearchFilter
        private constant group SearchGroup = CreateGroup()
    endglobals
    
    function GetAuraBuffLevel takes integer abil, real x, real y, real r, player p, boolean pos, boolean neg returns integer
    
        if neg or pos then
            
            set TempLevel = 0
            set TempAbil = abil
            set Negative = neg
            set Positive = pos
            set Owner = p
            call GroupEnumUnitsInRange(SearchGroup,x,y,r,BuffSearchFilter)
            
            return TempLevel
            
        endif
        
        return 0
        
    endfunction
    
    private function BuffSearch takes nothing returns boolean
    
        local unit u = GetFilterUnit()
        local integer lv = GetUnitAbilityLevel(u,TempAbil)
        
        if lv != 0 then
            
            if IsUnitEnemy(u,Owner) == Negative and lv > TempLevel then
                set TempLevel = lv
            endif
            
            if IsUnitEnemy(u,Owner) != Positive and lv > TempLevel then
                set TempLevel = lv
            endif
            
        endif
        
        set u = null
        return false
        
    endfunction

    private function Init takes nothing returns nothing
        set BuffSearchFilter = Filter( function BuffSearch)
    endfunction

endlibrary
Id did only a few test with this is i so i can´t guarantee this is completely bugless, but if someone has found a bug or suggestions for improvement you´re welcome to tell (except if you me to make this depending on other libraries).
 
Last edited:
Level 9
Joined
Aug 2, 2008
Messages
219
Thats why i added a player as parameter.
If you want to get the level of an enemy aura then put the enemy player and false in the function. For an allied aura put the allied player and true as parameters. (Sorry bad english here)
Well but i guess i have to use 2 booleans anyway, because some auras may affect both, enemies and allies.
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
For auras that is a perfectly fine way to do it, because the level of an aura and its buff are always going to be the exact same. In another situation though, say you Shadow Strike a unit, getting the level of the ability Shadow Strike will not always return the level of the buff, considering the ability could have been leveled since the buff was placed. Just something to think about.
 
Level 6
Joined
Mar 22, 2009
Messages
276
the idea of using 3 kinds of buff is correct.
just use the same name, description, icon, etc.
just put Editor Suffix to it like Buff (Level 1), Buff (level2), Buff(level3).
It'll be userfriendly because they'll just see one buff.
and Suffix (Level) can only be seen on World Editor.
 
Level 9
Joined
Aug 2, 2008
Messages
219
In another situation though, say you Shadow Strike a unit, getting the level of the ability Shadow Strike will not always return the level of the buff, considering the ability could have been leveled since the buff was placed. Just something to think about.

Why don´t you get the level of Shadow strike (or any other ability) when the ability is being cast and save it to a variable ?

the idea of using 3 kinds of buff is correct.
just use the same name, description, icon, etc.
just put Editor Suffix to it like Buff (Level 1), Buff (level2), Buff(level3).
It'll be userfriendly because they'll just see one buff.
and Suffix (Level) can only be seen on World Editor.

Ofc you could do it that why but what is if the ability should have about 100 levels ? I know it´s kinda rare this is happening but if someone really makes an ability with so many levels there would be a big hassle.
 
Level 6
Joined
Mar 22, 2009
Messages
276
Ofc you could do it that why but what is if the ability should have about 100 levels ? I know it´s kinda rare this is happening but if someone really makes an ability with so many levels there would be a big hassle.

i see..
may i ask if that skill will be used by many units? or just one?
 
Status
Not open for further replies.
Top