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

Complicated Spells

Status
Not open for further replies.
Level 6
Joined
Feb 6, 2015
Messages
266
Can't find spells

Hello there

I've been searching through the spells but couldn't find what I have in mind. Basically, I'm searching for 2 passives. (Multi-passives)
1- Passive : Replenishes 2% of HP & MP each second while out of combat
Aura that replenishes 0.5% of HP each second
Increases HP by +50 for each 10 points in strength

2- Passive : Aura that grants +2 armor
Increases attack speed by 20% for each 10 points in agility

IF there aren't such spells, some tips to making such spells are appreciated.

Cheers.
 
Last edited:
Level 6
Joined
Feb 6, 2015
Messages
266
Okay, I'm gonna need a cup of coffee for this.

EDIT : The EOT system solves the aura part. However, the 1st spell for example still needs out-of-combat function and a trigger that increases HP based on current strength.

Can this be achieved in Jass/GUI and how?
 
Last edited:
Level 24
Joined
Aug 1, 2013
Messages
4,657
Aura that grants +2 armor... Devotion Aura?
For the others it is quite tricky.
You will have to create a periodic timer.
Each iteration, you load the strenth and agility of your hero.
You will also have 2 variables (1 for strength, 1 for agility, arrays for both for MUI).
If current strength - strength from array is bigger than 10 or smaller than -10, then you add/remove the effect (hp bonus/attack speed).
And you will update the current value (rounded to the lowest 10).

You may want to use the SetUnitMaxState library which comes with BonusMod.
It allows you to add a number of health/mana.

To have the out-of-combat thingy, you can do this on a very easy way.
Create a group (or an array which is faster but requires more work).
Every 0.25-0.5 seconds, you iterate over the list of units and regenerate 0.5%-1.0% HP/MP.

When a unit takes damage, you remove both the attacking unit and attacked unit from the group.
On that same moment, you start a timer for x seconds that will add the unit to that group again. (x is the number of seconds that it takes to be out-of-combat since the last attack.)

You could make a "OutOfCombat" script pretty easily with a Unit Indexer and TimerUtils.
I had one a while ago but can't find it any more.
 
Level 6
Joined
Feb 6, 2015
Messages
266
I'm kind of relieved that the passives are even possible. This looks like a lot of work tho.

Also, since I'm still devouring tuts for JASS (which I'm assuming is the better way to create these passives with), there are things I still don't know, like the BonusMod thingy.

But this will help a lot in making the spells. Thanks!
 
Level 21
Joined
Mar 27, 2012
Messages
3,232
The first bonusmods were simply about giving the units abilities that give stats. The mathematics just so happens to be based on the number 2:
1
2
4
8
!6
...
You can combine those numbers to make any number from 0 to 31. For every number that you add the range that you can make doubles, because this is a very efficient way of using abilities.

Newer bonusmods use a glitch for some stats(health) so the ability wouldn't have to stay on the unit, which means you can just apply the bonusmod multiple times to get a larger number. This trick pretty much means that with at least 2 abilities you can make any bonus. Having more abilities makes it take less effort from the computer though.
 
Level 6
Joined
Feb 6, 2015
Messages
266
The first bonusmods were simply about giving the units abilities that give stats. The mathematics just so happens to be based on the number 2:
1
2
4
8
!6
...
You can combine those numbers to make any number from 0 to 31. For every number that you add the range that you can make doubles, because this is a very efficient way of using abilities.

Newer bonusmods use a glitch for some stats(health) so the ability wouldn't have to stay on the unit, which means you can just apply the bonusmod multiple times to get a larger number. This trick pretty much means that with at least 2 abilities you can make any bonus. Having more abilities makes it take less effort from the computer though.

Okay.. I think I get it. Can you give an example spell perhaps?
 
Level 21
Joined
Mar 27, 2012
Messages
3,232
A bonusmod is a general system, it doesn't have to be coded again for every spell.

The technique is as follows:

You want to add an amount of some stat(X) to a unit. How do you know which abilities to add?
1. Take the largest ability you have(you should store them in an array for easy access).
2. Check if the value is equal to or smaller than your bonus to be added.
3. If so, reduce the bonus to be added by how much this ability gives, give the unit this ability and proceed to the next ability.
4. If you've not exhausted all abilities yet, then restart from 2.

When storing bonuses you can store them to their powers of 2.
2**0 = 1
2**1 = 2
2**2 = 4
2**3 = 8
2**4 = 16
...
So you can place them in the array like this:
bonus[0] = ability1
bonus[1] = ability2
bonus[2] = ability4
bonus[3] = ability8
bonus[4] = ability16
Then in a separate variable you store the largest used array index(4 in this case). This is how you can always know the size of the current ability(just do 2**n, where n is the array index).

