New Bonus [vJASS][LUA]

Intro
Hello, this is my first submission in the spell section, so apologies in advance for any mistake. I present to you the New Bonus System. Since Object Merger stopped working and we still have no ways to edit the bonus values of a unit natively, I decided to create this light weight system to manage that and give everyone a simpler way to work with bonus values than the Bonus Mod.
How it works?
By using the new Object API introduced to Warcraft, we can now modify an unit ability field value, so when giving an unit a bonus, we add a specific ability to that unit that gives such bonus, if it do not have it already, and change that ability field bonus value to the desired value. Retrieving the amount is also trivial, by just reading that field value.

How to Import?
Importing New Bonus is really simple. Just copy the 9 abilities with the prefix "NewBonus" from the Object Editor into your map [Raw Codes Z001 to Z009 in demo map] and match their new raw code to the bonus types in the global block of the library. You can also define their raw code when pasting to be Z001 to Z009, that's why I created them with this raw codes. Then create a trigger called NewBonus, convert it to custom text, delete all text in it and paste the Library code there. That's it, you are done!
Requirements
NewBonus requires patch 1.31+ and RegisterPlayerUnitEvent Library. NewBonus Extended also Requires DamageInterface, CooldownReduction and Tenacity libraries.

vJASS:
function GetUnitBonus takes unit u, integer bonus_type returns real
    -> Returns the specified bonus amount for the unit
    -> Example: set amount = GetUnitBonus(GetTriggerUnit(), BONUS_AGILITY)

function SetUnitBonus takes unit u, integer bonus_type, real amount returns real
    -> Set the specified bonus type to amount for the unit
    -> Example: call SetUnitBonus(GetTriggerUnit(), BONUS_DAMAGE, 100)

function RemoveUnitBonus takes unit u, integer bonus_type returns nothing
    -> Removes the Specified bonus type from unit
    -> Example: call RemoveUnitBonus(GetTriggerUnit(), BONUS_AGILITY)

function AddUnitBonus takes unit u, integer bonus_type, real amount returns real
    -> Add the specified amount for the specified bonus tyte for unit
    -> Example: call AddUnitBonus(GetTriggerUnit(), BONUS_DAMAGE, 100)

function AddUnitBonusTimed takes unit u, integer bonus_type, real amount, real duration returns nothing
    -> Add the specified amount for the specified bonus type for unit for a duration
    -> Example: call AddUnitBonusTimed(GetTriggerUnit(), BONUS_ARMOR, 13, 10.5)

function LinkBonusToBuff takes unit u, integer bonus_type, real amount, integer buffId returns nothing
    -> Links the bonus amount specified to a buff or ability. As long as the unit has the buff or
    -> the ability represented by the parameter buffId the bonus is not removed.
    -> Example: call LinkBonusToBuff(GetTriggerUnit(), BONUS_ARMOR, 10, 'B000')

function LinkBonusToItem takes unit u, integer bonus_type, real amount, item i returns nothing
    -> Links the bonus amount specified to an item. As long as the unit has that item the bonus is not removed.
    -> Note that it will work for items with the same id, because it takes as parameter the item object.
    -> Example: call LinkBonusToItem(GetManipulatingUnit(), BONUS_ARMOR, 10, GetManipulatedItem())

function UnitCopyBonuses takes unit source, unit target returns nothing
    -> Copy the source unit bonuses using the Add functionality to the target unit
    -> Example: call UnitCopyBonuses(GetTriggerUnit(), GetSummonedUnit())

function UnitMirrorBonuses takes unit source, unit target returns nothing
    -> Copy the source unit bonuses using the Set functionality to the target unit
    -> Example: call UnitMirrorBonuses(GetTriggerUnit(), GetSummonedUnit())

function RegisterBonusEvent takes code c returns nothing
    -> Register code to run when any unit bonus is modified
    -> Example: RegisterBonusEvent(function YourFunction)

function RegisterBonusTypeEvent takes integer bonus, code c returns nothing
    -> Register code to run when a specific unit bonus is modified
    -> Example: RegisterBonusTypeEvent(BONUS_DAMAGE, function YourFunction)

function GetBonusUnit takes nothing returns unit
    -> Call this function to get the bonus event unit

function GetBonusType takes nothing returns integer
    -> Call this function to get the bonus event type

function SetBonusType takes integer bonus returns nothing
    -> Call this function to set the bonus event type

function GetBonusAmount takes nothing returns real
    -> Call this function to get the bonus event amount

