• 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] Why does it hate me?

Status
Not open for further replies.
Level 3
Joined
Mar 7, 2004
Messages
27
Code:
function GetHeroSphere takes unit u returns integer
   local integer i = 0
   loop
      exitwhen i>8
      if (udg_Hero[i] == u) then
         return i
      else
         set i=i+1
      endif
   endloop
   return 9
endfunction

function Trig_SphereSystem_Actions takes nothing returns nothing
    local integer i = 0
    local unit u = GetTriggerUnit()
    if ( udg_Hero[GetHeroSphere(u)] == GetAttacker() ) then
        call IssueTargetOrder( udg_Sphere[GetHeroSphere(u)], "attack", udg_Sphere[GetHeroSphere(u)] )
    else
       if ( udg_Hero[GetHeroSphere(u)] == GetAttackedUnitBJ() ) then
          return
       else
           if ( GetDyingUnit() == udg_Hero[GetHeroSphere(u)] ) then
              call ExplodeUnitBJ( udg_Sphere[GetHeroSphere(u)] )
              set udg_Sphere[GetHeroSphere(u)] = null
           else
               if ( GetRevivingUnit() == udg_Hero[GetHeroSphere(u)] ) then
                  set udg_Sphere[GetHeroSphere(u)] = CreateUnitAtLoc( Player(13), 'Hblm', GetUnitLoc(u), bj_UNIT_FACING )
                  call UnitAddAbilityBJ( udg_SphereAbil[GetHeroSphere(u)], udg_Sphere[GetHeroSphere(u)] )
                  call SetUnitInvulnerable( udg_Sphere[GetHeroSphere(u)], true )
                  call SetUnitPathing( udg_Sphere[GetHeroSphere(u)], false )
                  call SetUnitVertexColorBJ( udg_Sphere[GetHeroSphere(u)], 100, 100, 100, 100.00 )
                  call SetUnitPositionLoc( udg_Sphere[GetHeroSphere(u)], GetUnitLoc(udg_Hero[GetHeroSphere(u)]) )
               else
                  loop
                     exitwhen i > 8
                     set udg_Sphere[i] = CreateUnitAtLoc( Player(13), 'Hblm', GetUnitLoc(udg_Hero[i]), bj_UNIT_FACING )
                     call SetUnitVertexColorBJ( udg_Sphere[i], 100, 100, 100, 100.00 )
                     call UnitAddAbilityBJ( udg_SphereAbil[i], udg_Sphere[i] )
                     call SetUnitInvulnerable( udg_Sphere[i], true )
                     call SetUnitPathing( udg_Sphere[i], false )
                     call SetUnitPositionLoc( udg_Sphere[i], GetUnitLoc(udg_Hero[i]) )
                     set i = i+1
                  endloop
               endif
           endif
       endif
    endif
    set u = null
    call EnableTrigger( gg_trg_SphereSystem2 )
endfunction

//===========================================================================
function InitTrig_SphereSystem takes nothing returns nothing
    set gg_trg_SphereSystem = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_SphereSystem, EVENT_PLAYER_UNIT_DEATH )
    call TriggerRegisterTimerEventSingle( gg_trg_SphereSystem, 25.00 )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_SphereSystem, EVENT_PLAYER_UNIT_ATTACKED )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_SphereSystem, EVENT_PLAYER_HERO_REVIVE_FINISH )
    call TriggerAddAction( gg_trg_SphereSystem, function Trig_SphereSystem_Actions )
endfunction

-_-

Looks sound to me. (BTW, it is moving a 100% alphaed Bloodmage to the units every .1 seconds. The spheres moving work fine. These actions do not.)
 
Level 3
Joined
Mar 7, 2004
Messages
27
Ok. I coded this about 6 months ago so I'm looking at it again and finding some errors. So here is the updated code:

Code:
function GetHeroSphere takes unit u returns integer
   local integer i = 0
   loop
      exitwhen i>8
      if (udg_Hero[i] == u) then
         return i
      else
         set i=i+1
      endif
   endloop
   return 9
endfunction

function Trig_SphereSystem_Actions takes nothing returns nothing
    local integer i = 0
    local unit u = GetTriggerUnit()
    if ( udg_Hero[GetHeroSphere(u)] == GetAttacker() ) then
        call IssueTargetOrder( udg_Sphere[GetHeroSphere(u)], "attack", GetAttackedUnitBJ()] )
        set u = null
        return
    else
       if ( udg_Hero[GetHeroSphere(u)] == GetAttackedUnitBJ() ) then
          set u = null
          return
       else
           if ( GetDyingUnit() == udg_Hero[GetHeroSphere(u)] ) then
              call ExplodeUnitBJ( udg_Sphere[GetHeroSphere(u)] )
              set udg_Sphere[GetHeroSphere(u)] = null
              set u = null
              return
           else
               if ( GetRevivingUnit() == udg_Hero[GetHeroSphere(u)] ) then
                  set udg_Sphere[GetHeroSphere(u)] = CreateUnitAtLoc( Player(13), 'Hblm', GetUnitLoc(u), bj_UNIT_FACING )
                  call UnitAddAbilityBJ( udg_SphereAbil[GetHeroSphere(u)], udg_Sphere[GetHeroSphere(u)] )
                  call SetUnitInvulnerable( udg_Sphere[GetHeroSphere(u)], true )
                  call SetUnitPathing( udg_Sphere[GetHeroSphere(u)], false )
                  call SetUnitVertexColorBJ( udg_Sphere[GetHeroSphere(u)], 100, 100, 100, 100.00 )
                  call SetUnitPositionLoc( udg_Sphere[GetHeroSphere(u)], GetUnitLoc(udg_Hero[GetHeroSphere(u)]) )
                  set u = null
                  return
               else
                  loop
                     exitwhen i > 8
                     set udg_Sphere[i] = CreateUnitAtLoc( Player(13), 'Hblm', GetUnitLoc(udg_Hero[i]), bj_UNIT_FACING )
                     call SetUnitVertexColorBJ( udg_Sphere[i], 100, 100, 100, 100.00 )
                     call UnitAddAbilityBJ( udg_SphereAbil[i], udg_Sphere[i] )
                     call SetUnitInvulnerable( udg_Sphere[i], true )
                     call SetUnitPathing( udg_Sphere[i], false )
                     call SetUnitPositionLoc( udg_Sphere[i], GetUnitLoc(udg_Hero[i]) )
                     set i = i+1
                  endloop
               endif
           endif
       endif
    endif
    set u = null
    call EnableTrigger( gg_trg_SphereSystem2 )
