Spell Shakra Aura

Sooda

Diversity enchants
Reaction score
318
I have finished my first JASS ability ever ! It should be absolutely bug free (Atleast I thought through many cases.) First I started to do it because of somebodys help request in these forums and it evolved into perfectly working JASS triggered Aura. What it does ?
Specs.
Name:Shakra Aura
Description:Turns mana used by ability to health and heals nearby friendly units.
Level 1:Turns 25 % of mana used by ability to health and heals nearby friendly units. Can most heal 50 hp.
Level 2:Turns 50 % of mana used by ability to health and heals nearby friendly units. Can most heal 100 hp.
Level 3:Turns 75 % of mana used by ability to health and heals nearby friendly units. Can most heal 150 hp.
Screenshots:
herocastsabilitywm5.jpg

unitsgethealed2nm5.jpg


Q: How to implement it ?
A:When you copy paste this trigger make sure your new trigger name is "ManaCheckAoE" (Without "" and watch out it' s case sensitive !)

// Replace raw data with your ability raw Id. Default is custom Shakra Aura.
// Replace raw data with your ability buff raw Id. Default is custom Shakra Aura.

Full JASS code ( You can just copy paste this to your map and change ability raw Id and buff Id and it works !):
JASS:
function TempCS_H2I takes handle h returns integer
    // I recommend you to use real CSCache still.
    // This is for example only.
    return h
    return 0
endfunction


constant function abilityRawId takes nothing returns integer
    // Replace raw data with your ability raw Id. Default is custom Shakra Aura.
    return 'A000'
endfunction

constant function abilityBuffRawId takes nothing returns integer
    // Replace raw data with your ability buff raw Id. Default is custom Shakra Aura buff.
    return 'B000'
endfunction

constant function abilityEffect takes nothing returns string
    // Change this path to show different effect on units who gain Hp.
    // Effect should have death animation what can be seen by human eye. Otherwise you can' t see it.
    return "Abilities\\Spells\\Undead\\VampiricAura\\VampiricAuraTarget.mdl"
endfunction


constant function HealLimit takes nothing returns real
    // Limit per level is multiplied with level.
    return 50.
endfunction

function AbilityCon takes nothing returns boolean
    return GetUnitAbilityLevel(GetTriggerUnit(),abilityRawId())!= 0
endfunction

function MatchingUnit takes nothing returns boolean
    // Currently checks does unit is ally of caster and isn' t mechanical and has right buff.
    return IsUnitType(GetFilterUnit(),UNIT_TYPE_MECHANICAL) == false and IsUnitAlly(GetFilterUnit(),GetOwningPlayer(GetTriggerUnit())) == true and GetUnitAbilityLevel(GetFilterUnit(),abilityBuffRawId()) > 0
endfunction

function GettingManaBefore takes nothing returns nothing
    local unit u=GetTriggerUnit()
    local string key=I2S(TempCS_H2I(u))

    // You will have to use now game cache to pull this off.
    // Use CSCache or KaTTana' s or whatever.
    call StoreReal(bj_lastCreatedGameCache,"manaBefore",key,GetUnitState(u,UNIT_STATE_MANA))

    set u=null
endfunction

function ConvertUsedManaToHealth takes nothing returns nothing
    local unit u=GetTriggerUnit()
    local unit TempUnit
    
    local real currentHp=GetUnitState(u,UNIT_STATE_LIFE)
    local real currentMp=GetUnitState(u,UNIT_STATE_MANA)
    local real UnitX=GetUnitX(u)
    local real UnitY=GetUnitY(u)
    local real percent=.25 // Change this value to get higher, lower Mp to Hp conversion (1.00 is 100 %). Default is 0.25 what means 25 % grow per level.
    local real radius=900. // Change this value to get smaller, huger AoE. Default is 900.00 AoE.
    local real HpGain

    // Using H2I bug allows us to retrieve from cache each units mana before because it' s labled with unique Id what gives this bug.
    local string key=I2S(TempCS_H2I(u))
    local real manaBefore=GetStoredReal(bj_lastCreatedGameCache,"manaBefore",key)

    local integer level=GetUnitAbilityLevel(u,abilityRawId())
    local integer n=0
    
    local boolexpr b= Condition ( function MatchingUnit)
    local group g=CreateGroup()

    // Level Check
    loop
    exitwhen n>level
            if n==level then
                set percent=level*percent
            endif
    set n=n+1
    endloop    

    set HpGain=(manaBefore-currentMp)*percent
    // If unit has more mana than before end function or ability didn' t took mana.
    // There is potential enemy abuse when caster gets Mana Burn between effect of ability. That' s why limit check is needed.
    if HpGain<=0 then
        call DestroyBoolExpr(b)
        
        set g=null
        set b=null
        set u=null
        return // Ends function.
    endif
    
    // Limit Check
    if HpGain>level*HealLimit() then
        set HpGain=level*HealLimit()
    endif
    
    call GroupEnumUnitsInRange(g,UnitX,UnitY,radius,b)

    loop
        set TempUnit=null
        set TempUnit=FirstOfGroup(g)
        exitwhen TempUnit==null
            set currentHp=GetUnitState(TempUnit,UNIT_STATE_LIFE)

            call DestroyEffect(AddSpecialEffectTarget(abilityEffect(),TempUnit,"origin"))
            call SetUnitState(TempUnit, UNIT_STATE_LIFE,currentHp+HpGain)
            call GroupRemoveUnit(g,TempUnit)       
    endloop

    call FlushStoredReal(bj_lastCreatedGameCache,"manaBefore",key)
    call DestroyBoolExpr(b)

    set g=null
    set b=null
    set u=null
endfunction

function InitTrig_ManaCheckAoE takes nothing returns nothing
    local trigger ta=CreateTrigger()
    local trigger tb=CreateTrigger()
    
    if bj_lastCreatedGameCache==null then
        set bj_lastCreatedGameCache=InitGameCache("TempCache")
    endif
    
    call TriggerRegisterAnyUnitEventBJ( ta, EVENT_PLAYER_UNIT_SPELL_CAST )
    call TriggerRegisterAnyUnitEventBJ( tb, EVENT_PLAYER_UNIT_SPELL_FINISH )
    call TriggerAddCondition(ta, Condition ( function AbilityCon))
    
    call TriggerAddCondition(tb, Condition ( function AbilityCon))
    call TriggerAddAction(ta, function GettingManaBefore)
    call TriggerAddAction(tb, function ConvertUsedManaToHealth)
endfunction

Demo map is attached under my post.
Feedback always welcomed !

EDIT: Code updated, I have added very detailed README and fixed minor leaks what SFilip pointed out. Have fun making maps or using this ability.
 

Attachments

  • Mp2HpDemoMap.w3x
    25 KB · Views: 348
I

IKilledKEnny

Guest
A little above my level, but I could understand parts of it, good job! +REP. (Once I could).
 

Sooda

Diversity enchants
Reaction score
318
>A little above my level.
Nice, it isn' t so hard like you think. Btw main is the concept :D (Though I got it from another person.) What you all think of it and how does it look "in game". I' m curious.
 
I

IKilledKEnny

Guest
It's ok, a bit minimal in my opinion, though, maybe add Animate Dead's Special Effect on the hero each time the aura shoots? I would look much better in my opinion.
 

Sooda

Diversity enchants
Reaction score
318
>It's ok, a bit minimal in my opinion
1000 thanks you checked it. Still it' s aura.
> though, maybe add Animate Dead's Special Effect on the hero each time the aura shoots? I would look much better in my opinion.
> You have opportunity to do so. It isn' t hard to change effect created on units- nice and simple.
 
I

IKilledKEnny

Guest
>1000 thanks you checked it. Still it' s aura.
No problem, it always nice to see a master at work. :p

> You have opportunity to do so. It isn' t hard to change effect created on units- nice and simple
I guess I could figure it out, but I doubt if few other, newer members, can do it. Maybe add a comment where you can add the special effect if you want to do it? I don't know just a suggestion, your call of course. Either way, again, great job.
 

Ghan

Administrator - Servers are fun
Staff member
Reaction score
889
I like it. It's a nice idea. Though I can't code in JASS to save my life. :p +rep.
 

SFilip

Gone but not forgotten
Reaction score
634
Strings don't need to be set to "".
BoolExprs do need to be set to null. They also need to be destroyed using DestroyBoolExpr before that.

> I recommend you to use real CSCache still.
Then why didn't you use it? People usually don't know what it is, save knowing how to implement it and modify the code where needed.
Of course if you do so mention somewhere that it's needed.
Speaking of which you also need some implementation instructions - people usually don't look at the code that much. Mention which dummy unit/buff you used, how to copy it, what changes need to/can be made etc.
 

Sooda

Diversity enchants
Reaction score
318
Strings don't need to be set to "".
BoolExprs do need to be set to null. They also need to be destroyed using DestroyBoolExpr before that.

> I recommend you to use real CSCache still.
Then why didn't you use it? People usually don't know what it is, save knowing how to implement it and modify the code where needed.
Of course if you do so mention somewhere that it's needed.
Speaking of which you also need some implementation instructions - people usually don't look at the code that much. Mention which dummy unit/buff you used, how to copy it, what changes need to/can be made etc.

Eh constructive criticism, good. I try to fix these flaws asasp and reupload it.

EDIT: Updated and fixed ! It has now easy README included what explanes almost everything what you
could think of. Maybe even too much. Thanks all !
 

Sooda

Diversity enchants
Reaction score
318
>Grats on your first JASS spell... doesnt it make you feel proud?
I' m very proud. It took time and consumed my brains but I finished it.

EDIT: I' m very happy also !
 

lh2705

Just another Helper
Reaction score
111
Hey Sooda, congrats on your first Fully Jass spell :D
Pretty Neat :p
Tho I can barely read it xD
 

Chocobo

White-Flower
Reaction score
409
Code:
function InitTrig_ManaCheckAoE takes nothing returns nothing
    local trigger ta=CreateTrigger()
    local trigger tb=CreateTrigger()
    
    if bj_lastCreatedGameCache==null then
        set bj_lastCreatedGameCache=InitGameCache("TempCache")
    endif
    
    call TriggerRegisterAnyUnitEventBJ( ta, EVENT_PLAYER_UNIT_SPELL_CAST )
    call TriggerRegisterAnyUnitEventBJ( tb, EVENT_PLAYER_UNIT_SPELL_FINISH )
    call TriggerAddCondition(ta, Condition ( function AbilityCon))
    
    call TriggerAddCondition(tb, Condition ( function AbilityCon))
    call TriggerAddAction(ta, function GettingManaBefore)
    call TriggerAddAction(tb, function ConvertUsedManaToHealth)
endfunction

can be :

Code:
function InitTrig_ManaCheckAoE takes nothing returns nothing
    local trigger t=CreateTrigger()
    if bj_lastCreatedGameCache==null then
        set bj_lastCreatedGameCache=InitGameCache("TempCache")
    endif
    call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_SPELL_CAST)
    call TriggerAddCondition(t,Condition(function AbilityCon))
    call TriggerAddAction(t,function GettingManaBefore)
    set t=CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_SPELL_FINISH)
    call TriggerAddCondition(t,Condition(function AbilityCon))
    call TriggerAddAction(t,function ConvertUsedManaToHealth)
    set t=null
