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

Get accurate attack cooldown?

Status
Not open for further replies.

Antares

Spell Reviewer
Level 21
Joined
Dec 13, 2009
Messages
508
Hello,

I'm trying to find a way to get a unit's attack cooldown, including all buffs, items, and agility bonuses. The function added with the new natives "BlzGetUnitAttackCooldown" seems to only return the value set in the Cooldown Time field. It does the same thing as
JASS:
BlzGetUnitWeaponRealField(whichUnit , UNIT_WEAPON_RF_ATTACK_BASE_COOLDOWN , 0)
so I don't really see the point of this function. If there's no native for it or an easy way to get it, I might have to brute-force it by checking all items and buffs that grant attack speed.

I'm trying to calculate the attack delay of a unit, so that I can trigger something exactly on the projectile launch of the attack. If there's an easy way to do that with the new natives, this would be redundant, although I will probably still need the accurate attack cooldown for other systems later.

Thanks!
 

Antares

Spell Reviewer
Level 21
Joined
Dec 13, 2009
Messages
508
JASS:
BlzGetUnitWeaponRealField(whichUnit , UNIT_WEAPON_RF_ATTACK_DAMAGE_POINT , 0) / GetUnitAttackSpeedBonus(whichUnit)
gives a very accurate delay from EVENT_UNIT_TARGET_IN_RANGE to projectile launch. I don't know how turn rate is supposed to factor into this. I just need the function GetUnitAttackSpeedBonus to return an accurate number.

I would use triggers for projectiles if I were working on a new map. But I want to update a giant, old map and given the amount of work required to change every unit/hero, I'd rather take my chances with brute-forcing the attack speed calculation.
 
JASS:
BlzGetUnitWeaponRealField(whichUnit , UNIT_WEAPON_RF_ATTACK_DAMAGE_POINT , 0) / GetUnitAttackSpeedBonus(whichUnit)
gives a very accurate delay from EVENT_UNIT_TARGET_IN_RANGE to projectile launch. I don't know how turn rate is supposed to factor into this. I just need the function GetUnitAttackSpeedBonus to return an accurate number.

I would use triggers for projectiles if I were working on a new map. But I want to update a giant, old map and given the amount of work required to change every unit/hero, I'd rather take my chances with brute-forcing the attack speed calculation.
I've put every single buff and item in a system so I can ask it for bonus status (I.E "current bonus attack-speed") and add attack-speed from agi to make it work. It's some amount of work, but possible...
 

Antares

Spell Reviewer
Level 21
Joined
Dec 13, 2009
Messages
508
If unit A is in range of unit B but is facing away from B; then, in order to attack B, A must first turn to face B (not 100% directly but close, I'm not familiar with the actual angle range) before A's attack animation begins. This adds additional delay you need to account for.
But EVENT_UNIT_TARGET_IN_RANGE only triggers when the attack animation starts, not when the unit starts turning towards the enemy unit. You can see it in the test map attached (pickup the items to enable the effects). I think this system is pretty good.

I've put every single buff and item in a system so I can ask it for bonus status (I.E "current bonus attack-speed") and add attack-speed from agi to make it work. It's some amount of work, but possible...
Yea, I guess I have to do that. I just found a good way to use the new natives to get item attack speed bonuses. Loop over items in inventory and check whether they have attack speed increase abilities:

JASS:
function GetUnitAttackSpeedBonus takes unit whichUnit returns real
	local integer A = 0
	local integer B
	local real attackSpeedBonus = 0
	local item tempItem
	local integer id
	loop
	exitwhen A > 5
		set tempItem = UnitItemInSlot(whichUnit,A)
		set B = 0
		loop
		exitwhen B > 3
			set id = BlzGetAbilityId(BlzGetItemAbilityByIndex(tempItem,B))
			if id == 'AIsx' then
				set attackSpeedBonus = attackSpeedBonus + 0.5
			endif
			set B = B + 1
		endloop
		set A = A + 1
	endloop
	return (1.0 + attackSpeedBonus + 0.02*GetHeroAgi( whichUnit , true ))
endfunction
 

Attachments

  • AttackTest.w3m
    21.3 KB · Views: 15
Last edited:
Level 39
Joined
Feb 27, 2007
Messages
5,016
But EVENT_UNIT_TARGET_IN_RANGE only triggers when the attack animation starts, not when the unit starts turning towards the enemy unit. You can see it in the test map attached (pickup the items to enable the effects). I think this system is pretty good.
That event triggers when units come within range of each other; it has nothing to do with attacks. It works for allied units too and is entirely about crossing that range threshold. I have no idea what you're talking about because your test map doesn't show it to work that way either....

With any of the items on the Archmage, I can walk up to the peasant and attack (it plays the animation immediately)... and then no projectile appears for a good 1.5 seconds. Suddenly a projectile fires, thunderclaps appear, and the blink effect shows temporarily, all way after the attack went out. This is the same for coming into range of the peasant from far away, using attack move, automatically acquiring the target, and being told to attack it explicitly.

I also see no messages appear to inform me of what I'm supposed to be seeing in the test map.
 

Antares

Spell Reviewer
Level 21
Joined
Dec 13, 2009
Messages
508
I must be playing a different game then, because Notices target in range has always triggered for me when a unit begins an attack animation. I just tested it with acquires a target and here the turn animation has to be factored in. I know it's called "Notices target in range" and I've always wondered why it doesn't do what you would expect it to, but it triggers on attack animation.

I put an unreasonably long attack delay on the Archmage's attack so that one can see better whether the effects are triggered synchronously with the projectile being shot. He has a cooldown time of 15 and an animation damage point of 7.5. If you revert those values to default, it should be synced with the attack animation again.

I built this map just in the last couple of hours to test myself. Apologies for not making make it clear what's supposed to happen.
 
Status
Not open for further replies.
Top