Moderator
M
Moderator
12 Dec 2011
Bribe: Approved (useful).
Bribe: Approved (useful).
/*=======================Mimic v1.4=========================
============================================================
====================Made by: Mckill2009=====================
============================================================
============================================================
REQUIRES:
- JassNewGenPack by Vexorian
- TimerUtils by Vexorian
HOW TO USE:
- Make a new trigger and convert to custom text via EDIT >>> CONVERT CUSTOM TEXT
- Copy ALL that is written here (overwrite the existing texts in the trigger)
- Copy the Dummy unit and the custom ability OR make your own
- You MUST input or change the correct raw ID's (see below)
- To view raw ID, press CTRL+D in the object editor
FULL DESCRIPTION:
When activated, it gives a chance to mirror a Positive or Negative spell that is casted to the Hero. The mirrored spell is casted back to the caster.
|cffffcc00Level 1|r - Gives 10% chance.
|cffffcc00Level 2|r - Gives 20% chance.
|cffffcc00Level 3|r - Gives 30% chance.
|cffffcc00Level 4|r - Gives 40% chance.
|cffffcc00Level 5|r - Gives 50% chance.
*/
scope Mimic initializer init
globals
private constant hashtable HASH = InitHashtable()
private constant integer SPELL_ID = 'A000' //raw code, change if needed
private constant integer DUMMY_ID = 'e000' //raw code, change if needed
//===Configurables
private constant string BUFF_SFX = "Abilities\\Spells\\Items\\AIda\\AIdaTarget.mdl"
private constant string DUMMY_SFX = "Abilities\\Spells\\Orc\\FeralSpirit\\feralspiritdone.mdl"
endglobals
//===CONFIGURABLES:
private function GetChance takes integer i returns integer
return i * 10
endfunction
private function GetDuration takes integer i returns real
return 30.
endfunction
//===END OF CONFIGURABLES
private function UnitAlive takes unit u returns boolean
return not IsUnitType(u, UNIT_TYPE_DEAD)
endfunction
//target is the hero
private function MirrorSpellNow takes unit caster, unit target, integer abilityid returns nothing
local unit dummy
local real x
local real y
local integer orderid
local integer level = GetUnitAbilityLevel(caster, abilityid)
if GetRandomInt(1, 100) <= GetChance(level) then
set orderid = GetUnitCurrentOrder(caster)
set x = GetUnitX(target)+100*Cos(GetUnitFacing(target)*bj_DEGTORAD)
set y = GetUnitY(target)+100*Sin(GetUnitFacing(target)*bj_DEGTORAD)
call DestroyEffect(AddSpecialEffect(BUFF_SFX, x, y))
set dummy = CreateUnit(GetOwningPlayer(target), DUMMY_ID, x, y, GetUnitFacing(target))
call UnitApplyTimedLife(dummy, 'BTLF', 2.0)
call UnitAddAbility(dummy, abilityid)
call SetUnitAbilityLevel(dummy, abilityid, level)
call IssueTargetOrderById(dummy, orderid, caster)
set dummy = null
endif
endfunction
private function TimerLoop takes nothing returns nothing
local timer t = GetExpiredTimer()
local integer ID = GetTimerData(t)
local real duration = LoadReal(HASH, ID, 2)
if duration > 0 and UnitAlive(LoadUnitHandle(HASH, ID, 1)) then
call SaveReal(HASH, ID, 2, duration - 1)
else
call DestroyEffect(LoadEffectHandle(HASH, ID, 3))
call RemoveSavedInteger(HASH, GetHandleId(LoadUnitHandle(HASH, ID, 1)), 0x4568)
call ReleaseTimer(t)
endif
set t = null
endfunction
private function TimerAction takes unit u returns nothing
local timer t = NewTimer()
local integer ID = GetHandleId(t)
local integer level = GetUnitAbilityLevel(u, SPELL_ID)
//===Timer ID
call SaveUnitHandle(HASH, ID, 1, u)
call SaveReal(HASH, ID, 2, GetDuration(level))
call SaveEffectHandle(HASH, ID, 3, AddSpecialEffectTarget(BUFF_SFX, u, "overhead"))
//===Unit ID
call SaveInteger(HASH, GetHandleId(u), 0x4568, 1)
//===Saves the information
call SetTimerData(t, ID)
call TimerStart(t, 1.0, true, function TimerLoop)
set t = null
endfunction
private function Cond takes nothing returns boolean
if GetSpellAbilityId()==SPELL_ID then
call TimerAction(GetTriggerUnit())
elseif GetUnitAbilityLevel(GetSpellTargetUnit(), SPELL_ID) > 0 and HaveSavedInteger(HASH, GetHandleId(GetSpellTargetUnit()), 0x4568) then
call MirrorSpellNow(GetTriggerUnit(), GetSpellTargetUnit(), GetSpellAbilityId())
endif
return false
endfunction
private function init takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddCondition(t, Condition(function Cond))
set t = null
endfunction
endscope