endfunction


Code:
    local integer n=0
//[B] = local integer n[/B]


Code:
        set TempUnit=null
        set TempUnit=FirstOfGroup(g)
//[B]set TempUnit=FirstOfGroup(g)[/B]


Also avoid using bj_lastCreatedGameCache, if someone initializes it..


Code:
globals
    gamecache udg_g
endglobals

function TempCS_H2I takes handle h returns integer
    // I recommend you to use real CSCache still.
    // This is for example only.
    return h
    return 0
endfunction

constant function GameCache takes nothing returns gamecache
    //Gamecache
    return udg_g
endfunction

constant function abilityRawId takes nothing returns integer
    // Replace raw data with your ability raw Id. Default is custom Shakra Aura.
    return 'A000'
endfunction

constant function abilityBuffRawId takes nothing returns integer
    // Replace raw data with your ability buff raw Id. Default is custom Shakra Aura buff.
    return 'B000'
endfunction

constant function abilityEffect takes nothing returns string
    // Change this path to show different effect on units who gain Hp.
    // Effect should have death animation what can be seen by human eye. Otherwise you can' t see it.
    return "Abilities\\Spells\\Undead\\VampiricAura\\VampiricAuraTarget.mdl"
endfunction


constant function HealLimit takes nothing returns real
    // Limit per level is multiplied with level.
    return 50.
