• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] Help with movement ability

Status
Not open for further replies.
Level 6
Joined
Mar 20, 2008
Messages
208
If anyone has played Aotz, they are familiar with Janis's teleporting bomblike ability.

I'm trying to recreate a simpler version of it for one of my heros.
I have everyting looking decent with the exception of one problem.

The unit will teleport, but it won't stop going past its targeted area. So if the target location is 10 feet away,the maxed out spell will still jump 2000 feet.

Anyway, heres the spell, any comments or insight would be helpful.
(I removed the actual unit positioning for this, prior it was moving the unit to an offmap area and then moving it back to the x/y values)

JASS:
function WFc takes nothing returns boolean
    return GetSpellAbilityId() == 'AEbl'
endfunction

function WFa takes nothing returns nothing
   local unit u = GetTriggerUnit()
   local player p = GetOwningPlayer(u)
   local integer a = GetUnitAbilityLevel(u,'AEbl')
   local integer i = 1+a/2 //Amount of jumps
   local integer h = 0 //Temp integer to control turning
   local real f
   local location l = GetSpellTargetLoc()
   local location l2 = GetUnitLoc(u)
   local real x = GetLocationX(l)
   local real y = GetLocationY(l)

   set f = bj_RADTODEG * Atan2(y - GetLocationY(l2), x - GetLocationX(l2))  
//Sets the unit facting the direction of the targetted spell
   call SetUnitFacing(u,f)

   set x = GetLocationX(l2)
   set y = GetLocationY(l2)
   loop
       exitwhen i <= 0 

        call DestroyEffect(AddSpecialEffect("Abilities\\Spells\\Orc\\FeralSpirit\\feralspiritdone.mdl",x,y))
        call DestroyEffect(AddSpecialEffect("Abilities\\Spells\\Human\\ManaFlare\\ManaFlareBoltImpact.mdl",x,y))
        call DestroyEffect(AddSpecialEffect("Abilities\\Spells\\Undead\\DarkRitual\\DarkRitualTarget.mdl",x,y))


//poor attempt to  have the spell effects appear in a zigzag
          if(h == 0) then
             set f = f+45
             set h = 1
          elseif(h > 0) then
            set f = f+90           
          else
            set f = f-90
          endif

          set h = h*-1
 
        set x = x +200 * Cos(f * bj_DEGTORAD)
        set y = y +200 * Sin(f * bj_DEGTORAD)

       set i = i-1
   endloop

   call SetUnitState(u,UNIT_STATE_MANA, GetUnitState(u,UNIT_STATE_MANA) - a*20)

   call DestroyEffect(AddSpecialEffect("Abilities\\Spells\\Orc\\FeralSpirit\\feralspiritdone.mdl",x,y))
   call DestroyEffect(AddSpecialEffect("Abilities\\Spells\\Human\\ManaFlare\\ManaFlareBoltImpact.mdl",x,y))
   call DestroyEffect(AddSpecialEffect("Abilities\\Spells\\Undead\\DarkRitual\\DarkRitualTarget.mdl",x,y))

   call RemoveLocation(l)
   call RemoveLocation(l2)

  set l2 = null
  set l = null
  set p = null
  set u = null
endfunction

//===========================================================================
function InitTrig_W_Fla takes nothing returns nothing
    set gg_trg_W_Fla = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_W_Fla, EVENT_PLAYER_UNIT_SPELL_CAST )
    call TriggerAddCondition( gg_trg_W_Fla, Condition( function WFc ) )
    call TriggerAddAction( gg_trg_W_Fla, function WFa )
endfunction

So I'm not sure what to do/add in terms of code to prevent the unit from going too far.
 
Level 14
Joined
Nov 18, 2007
Messages
816
JASS:
function WFa takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local player p = GetOwningPlayer(u)
    local integer a = GetUnitAbilityLevel(u,'AEbl')
    local integer i = 1
    local integer j = 1+a/2 //Amount of jumps 
    local integer h = 1 //Temp integer to control turning
    local real maxRange = 2000. // Maximum Teleport range
    local real cx = GetUnitX(u) // caster X
    local real cy = GetUnitY(u) // caster Y
    local real tx = GetSpellTargetX() // target X
    local real ty = GetSpellTargetY() // target Y
    local real dx = tx-cx
    local real dy = ty-cy
    local real d = RMinBJ(SquareRoot(dx*dx+dy*dy), maxRange)/(j+1)
    local real f = Atan2(dy, dx)+bj_PI/4
    local real x = cx // current position of the caster
    local real y = cy
    
    loop
        exitwhen i>j
        call DestroyEffect(AddSpecialEffect("Abilities\\Spells\\Orc\\FeralSpirit\\feralspiritdone.mdl",x,y))
        call DestroyEffect(AddSpecialEffect("Abilities\\Spells\\Human\\ManaFlare\\ManaFlareBoltImpact.mdl",x,y))
        call DestroyEffect(AddSpecialEffect("Abilities\\Spells\\Undead\\DarkRitual\\DarkRitualTarget.mdl",x,y))
        //poor attempt to have the spell effects appear in a zigzag
        if (h < 0) then // CHANGED
            set f = f+bj_PI/2
        else
            set f = f-bj_PI/2
        endif
        set h = h*-1
        
        set x = cx+((i-1)*d*Cos(f+(h*bj_PI/4)))
        set y = cy+((i-1)*d*Sin(f+(h*bj_PI/4)))
        set x=x+d*Cos(f)
        set y=y+d*Sin(f)
        
        // You might want to set the casters position here.
        
        set i = i+1
    endloop
    call SetUnitState(u,UNIT_STATE_MANA, GetUnitState(u,UNIT_STATE_MANA) - a*20)
    call DestroyEffect(AddSpecialEffect("Abilities\\Spells\\Orc\\FeralSpirit\\feralspiritdone.mdl",tx,ty))
    call DestroyEffect(AddSpecialEffect("Abilities\\Spells\\Human\\ManaFlare\\ManaFlareBoltImpact.mdl",tx,ty))
    call DestroyEffect(AddSpecialEffect("Abilities\\Spells\\Undead\\DarkRitual\\DarkRitualTarget.mdl",tx,ty))
    //call SetUnitX(u, tx)
    //call SetUnitY(u, ty)
    set u = null
