JASS dash spell Inifinite Loops?

cleeezzz

The Undead Ranger.
Reaction score
268
does the move even work?

JASS:
private function Move takes nothing returns nothing
local data d = data(GetTimerData(GetExpiredTimer()))
local unit t = GetEnumUnit()
local real ux = GetUnitX(t)
local real uy = GetUnitY(t)
local real angle = Atan2(uy-d.y,ux-d.x)
local real cos = Cos(angle)
local real sin = Sin(angle)
set ux = ux + cos * TIME * d.speed
set uy = uy + sin * TIME * d.speed
call SetUnitPosition(t,ux,uy)
call DestroyEffect(AddSpecialEffect(EFFECT,ux,uy))
endfunction

i dont see how data d would be set to anything, its not set off by a timer

and 8 sfx per unit? or 8 sfx total
 

wraithseeker

Tired.
Reaction score
122
the whole code works , I am using TimerUtils , Right now I want to try and limit SFX and setting a speed limit , answer above.

8 SFX per unit.
 

wraithseeker

Tired.
Reaction score
122
Bump

New Error found , when ever I set

JASS:
set d.speed = d.speed + 30


to
JASS:

set d.speed = d.speed - 30


The unit gets pushed back and then pushed back to the caster location , stuck there for eternity. Anybody know why? I am trying to do acceleration, from fast to slow pushback. I merely changed + 30 to - 30.
 

wraithseeker

Tired.
Reaction score
122
Making my dash spell stop

Right now I have made the basics of dash spells , it moves to the target but never stops as I don't know how do I detect when the caster reaches the target.

Basicly , this spell is cast on a unit by the caster and the caster will charge towards the target no matter where he goes.

Here is the code , my first dash spell , comments are <3

JASS:
scope Dash initializer Init

globals
private constant integer SPELL = &#039;A003&#039;
private constant real TIME = 0.03
private constant real SPEED = 800

endglobals

private struct data
unit caster
unit target
real cos
real sin
real angle
real distance
timer t

static method create takes nothing returns data
local data d = data.allocate()
set d.caster = GetTriggerUnit()
set d.target = GetSpellTargetUnit()
set d.t = NewTimer()
return d
endmethod

method onDestroy takes nothing returns nothing
call ReleaseTimer(.t)
endmethod
endstruct

private function Conditions takes nothing returns boolean
return GetSpellAbilityId() == SPELL
endfunction

private function Move takes nothing returns nothing
local data d = data(GetTimerData(GetExpiredTimer()))
local real cx = GetUnitX(d.caster)
local real cy = GetUnitY(d.caster)
local real tx = GetUnitX(d.target)
local real ty = GetUnitY(d.target)
local real angle = Atan2(ty-cy,tx-cx)
local real sin = Sin(angle)
local real cos = Cos(angle)
set cx = cx + cos * TIME * SPEED
set cy = cy + sin * TIME * SPEED
call SetUnitPosition(d.caster,cx,cy)
endfunction

private function Actions takes nothing returns nothing
local data d = data.create()
local real cx = GetUnitX(d.caster)
local real cy = GetUnitY(d.caster)
local real tx = GetUnitX(d.target)
local real ty = GetUnitY(d.target)
local real angle = Atan2(ty-cy,tx-cx)
local real cos = Cos(angle)
local real sin = Sin(angle)
call SetTimerData(d.t,integer (d))
call TimerStart(d.t,0.03,true,function Move)
endfunction

//===========================================================================
private function Init takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddAction( t, function Actions)
    call TriggerAddCondition(t,Condition(function Conditions))
endfunction

endscope
 

T.s.e

Wish I was old and a little sentimental
Reaction score
133
JASS:

if SquareRoot(cx - tx * cx - tx + cy - ty * cy - ty) &lt;= 128 then
   call d.destroy()
endif
 

wraithseeker

Tired.
Reaction score
122
hmm... when I added that line .. The caster doesn't move anymore...

Code

JASS:
scope Dash initializer Init

globals
private constant integer SPELL = &#039;A003&#039;
private constant real TIME = 0.03
private constant real SPEED = 800