endfunction

function AbilityCon takes nothing returns boolean
    return GetUnitAbilityLevel(GetTriggerUnit(),abilityRawId())!= 0
endfunction

function MatchingUnit takes nothing returns boolean
    // Currently checks does unit is ally of caster and isn' t mechanical and has right buff.
    return IsUnitType(GetFilterUnit(),UNIT_TYPE_MECHANICAL) == false and IsUnitAlly(GetFilterUnit(),GetOwningPlayer(GetTriggerUnit())) == true and GetUnitAbilityLevel(GetFilterUnit(),abilityBuffRawId()) > 0
endfunction

function GettingManaBefore takes nothing returns nothing
    local unit u=GetTriggerUnit()
    local string key=I2S(TempCS_H2I(u))

    // You will have to use now game cache to pull this off.
    // Use CSCache or KaTTana' s or whatever.
    call StoreReal(GameCache(),"manaBefore",key,GetUnitState(u,UNIT_STATE_MANA))

    set u=null
endfunction

function ConvertUsedManaToHealth takes nothing returns nothing
    local unit u=GetTriggerUnit()
    local unit TempUnit
    
    local real currentHp=GetUnitState(u,ConvertUnitState(0))
    local real currentMp=GetUnitState(u,ConvertUnitState(2))
    local real UnitX=GetUnitX(u)
    local real UnitY=GetUnitY(u)
    local real percent=.25 // Change this value to get higher, lower Mp to Hp conversion (1.00 is 100 %). Default is 0.25 what means 25 % grow per level.
    local real radius=900. // Change this value to get smaller, huger AoE. Default is 900.00 AoE.
    local real HpGain

    // Using H2I bug allows us to retrieve from cache each units mana before because it' s labled with unique Id what gives this bug.
    local string key=I2S(TempCS_H2I(u))
    local real manaBefore=GetStoredReal(GameCache(),"manaBefore",key)

    local integer level=GetUnitAbilityLevel(u,abilityRawId())
    local integer n
    
    local boolexpr b=Condition(function MatchingUnit)
    local group g=CreateGroup()

    // Level Check
    loop
        exitwhen n>level
        if n==level then
            set percent=level*percent
        endif
        set n=n+1
    endloop

    set HpGain=(manaBefore-currentMp)*percent
    // If unit has more mana than before end function or ability didn' t took mana.
    // There is potential enemy abuse when caster gets Mana Burn between effect of ability. That' s why limit check is needed.
    if HpGain<=0 then
        call DestroyBoolExpr(b)
        
        set g=null
        set b=null
        set u=null
        return // Ends function.
    endif
    
    // Limit Check
    if HpGain>level*HealLimit() then
        set HpGain=level*HealLimit()
    endif
    
    call GroupEnumUnitsInRange(g,UnitX,UnitY,radius,b)

    loop
        set TempUnit=FirstOfGroup(g)
        exitwhen TempUnit==null
            set currentHp=GetUnitState(TempUnit,ConvertUnitState(0))

            call DestroyEffect(AddSpecialEffectTarget(abilityEffect(),TempUnit,"origin"))
            call SetUnitState(TempUnit,ConvertUnitState(0),currentHp+HpGain)
            call GroupRemoveUnit(g,TempUnit)
    endloop

    call FlushStoredReal(GameCache(),"manaBefore",key)
    call DestroyBoolExpr(b)

    set g=null
    set b=null
    set u=null
