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

[JASS] Increases attack speed

Status
Not open for further replies.
Level 10
Joined
Jun 20, 2017
Messages
333
Any ideas + Rep

I have these jass (reduce armor system). but I want same system work for increases attack speed and which ability to use properly for it?
JASS:
function Trig_ArmorReduce_Actions takes nothing returns nothing
local unit u
local timer tm
if GetUnitTypeId(GetAttacker()) == 'h01S' || GetUnitTypeId(GetAttacker()) == 'h00F' || GetUnitTypeId(GetAttacker()) == 'h007' then
set u = GetTriggerUnit()
if LoadTimerHandle(Main_Hash,GetHandleId(u),1) == null then
set tm = CreateTimer()
call SaveTimerHandle(Main_Hash,GetHandleId(u),1,tm)
call SaveUnitHandle(Main_Hash, GetHandleId(tm), 2, u)
call TriggerRegisterUnitEvent( gg_trg_Dynamic, u, EVENT_UNIT_DAMAGED )
endif
endif
set u = null
set tm = null
endfunction

function InitTrig_ArmorReduce takes nothing returns nothing
set gg_trg_ArmorReduce = CreateTrigger(  )
call TriggerRegisterAnyUnitEventBJ( gg_trg_ArmorReduce, EVENT_PLAYER_UNIT_ATTACKED )
call TriggerAddAction( gg_trg_ArmorReduce, function Trig_ArmorReduce_Actions )
endfunction

JASS:
define
B_REDUCE_PER_HIT = 1
HB_REDUCE_PER_HIT = 2
enddefine

function RemoveArmorEffect takes unit u returns nothing
local integer i = 0
loop
exitwhen i > 11
call UnitRemoveAbility(u, ReduceArmor[i])
set i = i + 1
endloop                                   
set u = null
endfunction

function RemoveArmorEffect2 takes nothing returns nothing
call RemoveArmorEffect(LoadUnitHandle(Main_Hash, GetHandleId(GetExpiredTimer()), 2))
call SaveInteger(Main_Hash, GetHandleId(GetExpiredTimer()), 3, 0)
endfunction

function Trig_Dynamic_Actions takes nothing returns nothing
local integer ReduceLocal = 0
local unit u = GetTriggerUnit()
local unit ds = GetEventDamageSource()
local integer reslvl = GetPlayerTechCount(GetOwningPlayer(ds), 'R010', true)
local timer tm
if (GetUnitTypeId(ds) == 'h01S') or (GetUnitTypeId(ds) == 'h00F') or (GetUnitTypeId(ds) == 'h007') then
call RemoveArmorEffect(u)
set tm = LoadTimerHandle(Main_Hash,GetHandleId(u),1)
set ReduceLocal = LoadInteger(Main_Hash, GetHandleId(tm), 3)
if ReduceLocal == 0
if reslvl == 0 || reslvl == 1
ReduceLocal = 0
elseif reslvl == 2
ReduceLocal = 0
endif
endif
if (GetUnitTypeId(ds) == 'h007') or (reslvl == 2) then
call SaveInteger(Main_Hash, GetHandleId(tm), 3, ReduceLocal + HB_REDUCE_PER_HIT)
elseif GetUnitTypeId(ds) == 'h00F' then
call SaveInteger(Main_Hash, GetHandleId(tm), 3, ReduceLocal + HB_REDUCE_PER_HIT)
elseif GetUnitTypeId(ds) == 'h01S' then
call SaveInteger(Main_Hash, GetHandleId(tm), 3, ReduceLocal + B_REDUCE_PER_HIT)
endif
if ReduceLocal >= 2048 then
call UnitAddAbility(u,ReduceArmor[11])
set ReduceLocal = ReduceLocal - 2048
endif
if ReduceLocal >= 1024 then
call UnitAddAbility(u,ReduceArmor[10])
set ReduceLocal = ReduceLocal - 1024
endif
if ReduceLocal >= 512 then
call UnitAddAbility(u,ReduceArmor[9])
set ReduceLocal = ReduceLocal - 512
endif
if ReduceLocal >= 256 then
call UnitAddAbility(u,ReduceArmor[8])
set ReduceLocal = ReduceLocal - 256
endif
if ReduceLocal >= 128 then
call UnitAddAbility(u,ReduceArmor[7])
set ReduceLocal = ReduceLocal - 128
endif
if ReduceLocal >= 64 then
call UnitAddAbility(u,ReduceArmor[6])
set ReduceLocal = ReduceLocal - 64
endif
if ReduceLocal >= 32 then
call UnitAddAbility(u,ReduceArmor[5])
set ReduceLocal = ReduceLocal - 32
endif
if ReduceLocal >= 16 then
call UnitAddAbility(u,ReduceArmor[4])
set ReduceLocal = ReduceLocal - 16
endif
if ReduceLocal >= 8 then
call UnitAddAbility(u,ReduceArmor[3])
set ReduceLocal = ReduceLocal - 8
endif
if ReduceLocal >= 4 then
call UnitAddAbility(u,ReduceArmor[2])
set ReduceLocal = ReduceLocal - 4
endif
if ReduceLocal >= 2 then
call UnitAddAbility(u,ReduceArmor[1])
set ReduceLocal = ReduceLocal - 2
endif
if ReduceLocal >= 1 then
call UnitAddAbility(u,ReduceArmor[0])
set ReduceLocal = ReduceLocal - 1
endif
call TimerStart(tm, 5.00, false, function RemoveArmorEffect2)
endif
set u = null
set ds = null
set tm = null
endfunction

function InitTrig_Dynamic takes nothing returns nothing
set gg_trg_Dynamic = CreateTrigger(  )
call TriggerAddAction( gg_trg_Dynamic, function Trig_Dynamic_Actions )
endfunction

JASS:
globals
hashtable Main_Hash
integer array ReduceArmor
endglobals

function Trig_Loading_Actions takes nothing returns nothing
local integer i = 0
set Main_Hash = InitHashtable()

set ReduceArmor[0] = 'A01U'
set ReduceArmor[1] = 'A02Q'
set ReduceArmor[2] = 'A01W'
set ReduceArmor[3] = 'A030'
set ReduceArmor[4] = 'A02Z'
set ReduceArmor[5] = 'A022'
set ReduceArmor[6] = 'A01R'
set ReduceArmor[7] = 'A01C'
set ReduceArmor[8] = 'A01E'
set ReduceArmor[9] = 'A01D'
set ReduceArmor[10] = 'A02Y'
set ReduceArmor[11] = 'A00W'
endfunction

function InitTrig_Loading takes nothing returns nothing
set gg_trg_Loading = CreateTrigger(  )
call TriggerAddAction( gg_trg_Loading, function Trig_Loading_Actions )
endfunction
 
Last edited:
Level 10
Joined
Jun 20, 2017
Messages
333
So I have these three different systems, but how do I put it into the tower?
example Reduce Armor; tower1 -1armor per hit * tower2 -2armor per hit * tower3 -3 armor per hit, and increases with the system.
example Attack Speed; tower add 10% attack speed per hit.
example Health; each upgrade tower adds +6 regeneration per second to unit and using command -bonus to check current value.
JASS:
library BonusStats initializer SetValues requires Misc
globals
private integer array BonusAbility
constant integer AttackSpeed_a = 0
constant integer AttackSpeed_b = 12
constant integer Armor_a = 13
constant integer Armor_b = 25
constant integer Health_a = 26
constant integer Health_b = 41
endglobals