endglobals

private struct data
unit caster
unit target
real cos
real sin
real angle
real distance
timer t

static method create takes nothing returns data
local data d = data.allocate()
set d.caster = GetTriggerUnit()
set d.target = GetSpellTargetUnit()
set d.t = NewTimer()
return d
endmethod

method onDestroy takes nothing returns nothing
call ReleaseTimer(.t)
endmethod
endstruct

private function Conditions takes nothing returns boolean
return GetSpellAbilityId() == SPELL
endfunction

private function Move takes nothing returns nothing
local data d = data(GetTimerData(GetExpiredTimer()))
local real cx = GetUnitX(d.caster)
local real cy = GetUnitY(d.caster)
local real tx = GetUnitX(d.target)
local real ty = GetUnitY(d.target)
local real angle = Atan2(ty-cy,tx-cx)
local real sin = Sin(angle)
local real cos = Cos(angle)
set cx = cx + cos * TIME * SPEED
set cy = cy + sin * TIME * SPEED
call SetUnitPosition(d.caster,cx,cy)
if SquareRoot(cx - tx * cx - tx + cy - ty * cy - ty) &lt;= 128 then
   call d.destroy()
endif
endfunction

private function Actions takes nothing returns nothing
local data d = data.create()
local real cx = GetUnitX(d.caster)
local real cy = GetUnitY(d.caster)
local real tx = GetUnitX(d.target)
local real ty = GetUnitY(d.target)
local real angle = Atan2(ty-cy,tx-cx)
local real cos = Cos(angle)
local real sin = Sin(angle)
call SetTimerData(d.t,integer (d))
call TimerStart(d.t,0.03,true,function Move)
endfunction

//===========================================================================
private function Init takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddAction( t, function Actions)
    call TriggerAddCondition(t,Condition(function Conditions))
endfunction

endscope
 

Azlier

Old World Ghost
Reaction score
461
Computers follow the order of operations. There is no parenthesis usage in your distance calculation, so it'll end up skewed.
 

wraithseeker

Tired.
Reaction score
122
I don't get what you mean, are you saying that 128 should be replaced with a variable that is my speed for the unit per 0.03 seconds?
 

Artificial

Without Intelligence
Reaction score
326
What he meant was this:
JASS:
(cx - tx * cx - tx + cy - ty * cy - ty)
// Change to:
((cx - tx) * (cx - tx) + (cy - ty) * (cy - ty))
 

wraithseeker

Tired.
Reaction score
122
Works nice + REP.

Since all has been done , right now what I want to know is how do I knock units away that the caster comes in contact with when he is charging at the target
 

wraithseeker

Tired.
Reaction score
122
With reference to my dash spell thread just now , now I have a problem , when the caster charges, I want it that units near them will get knocked back away.

Here is my code

JASS:
scope Dash initializer Init

globals
private constant integer SPELL = &#039;A003&#039;
private constant real TIME = 0.03
private constant real SPEED = 800
private boolexpr Check
endglobals

private function DISTANCE takes integer level returns integer
return level * 250
endfunction

private struct data
unit caster
unit target
real cos
real sin
real angle
real distance
timer t
timer h
group g

static method create takes nothing returns data
local data d = data.allocate()
set d.caster = GetTriggerUnit()
set d.target = GetSpellTargetUnit()
set d.t = NewTimer()
set d.h = NewTimer()
set d.distance = DISTANCE(GetUnitAbilityLevel(d.caster,SPELL))
set d.g = CreateGroup()
return d
endmethod

method onDestroy takes nothing returns nothing
call ReleaseTimer(.h)
endmethod
endstruct

private function Conditions takes nothing returns boolean
return GetSpellAbilityId() == SPELL
endfunction

private function KnockCheck takes nothing returns boolean
return true
endfunction