endfunction
Does that work as expected?

Edit: No, it doesnt, fixing...

Now it should.
 
Last edited:
Level 6
Joined
Mar 20, 2008
Messages
208
Deod that does not turn the special effects, it makes them all shoot from left to right at a 0 degree angle.

Although, it does lengthen and contrast depending on the distance...just not in the right direction. :sad:



just save the spelltarget location into a variable and move the unit to that point..

That does not stop the special effects from going past the target point.
 
Level 6
Joined
Mar 20, 2008
Messages
208
It zig zags at a larger distance, so his is fine (My bad), I just need to figure out how to get it turning on the angle the unit is facing.
 
Level 6
Joined
Mar 20, 2008
Messages
208
Deod already did that...his spell does not shoot spell effects at different angles as I've said before. They all shoot at a 0 degree, horizontal angle.

If you want to take a crack at it adiktuz, feel free, the codes posted.
 
Level 6
Joined
Mar 20, 2008
Messages
208
Its based off of blink, with the code you wrote, I am able to get rid of the unit movement and the forced mana cost.
 
Level 6
Joined
Mar 20, 2008
Messages
208
I had some time to work with Deod's code, and after some tweaks it almost works perfectly, which si good enough for me.

This is based off of blink.

JASS:
function WFc takes nothing returns boolean
    return GetSpellAbilityId() == 'AEbl'
endfunction

function WFa takes nothing returns nothing    
local unit u = GetTriggerUnit()    
local player p = GetOwningPlayer(u)    
local integer a = GetUnitAbilityLevel(u,'AEbl')    
local integer i = 1    
local integer j = 8+a/2 
local integer h = 1    
local real cx = GetUnitX(u)    
local real cy = GetUnitY(u)     
local real tx = GetSpellTargetX()    
local real ty = GetSpellTargetY()  
local real dx = tx-cx    
local real dy = ty-cy    
local real d = (SquareRoot(dx*dx+dy*dy)/(j+1))*2    
local real f = Atan2(dy, dx)+bj_PI/4    
local real x = cx    
local real y = cy    

call TriggerSleepAction(.2)

   loop        
      exitwhen i>j-2        
         call DestroyEffect(AddSpecialEffect("Abilities\\Spells\\Orc\\FeralSpirit\\feralspiritdone.mdl",x,y))      
         call DestroyEffect(AddSpecialEffect("Abilities\\Spells\\Human\\ManaFlare\\ManaFlareBoltImpact.mdl",x,y))       
         call DestroyEffect(AddSpecialEffect("Abilities\\Spells\\Undead\\DarkRitual\\DarkRitualTarget.mdl",x,y))        //poor attempt to have the spell effects appear in a zigzag    

          if (h < 0) then           
              set f = f+bj_PI/2        
          else           
              set f = f-bj_PI/2       
          endif        
          set h = h*-1        
                
          set x=x+GetRandomReal(-100,100)+d*Cos(f)        
          set y=y+GetRandomReal(-100,100)+d*Sin(f)        
       
      set i = i+1   
   endloop    
   call DestroyEffect(AddSpecialEffect("Abilities\\Spells\\Orc\\FeralSpirit\\feralspiritdone.mdl",tx,ty))    
   call DestroyEffect(AddSpecialEffect("Abilities\\Spells\\Human\\ManaFlare\\ManaFlareBoltImpact.mdl",tx,ty))    
   call DestroyEffect(AddSpecialEffect("Abilities\\Spells\\Undead\\DarkRitual\\DarkRitualTarget.mdl",tx,ty))    

   set u = null
   set p = null
endfunction

//===========================================================================
function InitTrig_W_Fla takes nothing returns nothing
    set gg_trg_W_Fla = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_W_Fla, EVENT_PLAYER_UNIT_SPELL_CAST )
    call TriggerAddCondition( gg_trg_W_Fla, Condition( function WFc ) )
    call TriggerAddAction( gg_trg_W_Fla, function WFa )
endfunction
 
Status
Not open for further replies.
Top