function SetBonusAmount takes real amount returns nothing
    -> Call this function to set the bonus event amount
Lua:
function GetUnitBonus(unit, type)
    -> Returns the specified bonus amount for the unit
    -> Example: set amount = GetUnitBonus(GetTriggerUnit(), BONUS_AGILITY)

function SetUnitBonus(unit, type, value)
    -> Set the specified bonus type to amount for the unit
    -> Example: call SetUnitBonus(GetTriggerUnit(), BONUS_DAMAGE, 100)

function RemoveUnitBonus(unit, type)
    -> Removes the Specified bonus type from unit
    -> Example: call RemoveUnitBonus(GetTriggerUnit(), BONUS_AGILITY)

function AddUnitBonus(unit, type, value)
    -> Add the specified amount for the specified bonus tyte for unit
    -> Example: call AddUnitBonus(GetTriggerUnit(), BONUS_DAMAGE, 100)

function AddUnitBonusTimed(unit, type, amount, duration)
    -> Add the specified amount for the specified bonus type for unit for a duration
    -> Example: call AddUnitBonusTimed(GetTriggerUnit(), BONUS_ARMOR, 13, 10.5)

function LinkBonusToBuff(unit, type, amount, buff)
    -> Links the bonus amount specified to a buff or ability. As long as the unit has the buff or
    -> the ability represented by the parameter buffId the bonus is not removed.
    -> Example: call LinkBonusToBuff(GetTriggerUnit(), BONUS_ARMOR, 10, 'B000')

function LinkBonusToItem(unit, type, amount, item)
    -> Links the bonus amount specified to an item. As long as the unit has that item the bonus is not removed.
    -> Note that it will work for items with the same id, because it takes as parameter the item object.
    -> Example: call LinkBonusToItem(GetManipulatingUnit(), BONUS_ARMOR, 10, GetManipulatedItem())

function UnitCopyBonuses(source, target)
    -> Copy the source unit bonuses using the Add functionality to the target unit
    -> Example: call UnitCopyBonuses(GetTriggerUnit(), GetSummonedUnit())

function UnitMirrorBonuses(source, target)
    -> Copy the source unit bonuses using the Set functionality to the target unit
    -> Example: call UnitMirrorBonuses(GetTriggerUnit(), GetSummonedUnit())

function RegisterBonusEvent(code)
    -> Register code to run when any unit bonus is modified
    -> Example: RegisterBonusEvent(function() YourFunctionc end)

function RegisterBonusTypeEvent(type, code)
    -> Register code to run when a specific unit bonus is modified
    -> Example: RegisterBonusTypeEvent(BONUS_DAMAGE, function() YourFunction end)

function GetBonusUnit()
    -> Call this function to get the bonus event unit

function GetBonusType()
    -> Call this function to get the bonus event type

function SetBonusType(type)
    -> Call this function to set the bonus event type

function GetBonusAmount()
    -> Call this function to get the bonus event amount

function SetBonusAmount(real)
    -> Call this function to set the bonus event amount
  • BONUS_DAMAGE
  • BONUS_ARMOR
  • BONUS_AGILITY
  • BONUS_STRENGTH
  • BONUS_INTELLIGENCE
  • BONUS_HEALTH
  • BONUS_MANA
  • BONUS_MOVEMENT_SPEED
  • BONUS_SIGHT_RANGE
  • Real Value Bonusses
  • BONUS_HEALTH_REGEN
  • BONUS_MANA_REGEN
  • BONUS_ATTACK_SPEED
  • BONUS_MAGIC_RESISTANCE
  • BONUS_EVASION_CHANCE
  • BONUS_CRITICAL_CHANCE
  • BONUS_CRITICAL_DAMAGE
  • BONUS_LIFE_STEAL
  • BONUS_DAMAGE
  • BONUS_ARMOR
  • BONUS_AGILITY
  • BONUS_STRENGTH
  • BONUS_INTELLIGENCE
  • BONUS_HEALTH
  • BONUS_MANA
  • BONUS_MOVEMENT_SPEED
  • BONUS_SIGHT_RANGE
  • Real Value Bonusses
  • BONUS_HEALTH_REGEN
  • BONUS_MANA_REGEN
  • BONUS_ATTACK_SPEED
  • BONUS_MAGIC_RESISTANCE
  • BONUS_EVASION_CHANCE
  • BONUS_MISS_CHANCE
  • BONUS_CRITICAL_CHANCE
  • BONUS_CRITICAL_DAMAGE
  • BONUS_SPELL_POWER_FLAT
  • BONUS_SPELL_POWER_PERCENT
  • BONUS_LIFE_STEAL
  • BONUS_SPELL_VAMP
  • BONUS_COOLDOWN_REDUCTION
  • BONUS_COOLDOWN_REDUCTION_FLAT
  • BONUS_COOLDOWN_OFFSET
  • BONUS_TENACITY
  • BONUS_TENACITY_FLAT
  • BONUS_TENACITY_OFFSET

(v1.0)
  • Submission
(v1.1)
  • Updated the code to use BlzSetUnitMaxHP() and BlzSetUnitMaxMana() in order to make Bonus_Health and Bonus_Mana work properly.
(v1.2)
  • Implemented the ability to link a bonus amount to a buff or ability as per requested by @The_Silent . Refactored the code and added a new example of this new functionality in the test map.
(v1.3)
  • FIxed a bug on AddUnitBonusExTimed()
(v1.4)
  • Normalized the AMOUNT input parameter to Integer instead of real to fix a type conversion problem when converting real to integer for abilities which field value is a integer value.
(v1.5)
  • Updated the system to respect integer fields bounds when adding to existing bonus (max 2147483647 and min -2147483648).
  • It's still the users job to pass the correct amount, the system will only handle addtions and subtractions that overflow/underflow.
(v1.6)
  • Split NewBonus into 2 libraries
    • NewBonus contains the core system to set / remove / add bonus types
    • NewBonusUtils contains extra functionalities such as timed and linked bonuses
  • Redesigned timed and linked bonuses to improve performance.
  • New utility functions AddUnitBonusTimed(), LinkBonusToBuff(), LinkBonusToItem()
  • Renamed Constans to upper case to be more visible.
  • Updated test map: included examples for the 3 new utility functions.
(v1.7)
  • Fixed a bug when Adding Health/Mana bonus not keeping the unit Health/Mana Percentage
  • Added the funcitons: They manipuilate real bonuses values correctly.
    • GetUnitBonusReal()
    • SetUnitBonusReal()
    • RemoveUnitBonusReal()
    • AddUnitBonusReal()
  • Refactored the LinkBonusToItem() to use the On Drop event instead of a periodic timer to check the link
  • Included an Expanded version of NewBonus and NewBonusUtils that take advangtage of the Damage Inteface System and Cooldown Reduction System
  • Renamed 4 bonus types for better readability.
  • Removed the "Ex" from the end of the API functions
(v1.8)
  • 2 new bonus types:
    • Sight Range
    • Magic Resistence (real)
  • 2 new functionalities in the NewBonusUtils (See API for usage): Thx to SinisterLuffy for the idea
    • function UnitCopyBonuses takes unit source, unit target returns nothing
    • function UnitMirrorBonuses takes unit source, unit target returns nothing
(v1.9)
  • Correction of a minor spelling error.
(v2.0)
  • Fixed a minor syntax error for the non extended Utils library
(v2.1)
  • System ported to LUA
  • 4 new bonus types for the non-Extended version of the system
    • Evasion Chance
    • Critical Strike Chance
    • Critical Strike Damage
    • Life Steal
(v2.2)
  • Removed the functions GetUnitBonusReal, SetUnitBonusReal, AddUnitBonusReal and RemoveUnitBonusReal
  • Now the functions GetUnitBonus, SetUnitBonus, AddUnitBonus and RemoveUnitBonus handles both real and integer bonus types correctly
  • Fix a minor bug in the NewBonusUtils Library
(v2.3)
  • Support for Bonus Events!!
  • Merged the normal and extended version into one library. (You can control which version is enabled by setting the new EXTENDED constant in the global section)
  • Code Cleaning and formatting.
(v2.4)
  • Fixed a bug in bonus event evaluation
  • 3 new bonus types included from the new Tenacity system
    • BONUS_TENACITY,
    • BONUS_TENACITY_FLAT
    • BONUS_TENACITY_OFFSET


For a quick import of the abilities use the editor Object Data.
For those with problems to open the map because of Reforged 1.32 patch, please see this
Contents

NewBonus (Map)

New Bonus (Map)

Reviews
MyPad
Considering the test map alone, I would approve this system. However, certain things addressed in the Code section of the review would need to be resolved before approval. Hence, this has been moved to Awaiting Update.
Level 1
Joined
Apr 8, 2020
Messages
110
For bonus health and mana, you could use the new natives that manipulate max health and mana instead of using abilities.

