• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] Spell gone wrong :p[vJass]

Status
Not open for further replies.
Level 25
Joined
Jun 5, 2008
Messages
2,573
I have a problem, i am new to vJass but i am picking up fast so i tried to make a spell but i have a problem.
The spells should create a unit which moves(bounces) acros the area but for some reason my script bugs :p
I don't care if i didn't used a proper code for angles just tell me why this bugs.
Well if you are good with structs/vJass please help me.

JASS:
scope SpiritBomb initializer InitSB
//**********************************************
//Settings - All of the spell settings are here*
//**********************************************
globals
 private constant integer SpellID = 'A000' 
 private constant integer DummyID = 'e000'
 private constant string MissileEff = "Abilities\\Spells\\Other\\AcidBomb\\BottleMissile.mdl" 
 private constant string ImpactEff = "Abilities\\Weapons\\SpiritOfVengeanceMissile\\SpiritOfVengeanceMissile.mdl" 
 private constant string UnitEff = "Abilities\\Spells\\Human\\Feedback\\ArcaneTowerAttack.mdl" 
 private constant real Mb_base = 50 
 private constant real Mb_inc = 35 
 private constant integer Bn_base = 2 
 private constant integer Bn_inc = 1 
 private constant real Ie_AOE = 250 
 private constant real M_speed = 14 
 private constant real M_height = 450 
 private constant real Bonus_mb = 20 
 private constant real Bounce_dist = 200 
 private constant real FeedV = 400 
endglobals
//***************************************************************************************
//Settings end - Do not modify anything below this if you don't know what you are doing!*
//***************************************************************************************
globals
 private group tg
 private unit tu
 private integer i = 0
 private boolexpr tf = null
 private player tp
 endglobals

 private struct SB
    unit c
    unit m
    integer l
    real mh
    real a
    real d
    real cd = 0
    integer bn
    real mb
    integer f
    player p
    effect e
 
    static SB array ind
    static integer sca = 0
    static timer counter = CreateTimer()
 
    static method Motion takes nothing returns nothing
     local SB v
     local real x
     local real y
     local real ang
     local integer i = 0
     loop
      exitwhen i >= SB.sca
      set v = SB.ind[i]
      if v.cd < v.d then
         set x = GetUnitX(v.m) + M_speed * Cos(bj_RADTODEG * v.a)
         set y = GetUnitY(v.m) + M_speed * Sin(bj_RADTODEG * v.a)
         set v.cd = v.cd + M_speed
         call SetUnitX(v.m,x)
         call SetUnitY(v.m,y)
      else
         if v.bn > 0 then
          set ang = GetRandomReal(0,360)
          set x = x + Bounce_dist * Cos(bj_RADTODEG * ang)
          set y = y + Bounce_dist * Cos(bj_RADTODEG * ang)
          set v.a = Atan2(y - GetUnitY(v.m),x - GetUnitX(v.m))
          set v.cd = 0.00
          set v.bn = v.bn - 1
         else
          call DestroyEffect(v.e)
          call RemoveUnit(v.m)
          set v.e = null
          set v.c = null
          set v.m = null    
          call v.destroy()
          set SB.sca = SB.sca - 1
          set SB.ind[i] = v.ind[SB.sca]                        
          set i  = i - 1  
         endif
      endif
      set i = i + 1
     endloop
     set i = 0
     if SB.sca == 0 then
      call PauseTimer(SB.counter)
     endif
  endmethod
 
  static method GetVal takes unit c,unit m,real a,real d,integer lvl,real mb,integer bn,player p,effect e returns nothing
   local SB v = SB.allocate()
   set v.c = c
   set v.m = m
   set v.a = a
   set v.d = d
   set v.l = lvl
   set v.mb = mb
   set v.bn = bn
   set v.p = p
   set v.e = e
   set v.f = 0
   set v.cd = 0.00
   if SB.sca == 0 then
    call TimerStart(SB.counter,0.03,true,function SB.Motion)
   endif
   set SB.ind[SB.sca] = v
   set SB.sca = SB.sca + 1
  endmethod

 endstruct
 
 //unit filter 
private function filter takes nothing returns boolean
 return GetWidgetLife(GetFilterUnit()) > 0 and IsUnitEnemy(GetFilterUnit(),tp) and IsUnitType(GetFilterUnit(),UNIT_TYPE_FLYING) == false and IsUnitType(GetFilterUnit(),UNIT_TYPE_STRUCTURE) == false 
endfunction

private function Cond takes nothing returns boolean
 return GetSpellAbilityId() == SpellID
endfunction
 
private function SetValues takes nothing returns nothing
 local unit c = GetTriggerUnit()
 local player p = GetOwningPlayer(c)
 local location loc = GetUnitLoc(c)
 local location loc2 = GetSpellTargetLoc()
 local real a = Atan2(GetLocationY(loc2) - GetLocationY(loc),GetLocationX(loc2) - GetLocationX(loc))
 local real d = Bounce_dist
 local unit m = CreateUnit(p,DummyID,GetLocationX(loc),GetLocationY(loc),a)
 local integer lvl = GetUnitAbilityLevel(c,SpellID)
 local real mb = (Mb_base + Mb_inc*(I2R(lvl-1)))
 local integer bn = (Bn_base + Bn_inc*(lvl-1)) 
 local effect e = AddSpecialEffectTarget(MissileEff,m,"chest")
 call UnitAddAbility(m,'Arav')
 call UnitRemoveAbility(m,'Arav')
 call SB.GetVal(c,m,a,d,lvl,mb,bn,p,e)
 call RemoveLocation(loc)
 call RemoveLocation(loc2)
 set loc = null
 set loc2 = null
endfunction


private function InitSB takes nothing returns nothing
    local trigger t = CreateTrigger()
    local integer i = 0
    loop
     call TriggerRegisterPlayerUnitEvent(t,Player(i),EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
     set i = i + 1
     exitwhen i == bj_MAX_PLAYER_SLOTS
    endloop
    set i = 0
    call TriggerAddCondition(t,Condition(function Cond))
    call TriggerAddAction(t,function SetValues)
    call Preload(MissileEff)
    call Preload(ImpactEff)
    call Preload(UnitEff)
    call PreloadStart()
endfunction
endscope
 
Level 6
Joined
Jul 25, 2005
Messages
221
Don't really know what you're trying to accomplish with this 'cause its a mess so I can't really read it...
You should use CAPITAL letters for globals, so you can easily spot them, and even though some BJ functions are useless, some are actually very good to use, so when you calculate a distance, you might as well use their function, it's shorter and easier to read. That's what I got so far, I'll see what I can do with your spell.
 
Level 6
Joined
Jul 25, 2005
Messages
221
What is the main issue, what is the bug? When I try it, the dummy unit just stands there, doesn't do anything XD

The first time I cast it though, it moves backwards for some reason.
 
Level 6
Joined
Jul 25, 2005
Messages
221
There's some code to look through, but seeing as you haven't done much commenting, it's hard solving the problem, but I could guess it has to do with the reseting (duuh) for each bounce, because if you swap the statement, the dummy moves and then is removed. But in your case the dummy remains and the timer is paused. Check your motion trigger.

Besides, I think you're making it too difficult for yourself, I'd go for a simpler approach
 
Status
Not open for further replies.
Top