Rheias
New Helper (I got over 2000 posts)
- Reaction score
- 232
This is my first spell that I posted here so please be kind with your comments, I'll learn so I'll be better next time.
Version 1.21
Feedbacks are welcomed, thanks.
Version 1.21
The caster will choose a victim, the victim will immediatly flee in terror to random directions. The unit will stop fleeing either after 4 / 8 / 12 seconds or by a random event. Also every 0.4 second the chance that the unit will be damaged will increase. Once the target is damaged the unit will get out of the fleeing sitaution and become stunned for one second before fighting again
JASS:
constant function Fear_EffectID takes nothing returns string
return "Abilities\\Spells\\Undead\\Curse\\CurseTarget.mdl"
endfunction
constant function Fear_Time takes nothing returns real
// The amount of time the spell will last. It is level of the ability * this function (4).
return 4.00
endfunction
constant function Fear_IgnorePercent takes nothing returns real
// The increasement rate of the ignoring percent.
return 2.00
endfunction
constant function Fear_DamagePercent takes nothing returns real
// The increasement rate of the damaging percent.
return 10.00
endfunction
constant function Fear_TurnPercent takes nothing returns real
// The increasement rate of the turning percent.
return 20.00
endfunction
constant function Fear_RunTime takes nothing returns real
// What is the frequency that the timer will run
return 0.4
endfunction
constant function Fear_SpellId takes nothing returns integer
// The spell ID, you should modify this so it will match your map.
return 039;A000039;
endfunction
constant function Fear_DummySpellId takes nothing returns integer
// The dummy spell ID, you should modify this so it will match your map.
return 039;A001039;
endfunction
constant function Fear_Dummy takes nothing returns integer
// The dummy ID, you should modify this so it will match your map.
return 039;h000039;
endfunction
// ============================================================================================== \\
// You should not modify the functions found under this line, they are influnced from the above
// functions.
function Fear_Conditions takes nothing returns boolean
return GetSpellAbilityId() == Fear_SpellId()
endfunction
function Fear_Mover takes nothing returns nothing
local timer mover = GetExpiredTimer()
local unit target = GetHandleUnit(mover,"target")
local real facing = GetHandleReal(mover,"facing")
local location targetLoc = GetUnitLoc(target)
local location goalLoc
set goalLoc = PolarProjectionBJ(targetLoc,GetRectMaxX(GetWorldBounds()),facing)
call IssuePointOrderLoc(target,"move",goalLoc)
call RemoveLocation(goalLoc)
call RemoveLocation(targetLoc)
set goalLoc = null
set target = null
set target = null
set mover = null
endfunction
function Fear_Main takes nothing returns nothing
local timer caller = GetExpiredTimer()
local unit target = GetHandleUnit(caller,"target")
local effect sfx = GetHandleEffect(caller,"sfx")
local real turnPercent = GetHandleReal(caller,"turnPercent") + Fear_TurnPercent()
local real damagePercent = GetHandleReal(caller,"damagePercent") + Fear_DamagePercent()
local real ignorePercent = GetHandleReal(caller,"ignorePercent") + Fear_IgnorePercent()
local real fearTime = GetHandleReal(caller,"fearTime")
local real count = GetHandleReal(caller,"count") + Fear_RunTime()
local integer level = GetHandleInt(caller,"level")
local timer mover = GetHandleTimer(caller,"mover")
local unit dummy
local location targetLoc
if count >= fearTime then
call DestroyEffect(sfx)
call PauseTimer(mover)
call FlushHandleLocals(mover)
call DestroyTimer(mover)
set mover = null
set target = null
set sfx = null
call FlushHandleLocals(caller)
call PauseTimer(caller)
call DestroyTimer(caller)
set caller = null
return
endif
if GetRandomReal(1,100) < ignorePercent then
call DestroyEffect(sfx)
call PauseTimer(mover)
call FlushHandleLocals(mover)
call DestroyTimer(mover)
set mover = null
set target = null
set sfx = null
call FlushHandleLocals(caller)
call PauseTimer(caller)
call DestroyTimer(caller)
set caller = null
return
endif
if GetRandomReal(1,100) < turnPercent then
call SetUnitFacing(target,GetRandomReal(0,360))
call SetHandleReal(mover,"facing",GetUnitFacing(target))
set turnPercent = 0
endif
if GetRandomReal(1,100) < damagePercent then
set targetLoc = GetUnitLoc(target)
set dummy=CreateUnitAtLoc(Player(12),Fear_Dummy(),targetLoc,0)
call UnitAddAbility(target,Fear_DummySpellId())
call SetUnitAbilityLevel(target,Fear_DummySpellId(),level)
call IssueTargetOrder(dummy,"thunderbolt",target)
call UnitApplyTimedLife(dummy,039;BTLF039;,2)
call DestroyEffect(sfx)
call SetUnitOwner(target,Player(12),true)
call DestroyEffect(sfx)
call PauseTimer(mover)
call FlushHandleLocals(mover)
call DestroyTimer(mover)
set mover = null
set target = null
set sfx = null
call FlushHandleLocals(caller)
call PauseTimer(caller)
call DestroyTimer(caller)
set caller = null
endif
call SetHandleReal(caller,"damagePercent",damagePercent)
call SetHandleReal(caller,"turnPercent",turnPercent)
call SetHandleReal(caller,"ignorePercent",ignorePercent)
call SetHandleReal(caller,"count",count)
call RemoveLocation(targetLoc)
set caller = null
set targetLoc = null
set target = null
set sfx = null
set dummy = null
set mover = null
endfunction
function Fear_Actions takes nothing returns nothing
local unit target = GetSpellTargetUnit()
local timer mover = CreateTimer()
local timer caller = CreateTimer()
local effect sfx = AddSpecialEffectTarget(Fear_EffectID(),target,"overhead")
local integer level = GetUnitAbilityLevel(GetTriggerUnit(),Fear_SpellId())
local real fearTime = Fear_Time()*level
local real facing = GetUnitFacing(target)
call SetHandleHandle(caller,"mover",mover)
call SetHandleHandle(caller,"target",target)
call SetHandleHandle(caller,"sfx",sfx)
call SetHandleInt(caller,"level",level)
call SetHandleReal(caller,"fearTime",fearTime)
call SetHandleReal(mover,"facing",facing)
call SetHandleHandle(mover,"target",target)
call TimerStart(caller,Fear_RunTime(),true,function Fear_Main)
call TimerStart(mover,0.004,true,function Fear_Mover)
set target = null
set caller = null
set sfx = null
endfunction
//===========================================================================
function InitTrig_Fear takes nothing returns nothing
set gg_trg_Fear = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(gg_trg_Fear,EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddCondition(gg_trg_Fear,Condition(function Fear_Conditions))
call TriggerAddAction(gg_trg_Fear,function Fear_Actions)
endfunction
Feedbacks are welcomed, thanks.