//! textmacro ChangeUnitStats takes NAME_ADD, CONST, NAME_REMOVE, REDUCTION_VALUE
function $NAME_ADD$ takes unit u, integer amount returns nothing
local integer i = 0
local boolean a = amount < 0
if a then
set amount = $REDUCTION_VALUE$ + amount
endif
loop
exitwhen amount == 0 or i == $CONST$_b
if amount - (amount/2)*2 == 1 then
call UnitAddAbility(u, BonusAbility[$CONST$_a + i])
endif
set amount = amount/2
set i = i + 1
endloop
if a then
call UnitAddAbility(u, BonusAbility[$CONST$_b])
call UnitMakeAbilityPermanent(u, true, BonusAbility[$CONST$_b])
endif
endfunction

function $NAME_REMOVE$ takes unit u returns nothing
local integer i = $CONST$_b
loop
exitwhen i < $CONST$_a
call UnitRemoveAbility(u, BonusAbility[i])
set i = i - 1
endloop
endfunction

//! endtextmacro
//! runtextmacro ChangeUnitStats("UnitAddDamage","damage","RemoveBonusDamage","4096")
//! runtextmacro ChangeUnitStats("UnitAddArmor","armor","RemoveBonusArmor","4096")
//! runtextmacro ChangeUnitStats("UnitAddHealth","health","RemoveBonusHealth","32768")

private function SetValues takes nothing returns nothing
// Attack Speed
//set BonusAbility[0] = 'A05H' //1
//set BonusAbility[1] = 'A05I' //2
//set BonusAbility[2] = 'A05J' //4
//set BonusAbility[3] = 'A05K' //8
//set BonusAbility[4] = 'A05L' //16
//set BonusAbility[5] = 'A05M' //32
//set BonusAbility[6] = 'A05N' //64
//set BonusAbility[7] = 'A05O' //128
//set BonusAbility[8] = 'A05P' //256
//set BonusAbility[9] = 'A05Q' //516
//set BonusAbility[10] = 'A05R' //1024
//set BonusAbility[11] = 'A05S' //2048
//set BonusAbility[12] = 'A07G' //-4096
// Armor
set BonusAbility[13] = 'A01U' //-0001
set BonusAbility[14] = 'A02Q' //-0002
set BonusAbility[15] = 'A01W' //-0004
set BonusAbility[16] = 'A030' //-0008
set BonusAbility[17] = 'A02Z' //-0016
set BonusAbility[18] = 'A022' //-0032
set BonusAbility[19] = 'A01R' //-0064
set BonusAbility[20] = 'A01C' //-0128
set BonusAbility[21] = 'A01E' //-0256
set BonusAbility[22] = 'A01D' //-0516
set BonusAbility[23] = 'A02Y' //-1024
set BonusAbility[24] = 'A00W' //-2048
set BonusAbility[25] = 'A00F' //-4096
// Health
set BonusAbility[26] = 'A065' //1
set BonusAbility[27] = 'A066' //2
set BonusAbility[28] = 'A067' //4
set BonusAbility[29] = 'A068' //8
set BonusAbility[30] = 'A069' //16
set BonusAbility[31] = 'A06A' //32
set BonusAbility[32] = 'A06B' //64
set BonusAbility[33] = 'A06C' //128
set BonusAbility[34] = 'A06D' //256
set BonusAbility[35] = 'A06E' //516
set BonusAbility[36] = 'A06F' //1024
set BonusAbility[37] = 'A06G' //2048
set BonusAbility[38] = 'A06H' //4096
set BonusAbility[39] = 'A06I' //8192
set BonusAbility[40] = 'A06J' //16384
set BonusAbility[41] = 'A07H' //-32768
endlibrary
 
Last edited:

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,199
Just in case you were not aware, attack speed has both a minimum and maximum cap of -80% and +400% respectively. One can work around this limit using the recently added attack speed setting native. There is an absolute maximum of 50 attacks per second.

Likewise armor has a minimum cap, past which less armor has no effect. I think it was -20 armor, but honestly I am not sure.
 
Status
Not open for further replies.
Top