JASS:
struct SpikeTrap
//Configuration
private static constant integer ABILITY_ID = 039;A000039;
//The raw code of the spell, use Ctrl+D in the object editor to find it
private static constant string TRAP_EFFECT = "Abilities\\Spells\\Orc\\SpikeBarrier\\SpikeBarrier.mdl"
//The model of the trap
private static constant string TRIGGER_EFFECT = "Abilities\\Spells\\Undead\\AnimateDead\\AnimateDeadTarget.mdl"
//The effect emitted when the traps are triggered
private static constant integer MAX_EFFECTS = 3
//Maximum trap effects
private static constant real EFFECT_SPACING = 45.
//How far effects a created from the caster
private static constant real RADIUS = 45.
//How far a unit has to be from the center of a trap to be affected
private static constant attacktype ATTACK_TYPE = ATTACK_TYPE_CHAOS
//The attack type
private static constant damagetype DAMAGE_TYPE = DAMAGE_TYPE_UNIVERSAL
//The damage type
private static constant weapontype WEAPON_TYPE = WEAPON_TYPE_WHOKNOWS
//The weapon type
private static method DAMAGE takes integer level returns real
return I2R(level) * 50 + 25
endmethod
//The damage
private static method TRAP_DURATION takes integer level returns real
return 16 - I2R(level) * 4
endmethod
//How long the traps last
//End of Configuration
private static group GROUP = CreateGroup()
private static thistype TEMPORARY_INSTANCE
private static filterfunc FILTER
unit caster
player owner
real x
real y
fogmodifier visibility
integer level
integer tick
effect array effects[.MAX_EFFECTS]
boolean isTriggered = false
private static method groupActions takes nothing returns boolean
local unit u = GetEnumUnit()
call BJDebugMsg(I2S(.TEMPORARY_INSTANCE))
call BJDebugMsg("ZOMG1")
if(IsUnitEnemy(u, .TEMPORARY_INSTANCE.owner) and IsUnitType(u, UNIT_TYPE_GROUND)) then
call BJDebugMsg("ZOMG")
set bj_lastCreatedEffect = AddSpecialEffect(TRIGGER_EFFECT, GetUnitX(u), GetUnitY(u))
call DestroyEffect(bj_lastCreatedEffect)
call .DAMAGE(.TEMPORARY_INSTANCE.level)
set .TEMPORARY_INSTANCE.tick = T32_Tick
endif
return false
endmethod
private method periodic takes nothing returns nothing
local integer i = 0
if(this.tick >= T32_Tick) then
call BJDebugMsg(I2S(this))
set thistype.TEMPORARY_INSTANCE = this
call GroupEnumUnitsInRange(thistype.GROUP, this.x, this.y, thistype.RADIUS + thistype.EFFECT_SPACING, thistype.FILTER)
call BJDebugMsg("ZOMG0")
else
call BJDebugMsg("wee")
call this.stopPeriodic()
call PauseUnit(this.caster, false)
call ShowUnit(this.caster, true)
loop
exitwhen i == thistype.MAX_EFFECTS
call DestroyEffect(this.effects<i>)
set i = i + 1
endloop
set this.caster = null
call FogModifierStop(this.visibility)
call DestroyFogModifier(this.visibility)
call this.destroy()
endif
call GroupClear(thistype.GROUP)
endmethod
implement T32x
private static method actions takes nothing returns nothing
local thistype d = thistype.create()
local unit u = GetTriggerUnit()
local integer i = 1
local real r = 0
local real x = GetUnitX(u)
local real y = GetUnitY(u)
set d.x = x
set d.y = y
set d.caster = u
set d.owner = GetOwningPlayer(d.caster)
set d.effects[0] = AddSpecialEffect(.TRAP_EFFECT, x, y)
set d.visibility = CreateFogModifierRadius(d.owner, FOG_OF_WAR_VISIBLE, d.x, d.y, .RADIUS + .EFFECT_SPACING, true, false)
call FogModifierStart(d.visibility)
loop
exitwhen i == .MAX_EFFECTS
set x = d.x + .EFFECT_SPACING * Cos(360 / i * bj_DEGTORAD)
set y = d.y + .EFFECT_SPACING * Sin(360 / i * bj_DEGTORAD)
set d.effects<i> = AddSpecialEffect(.TRAP_EFFECT, x, y)
set i = i + 1
endloop
set d.level = GetUnitAbilityLevel(d.caster, .ABILITY_ID)
set d.tick = T32_Tick + R2I(.TRAP_DURATION(d.level) / T32_PERIOD)
call PauseUnit(d.caster, true)
call ShowUnit(d.caster, false)
call d.startPeriodic()
endmethod
private static method condition takes nothing returns boolean
if(GetSpellAbilityId() == .ABILITY_ID) then
call .actions()
endif
return false
endmethod
private static method onInit takes nothing returns nothing
local trigger t = CreateTrigger()
local integer i = 0
set .FILTER = Filter(function thistype.groupActions)
loop
exitwhen i == 15
call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
set i = i + 1
endloop
call TriggerAddCondition(t, Condition(function thistype.condition))
endmethod
endstruct
</i></i>
It works, but the group enumeration thing and the fog modifier won't do anything... How do you fix it?