Which patch did you work on? My 1.31.1 world editor cannot open the test map. Level info missing comes up as an error.
 
Level 20
Joined
May 16, 2012
Messages
635
For bonus health and mana, you could use the new natives that manipulate max health and mana instead of using abilities.

Which patch did you work on? My 1.31.1 world editor cannot open the test map. Level info missing comes up as an error.

I know about the new natives, and i think there is no point into using them in the system, it would create more code just to keep track of the amount, and jassers can use the natives directly. I'm still thinking on using it, just so the the system is complete. I'm on the latest reforged patch and created the map using the new editor. The file format is w3m. I'll try to save it as w3x.

Edit 1: Map format updated.
Edit 2: 2 more lines of code to make Health and Mana works as intended.
 
Last edited:
Level 1
Joined
Apr 8, 2020
Messages
110
Copying nine abilities is still a bit cumbersome, especially for maps already in development. If only it were possible to copy multiple objects at once, then it would be less tedious of a process.

I find JNGP Lua Edition still operable even in Reforged because the findpath.lua file has been modified to be simpler. Replacing that file in any version of JNGP of your choice with the one in Lua Edition's makes that JNGP usable. The Object Merger can then be utilized to make installing this system smoother.
 
Level 8
Joined
Mar 19, 2017
Messages
248
A potential good system, but i'm pretty sure the ability field modifiers don't work with item abilities (ej. item damage bonus ability that maybe you are using for bonus damage effect) at least in 1.31. This was my experience trying to code a bonus system and failing because of that.
Maybe such functionality works in 1.32+?
 
Level 20
Joined
May 16, 2012
Messages
635
A potential good system, but i'm pretty sure the ability field modifiers don't work with item abilities (ej. item damage bonus ability that maybe you are using for bonus damage effect) at least in 1.31. This was my experience trying to code a bonus system and failing because of that.
Maybe such functionality works in 1.32+?

I tested all the bonusses, they work fine, and quite a few of them are from item abilities. I think what you experienced is indeed a bug that occurs when you change the field value of an ability and dont increase and decrease its level to update it.. You can download the map and see for yourself.
 
Level 20
Joined
May 16, 2012
Messages
635
Looks great.

This might not be worth the effort, but would you consider adding a version of AddUnitBonus that is tied to a buff integer code. So it lasts as long as the unit has that specific buff? Would be extremely useful for spells.

I will try, but can you give me an example, because there is multiple ways i could interpret that. I mean give the parameters that you were thinking and i will work from it.

Edit 1: Request Implemented.
 
Last edited:
Say the function looks like this:
call AddUnitBonusExBuff(unit whichUnit, integer bonus_type, real amount, integer buffid)
And it checks evey 0.04 second if the unit still has the buff. If it does not, the bonus ends.

Say you want the Frenzy ability to give a +10 agility bonus.

  • Untitled Trigger 001
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Frenzy
    • Actions
      • Custom script: call AddUnitBonusExBuff(GetTriggerUnit(), Bonus_Agility, 10, 'Bfzy')
So it just automatically handles removing the bonus again once the buff have expired or been dispelled. Dispelled is probably the most important aspect here, since AddUnitBonusExTimed would work otherwise. (Or it might be a channeled spell, etc.)
 
Level 20
Joined
May 16, 2012
Messages
635
Say the function looks like this:
call AddUnitBonusExBuff(unit whichUnit, integer bonus_type, real amount, integer buffid)
And it checks evey 0.04 second if the unit still has the buff. If it does not, the bonus ends.

Say you want the Frenzy ability to give a +10 agility bonus.

  • Untitled Trigger 001
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Frenzy
    • Actions
      • Custom script: AddUnitBonusExBuff(GetTriggerUnit(), Bonus_Agility, 10, 'Bfzy')
So it just automatically handles removing the bonus again once the buff have expired or been dispelled. Dispelled is probably the most important aspect here, since AddUnitBonusExTimed would work otherwise. (Or it might be a channeled spell, etc.)

Ok, i'm on it!
 
Level 20
Joined
May 16, 2012
Messages
635
Such functionality that only bases on the system should probably be be a new library, like a helper or tools library. Because otherwise it might bloat the core system. Some other user might want to use not only buffs, but maybe also items, too, when a unit owns/drops one item of one type... and so forth.

For items the events of on pickup and drop could be used with the normal functions. For buffs and abilities only one new function is enough since both are checked using GetUnitAbilityLevel > 0
 
