• 🏆 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!

Dangit. Cant see why.

Status
Not open for further replies.
Level 6
Joined
Jul 18, 2009
Messages
200
Hello. My spell doesnt do anything. And i get so angry at it.


Code:

JASS:
scope WaterGodSpell initializer Init
   
   globals
      private constant integer SpellID = 'A000'
      private constant integer CARRIONSWARMID = 'A001'
      private constant integer DummyID = 'u000'
      private constant integer DUMMYAMOUNT = 8
      private constant string SFX = "Abilities\\Weapons\\PhoenixMissile\\Phoenix_Missile_mini.mdl"
      private constant string SFX2 = "Abilities\\Spells\\Undead\\ReplenishMana\\ReplenishManaCasterOverhead.mdl"
      private constant real DISTANCEFROMCASTER = 25.00
   endglobals

     private function SFXCREATE takes nothing returns nothing
        local Shape sd = Shape.getData()
        call DestroyEffect(AddSpecialEffect(SFX,sd.x,sd.y))
        call DestroyEffect(AddSpecialEffect(SFX2,sd.x,sd.y))
    endfunction

    private function onTest takes nothing returns nothing
        local unit u = GetTriggerUnit()
        local real x = GetUnitX(u)
        local real y = GetUnitY(u)
        local real a =  GetUnitFacing(u)*bj_DEGTORAD
        local Shape sd = 0
        set sd = Shape.createIntersectedStarPolygon(x,y,a,5,500.,1,15,0.,function SFXCREATE)
    endfunction
   
private function CrushWaveAct takes nothing returns nothing
      local integer i = 0
      local unit caster = GetTriggerUnit()
      local real rad = GetUnitFacing(caster) * bj_DEGTORAD
      local player playcast = GetTriggerPlayer()
      local unit dummy
      local real radIncrease = ((bj_PI)*2) / DUMMYAMOUNT
      local real DummyX = GetUnitX(caster) + (DISTANCEFROMCASTER) * Cos(rad)
      local real DummyY = GetUnitY(caster) + (DISTANCEFROMCASTER) * Sin(rad)
      call onTest()
      loop
      exitwhen i == DUMMYAMOUNT * GetUnitAbilityLevel(caster,SpellID)
         set dummy = CreateUnit(playcast, DummyID, DummyX, DummyY, (rad) * bj_RADTODEG)
         call UnitAddAbility(dummy, CARRIONSWARMID)
         call IssuePointOrder(dummy, "carrionswarm", GetUnitX(caster) + (DISTANCEFROMCASTER+100) * Cos(rad), GetUnitY(caster) + (DISTANCEFROMCASTER+100) * Sin(rad))
         call UnitApplyTimedLife(dummy, 'BTLF', 2/GetUnitAbilityLevel(caster,SpellID))
         set dummy = null
      
         set rad = rad + radIncrease
         set DummyX = GetUnitX(caster) + (DISTANCEFROMCASTER) * Cos(rad)
         set DummyY = GetUnitY(caster) + (DISTANCEFROMCASTER) * Sin(rad)
      set i = i+1
      endloop
      call PauseUnit( caster , false )
      call IssueImmediateOrder( caster , "stop" )
      set caster = null
   endfunction




   private function CrushWaveCond takes nothing returns boolean
      return GetSpellAbilityId() == SpellID
   endfunction

   private function Init takes nothing returns nothing
      local trigger t = CreateTrigger()
      local integer i = 12

      loop
      exitwhen i == 0
         call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
      set i = i-1
      endloop

      call TriggerAddCondition(t, Condition(function CrushWaveCond))
      call TriggerAddAction(t, function CrushWaveAct)
   endfunction

endscope

Everything should be as it should

//Chaos_Knight :grin:
 
JASS:
call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
If you use no filter function, then why don't you use the BJ version instead?
JASS:
call TriggerRegisterPlayerUnitEventBJ (t, Player(i), EVENT_PLAYER_UNIT_SPELL_EFFECT)

And this:
JASS:
local player playcast = GetTriggerPlayer()
Should be
JASS:
local player playcast = GetOwningPlayer(caster)
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,468
Here, the spell will run faster as it is more efficient now with fewer function calls. I recommend doing all triggeractions/triggerconditions the way I did them, because combining them both into a triggeraction means that you generate 1/3 of the handles and you can easily pass parameters to the action function so that you don't have to declare/null locals.

JASS:
scope WaterGodSpell initializer Init
 
   globals
      private constant integer SpellID = 'A000'
      private constant integer CARRIONSWARMID = 'A001'
      private constant integer DummyID = 'u000'
      private constant integer DUMMYAMOUNT = 8
      private constant string SFX = "Abilities\\Weapons\\PhoenixMissile\\Phoenix_Missile_mini.mdl"
      private constant string SFX2 = "Abilities\\Spells\\Undead\\ReplenishMana\\ReplenishManaCasterOverhead.mdl"
      private constant real DISTANCEFROMCASTER = 25.00
   endglobals
 
     private function SFXCREATE takes nothing returns nothing
        local Shape sd = Shape.getData()
        call DestroyEffect(AddSpecialEffect(SFX,sd.x,sd.y))
        call DestroyEffect(AddSpecialEffect(SFX2,sd.x,sd.y))
    endfunction
 
    private function onTest takes unit u,real x,real y,real a returns nothing
        local Shape sd = Shape.createIntersectedStarPolygon(x,y,a,5,500.,1,15,0.,function SFXCREATE)
    endfunction
 
