Rheias
New Helper (I got over 2000 posts)
- Reaction score
- 232
Version 1.2. - Further leak cleaning.
A very simple spell, the hero casts the spell on a target enemy, once it does all damage it will deal to the hero will be stored. Once the caster casts the spell on himself he will teleport to the unit's current location and deal it 75 / 150 / 215 percent of the damage it dealt to him.
Almost everything in the ability can be modified easily so it would fit your needs the best. Requires NewGen pack. Completely MUI, no leaks, no bugs, etc. Importing instructions in the map.
The ability uses the hero's custom value, keep that in mind.
The code is short and simple, makes it easy for people who are just learning vJass to understand it and learn from it. Everything is stored on a sturct which is stored on a unit. It is stored in it's User Data (custom value), so no special systems are needed.
Have fun with it.
A very simple spell, the hero casts the spell on a target enemy, once it does all damage it will deal to the hero will be stored. Once the caster casts the spell on himself he will teleport to the unit's current location and deal it 75 / 150 / 215 percent of the damage it dealt to him.
Almost everything in the ability can be modified easily so it would fit your needs the best. Requires NewGen pack. Completely MUI, no leaks, no bugs, etc. Importing instructions in the map.
The ability uses the hero's custom value, keep that in mind.
The code is short and simple, makes it easy for people who are just learning vJass to understand it and learn from it. Everything is stored on a sturct which is stored on a unit. It is stored in it's User Data (custom value), so no special systems are needed.
JASS:
// ********
// * V1.2 *
// ********
scope Rememberance
struct PS
unit target
real damage = 0.
integer lvl = 0
trigger ex
endstruct
globals
private integer spellId = 039;A000039; // The spell's Id in your map. MODIFY THIS
private real multi = .75 // multi * level will return the percentage of the damage that will be dealt to the target
private string animation = "spell" // Unit's animation when casting the spell
private string effectInSource = "Abilities\\Spells\\NightElf\\Blink\\BlinkCaster.mdl" // Effect in the source location
private string effectInDes = "Abilities\\Spells\\NightElf\\Blink\\BlinkTarget.mdl" // Effect on the target's location
private string effectOnTarget = "Abilities\\Spells\\Human\\Polymorph\\PolyMorphDoneGround.mdl" // Effect casted on the target
endglobals
private function ex_Conditions takes nothing returns boolean
local PS data = GetUnitUserData(GetTriggerUnit())
if GetEventDamageSource() == data.target then
call ExecuteFunc(SCOPE_PRIVATE +"ex_Actions")
endif
return false
endfunction
private function ex_Actions takes nothing returns nothing
local PS data = GetUnitUserData(GetTriggerUnit())
local integer lvl = data.lvl
local trigger ex = data.ex
local real damage = GetEventDamage() + data.damage
call data.destroy()
set data = PS.create()
set data.damage = damage
set data.target = GetEventDamageSource()
set data.lvl = lvl
set data.ex = ex
call SetUnitUserData(GetTriggerUnit(),data)
set ex = null
endfunction
private function Conditions takes nothing returns boolean
return GetSpellAbilityId() == spellId
endfunction
private function Actions takes nothing returns nothing
local unit c = GetTriggerUnit()
local unit tar = GetSpellTargetUnit()
local trigger ex
local integer lvl = GetUnitAbilityLevel(c,spellId)
local PS data
local real x
local real y
local integer ud = GetUnitUserData(c)
if tar != c then
if ud != 0 then
call PS.destroy(GetUnitUserData(c))
endif
set ex = CreateTrigger()
set data = PS.create()
set data.target = tar
set data.lvl = lvl
set data.ex = ex
call SetUnitUserData(c,data)
call TriggerRegisterUnitEvent(ex,c, EVENT_UNIT_DAMAGED)
call TriggerAddCondition(ex,Condition(function ex_Conditions))
set c = null
set tar = null
set ex = null
return
endif
if ud != 0 then
set data = GetUnitUserData(c)
call DisableTrigger(data.ex)
call DestroyTrigger(data.ex)
set x = GetUnitX(c)
set y = GetUnitY(c)
call DestroyEffect(AddSpecialEffect(effectInSource,x,y))
set x = GetUnitX(data.target)
set y = GetUnitY(data.target)
call SetUnitPosition(c,x,y)
call DestroyEffect(AddSpecialEffect(effectInDes,x,y))
call DestroyEffect(AddSpecialEffectTarget(effectOnTarget,data.target,"chest"))
call SetUnitAnimation(c,animation)
call UnitDamageTarget(c,data.target,data.damage * multi * data.lvl,true,false,ATTACK_TYPE_MAGIC,DAMAGE_TYPE_MAGIC,WEAPON_TYPE_WHOKNOWS)
call data.destroy()
endif
set c = null
set tar = null
endfunction
//===========================================================================
public function InitTrig takes nothing returns nothing
set gg_trg_Rememberance = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Rememberance, EVENT_PLAYER_UNIT_SPELL_EFFECT )
call TriggerAddCondition( gg_trg_Rememberance, Condition( function Conditions ) )
call TriggerAddAction( gg_trg_Rememberance, function Actions )
endfunction
endscope
Have fun with it.