- Joined
- Jul 19, 2007
- Messages
- 966
Ok so I imported a new ability in to my map named "Cover of Darkness" at it is meant to reduce the sight range of enemy heroes in the target area but for some reason it seems to also affect the casteing hero and allies that is in the target area but I can't see why it does... What's wrong with the trigger and how to fix it? Pls help...
JASS:
//TESH.scrollpos=99
//TESH.alwaysfold=0
scope CoverofDarkness initializer InitTrig
//=====================================================================//
// Cover of Darkness //
// by iAyanami aka Glenphir //
//=====================================================================//
// //
//=====================================================================//
// Implementation Instructions //
//---------------------------------------------------------------------//
// Copy these objects into your map //
// [Abilities] //
// 1) Cover of Darkness //
// 2) Cover of Darkness (Movement Speed) //
// 3) Cover of Darkness (Sight - Level 1) //
// 4) Cover of Darkness (Sight - Level 2) //
// 5) Cover of Darkness (Sight - Level 3) //
// //
// [Buffs] //
// 1) Cover of Darkness //
// //
//=====================================================================//
//=====================================================================//
// CONFIGURATION //
//=====================================================================//
globals
private constant integer ABIL_ID1 = 'A0T4' // raw code of Ability "Cover of Darkness"
private constant integer ABIL_ID2 = 'A0T5' // raw code of Ability "Cover of Darkness (Movement Speed)"
private constant integer ABIL_ID3 = 'A0T6' // raw code of Ability "Cover of Darkness (Sight - Level 1)"
private constant integer ABIL_ID4 = 'A0T7' // raw code of Ability "Cover of Darkness (Sight - Level 2)"
private constant integer ABIL_ID5 = 'A0T8' // raw code of Ability "Cover of Darkness (Sight - Level 3)"
private constant real AOE = 1000.00 // area of effect
private constant boolean HERO = true // set to true to only affect enemy heroes
endglobals
private function GetDuration takes unit caster returns real
return 2.00 + (2.00 * GetUnitAbilityLevel(caster, ABIL_ID1)) // duration of blind
endfunction
//=====================================================================//
// END CONFIGURATION //
//=====================================================================//
globals
private player PLAYER
private unit UNIT
endglobals
private struct cod
real r
group g
unit u
endstruct
private function RemoveVision takes nothing returns nothing
local unit u = GetEnumUnit()
local player ou = GetOwningPlayer(u)
local integer i = 0
if GetUnitAbilityLevel(UNIT, ABIL_ID2) == 0 then
call UnitAddAbility(u, ABIL_ID2)
if GetUnitAbilityLevel(UNIT, ABIL_ID1) == 1 then
call UnitAddAbility(u, ABIL_ID3)
elseif GetUnitAbilityLevel(UNIT, ABIL_ID1) == 2 then
call UnitAddAbility(u, ABIL_ID4)
elseif GetUnitAbilityLevel(UNIT, ABIL_ID1) == 3 then
call UnitAddAbility(u, ABIL_ID4)
endif
endif
loop
if GetPlayerAlliance(Player(i), ou, ALLIANCE_SHARED_VISION) then
call SetPlayerAlliance(Player(i), ou, ALLIANCE_SHARED_VISION, false)
endif
exitwhen i == 15
set i = i + 1
endloop
set u = null
set ou = null
endfunction
private function Restore takes nothing returns nothing
local unit u = GetEnumUnit()
local player ou = GetOwningPlayer(u)
local integer i = 0
call UnitRemoveAbility(GetEnumUnit(), ABIL_ID2)
call UnitRemoveAbility(GetEnumUnit(), ABIL_ID3)
call UnitRemoveAbility(GetEnumUnit(), ABIL_ID4)
call UnitRemoveAbility(GetEnumUnit(), ABIL_ID5)
loop
if IsPlayerAlly(ou, Player(i)) and not GetPlayerAlliance(Player(i), ou, ALLIANCE_SHARED_VISION) then
call SetPlayerAlliance(Player(i), ou, ALLIANCE_SHARED_VISION, true)
endif
exitwhen i == 15
set i = i + 1
endloop
set u = null
set ou = null
endfunction
private function Periodic takes nothing returns boolean
local cod d = KT_GetData()
local integer i
set d.r = d.r - 0.10
if d.r <= 0 then
call ForGroup(d.g, function Restore)
call Group.release(d.g)
call d.destroy()
return true
endif
set PLAYER = GetOwningPlayer(d.u)
set UNIT = d.u
call ForGroup(d.g, function RemoveVision)
return false
endfunction
private function Conditions takes nothing returns boolean
return GetSpellAbilityId() == ABIL_ID1
endfunction
private function Actions takes nothing returns nothing
local cod d = cod.create()
local real x = GetSpellTargetX()
local real y = GetSpellTargetY()
local boolean check
local integer i
local unit u
set d.g = Group.get()
set d.u = GetTriggerUnit()
set d.r = GetDuration(d.u)
set i = CountUnitsInGroup(d.g)
call GroupEnumUnitsInRange(d.g, x, y, AOE, null)
loop
exitwhen i == 0
set u = FirstOfGroup(d.g)
set i = i - 1
if HERO then
set check = not IsUnitType(u, UNIT_TYPE_STRUCTURE) and IsUnitEnemy(u, GetOwningPlayer(d.u)) and IsUnitType(u, UNIT_TYPE_HERO)
else
set check = not IsUnitType(u, UNIT_TYPE_STRUCTURE) and IsUnitEnemy(u, GetOwningPlayer(d.u))
endif
if check then
if GetUnitAbilityLevel(d.u, ABIL_ID1) == 1 then
call UnitAddAbility(u, ABIL_ID3)
elseif GetUnitAbilityLevel(d.u, ABIL_ID1) == 2 then
call UnitAddAbility(u, ABIL_ID4)
elseif GetUnitAbilityLevel(d.u, ABIL_ID1) == 3 then
call UnitAddAbility(u, ABIL_ID4)
endif
else
call GroupRemoveUnit(d.g, u)
endif
endloop
call KT_Add(function Periodic, d, 0.10)
set u = null
endfunction
private function InitTrig takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddCondition(t, Condition(function Conditions))
call TriggerAddAction(t, function Actions)
endfunction
endscope
