Spell description:
The earthfather links to a unit through nature taking 70% of the damage the unit receives whilst linked.
What happens:
Things to do:
If anyone can help me out with this spell whether it be editing the code for me or pointing out what's going wrong would be a great help.
The earthfather links to a unit through nature taking 70% of the damage the unit receives whilst linked.
JASS:
globals
unit Earthfather = GetSpellAbilityUnit()
unit G_Unit = GetSpellTargetUnit()
boolean G_Protect = false
// local buff G_Buff
lightning G_Effect
location G_Start = GetUnitLoc(Earthfather)
location G_Finish = GetSpellTargetUnit()
endglobals
function GuardianJ_Conditions takes nothing returns boolean
if ( not ( 'A007' == GetSpellAbilityId() ) ) then
return false
endif
return true
endfunction
function GuardianJ_Actions takes nothing returns nothing
if ( IsUnitAliveBJ(G_Unit) == true ) then
// For testing
call DisplayTextToForce( GetPlayersAll(), "Spell Reset" )
// Disable current casting
set G_Protect = false
call DestroyLightningBJ( G_Effect )
set G_Effect = null
call UnitRemoveBuffBJ( 'B002', G_Unit )
// Set current casting
call AddLightningLoc( "DRAL", G_Start, G_Finish )
set G_Effect = GetLastCreatedLightningBJ()
else
call DisplayTextToForce(GetPlayersAll(), "First time cast")
call AddLightningLoc( "DRAL", G_Start, G_Finish )
set G_Effect = GetLastCreatedLightningBJ()
endif
endfunction
function GuardianP_Conditions takes nothing returns boolean
if ( not ( GetAttackedUnitBJ() == G_Unit ) ) then
return false
endif
if ( not ( IsUnitEnemy(GetAttacker(), GetOwningPlayer(GetAttackedUnitBJ())) == true ) ) then
return false
endif
if ( not ( UnitHasBuffBJ(GetAttackedUnitBJ(), 'B002') == true ) ) then
return false
endif
return true
endfunction
function GuardianP_Actions takes nothing returns nothing
call SetUnitLifeBJ( G_Unit, ( GetUnitStateSwap(UNIT_STATE_LIFE, G_Unit) + ( GetEventDamage() * 0.70 ) ) )
call UnitDamageTargetBJ( GetEventDamageSource(), Earthfather, ( GetEventDamage() * 0.70 ), ATTACK_TYPE_MELEE, DAMAGE_TYPE_NORMAL )
endfunction
function GuardianE_Conditions takes nothing returns boolean
if ( not ( UnitHasBuffBJ(G_Unit, 'B002') == true ) ) then
return false
endif
return true
endfunction
function GuardianE_Actions takes nothing returns nothing
call MoveLightningLoc(G_Effect, G_Start, G_Finish)
endfunction
//===========================================================================
function InitTrig_GuardianJass takes nothing returns nothing
local trigger GuardianJass = CreateTrigger( )
local trigger GuardianProtect = CreateTrigger( )
local trigger GuardianEffect = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( GuardianJass, EVENT_PLAYER_UNIT_SPELL_CAST )
call TriggerAddCondition( GuardianJass, Condition( function GuardianJ_Conditions ) )
call TriggerAddAction( GuardianJass, function GuardianJ_Actions )
call TriggerRegisterUnitEvent( GuardianProtect, G_Unit, EVENT_UNIT_DAMAGED )
call TriggerAddCondition( GuardianProtect, Condition( function GuardianP_Conditions ) )
call TriggerAddAction( GuardianProtect, function GuardianP_Actions )
call TriggerRegisterTimerEventPeriodic( GuardianEffect, 0.01 )
call TriggerAddCondition( GuardianEffect, Condition( function GuardianE_Conditions ) )
call TriggerAddAction( GuardianEffect, function GuardianE_Actions )
endfunction
What happens:
Earthfather casts the spell on a target unit.
Unit has buff effect
Unit does not have a lightning effect linked between it and the Earthfather
Unit takes full damage when attacked (Not ment to happen)
Things to do:
Add a distance that the link will work and will cancel out if too far away
Touch up possible leaks
Improve code if possible
If anyone can help me out with this spell whether it be editing the code for me or pointing out what's going wrong would be a great help.