# [Solved] Counting buffs

Discussion in 'World Editor Help Zone' started by Watcher, Mar 7, 2018.

1. ### Watcher

Joined:
Aug 31, 2011
Messages:
87
Resources:
0
Resources:
0
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: Mar 7, 2018

### JASS Reviewer

Joined:
Mar 25, 2016
Messages:
1,287
Resources:
0
Resources:
0
• 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 ...

3. ### Watcher

Joined:
Aug 31, 2011
Messages:
87
Resources:
0
Resources:
0

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

### JASS Reviewer

Joined:
Mar 25, 2016
Messages:
1,287
Resources:
0
Resources:
0
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.

5. ### Watcher

Joined:
Aug 31, 2011
Messages:
87
Resources:
0
Resources:
0
Big thanks m8!

Thank you for clarification.

+rep