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

[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