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

[Solved] Counting buffs

Status
Not open for further replies.
Level 4
Joined
Aug 31, 2011
Messages
88
Hi guys,

Can I somehow count how many buffs has a unit?

I know that I can check if unit has a specific buff, but can I somehow count them?

Can I count them by checking which buff it has and then setting the variable count to 1 or is there some easier workaround?
 
Last edited:

Jampion

Code Reviewer
Level 15
Joined
Mar 25, 2016
Messages
1,327
  • Set i = (Number of All buffs considered Magic or physical on (Triggering unit) (Include expiration timers, Include auras))
You can find it under Integer, Unit - Count Buffs by type ...
 
Level 4
Joined
Aug 31, 2011
Messages
88
How about counting specific buffs?

For example count Cripple and Curse, but not Slow, as all of them are negative buffs.
 

Jampion

Code Reviewer
Level 15
Joined
Mar 25, 2016
Messages
1,327
The game cannot distinguish Cripple and Curse from Slow, because as you said, they are all negative.
Because of that, you will have to manully tell the game which buff needs to be counted, so you will count them manually.

If you wanted to count only Cripple and Curse, you would use:
set count = 0
if unit has buff cripple then
set count = count + 1
if unit has buff curse then
set count = count + 1

If you want to count all buffs except slow, you would use:
set count = 0
if unit has buff slow then
set count = count - 1

set count = count + CountAllBuffs


If the list is longer, it makes sense to use a loop and an array.
 
Status
Not open for further replies.
Top