private function CrushWaveAct takes unit caster,unit dummy returns nothing
      local integer i = 0
      local integer level = GetUnitAbilityLevel(caster,SpellID)
      local real rad = GetUnitFacing(caster) * bj_DEGTORAD
      local player playcast = GetTriggerPlayer()
      local real radIncrease = bj_PI*2/DUMMYAMOUNT
      local real x = GetUnitX(caster)
      local real y = GetUnitY(caster)
      local real cr = Cos(rad)
      local real sr = Sin(rad)
      call onTest(caster,x,y,rad)
      loop
      exitwhen i == DUMMYAMOUNT * level
         set dummy = CreateUnit(playcast,DummyID,x + (DISTANCEFROMCASTER)*cr,y + (DISTANCEFROMCASTER)*sr,rad*bj_RADTODEG)
         call UnitAddAbility(dummy, CARRIONSWARMID)
         set cr = Cos(rad)
         set sr = Sin(rad)
         call IssuePointOrder(dummy, "carrionswarm", x + (DISTANCEFROMCASTER+100) * cr, y + (DISTANCEFROMCASTER+100) * sr)
         call UnitApplyTimedLife(dummy, 'BTLF', 2/level
 
         set rad = rad + radIncrease
      set i = i + 1
      endloop
      call PauseUnit( caster , false )
      call IssueImmediateOrder( caster , "stop" )
   endfunction
 
 
   private function CrushWaveCond takes nothing returns boolean
      if(GetSpellAbilityId() == SpellID)then
          call CrushWaveAct(GetTriggerUnit(),null)
      endif
   endfunction
   private function Init takes nothing returns nothing
      local trigger t = CreateTrigger()
      call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_SPELL_EFFECT)
      call TriggerAddAction(t, function CrushWaveCond)
   endfunction
endscope
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,468
JASS:
scope WaterGodSpell initializer Init
 
   globals
      private constant integer SpellID = 'A000'
      private constant integer CARRIONSWARMID = 'A001'
      private constant integer DummyID = 'u000'
      private constant integer DUMMYAMOUNT = 8
      private constant string SFX = "Abilities\\Weapons\\PhoenixMissile\\Phoenix_Missile_mini.mdl"
      private constant string SFX2 = "Abilities\\Spells\\Undead\\ReplenishMana\\ReplenishManaCasterOverhead.mdl"
      private constant real DISTANCEFROMCASTER = 25.
   endglobals
 
     private function SFXCREATE takes nothing returns nothing
        local Shape sd = Shape.getData()
        call DestroyEffect(AddSpecialEffect(SFX,sd.x,sd.y))
        call DestroyEffect(AddSpecialEffect(SFX2,sd.x,sd.y))
    endfunction
 
    private function onTest takes unit u,real x,real y,real a returns nothing
        local Shape sd = Shape.createIntersectedStarPolygon(x,y,a,5,500.,1,15,0.,function SFXCREATE)
        //you don't have to set anything here because you already declared all these things in the main function.
        //I just added some parameters here which pass the values from that function to this one.
    endfunction
 
private function CrushWaveAct takes unit caster,unit dummy returns nothing
      local integer i = 0
      // you kept using GetUnitAbilityLevel so I made that a variable too.
      local integer level = GetUnitAbilityLevel(caster,SpellID)
      local real rad = GetUnitFacing(caster)*bj_DEGTORAD
      local player playcast = GetTriggerPlayer()
      local real radIncrease = bj_PI*2./DUMMYAMOUNT
      //You kept using GetUnitX/Y so I just made them variables so you only have to GetUnitX/Y once.
      local real x = GetUnitX(caster)
      local real y = GetUnitY(caster)
      local real cr = Cos(rad)
      local real sr = Sin(rad)
      call onTest(caster,x,y,rad)
      loop
      exitwhen i == DUMMYAMOUNT * level
         set dummy = CreateUnit(playcast,DummyID,x + (DISTANCEFROMCASTER)*cr,y + (DISTANCEFROMCASTER)*sr,rad*bj_RADTODEG)
         call UnitAddAbility(dummy, CARRIONSWARMID)
         // you use Cos(rad) and Sin(rad) twice per loop so I made those variables, too.
         set cr = Cos(rad)
         set sr = Sin(rad)
         call IssuePointOrder(dummy, "carrionswarm", x + (DISTANCEFROMCASTER + 100.)*cr, y + (DISTANCEFROMCASTER + 100.)*sr)
         call UnitApplyTimedLife(dummy, 'BTLF', 2/level
 
         set rad = rad + radIncrease
      set i = i + 1
      endloop
      call PauseUnit( caster , false )
      call IssueImmediateOrder( caster , "stop" )
   endfunction
 
 
   private function CrushWaveCond takes nothing returns nothing
      if(GetSpellAbilityId() == SpellID)then
          call CrushWaveAct(GetTriggerUnit(),null) //Call the actions if the trigger conditions are true (consolidates the code)
      endif                                        //Also, this makes it possible to pass variables to the action function, as 
   endfunction                                     //you can see in "GetTriggerUnit(),null".  You can initialize a parameter w/ null.
   private function Init takes nothing returns nothing
      local trigger t = CreateTrigger()
      //TriggerRegisterAnyUnitEventBJ is fine.  There is really nothing wrong with this call.
      call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_SPELL_EFFECT)
      call TriggerAddAction(t, function CrushWaveCond) //Conditions are now actions
   endfunction
endscope
 
Status
Not open for further replies.
Top