Name | Type | is_array | initial_value |
TempInt | integer | No | |
TempU | unit | No |
//TESH.scrollpos=0
//TESH.alwaysfold=0
//-----------------------------------------------------------------------------
// Library AttackSpeedBonus can add attack speed bonus to a single unit.
// made by ZibiTheWand3r3r
//-----------------------------------------------------------------------------
// functions:
// UnitClearASBonus(unit <whatUnit>) --> clear AS (attack speed) bonus set by this library
// UnitSetASBonus(unit <whatUnit>, integer <bonus>) -->
// This function clears any previously applied bonus on <whatUnit>, and setting
// new attack speed bonus. Range: from -80 to +400 (%)
// Value outside range will be modified. However in Warcaft3 values lower then -80%
// or higher then +400% cannot afftect unit's attack speed more then -80% / +400%.
// UnitGetASBonus(unit whatUnit) returns integer -->
// Returns AS bonus amount currently applied to <whatUnit> by this system.
//-----------------------------------------------------------------------------
// Instalation:
// copy this trigger and paste into your map
// copy 3 abilities, and set below their raw codes
//-----------------------------------------------------------------------------
library AttackSpeedBonus initializer Init
// please make sure these abilities' raw codes are the same as copied into your map:
globals
private integer BonusAbility001 = 'A00E' //AttackSpeedBonus1 ability
private integer BonusAbility010 = 'A00F' //AttackSpeedBonus10 ability
private integer BonusAbility100 = 'A00G' //AttackSpeedBonus100 ability
endglobals
//------------------------------------------------------------------------------
// system code : do not edit below --------------------------------------
//------------------------------------------------------------------------------
private function UnitAddAbilityLevel takes unit u, integer abiId, integer level returns nothing
call UnitAddAbility(u, abiId)
call SetUnitAbilityLevel(u, abiId, level)
call UnitMakeAbilityPermanent(u, true, abiId)
endfunction
//-------------------------------
function UnitClearASBonus takes unit u returns nothing
call UnitRemoveAbility(u, BonusAbility001)
call UnitRemoveAbility(u, BonusAbility010)
call UnitRemoveAbility(u, BonusAbility100)
endfunction
//-------------------------------
function UnitSetASBonus takes unit u, integer bonus returns nothing
local integer a
call UnitClearASBonus(u)
if bonus > 0 then // -positive- bonus
set bonus = IMinBJ(bonus, 400)
set a = bonus/100 //100
if a > 0 then
call UnitAddAbilityLevel(u, BonusAbility100, a)
set bonus = bonus - (a*100)
endif
set a = bonus/10 //10
if a > 0 then
call UnitAddAbilityLevel(u, BonusAbility010, a+9)
set bonus = bonus - (a*10)
endif
if bonus > 0 then //1
call UnitAddAbilityLevel(u, BonusAbility001, bonus+9)
endif
elseif bonus < 0 then // -negative-bonus
set bonus = IMaxBJ(bonus, -80)
set a = bonus/ (-10) // 10
if a > 0 then
call UnitAddAbilityLevel(u, BonusAbility010, a)
set bonus = bonus + (a*10)
endif
set a = -bonus // 1
if a > 0 then
call UnitAddAbilityLevel(u, BonusAbility001, a)
endif
endif
endfunction
//----------------------------------------------------------------
function UnitGetASBonus takes unit u returns integer
local integer i10 = GetUnitAbilityLevel(u, BonusAbility010)
local integer i1 = GetUnitAbilityLevel(u, BonusAbility001)
local integer bonus = 0
set bonus = GetUnitAbilityLevel(u, BonusAbility100) * 100 // hundreds [+]
if i10 > 9 then // tens [+]
set bonus = bonus + ((i10-9)*10)
elseif i10 > 0 then // tens [-]
set bonus = - (i10*10)
endif
if i1 > 9 then // single [+]
set bonus = bonus + (i1-9)
elseif i1 > 0 then // single [-]
set bonus = bonus - i1
endif
return bonus
endfunction
//------------------------------
private function Init takes nothing returns nothing
local unit u = CreateUnit(Player(15), 'hpea', 0, 0, 0)
call UnitAddAbility(u, BonusAbility001)
call UnitAddAbility(u, BonusAbility010)
call UnitAddAbility(u, BonusAbility100)
call RemoveUnit(u)
set u=null
endfunction
endlibrary
//-----------------------------------------------------------------------------