- Joined
- Feb 22, 2013
- Messages
- 161
I am creating a knockback script for a campaign my friend is making, and so far the syntax checks out but for some reason it doesn't even register the event
Why isn't it?
EDIT: Solved that problem but now the setup method doesn't run the create method
EDIT2: So I figured out that the problem has to do with the loop in the setup method for some reason, because it wouldn't even display the BJDebugMsg in the loop.
JASS:
library KnockbackAttack
globals
private real KB_distanceTotal = 500.00
private real KB_interval = 0.035
private integer KB_totalExecutions = R2I(KB_distanceTotal/KB_interval)
private real KB_moveDistanceLoop = 2*KB_distanceTotal/(KB_totalExecutions + 1)
private real KB_moveDistanceLoopDecel = KB_moveDistanceLoop/KB_totalExecutions
private real KB_damageDealt = 800.00
private timer KB_loopTimer = CreateTimer()
private integer KB_newestIndex = 0
private integer array KB_structCurrentIndex
endglobals
struct KnockbackStruct
unit attackedUnit
real angle
effect targetEffect
integer counter
static method create takes unit u, real a returns thistype
local thistype this = thistype.allocate()
set KB_newestIndex = KB_newestIndex + 1
set this.attackedUnit = u
set this.angle = a
set this.targetEffect = AddSpecialEffectTarget("Abilities\\Spells\\Other\\Silence\\SilenceAreaBirth.mdl", u, "chest")
set this.counter = 0
call BJDebugMsg("KB Struct Instance Created.")
call SetUnitPosition(this.attackedUnit, GetUnitX(this.attackedUnit), GetUnitY(this.attackedUnit))
call PauseUnit(this.attackedUnit, true)
return this
endmethod
static method KB_unitMove takes nothing returns nothing
local thistype this
local integer i = 1
local real x
local real y
loop
exitwhen i > KB_newestIndex
set this = KB_structCurrentIndex[i]
set this.counter = this.counter + 1
if this.counter == KB_totalExecutions then
call this.destroy()
elseif this.counter < KB_totalExecutions then
set x = GetUnitX(this.attackedUnit) + KB_moveDistanceLoop*Cos(this.angle)
set y = GetUnitY(this.attackedUnit) + KB_moveDistanceLoop*Sin(this.angle)
call SetUnitX(this.attackedUnit, x)
call SetUnitY(this.attackedUnit, y)
endif
set i = i + 1
endloop
if KB_newestIndex == 0 then
call PauseTimer(KB_loopTimer)
endif
endmethod
static method setup takes nothing returns nothing
local thistype this
local unit u
local real a
local group grp
local real x = GetUnitX(udg_Sauron) + 160.00*Cos(GetUnitFacing(udg_Sauron)*bj_DEGTORAD)
local real y = GetUnitY(udg_Sauron) + 160.00*Sin(GetUnitFacing(udg_Sauron)*bj_DEGTORAD)
call BJDebugMsg("KB Running Setup.")
call GroupEnumUnitsInRange(grp, x, y, 160.00, null)
loop
set u = FirstOfGroup(grp)
set a = (180.00/3.14159265358979323846)*Atan2(GetUnitY(u) - GetUnitY(udg_Sauron), GetUnitX(u) - GetUnitX(udg_Sauron))
call BJDebugMsg("Enum Unit = " + GetUnitName(u))
exitwhen u == null
if u != udg_Sauron then
set this = thistype.create(u, a)
set KB_structCurrentIndex[KB_newestIndex] = this
if KB_newestIndex == 1 then
call TimerStart(KB_loopTimer, KB_interval, true, function thistype.KB_unitMove)
endif
endif
call GroupRemoveUnit(grp, u)
endloop
endmethod
static method attackConditions takes nothing returns boolean
if GetAttacker() == udg_Sauron then
call thistype.setup()
call BJDebugMsg("KB Condition Registered.")
return true
else
call BJDebugMsg("KB Condition Registered But != Sauron.")
return false
endif
endmethod
static method onInit takes nothing returns nothing
set gg_trg_KnockbackAttack = CreateTrigger()
call BJDebugMsg("KB Initialized.")
call TriggerRegisterAnyUnitEventBJ(gg_trg_KnockbackAttack, EVENT_PLAYER_UNIT_ATTACKED)
call TriggerAddCondition(gg_trg_KnockbackAttack, Condition(function thistype.attackConditions))
endmethod
endstruct
endlibrary
Why isn't it?
EDIT: Solved that problem but now the setup method doesn't run the create method
EDIT2: So I figured out that the problem has to do with the loop in the setup method for some reason, because it wouldn't even display the BJDebugMsg in the loop.
Last edited: