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:
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 !):
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.
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:
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 039;A000039;
endfunction
constant function abilityBuffRawId takes nothing returns integer
// Replace raw data with your ability buff raw Id. Default is custom Shakra Aura buff.
return 039;B000039;
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.