• 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.

[vJASS] Creep casting spell

Status
Not open for further replies.
Level 4
Joined
Apr 7, 2012
Messages
63
I need to improve this.You will realize there is a few leaks.

JASS:
scope Barbedbristleback  initializer Init

globals
    private constant integer ABIL_ID = 'A00C'
    private constant string ORDER = "fanofknives"
endglobals    

private function  Barbedbristleback_Conditions takes nothing returns boolean
    return GetUnitTypeId(GetAttacker()) =='n000' 
endfunction

private function Actions takes nothing returns nothing
     local integer  abilityint  = 0
     local unit bristle = GetAttacker()
     local unit target = GetTriggerUnit()
     local real mana = GetUnitState(bristle,UNIT_STATE_MANA)
     
      
      if mana >= 20 then
              
              call UnitAddAbility(bristle,ABIL_ID)
              call SetUnitAbilityLevel(bristle,ABIL_ID,1)
              call IssueTargetOrder(bristle,ORDER,target)
      endif  
endfunction

//===========================================================================
private function Init takes nothing returns nothing
    local trigger BarbedbristlebackTrg  = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( BarbedbristlebackTrg, EVENT_PLAYER_UNIT_ATTACKED )
    call TriggerAddCondition( BarbedbristlebackTrg, Condition( function Barbedbristleback_Conditions ) )
    call TriggerAddAction( BarbedbristlebackTrg, function Actions )
endfunction
endscope

Any ideas will be appreciated.
 
Level 8
Joined
Sep 18, 2011
Messages
195
I read this somewhere, you can make this to avoid some errors, but I think it is not necessary.
JASS:
call UnitAddAbility(bristle,ABIL_ID)
call SetUnitAbilityLevel(bristle,ABIL_ID,1)
call IssueTargetOrder(bristle,ORDER,target)
--►
JASS:
if UnitAddAbility(bristle,ABIL_ID) then
     call SetUnitAbilityLevel(bristle,ABIL_ID,1)
     call IssueTargetOrder(bristle,ORDER,target)
endif
 
Level 4
Joined
Apr 7, 2012
Messages
63
I'll null the handles this time,thanks!
Oh yes,this is for multiple units and sometimes if I attack one bristle the other one also starts to cast the spell.
 
Status
Not open for further replies.
Top