endfunction

//===========================================================================
function InitTrig_SphereSystem takes nothing returns nothing
    set gg_trg_SphereSystem = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_SphereSystem, EVENT_PLAYER_UNIT_DEATH )
    call TriggerRegisterTimerEventSingle( gg_trg_SphereSystem, 25.00 )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_SphereSystem, EVENT_PLAYER_UNIT_ATTACKED )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_SphereSystem, EVENT_PLAYER_HERO_REVIVE_FINISH )
    call TriggerAddAction( gg_trg_SphereSystem, function Trig_SphereSystem_Actions )
endfunction
 
Level 3
Joined
Mar 27, 2004
Messages
70
Try this:
JASS:
function GetHeroSphere takes unit u returns integer
   local integer i = 0
   loop
      exitwhen i>8
      if (udg_Hero[i] == u) then
         return i
      else
         set i=i+1
      endif
   endloop
   return 9
endfunction

function Trig_SphereSystem_Actions takes nothing returns nothing
    local integer i = 0
    local unit u = GetTriggerUnit()
    local integer x = GetHeroSphere(u)
    if ( u == GetAttacker() ) then
        call IssueTargetOrder( udg_Sphere[x], "attack", GetAttackedUnitBJ() )
        set u = null
        return
    else
       if ( u == GetAttackedUnitBJ() ) then
          set u = null
          return
       else
           if ( GetDyingUnit() == u ) then
              call ExplodeUnitBJ( udg_Sphere[x] )
              set udg_Sphere[x] = null
              set u = null
              return
           else
               if ( GetRevivingUnit() == u ) then
                  set udg_Sphere[x] = CreateUnit( Player(13), 'Hblm', GetUnitX(u), GetUnitY(u), bj_UNIT_FACING )
                  call UnitAddAbilityBJ( udg_SphereAbil[x], udg_Sphere[x] )
                  call SetUnitInvulnerable( udg_Sphere[x], true )
                  call SetUnitPathing( udg_Sphere[x], false )
                  call SetUnitVertexColorBJ( udg_Sphere[x], 100, 100, 100, 100.00 )
                  call SetUnitPosition( udg_Sphere[x], GetUnitX(u), GetUnitY(u) )
                  set u = null
                  return
               else
                  loop
                     exitwhen i > 8
                     set udg_Sphere[i] = CreateUnit( Player(13), 'Hblm', GetUnitX(udg_Hero[i]), GetUnitY(udg_Hero[i]), bj_UNIT_FACING )
                     call SetUnitVertexColorBJ( udg_Sphere[i], 100, 100, 100, 100.00 )
                     call UnitAddAbilityBJ( udg_SphereAbil[i], udg_Sphere[i] )
                     call SetUnitInvulnerable( udg_Sphere[i], true )
                     call SetUnitPathing( udg_Sphere[i], false )
                     call SetUnitPosition( udg_Sphere[i], GetUnitX(udg_Hero[i]), GetUnitY(udg_Hero[i]) )
                     set i = i+1
                  endloop
               endif
           endif
       endif
    endif
    set u = null
    call EnableTrigger( gg_trg_SphereSystem2 )
endfunction

//===========================================================================
function InitTrig_SphereSystem takes nothing returns nothing
    set gg_trg_SphereSystem = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_SphereSystem, EVENT_PLAYER_UNIT_DEATH )
    call TriggerRegisterTimerEventSingle( gg_trg_SphereSystem, 25.00 )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_SphereSystem, EVENT_PLAYER_UNIT_ATTACKED )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_SphereSystem, EVENT_PLAYER_HERO_REVIVE_FINISH )
    call TriggerAddAction( gg_trg_SphereSystem, function Trig_SphereSystem_Actions )
endfunction
I tried optimizing it and prevented a couple of location leaks.

I believe your compile error was due to the ] in this line:
call IssueTargetOrder( udg_Sphere[GetHeroSphere(u)], "attack", GetAttackedUnitBJ()] )
 
Level 3
Joined
Mar 7, 2004
Messages
27
Err...I hadn't actually tried that in the WE. I just edited it here on the mistakes I saw while rereading it. I guess that is what I get for trying to edit code on forums :p

Anyways...I'll give it a try and see what happens. Thanks.
 
Status
Not open for further replies.
Top