Check my spell please

Moon_Raven

New Member
Reaction score
8
Ok, so here is one of the first spells I made by my self in JASS. So, could you please check it, by checking I primarely mean leaks, and I am unsure about using that unit array. It makes nulling easier but still does it consume too much memory? The spell should Create 1/2/3 unkillable and unselectable and immovable hydras(like in Diablo 2), so they have locust and invurnerable in the editor(like that matters anyway). So here is the code:
JASS:

function Hydras takes integer n returns integer
    if(n==1) then
        return 'o001'
    elseif(n==2) then
        return 'o002'
    else
       return 'o000'
    endif
endfunction

function Trig_Hydra_Actions takes nothing returns nothing
    local integer n = 1
    local location l = GetSpellTargetLoc()
    local real x
    local real y = GetLocationY(l)
    local integer level = GetUnitAbilityLevel(GetTriggerUnit(),'A003')
    local unit array u
    set u[4] = GetTriggerUnit()
    loop
    exitwhen(n==level+1)
        set x = GetLocationX(l)
        set u[n] = CreateUnitAtLoc(GetOwningPlayer(u[4]),Hydras(level),l,0)
        call UnitApplyTimedLife(u[n],'BTLF',30)
        set n = n+1
        set l = Location(x+100,y)
    endloop
    call RemoveLocation(l)
    set u[1] = null
    set u[2] = null
    set u[3] = null
    set u[4] = null
    set l = null
endfunction
function CheckSpellHydra takes nothing returns boolean
    return (GetSpellAbilityId()=='A003')
endfunction
//===========================================================================
function InitTrig_Hydra takes nothing returns nothing
    set gg_trg_Hydra = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ(gg_trg_Hydra,EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(gg_trg_Hydra,Condition(function CheckSpellHydra))
    call TriggerAddAction( gg_trg_Hydra, function Trig_Hydra_Actions )
    set gg_trg_Hydra = null
endfunction

I also doubt the Hydras method of working(if/then/else) is the best one available...
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
I trusted arrays are slower. So, i will do it like that


JASS:


function Hydras takes integer n returns integer
    if(n==1) then
        return 'o001'
    elseif(n==2) then
        return 'o002'
    else
       return 'o000'
    endif
endfunction

function Trig_Hydra_Actions takes nothing returns nothing
    local unit cs = GetTriggerUnit()
    local integer n = 1
    local location l = GetSpellTargetLoc()
    local real x = GetLocationX(l)
    local real y = GetLocationY(l)
    local integer level = GetUnitAbilityLevel(GetTriggerUnit(),'A003')
    local unit u
    set u[4] = GetTriggerUnit()
    loop
    exitwhen n==level+1
        set x = GetLocationX(l)+100
        set u = CreateUnit(GetOwningPlayer(cs),Hydras(level),x+100,y,0)
        call UnitApplyTimedLife(u,'BTLF',30)
        set n = n+1
    endloop
    call RemoveLocation(l)
    set u = null
    set cs = null
    set l = null
endfunction

function CheckSpellHydra takes nothing returns boolean
    return GetSpellAbilityId()=='A003'
endfunction

function InitTrig_Hydra takes nothing returns nothing
    local trigger Hydra = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ(Hydra,EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(Hydra,Condition(function CheckSpellHydra))
    call TriggerAddAction(Hydra, function Trig_Hydra_Actions )
    set Hydra = null
endfunction
 

~GaLs~

† Ғσſ ŧħə ѕαĸε Φƒ ~Ğ䣚~ †
Reaction score
180
JASS:
function Hydras takes integer n returns integer
    if n==1 then
        return 'o001'
    elseif n==2 then
        return 'o002'
    else
       return 'o000'
    endif
endfunction

function Trig_Hydra_Actions takes nothing returns nothing
    local integer level = GetUnitAbilityLevel(GetTriggerUnit(),'A003')
    local integer n = 1
    local location l = GetSpellTargetLoc()
	local unit u
	
    loop
    exitwhen(n==level+1)
        set u = CreateUnitAtLoc(GetOwningPlayer(GetTriggerUnit()),Hydras(level),l,0)
        call UnitApplyTimedLife(u,'BTLF',30)
		call RemoveLocation(l)
        set l = Location(GetLocationX(l)+100,GetLocationY(l))
	set n = n+1
    endloop
	
    call RemoveLocation(l)
    set u = null
    set l = null
endfunction

function CheckSpellHydra takes nothing returns boolean
    return GetSpellAbilityId()=='A003'
endfunction
//===========================================================================
function InitTrig_Hydra takes nothing returns nothing
    set gg_trg_Hydra = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ(gg_trg_Hydra,EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(gg_trg_Hydra,Condition(function CheckSpellHydra))
    call TriggerAddAction( gg_trg_Hydra, function Trig_Hydra_Actions )
    set gg_trg_Hydra = null
endfunction
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top