- Joined
- Dec 12, 2008
- Messages
- 7,385
I made a spell (Time Bend) for my map (new upcoming hero ^^)
There are a few issues with the code though (The knockback struct won't
function properly)
Here's the code:
What happens is that I get a movespeed bonus for 5 seconds and all units
get slowed, and whenever I walk up to a unit, it's knocked back (I know this
can hit the op limit pretty fast, but I'll work something out ;p)
The only thing that happens when I cast the spell is ... NOTHING .. except
the speed bonus
I think the problem is with the KB struct.
Anyone who can help, will be properly credited
There are a few issues with the code though (The knockback struct won't
function properly)
Here's the code:
JASS:
scope TimeBend initializer Init
globals
private constant integer ABIL_CODE = 'A045'
private constant integer MSH = 'A082'
private constant integer SLOW = 'A083'
private integer int
endglobals
private struct KB
unit cst
unit kb
real r
real v
real ang
real md
timer tmr
timer lp
static method endkb takes nothing returns nothing
local thistype this = GetTimerData(GetExpiredTimer())
call destroy()
call ReleaseTimer(tmr)
call ReleaseTimer(lp)
endmethod
static method move takes nothing returns nothing
local thistype this = GetTimerData(GetExpiredTimer())
call SetUnitX(kb,GetUnitX(kb)+v*Cos(bj_DEGTORAD*ang))
call SetUnitY(kb,GetUnitY(kb)+v*Sin(bj_DEGTORAD*ang))
endmethod
static method create takes unit u, unit cs returns KB
local KB this = KB.allocate()
set this.kb = u
set this.cst = cs
set this.ang = bj_RADTODEG * Atan2(GetUnitY(this.kb) - GetUnitY(this.cst), GetUnitX(this.kb) - GetUnitX(this.cst))
set this.md = 300.00
set this.v = 9.00
set this.tmr = NewTimer()
set this.lp = NewTimer()
call TimerStart(this.tmr, 2.00, false, function KB.endkb)
call SetTimerData(this.tmr,this)
call TimerStart(this.lp, 0.03, true, function KB.move)
call SetTimerData(this.lp,this)
return this
endmethod
method onDestroy takes nothing returns nothing
set cst = null
set kb = null
endmethod
endstruct
private struct Data
unit cs
group g
integer lvl
player p
static method filtr takes nothing returns boolean
local thistype this = int
return IsPlayerEnemy(p, GetOwningPlayer(GetFilterUnit()))
endmethod
static method create takes unit u returns Data
local Data this = Data.allocate()
set this.cs = u
set this.p = GetTriggerPlayer()
set this.g = CreateGroup()
set this.lvl = GetUnitAbilityLevel(this.cs, ABIL_CODE)
set int = this
call GroupEnumUnitsInRange(this.g,GetUnitX(this.cs),GetUnitY(this.cs),999999.00, function Data.filtr)
return this
endmethod
static method slow takes nothing returns nothing
call UnitAddAbility(GetEnumUnit(), SLOW)
endmethod
static method gc takes nothing returns nothing
call UnitRemoveAbility(GetEnumUnit(), SLOW)
endmethod
static method end takes nothing returns nothing
local thistype this = GetTimerData(GetExpiredTimer())
call ForGroup(g, function Data.gc)
call UnitRemoveAbility(cs, MSH)
call DestroyGroup(g)
call destroy()
endmethod
method onDestroy takes nothing returns nothing
set cs = null
set p = null
endmethod
endstruct
private function Knockem takes nothing returns nothing
local KB k = KB.create(GetEnumUnit(), GetTriggerUnit())
endfunction
private function Enumf takes nothing returns boolean
return IsUnitType(GetFilterUnit(), UNIT_TYPE_STRUCTURE)==false and GetWidgetLife(GetFilterUnit()) > 0.405
endfunction
private function KnockbackE takes nothing returns nothing
local group g = CreateGroup()
local unit u = GetTriggerUnit()
call GroupEnumUnitsInRange(g, GetUnitX(u), GetUnitY(u), 200.00, function Enumf)
call ForGroup(g, function Knockem)
endfunction
private function Act takes nothing returns nothing
local Data d = Data.create(GetTriggerUnit())
local timer t = NewTimer()
local timer tm = NewTimer()
call UnitAddAbility(d.cs, MSH)
call ForGroup(d.g, function Data.slow)
call TimerStart(t, 5.00, false, function Data.end)
call SetTimerData(t,d)
call TimerStart(t, 0.03, true, function KnockbackE)
endfunction
private function Cond takes nothing returns boolean
return GetSpellAbilityId()==ABIL_CODE
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))
call TriggerAddAction(t, function Act)
endfunction
endscope
What happens is that I get a movespeed bonus for 5 seconds and all units
get slowed, and whenever I walk up to a unit, it's knocked back (I know this
can hit the op limit pretty fast, but I'll work something out ;p)
The only thing that happens when I cast the spell is ... NOTHING .. except
the speed bonus
I think the problem is with the KB struct.
Anyone who can help, will be properly credited