The code is easily understandable, as well as being well-documented, and exceptionally clean. The only drawback is the inclusion of functions that are best suited in another library (something like BonusHelper). The functions in question are the following:

JASS:
function AddUnitBonusExTimed
function AddUnitBonusLinked

A minor gripe with this is how the constants are cased. They should be capitalized to help the user identify them as constants.

The test map best demonstrates the capabilities of this system. With the ability to print out information at will, as well as manipulate the bonuses easily at run-time, this will leave no doubt of the system's performance to the end-user.

Considering the test map alone, I would approve this system. However, certain things addressed in the Code section of the review would need to be resolved before approval. Hence, this has been moved to Awaiting Update.
 
Level 20
Joined
May 16, 2012
Messages
635
The code is easily understandable, as well as being well-documented, and exceptionally clean. The only drawback is the inclusion of functions that are best suited in another library (something like BonusHelper). The functions in question are the following:

JASS:
function AddUnitBonusExTimed
function AddUnitBonusLinked

A minor gripe with this is how the constants are cased. They should be capitalized to help the user identify them as constants.

The test map best demonstrates the capabilities of this system. With the ability to print out information at will, as well as manipulate the bonuses easily at run-time, this will leave no doubt of the system's performance to the end-user.

Considering the test map alone, I would approve this system. However, certain things addressed in the Code section of the review would need to be resolved before approval. Hence, this has been moved to Awaiting Update.

System Updated as required.
 
Level 20
Joined
May 16, 2012
Messages
635
Great system, good work. But how does one go about adding Real values? Such as adding 0.25 HP Regen or something.

Initially the amount parameter was a real, but i had to change that in version 1.4 because of a issue with converting reals to integers. I noticed that the conversion back and forth was returning different values, resulting in differences in a bonus operation.

Yeah, I have the same issue, want to give a unit a +15% attack rate bonus (0.15).

You still can do that @The_Silent you just need to call UnitAddBonusEx(u, BONUS_ATTACKSPEED, 15). If you see the code, internally for attack speed bonus it multiply the amount by 0.01 to be passed as parameter for the functions that manipulates the ability field and multiply by 100 when returning it. Attack Speed bonus take that advantage.

I will try to think of a solution for the real parameter case, but for now I'll keep the more stable version on.
 
Level 20
Joined
May 16, 2012
Messages
635
Found an issue, when adding Health to a unit, it's maximum health is increased but it's current health stays the same value. It's not updating the percentage of health.

In other words, a unit with 100 hp that is given +50 health goes from 100/100 hp to 100/150 hp.

Ok, thank you for posting it. If for Health it happens, then probably for Mana it will happen too. Soon enough I will update it fixing those issues.
 
Level 20
Joined
May 16, 2012
Messages
635
Should/Could magic resistance and evasion be added?

Theoretically, using the method I use to implement New Bonus, one can expand this system to be able to manipulate any ability field in the game, and I just implemented the ones that I thought would be the most used overall. So yes, it could be added, but for now I'll not do it because I'm focusing in another projects of my own, but maybe in the future. Feel free to do it yourself if you have the knowledge.
 
Level 8
Joined
Mar 19, 2017
Messages
248
I use 1.31 and i still can't open the 1.6 version test map. Code compiles fine though.
Still, thanks for the inc + dec level trick to fix the bug with the ability field problem.
It should be knowed that, atleast regarding my experience with 1.31, that trick only works, allowing to modify a field that will otherwise bug, on some ability fields -ie. i tried it on the flare number count field -Flare abilty- and it didn't work at all, so some ability fields just can't be modified with or without the trick-. This should be documented on the patch bugs thread but anyway.
 
Last edited:
Level 20
Joined
May 16, 2012
Messages
635
I use 1.31 and i still can't open the 1.6 version test map. Code compiles fine though.

Are you using the latest patch version? Opening the map with the default editor?

I should be knowed that, atleast regarding my experience with 1.31, that trick only works, allowing to modify a field that will otherwise bug, on some ability fields -ie. i tried it on the flare number count field -Flare abilty- and it didn't work at all, so some ability fields just can't be modified with or without the trick-. This should be documented on the patch bugs thread but anyway.

The Object API is very buggy for a while now, in theory the inc + dec trick shouldn't be needed, but yeah, a lot of abilities fields can't be modified, but I'm not aware of any list.
 
Level 12
Joined
Jan 30, 2020
Messages
875
Oh nice !

If I had found this a while back, I would have saved a lot of time implementing my custom hero attributes !!!

I wouldn't have been able to use this system exactly because one of the attributes increases the critical hits multiplier, but the principle is similar so that would have been handy.

I can confirm a lot of issues with modifying abilities, in particular hero abilities tooltips beyond level 3 !
I had to fix this using a dummy hero ability and a unit ability (1 for each player - this is important), then I modify the tooltips and the fields of the ability on the fly every time a hero levels up or the player buys "tomes" for the custom attributes that impact the ability.

Anyways, nice work indeed !

EDIT:
A Lua version would be nice too, and maybe it would allow more flexibility.
If you plan to do so and need some help, let me know (I use Reforged)
 
Level 20
Joined
May 16, 2012
Messages
635
Oh nice !

If I had found this a while back, I would have saved a lot of time implementing my custom hero attributes !!!

I wouldn't have been able to use this system exactly because one of the attributes increases the critical hits multiplier, but the principle is similar so that would have been handy.

I can confirm a lot of issues with modifying abilities, in particular hero abilities tooltips beyond level 3 !
I had to fix this using a dummy hero ability and a unit ability (1 for each player - this is important), then I modify the tooltips and the fields of the ability on the fly every time a hero levels up or the player buys "tomes" for the custom attributes that impact the ability.

Anyways, nice work indeed !

EDIT:
A Lua version would be nice too, and maybe it would allow more flexibility.
If you plan to do so and need some help, let me know (I use Reforged)

