• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Ability Charges

Status
Not open for further replies.
Level 10
Joined
Mar 17, 2012
Messages
582
Hello guys! Today i was wondering how to make ability to have charges, like items have? For example how to make ability Goblin Land Mine to have 5 mines to be placet without cooldown and then to have cooldown one by one? :vw_wtf:
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
I can suggest you a Workaround...

an Enabled Mine ability, and Disabled Mine ability. Each Mine charge has it's own cooldown, and when charges are depleted the ability is replaced with a Disabled Mine ability.

<< EDIT >> First time I do something like this :p. This script/map works for one unit only, but you can use the same logic to base the charges off Unit Custom Value (If you use Unit Indexer) or a Hashtable (Using Unit Handle Id) to make it MUI.

Feel Free to ask about anything.

JASS:
globals
    hashtable H = InitHashtable()
    integer Charges = 5
endglobals

function Trig_Mine_Count_Conditions takes nothing returns boolean
    return GetUnitTypeId(GetTriggerUnit()) == 'nglm'
endfunction

function TimerMines takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local unit u = LoadUnitHandle(H, GetHandleId(t), 0)
    
    set Charges = Charges+1
    if Charges == 1 then
        call UnitRemoveAbility(u, 'A001') // Remove Disabled Mines
        call UnitAddAbility(u, 'A000') // Add Enabled Mines
    endif
    
    call PauseTimer(t)
    call FlushChildHashtable(H, GetHandleId(t))
    call DestroyTimer(t)
    set t = null
    set u = null
    
    call BJDebugMsg("Timer Expired. Your charges increases to |cffff0000" + I2S(Charges) + "|r")
    
endfunction

function Trig_Mine_Count_Actions takes nothing returns nothing
    local unit u = GetSummoningUnit()
    local timer t = CreateTimer()
    local real Cooldown = 15
    
    set Charges = Charges-1 // Reduce Charges
    
    call TimerStart(t, Cooldown, false, function TimerMines) // Start Timer
    call SaveUnitHandle(H, GetHandleId(t), 0, u)
    
    if Charges == 0 then
        call TriggerSleepAction(0.0) // Allow Finishing Casting Animation
        call UnitRemoveAbility(u, 'A000') // Remove Enabled Mines
        call UnitAddAbility(u, 'A001') // Add Disabled Mines    
    endif
    
    set u = null
    set t = null
    
    call BJDebugMsg("|cffff0000" + I2S(Charges) + "|r Charges remaining")
    
endfunction

//===========================================================================
function InitTrig_Mine_Count takes nothing returns nothing
    set gg_trg_Mine_Count = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Mine_Count, EVENT_PLAYER_UNIT_SUMMON )
    call TriggerAddCondition( gg_trg_Mine_Count, Condition( function Trig_Mine_Count_Conditions ) )
    call TriggerAddAction( gg_trg_Mine_Count, function Trig_Mine_Count_Actions )
endfunction
 

Attachments

  • Mine Charges.w3x
    17.5 KB · Views: 91
Last edited:
Level 20
Joined
Jul 14, 2011
Messages
3,213
In GUI it's actually harder, heavier, and slower. This is pretty simple in JASS. I suggest you ask any question you have in order to understand this simple JASS script. Understanding would be easier than doing this in GUI :p

What the script basically does is Create a Timer with the Cooldown duration, and reduce charges by 1. When the timer expires, it increases the Charges by 1. If Charges reaches 0, the Enabled Ability is replaced with the Disabled Ability, when Charges goes over 0, the Disabled Ability is replaced with the Enabled Ability. That's all.
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
You need JNPG. It uses some features only JNPG supports.

Post a screenshot of the errors, they're probably due to different names, and different abilities.

You have to replace 'A000' with the Raw ID of your enabled Mines, and 'A001' with the Raw ID of your Disabled mines.

You also have to name your trigger "Mine Count" (at least unless you know what to modify in the script to make it work with another name)

You also have to replace 'nglm' with the Raw ID of the Unit-Type of Mine you're summoning.
 
Level 10
Joined
Mar 17, 2012
Messages
582
You need JNPG. It uses some features only JNPG supports.

Post a screenshot of the errors, they're probably due to different names, and different abilities.

You have to replace 'A000' with the Raw ID of your enabled Mines, and 'A001' with the Raw ID of your Disabled mines.

You also have to name your trigger "Mine Count" (at least unless you know what to modify in the script to make it work with another name)

You also have to replace 'nglm' with the Raw ID of the Unit-Type of Mine you're summoning.

I downloadede your Mine Charges.w3x sample, but it gave me a lot of errors)) I didn't place it to my map)) Nameless.jpg
 
Level 10
Joined
Mar 17, 2012
Messages
582
Level 20
Joined
Jul 14, 2011
Messages
3,213
Not at all. It's perfectly safe. It just adds features and improvements.

The only downside is not being able to select Key(Handle) on GUI. The list just doesn't show up. That's a Hashtable thing, but working Hashtables with Custom scripts is even easier than GUI :p
 
Level 10
Joined
Mar 17, 2012
Messages
582
Not at all. It's perfectly safe. It just adds features and improvements.

The only downside is not being able to select Key(Handle) on GUI. The list just doesn't show up. That's a Hashtable thing, but working Hashtables with Custom scripts is even easier than GUI :p

I was allways wondering... Can i make a dummy to cast a new created spell? or it can use only constant spells like "NightElf - Warden - Fan of Knives" e.t.c? :ogre_icwydt:
 
Level 10
Joined
Mar 17, 2012
Messages
582
You order him to use the base ability and he will use the custom one...

like if your base spell was stormbolt and named ZIGORBOLT, you will order the dummy to cast stormbolt and he will cast ZIGORBOLT...

about the viruses, its totally safe, it's just your antivirus running amok because of the method on how some of JNGP's parts works...

btw, that is not the latest JNGP anymore... moyack already uploaded quite some time ago maybe months ago, jngp 1.5e on his website... it's also already equipped with the two "latest" jass helpers so no need for extra downloads
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
Thank's a lot for that tip! And sorry for forgotting about that "virus" thing. It's safe, as Adiktuz said. And, yes, you can use a dummy, but creating units also creates permanent leaks, and is slower.
 
Level 10
Joined
Mar 17, 2012
Messages
582
You order him to use the base ability and he will use the custom one...

like if your base spell was stormbolt and named ZIGORBOLT, you will order the dummy to cast stormbolt and he will cast ZIGORBOLT...

You mean if I'll create new Storm Bolt and name him ZIGORBOLT, give it to my dummy and order to cast Storm Bolt - it will cast ZIGORBOLT instead?
Or is it have to be original spell???:ogre_icwydt:
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
Yes, it will cast ZIGORBOLT instead. It doesn't have to be the original spell.

Any custom ability can be casted by ordering the unit to cast the original ability the custom one is based on.
 
Status
Not open for further replies.
Top