private function Knock takes nothing returns nothing
local data d = data(GetTimerData(GetExpiredTimer()))
local real cx = GetUnitX(d.caster)
local real cy = GetUnitY(d.caster)
local real tx = GetUnitX(d.target)
local real ty = GetUnitY(d.target)
local real angle = Atan2(ty-cy,tx-cx)
local real sin = Sin(angle)
local real cos = Cos(angle)
set tx = tx + cos * TIME * SPEED
set ty = ty + sin * TIME * SPEED
call SetUnitX(d.target,tx)
call SetUnitY(d.target,ty)
set d.distance = d.distance - TIME * SPEED
if d.distance &lt;= 0 then
call d.destroy()
endif
endfunction

private function Move takes nothing returns nothing
local data d = data(GetTimerData(GetExpiredTimer()))
local real cx = GetUnitX(d.caster)
local real cy = GetUnitY(d.caster)
local real tx = GetUnitX(d.target)
local real ty = GetUnitY(d.target)
local real angle = Atan2(ty-cy,tx-cx)
local real sin = Sin(angle)
local real cos = Cos(angle)
local unit u
local real x
local real y
local real angles
local real sins
local real coss
set cx = cx + cos * TIME * SPEED
set cy = cy + sin * TIME * SPEED
call SetUnitX(d.caster,cx)
call SetUnitY(d.caster,cy)
call GroupEnumUnitsInRange(d.g,cx,cy,180,Check)
loop
set u = FirstOfGroup(d.g)
exitwhen d.g == null
set x = GetUnitX(u)
set y = GetUnitY(u)
set angles = Atan2(cy-y,cx-x)
set sins = Sin(angles)
set coss = Cos(angles)
set x = cx + coss * TIME * SPEED
set y = cy + sins * TIME * SPEED
call SetUnitX(u,x)
call SetUnitY(u,y)
call GroupRemoveUnit(d.g,u)
endloop
if SquareRoot((cx - tx) * (cx - tx) + (cy - ty) * (cy - ty)) &lt;= 128 then
   call SetUnitAnimation(d.caster, &quot;attack slam alternate&quot;)
   call SetUnitAnimation(d.target, &quot;DEATH&quot;)
   call ReleaseTimer(d.t)
   call SetTimerData(d.h,integer (d))
   call TimerStart(d.h,0.03,true,function Knock)
endif
endfunction

private function Actions takes nothing returns nothing
local data d = data.create()
call SetTimerData(d.t,integer (d))
call TimerStart(d.t,0.03,true,function Move)
endfunction

//===========================================================================
private function Init takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddAction( t, function Actions)
    call TriggerAddCondition(t,Condition(function Conditions))
    set Check = Condition(function KnockCheck)
endfunction

endscope


When I added this block of codes , it lagged like tomorrow was never going to come.


JASS:
call GroupEnumUnitsInRange(d.g,cx,cy,180,Check)
loop
set u = FirstOfGroup(d.g)
exitwhen d.g == null
set x = GetUnitX(u)
set y = GetUnitY(u)
set angles = Atan2(cy-y,cx-x)
set sins = Sin(angles)
set coss = Cos(angles)
set x = cx + coss * TIME * SPEED
set y = cy + sins * TIME * SPEED
call SetUnitX(u,x)
call SetUnitY(u,y)
call GroupRemoveUnit(d.g,u)
endloop
 

Viikuna

No Marlo no game.
Reaction score
265
JASS:
exitwhen d.g == null // this is your group.
// I think what you meam  is exitwhen u==null
 

wraithseeker

Tired.
Reaction score
122
Yeah that solved it silly me ! -.-.

Error spotted , after casting the spell , I noticed the caster and the target seems to sway to a direction due to SetUnitX and Y?
 

Azlier

Old World Ghost
Reaction score
461
>I noticed the caster and the target seems to sway to a direction due to SetUnitX and Y?

What does that even mean?
 

wraithseeker

Tired.
Reaction score
122
I did a test today and had something strange , the first spell didn't bug at all. At the second cast , when I casted on the same target again , When I tried to move downwards, there seems to be a force trying not to let me down which I assume is the problem of SetUnitX and SetUnitY. And when I got near the target , they seem to get pushed back even though no spell was casted
 

Azlier

Old World Ghost
Reaction score
461
It's just so infuriating. Dual polar projection is bad enough, but no indentation at all?! :banghead:
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top