Thx! to make a LUA version I would have to learn LUA first, which I intend too, but for now I can`t cuz of work and college.
 
Level 12
Joined
Jan 30, 2020
Messages
875
No worries, I fully understand.

My offer will still stand in the future, so contact me when you will have more time :)

Take care and good luck for college !!!
 
Level 20
Joined
Aug 13, 2013
Messages
1,696
I can't open the demo map of this either, regardless of having 1.31.1 editor already... (same case to DamageEngine 5.5+)
It looks like maps saved in reforged editor causes it to be unopenable despite of code.
If code compiles enough properly, can you provide informations on how to "recreate" these objects that I have to import?
Not sure if you can just use OE -> File - "Export All Object Data" and send the file here for me to import it on a blank map.
That way is easier I think than discussing what fields/settings I have to setup in each ability? (only If it works)

Regardless, I just want to include this system and the latest DamageEngine to my future resources as they're essentials in spell-making.
 
Level 20
Joined
May 16, 2012
Messages
635
I can't open the demo map of this either, regardless of having 1.31.1 editor already... (same case to DamageEngine 5.5+)
It looks like maps saved in reforged editor causes it to be unopenable despite of code.
If code compiles enough properly, can you provide informations on how to "recreate" these objects that I have to import?
Not sure if you can just use OE -> File - "Export All Object Data" and send the file here for me to import it on a blank map.
That way is easier I think than discussing what fields/settings I have to setup in each ability? (only If it works)

Regardless, I just want to include this system and the latest DamageEngine to my future resources as they're essentials in spell-making.

I'll try to export and send to you.
 
Level 20
Joined
Aug 13, 2013
Messages
1,696
I'll try to export and send to you.
As @SinisterLuffy said, it's a best course of action to note this in the resource thread description instead
to truly support 1.31.1 users as you noted it requires this patch to make it work but somehow starters
would definitely fail to acknowledge this as the demo map refuses to open with patches below of 1.32.

I'm looking forward to this. I don't think the method above should work as reforged's object data != legacy's object data,
which eventually forces you to give at least information/showcase how to setup those required objects manually to make
your NewBonus even work with 1.31.1 editor for the sake of compatibility. ;)
 
Level 20
Joined
May 16, 2012
Messages
635
For those who cant open the map because of Reforged, here is the Object Data and the pictures of the 9 abilities and it's fields modified so you can create them yourselves.

NewBonus_Armor_Ability.png NewBonus_AttackSpeed_Ability.png NewBonus_Damage_Ability.png NewBonus_Health_Ability.png NewBonus_HealthRegen_Ability.png NewBonus_Mana_Ability.png NewBonus_ManaRegen_Ability.png NewBonus_MovementSpeed_Ability.png NewBonus_Stats_Ability.png NewBonus_SightRange.png NewBonus_MagicResistence.png

Sorry for the delay, power grid went off because of a cyclone here.

EDIT: Updated the object data to match the version 2.1
 

Attachments

  • ObjectData.rar
    2.2 KB · Views: 70
Last edited:
Level 20
Joined
Aug 13, 2013
Messages
1,696
@chopinski

Yeah, exported reforged object data file works when importing it within latest legacy editor.

NewBonus script compiles properly, except for NewBonusUtils which you've forgot to include
RegisterPlayerUnitEvent library & a link on its library declaration as one of the requirements
since we don't have the actual demo map. Other than that, I only tried testing the system by
manipulating a bonus damage, all of the functions work as expected. I don't know about
the 'Expanded' variants as I don't think I'll sort into them yet.

Regardless, just like the latest DamageEngine version:
I would also like to clarify that this system works properly in 1.31.1 (despite of unopenable demo map)
 
Level 20
Joined
May 16, 2012
Messages
635
@chopinski

Yeah, exported reforged object data file works when importing it within latest legacy editor.

NewBonus script compiles properly, except for NewBonusUtils which you've forgot to include
RegisterPlayerUnitEvent library & a link on its library declaration as one of the requirements
since we don't have the actual demo map. Other than that, I only tried testing the system by
manipulating a bonus damage, all of the functions work as expected. I don't know about
the 'Expanded' variants as I don't think I'll sort into them yet.

Regardless, just like the latest DamageEngine version:
I would also like to clarify that this system works properly in 1.31.1 (despite of unopenable demo map)

Oh, thanks, i will update the thread with the required library included in the code section and linked. Glad it worked.
 
Level 20
Joined
May 16, 2012
Messages
635
This is a very useful system but I did find a bug: The move speed bonus seems to interact incorrectly with a hero that has the boots of speed item.

That's because the ability that is used to manipulate the movement speed bonus is the same as the ability used by the boots of speed and a unit can only have one ability of the same type. The idea behind this system is to allow you to control all those bonuses. For example , you could use the LinkBonusToItem() function to add the movement speed you desire when acquiring the boots of speed and remove the ability from the item in the editor and the system will do the rest. It's not a bug, it's just how the game works.
 
Level 1
Joined
Apr 8, 2020
Messages
110
Sight Range Bonus would be a nice addition.
LinkBonusToItemId(bonusType, amount, itemTypeId) would do wonders.

When I first looked at LinkBonusToItem(), I thought the stats would be bound to the item, so that I can regain the stats if I picked up the item after dropping it. The function name is a bit misleading.

You might want to note that illusions will not inherit the real unit's bonus stats. Bonuses must be added manually to the illusion.
 
Last edited:
Level 20
Joined
May 16, 2012
Messages
635
Sight Range Bonus would be a nice addition.
LinkBonusToItemId(bonusType, amount, itemTypeId) would do wonders.

When I first looked at LinkBonusToItem(), I thought the stats would be bound to the item, so that I can regain the stats if I picked up the item after dropping it. The function name is a bit misleading.

You might want to note that illusions will not inherit the real unit's bonus stats. Bonuses must be added manually to the illusion.

It's not misleading. A bonus is linked to an item object, which is much better then simply an item type. Think of it, lets say you link +10 damage to a claws of attack ITEM on pickup, then you pick up 5 claws of attack. Your unit will gain +10 damage 5x = 50 damage. Your unit drop 1 claws of attack and lose 10 damage. That's logical and its what NewBonus do. Now let's see what your way would do. You do the same, link +10 damage to claws of attack TYPE. Your unit pick up 5 claws of attack and gain 10 damage 5x, so far so good. Now your unit drops 1 claws of attack, but it will not lose 10 damage because your unit still have 4 claws of attack. See the diference. LinkBonusToItem() is not misleading. it does exactly what it supposed to do. Try it out, create an Item Pick Up Event, link a bonus to that item, see your unit gain such bonus. Drop that item, see your unit lose such bonus. Pick it up again and ......

Someday i might expand to more bonus types, right now I'm a bit full of other stuff.

Regarding illusions, yeah, the bonus a per unit not a global thing, so you have to do it yourself. Adding support to that kind of stuff would just make system huge for no reason.
 
Last edited:
Level 1
Joined
Apr 8, 2020
Messages
110
Not quite what I had in mind regarding that function or your function. I was thinking more along the lines of CSS. I would think that since the bonus is "linked" to the item handle, if another unit picks up the item after the first unit drops it, that other unit would gain the stats supposedly linked to the item handle.

Anyway, I guess CSS-like functionality was never your intention with that function. Rather, your bonus system should be the base for such a system.

Since that is not the case, I just have to code it myself using your system as a base. Not a big problem.

CSS had the limitation of being restricted to item ids. I was going to create a derivative of it that works with item handles instead by using your bonus system.
 
Last edited:
Level 20
Joined
May 16, 2012
Messages
635
Not quite what I had in mind regarding that function or your function. I was thinking more along the lines of CSS. I would think that since the bonus is "linked" to the item handle, if another unit picks up the item after the first unit drops it, that other unit would gain the stats supposedly linked to the item handle.

Oh, I see what you want to do. Link the bonus to a handle. It's possible, once i have a bit more time i can add that to NewBonusUtils, although it's already possible to do that, you would only need to differentiate your item on pick up.
 
Last edited:
Level 1
Joined
Apr 8, 2020
Messages
110
A function like the following would be very useful for stuff like illusions and such:
JASS:
static method CopyBonuses takes unit u, unit target returns nothing
            local integer i = 1
            loop
                exitwhen i > 11
                    if i < 9 then
                        if not (GetUnitBonus(u, i) == 0) then
                            call AddUnitBonus(target, i, GetUnitBonus(u, i))
                        endif
                    else
                        if not (GetUnitBonusReal(u, i) == 0) then
                            call AddUnitBonusReal(target, i, GetUnitBonusReal(u, i))
                        endif
                    endif
                set i = i + 1
            endloop
endmethod

//JASS one-liner equilvalent
function CopyUnitBonuses takes unit u, unit target returns nothing
        call NewBonusUtils.CopyBonuses(u, target)
endfunction
Then you can do this for illusions:

  • Test Illusion
    • Events
      • Unit - A unit Spawns a summoned unit
    • Conditions
      • ((Summoned unit) is an illusion) Equal to True
    • Actions
      • Set TempUnit = (Triggering unit)
      • Set RealUnit = (Summoning unit)
      • Custom script: call CopyUnitBonuses(udg_RealUnit, udg_TempUnit)
Way simpler, right?
 
Level 20
Joined
May 16, 2012
Messages
635
A function like the following would be very useful for stuff like illusions and such:
JASS:
static method CopyBonuses takes unit u, unit target returns nothing
            local integer i = 1
            loop
                exitwhen i > 11
                    if i < 9 then
                        if not (GetUnitBonus(u, i) == 0) then
                            call AddUnitBonus(target, i, GetUnitBonus(u, i))
                        endif
                    else
                        if not (GetUnitBonusReal(u, i) == 0) then
                            call AddUnitBonusReal(target, i, GetUnitBonusReal(u, i))
                        endif
                    endif
                set i = i + 1
            endloop
endmethod

//JASS one-liner equilvalent
function CopyUnitBonuses takes unit u, unit target returns nothing
        call NewBonusUtils.CopyBonuses(u, target)
endfunction
Then you can do this for illusions:

  • Test Illusion
    • Events
      • Unit - A unit Spawns a summoned unit
    • Conditions
      • ((Summoned unit) is an illusion) Equal to True
    • Actions
      • Set TempUnit = (Triggering unit)
      • Set RealUnit = (Summoning unit)
      • Custom script: call CopyUnitBonuses(udg_RealUnit, udg_TempUnit)
Way simpler, right?

That's nice. Will add it in the next update soon enough.
 
Level 12
Joined
May 16, 2020
Messages
660
Yeah, absolutely, you just need to use the Custom script from GUI to call the functionalities you want. If you click on Preview Triggers, in the example 2, there's a little demonstration of how you can do it with GUI.
Thanks! I'm still studying how it works, but what I also want to ask: Is it possible to add pure damage to a unit with this system? I mean not by adding for example strength if the main attribute is strength, but a pure damage "attribute"?

Such system would be very useful to create Ursa from dota, which adds damage (visible next to the attack) based on the hero's HP.
 
Level 20
Joined
May 16, 2012
Messages
635
Thanks! I'm still studying how it works, but what I also want to ask: Is it possible to add pure damage to a unit with this system? I mean not by adding for example strength if the main attribute is strength, but a pure damage "attribute"?

Such system would be very useful to create Ursa from dota, which adds damage (visible next to the attack) based on the hero's HP.

Yeah, that's the purpose of this sytem. It allows you to manipulate many aspects of units, including the green damage amount. When calling the AddUnitBonus or SetUnitBonus functions just use the BONUS_DAMAGE as the parameter for the bonus type and you will be manipulating chosen unit green damage bonus directly.
 
Top