If you have trouble understanding this I can give a GUI and JASS example. (Both, because it's actually easier to do stuff like this in JASS)
 
Level 6
Joined
Feb 6, 2015
Messages
266
It's more clear now. Nice explanation.

But question is, where is this system written in the WE?

And please, give away. (preferably JASS)
 
Level 21
Joined
Mar 27, 2012
Messages
3,232
In regular WE you would write it in the map header(click the map name in trigger editor). Do you have JNGP? If so, it would be a bit easier since with JNGP you can create globals through text, without variable editor. Basic vJASS is even easier than just JASS.
If you already prefer JASS then I won't bother with writing it in GUI - JASS is superior anyway and I offered giving both only to promote JASS. (JASS raises the standard of living, all hail JASS!)
 
Level 6
Joined
Feb 6, 2015
Messages
266
As a matter of fact, I do have JNGP. And lately, I've been preferring JASS. Typing > Clicking. Am I right?!
 
Level 21
Joined
Mar 27, 2012
Messages
3,232
There are 3 methods for giving stat bonuses:
Adding abilities - Usable for almost all stats. Shows a green number except with health and mana. There's a limit based on how many abilities you have and you have to always consider which abilities you've already added, meaning that on the system level you set the bonus, instead of adding it.
Glitching with levels - Infinite bonuses possible, since you can keep doing this.
Tomes - Works essentially the same as glitching with levels, except that instead of the glitch trick you just use items, which you can delete after that. Usable for base hero attributes(useless, because you have a function for that), damage and health.

Adding is the cheapest, but has a limit based on the number of abilities.
Glitching is the best because it's not much more expensive than adding, but provides an unlimited range of bonuses.
Tomes are for when you can't use either adding or glitching.

I've included the first 2 in the testmap. For now I'm quite tired, so I only wrote up the thinking involved in the health part(glitching), but the armor one is easier(adding), so you might be able to figure it out based on the other explanation and on the test map.
There are also the formulas for maximum(and minimum) possible bonuses in the armor example.

Health:
When you give the unit an ability that increases health, its health gets modified by the level 1 amount. When it's removed, the amount of the current level is detracted. There's a bug that when the level of such an ability is changed, it doesn't notice at all, so the health given doesn't change.

So here's the trick:
Make the first level of the ability give no bonus(0).
Make all other levels give the opposite of the bonus that they usually would give.
So with this we get a lineup of
0
1
2
4
8
16
...
4096
-8192

Why is the last number negative? Well, this is how we handle both positive and negative numbers. Keep in mind that with this bug, each health amount is actually the opposite of what it really adds, so the last level actually gives health and all others(except level 1) reduce it.
However, we have a few problems:
The first level of an ability can not be 0, so we had to shift all values one level up.
In addition, we wanted the first level to be 0, so that's another time we shifted all values up by a level. It's easy to handle in the code though:
Whenever we calculate the bonus that a level gives with Pow(2,level) we instead use Pow(2,level-2).

Okay, so what's more in this code? Since by abusing this bug we don't need the abilities to stay on the unit we can just keep doing this and get any bonus we want(positive or negative). I included this automatically in the code.

Since most of the bonuses really reduce health we also have one other potential problem - if unit (max) health gets negative while it's being changed the unit will simply die. To solve this we first check if the amount to add is positive and if so, give the unit the highest possible bonus. We repeat this, for reasons outlined in the previous paragraph, until the amount is no longer over 0.

However, the math doesn't work right if numbers are negative(even(as opposed to odd) powers of a number can never give negative numbers). For this reason we change the bonus to the opposite of what it was and act like the next abilities we add were actually positive. It's easier mathematically this way.
 

Attachments

  • BonusMod Example.w3x
    18.2 KB · Views: 36
Level 6
Joined
Feb 6, 2015
Messages
266
When you give the unit an ability that increases health, its health gets modified by the level 1 amount. When it's removed, the amount of the current level is detracted.

This works even if the amount changes while the spell is still level 1, right ? (for example : by having 10 strength the hero gains +50 more health, assuming the hero levels up and gains another 10 strength but the passive level is 1, he'll still get another +50?)

I'll check the example tomorrow, it's kinda late here.

Good explanation btw, the complex seems easy now.

EDIT : After reading the coding it's clearer to me now. However, when I tried to implement the custom item ability to an item (Khadgar's gem of health) and after picking it up nothing happened. Even though I made a function for actions to take place when the item is lifted by the hero.
 
Last edited:
Status
Not open for further replies.
Top