endfunction

function InitTrig_ManaCheckAoE takes nothing returns nothing
    local trigger t=CreateTrigger()
    set udg_g=InitGameCache("TC")
    call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_SPELL_CAST)
    call TriggerAddCondition(t,Condition(function AbilityCon))
    call TriggerAddAction(t,function GettingManaBefore)
    set t=CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_SPELL_FINISH)
    call TriggerAddCondition(t,Condition(function AbilityCon))
    call TriggerAddAction(t,function ConvertUsedManaToHealth)
    set t=null
endfunction

but you will need a global. Useless but only for optimizations.
 

SFilip

Gone but not forgotten
Reaction score
634
> avoid using bj_lastCreatedGameCache
"// This is for example only."

Though I doubt many people know how to change it so that it uses handle vars/CSCache.
I still think you should modify it yourself to make it use CSCache instead.

But anyway approved. Sorry for the wait.
 
B

BOOMER

Guest
Because my knowing nothing about JASS can i ask you something how can i detect mana cost of a cast ability or mana used while doing somehing
 

Sooda

Diversity enchants
Reaction score
318
>Because my knowing nothing about JASS can i ask you something how can i detect mana cost of a cast ability
First you store current mana of triggering unit with event "unit starts casting ability" and then after unit has finished casting ability use event "unit finishes casting ability" and store again current mana. Then do math:
manaBefore- ManaCurrent= ManaUsedByAbility
> or mana used while doing somehing
For that detect when unit starts to channel ability and store current mana. Then use another event "Unit finishes casting ability" and store again current mana and do like before.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top