Changes a unit's damage without showing +(amount) or -(amount). A testmap with the needed abilities is attached at the bottom; to test the system, type a number ingame, and the mortar team's damage will change by that number.
Note: The Demo Map's code is a little older and thus should not be used, instead use the code in this thread.
Known bugs
Does not work on units with any form of Unit Inventory (IE an inventory which can store but not use items) Note: this applies even if it is an ability which requires an upgrade which has not yet been researched.
Maintenance
When imported, the DamageModifierId function must be changed to have the correct item IDs of the tomes.
The HasNoInventory function should be updated to include any custom inventories based off Inventory (Hero), or any other inventory which allows use of items.
Behavior in detail
When used, the unit's Base Damage will increase by 'amount' (or decrease of amount is negative)
If a damage value (minimum or maximum) becomes negative, it will be treated and displayed as 0 but still stored as negative, meaning that if you give a unit with 1-1 damage -2 damage, it will display as 0-0, but adding 1 damage will cause it to remain at 0-0. Adding an additional point of damage would move it to 1-1.
Use in GUI
If using vJass/JassNewGenPack, put the vJass script in a new trigger (I recommend calling it UnitAddDamage, but it doesn't matter).
If not using vJass/JassNewGenPack, copy this script to the "Custom Script Section", which is accessed by clicking on what looks like your map file on the top of the trigger tree in the Trigger Editor. Paste the non-vJass code in the bottom box on the right.
library UnitAddDamage globals privateinteger ans endglobals privatefunction HasNoInventory takesunit u returnsboolean return GetUnitAbilityLevel(u,'AInv') == 0 endfunction privatefunction DamageModifierId takesreal amount returnsinteger if amount >= 10 then set ans = 10 return'I001'//+10 damage elseif amount >= 1 then set ans = 1 return'I000'//+1 damage elseif amount <= -10 then set ans = -10 return'I003'//-10 damage elseif amount <= -1 then set ans = -1 return'I002'//-1 damage endif return 0 endfunction function UnitAddDamage takesunit u, integer amount returnsnothing localboolean b = HasNoInventory(u) if b then call UnitAddAbility(u,'AInv') endif loop exitwhen amount == 0 call UnitAddItemById(u,DamageModifierId(amount)) set amount = amount - ans endloop if b then call UnitRemoveAbility(u,'AInv') endif endfunction endlibrary
Jass
function HasNoInventory takesunit u returnsboolean return GetUnitAbilityLevel(u,'AInv') == 0 endfunction function DamageModifierId takesreal amount returnsinteger if amount >= 10 then return'I001'//+10 damage elseif amount >= 1 then return'I000'//+1 damage elseif amount <= -10 then return'I003'//-10 damage elseif amount <= -1 then return'I002'//-1 damage endif return 0 endfunction function UnitAddDamage takesunit u, integer amount returnsnothing localboolean b = HasNoInventory(u) if b then call UnitAddAbility(u,'AInv') endif loop exitwhen amount == 0 call UnitAddItemById(u,DamageModifierId(amount)) if amount >= 10 then set amount = amount - 10 elseif amount >= 1 then set amount = amount - 1 elseif amount <= -10 then set amount = amount + 10 elseif amount <= -1 then set amount = amount + 1 endif endloop if b then call UnitRemoveAbility(u,'AInv') endif endfunction
Last edited by PurplePoot; 11-22-2008 at 07:24 PM..
Reason: Fixed bugginess in the test map