HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

check if ability is on cooldown

09-21-2009, 04:15 PM#1
Tot
how to check if an units ability is on cooldown (do only need a boolean value)?

btw
how to change a units color/size for only one player (like illusions)?
09-22-2009, 03:36 AM#2
fX_
tried this in WE. you can detect cd by trying to issue the order of the ability *WHEN ALL OTHER FACTORS PERMITTING THE CASTING OF THE ABILITY BESIDES COOLDOWN ARE OK*:
Collapse JASS:
scope Test2 initializer Run

    globals
    private unit u
    endglobals

    private function aaa takes nothing returns nothing
        call SetUnitState(u, UNIT_STATE_MANA, GetUnitState(u, UNIT_STATE_MAX_MANA))
        if IssueImmediateOrder(u, "fanofknives") then
            call BJDebugMsg("Fan of knives ordering")
        else
            call BJDebugMsg("Fan of knives not ordering")
        endif
    endfunction

    private function Run takes nothing returns nothing
        set u = CreateUnit(Player(0), 'Hpal',0,0,0)
        call UnitAddAbility(u, 'AEfk')
        call SetUnitAbilityLevel(u, 'AEfk', 3)
        call TimerStart(CreateTimer(), 0.50, true, function aaa)
    endfunction

endscope

edit: so, assuming the condition above (all caps): for immediate abilities just issue the order (IssueImmediateOrder);
for point abilities maybe just order the unit to cast the spell at a point some distance in front of it (min cast range (if there is any)<distnace<cast range);
for unit/item/destructable target abilities maybe make an invisible dummy (that can be targeted by the ability) in front of the caster and order the latter to cast the spell on the former. also note there are special spells with special requirements to be casted - these requirements must be satisfied (see all caps above). eg Raise/Animate Dead requires that there are nearby corpses; etc.
then refer to the boolean from issuing the order (Issue-Immediate/Point/Target-Order takes stuff returns boolean).
then make the caster stop casting the spell after you get the boolean. maybe use the LastOrder by either anitarf/rising_dusk (i always mix up those two) library somewhere in this site.

====================================================================================================
to change unit color stuff for a player you can use GetLocalPlayer():
Collapse JASS:
if GetLocalPlayer() == playerIWantToChangeColorFor then
call SetUnitVertexColor(etc) //change color
call SetUnitScale ??? // size
endif
09-22-2009, 05:14 PM#3
Tot
Quote:
Originally Posted by fX_
to change unit color stuff for a player you can use GetLocalPlayer():
Collapse JASS:
if GetLocalPlayer() == playerIWantToChangeColorFor then
call SetUnitVertexColor(etc) //change color
call SetUnitScale ??? // size
endif

but you dont give the player you want to change to the change color/sizte function, so why does he know which player to affect?
09-22-2009, 07:12 PM#4
Storyyeller
They don't, but the functions are only called for the player you want anyway.
09-22-2009, 07:26 PM#5
Tot
its always better to read AND use your brain

thx storyyeller, i've overread GetLocalPlayer()/didn't get what it is
09-23-2009, 03:44 AM#6
DioD
read moar and divine brilliance will clarify your soul with knowlege of GetLocalPlayer() usage!!!

GetLocalPlayer() is local player, no more no less, if local player 1 its machine of player 1
09-24-2009, 07:52 AM#7
Quillraven
wonder if u can use the issueorder functions for this. they return boolean, if the order you are given is doable for the unit or not. so maybe if u order the unit to cast f.e. flamestrike on its position and the function returns false, the abilit still has cooldown.

just a short idea :)
09-24-2009, 08:50 AM#8
Anitarf
The problem I see is that you'd need some sort of a database to know what are the valid targets for each ability so you can issue the order properly, if you have to do that you might as well store the ability cooldowns to that database instead and then simply use a timer whenever an ability is cast that waits until that ability's cooldown finishes.
09-24-2009, 11:21 AM#9
Tot
Quote:
Originally Posted by Anitarf
The problem I see is that you'd need some sort of a database to know what are the valid targets for each ability so you can issue the order properly, if you have to do that you might as well store the ability cooldowns to that database instead and then simply use a timer whenever an ability is cast that waits until that ability's cooldown finishes.


why not issue all possible orders and check if one of these is true?

Under the condition that Qillraven is right
09-24-2009, 01:16 PM#10
Anitarf
Quote:
Originally Posted by Tot
why not issue all possible orders and check if one of these is true?
Because you need to also take into account that target spells could only work against either friendly or enemy targets, mechanical or organic not to mention custom maps could use other classifications such as ancient or suicidal to further sort the allowed targets of some spells. In addition to that, you must then bother with cancelling the order and restoring the original order.
09-24-2009, 01:58 PM#11
Rising_Dusk
A better solution is to just run a timer when the unit casts your desired spell. If the timer is running, then it is on cooldown, otherwise it is not. You will need to hardcode in the duration of the cooldown to the timer, however, but this is still the cleanest solution.

Anyways, Anitarf is right, don't use the order method. It sucks and there are so many ways it can falter it's not even funny. Furthermore, even if you get the order right, then you have to go to the trouble of canceling it. Even worse, what if you have two spells on your hero and you get the wrong one right? Now you have a false positive, unless you've associated orderids to raw codes and well, that is way too much hardcoding for anyone to do.
09-24-2009, 03:42 PM#12
Tot
Quote:
Originally Posted by Rising_Dusk
A better solution is to just run a timer when the unit casts your desired spell. If the timer is running, then it is on cooldown, otherwise it is not. You will need to hardcode in the duration of the cooldown to the timer, however, but this is still the cleanest solution.

Anyways, Anitarf is right, don't use the order method. It sucks and there are so many ways it can falter it's not even funny. Furthermore, even if you get the order right, then you have to go to the trouble of canceling it. Even worse, what if you have two spells on your hero and you get the wrong one right? Now you have a false positive, unless you've associated orderids to raw codes and well, that is way too much hardcoding for anyone to do.

Quote:
Originally Posted by Marge Simpson
HRMM.....