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

Problem with spell

Status
Not open for further replies.
Level 3
Joined
May 18, 2009
Messages
30
hello all, i try to make this spell but that not works...

JASS:
//This spell pauses all unit within 300/400/500 range
//for 3/4/5 seconds and change his vertex color to Blue.

library ParalizingField
globals
    private integer array SPELL_DUR
    private integer array SPELL_AOE
    private integer AbilityID = 'A000'
endglobals

private function SetUpDuration takes nothing returns nothing
    set SPELL_DUR[1] = 3
    set SPELL_DUR[2] = 4
    set SPELL_DUR[3] = 5
endfunction

private function SetUpSpellAoe takes nothing returns nothing
    set SPELL_AOE[1] = 300
    set SPELL_AOE[2] = 400
    set SPELL_AOE[3] = 500
endfunction

private function Spell_Dur takes integer level returns integer
    return SPELL_DUR[level]
endfunction

private function Spell_Aoe takes integer level returns integer
    return SPELL_AOE[level]
endfunction

function ParalizingCondition takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'A000' ) ) then
        return false
    endif
    return true
endfunction

function CallBack takes nothing returns nothing
    call BJDebugMsg(GetUnitName(GetEnumUnit()))
endfunction

function ParalizingField takes nothing returns nothing 
    local unit e
    local group g
    local unit u = GetTriggerUnit()
    local integer level = GetUnitAbilityLevel (u, AbilityID)
    set g = CreateGroup()
    call ForGroupBJ( GetUnitsInRangeOfLocAll(300.00, GetUnitLoc(GetTriggerUnit())), function CallBack )
    set e = GetEnumUnit()
    call GroupAddUnit(g, e)
    call PauseUnit(e, true)
    call SetUnitVertexColorBJ(e, 0.00, 0.00, 100, 0 )
    call TriggerSleepAction(SPELL_DUR[level])
    call PauseUnit(e, false)
    call SetUnitVertexColorBJ(e, 100, 100, 100, 0 )
    call DestroyGroup(g)
    set u = null
    set e = null
    set g = null
endfunction
//===========================================================================
function InitTrig_Paralizing_Field takes nothing returns nothing
    set gg_trg_Paralizing_Field = CreateTrigger( )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Paralizing_Field, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Paralizing_Field, Condition( function ParalizingCondition ) )
    call TriggerAddAction( gg_trg_Paralizing_Field, function ParalizingField )
endfunction
endlibrary

what is wrong? i need to fix this please. Thanks for help

EDIT:i optimized the code but stills not works
 
Last edited:
Level 12
Joined
Dec 10, 2008
Messages
850
GetEnumUnit needs a unit to work, and you dont pass anything for it to call an enemy. Your script is also funny to look at. Did you even try to optimise the condition and the Init functions?

Also, watch the multi posting. You've bumped this 3 times within a day.

EDIT: Looking at it again reveals many lolz in effieficency. And leaks
 

Cokemonkey11

Code Reviewer
Level 29
Joined
May 9, 2006
Messages
3,516
JASS:
scope paralizingField initializer i
    private struct timeDat
        unit u
        integer s   //seconds
    endstruct
    
    globals
        private group grp=CreateGroup()
        private unit caster=null
        private integer abilLevel=0
        private integer dbIndex=-1
        private timeDat array timeDB
        private timer time=CreateTimer()
        private constant integer PARALIZECODE='A000'
        private constant integer INTERCEPT=2    //Y intercept of pause time function (you're using y=abilityLevel+2)
        private constant real RADIUS=300
    endglobals
    
    private function p takes nothing returns nothing
        local integer index=0
        local timeDat tempDat
        loop
            exitwhen index>dbIndex
            set tempDat=timeDB[index]
            set tempDat.s=tempDat.s-1
            if tempDat.s<1 then
                call PauseUnit(tempDat.u,false)
                call SetUnitVertexColor(tempDat.u,255,255,255,255)
                set timeDB[index]=timeDB[dbIndex]
                set dbIndex=dbIndex-1
                if dbIndex<0 then
                    call PauseTimer(time)
                endif
            set index=index+1
        endloop
    endfunction
    
    private function f2 takes nothing returns boolean
        local timeDat tempDat
        if GetFilterUnit()!=caster then
            set tempDat=timeDat.create()
            set tempDat.u=GetFilterUnit()
            set tempDat.s=INTERCEPT+abilLevel
            set dbIndex=dbIndex+1
            set timeDB[dbIndex]=tempDat
            if dbIndex==0 then
                call TimerStart(time,1,true,function p)
            endif
            call SetUnitVertexColor(GetFilterUnit(),0,0,255,255)
            call PauseUnit(GetFilterUnit(),true)
        endif
        return false
    endfunction
    
    private function f1 takes nothing returns boolean
        if GetSpellAbilityId()==PARALIZECODE then
            set caster=GetTriggerUnit()
            set abilLevel=GetUnitAbilityLevel(GetTriggerUnit(),PARALIZECODE)
            call GroupEnumUnitsInRange(grp,GetUnitX(GetTriggerUnit()),GetUnitY(GetTriggerUnit()),RADIUS,Filter(function f2))
        endif
        return false
    endfunction
    
    private function i takes nothing returns nothing
        local trigger t=CreateTrigger()
        local integer index=0
        loop
            exitwhen index>11   //Assuming passive and hostile don't use this ability..
            call TriggerRegisterPlayerUnitEvent(t,Player(index),EVENT_PLAYER_SPELL_EFFECT,Filter(function f1))
            set index=index+1
        endloop
    endfunction
endscope

that should work :)
 

Cokemonkey11

Code Reviewer
Level 29
Joined
May 9, 2006
Messages
3,516
My mistake.

Change:

JASS:
            if tempDat.s<1 then
                call PauseUnit(tempDat.u,false)
                call SetUnitVertexColor(tempDat.u,255,255,255,255)
                set timeDB[index]=timeDB[dbIndex]
                set dbIndex=dbIndex-1
                if dbIndex<0 then
                    call PauseTimer(time)
                endif
            set index=index+1

to:

JASS:
            if tempDat.s<1 then
                call PauseUnit(tempDat.u,false)
                call SetUnitVertexColor(tempDat.u,255,255,255,255)
                set timeDB[index]=timeDB[dbIndex]
                set dbIndex=dbIndex-1
                if dbIndex<0 then
                    call PauseTimer(time)
                endif
            set index=index+1
            endif
 
Level 3
Joined
May 18, 2009
Messages
30
here is the code now

JASS:
scope paralizingField initializer i
    private struct timeDat
        unit u
        integer s //seconds
    endstruct

    globals
        private group grp=CreateGroup()
        private unit caster=null
        private integer abilLevel=0
        private integer dbIndex=-1
        private timeDat array timeDB
        private timer time=CreateTimer()
        private constant integer PARALIZECODE='A000'
        private constant integer INTERCEPT=2 //Y intercept of pause time function (you're using y=abilityLevel+2)
        private constant real RADIUS=300
    endglobals

    private function p takes nothing returns nothing
        local integer index=0
        local timeDat tempDat
        loop
            exitwhen index>dbIndex
            set tempDat=timeDB[index]
            set tempDat.s=tempDat.s-1
            if tempDat.s<1 then
                call PauseUnit(tempDat.u,false)
                call SetUnitVertexColor(tempDat.u,255,255,255,255)
                set timeDB[index]=timeDB[dbIndex]
                set dbIndex=dbIndex-1
                if dbIndex<0 then
                    call PauseTimer(time)
                endif
            set index=index+1
            endif
        endloop
    endfunction

    private function f2 takes nothing returns boolean
        local timeDat tempDat
        if GetFilterUnit()!=caster then
            set tempDat=timeDat.create()
            set tempDat.u=GetFilterUnit()
            set tempDat.s=INTERCEPT+abilLevel
            set dbIndex=dbIndex+1
            set timeDB[dbIndex]=tempDat
            if dbIndex==0 then
                call TimerStart(time,1,true,function p)
            endif
            call SetUnitVertexColor(GetFilterUnit(),0,0,255,255)
            call PauseUnit(GetFilterUnit(),true)
        endif
        return false
    endfunction

    private function f1 takes nothing returns boolean
        if GetSpellAbilityId()==PARALIZECODE then
            set caster=GetTriggerUnit()
            set abilLevel=GetUnitAbilityLevel(GetTriggerUnit(),PARALIZECODE)
            call GroupEnumUnitsInRange(grp,GetUnitX(GetTriggerUnit()),GetUnitY(GetTriggerUnit()),RADIUS,Filter(function f2))
        endif
        return false
    endfunction

    private function i takes nothing returns nothing
        local trigger t=CreateTrigger()
        local integer index=0
        loop
            exitwhen index>11 //Assuming passive and hostile don't use this ability..
            call TriggerRegisterPlayerUnitEvent(t,Player(index),EVENT_PLAYER_UNIT_SPELL_EFFECT,Filter(function f1))
            set index=index+1
        endloop
    endfunction
endscope

i change EVENT_PLAYER_SPELL_EFFECT for EVENT_PLAYER_UNIT_SPELL_EFFECT

but nothing was happens :S
 

Cokemonkey11

Code Reviewer
Level 29
Joined
May 9, 2006
Messages
3,516
My mistake, EVENT_PLAYER_UNIT_SPELL_EFFECT is correct.

"nothing happens" must mean my register isn't working properly (oops :p)

Change:

JASS:
    private function f1 takes nothing returns boolean
        if GetSpellAbilityId()==PARALIZECODE then
            set caster=GetTriggerUnit()
            set abilLevel=GetUnitAbilityLevel(GetTriggerUnit(),PARALIZECODE)
            call GroupEnumUnitsInRange(grp,GetUnitX(GetTriggerUnit()),GetUnitY(GetTriggerUnit()),RADIUS,Filter(function f2))
        endif
        return false
    endfunction

    private function i takes nothing returns nothing
        local trigger t=CreateTrigger()
        local integer index=0
        loop
            exitwhen index>11 //Assuming passive and hostile don't use this ability..
            call TriggerRegisterPlayerUnitEvent(t,Player(index),EVENT_PLAYER_UNIT_SPELL_EFFECT,Filter(function f1))
            set index=index+1
        endloop
    endfunction
endscope

to:

JASS:
    private function c takes nothing returns boolean
        if GetSpellAbilityId()==PARALIZECODE then
            set caster=GetTriggerUnit()
            set abilLevel=GetUnitAbilityLevel(GetTriggerUnit(),PARALIZECODE)
            call GroupEnumUnitsInRange(grp,GetUnitX(GetTriggerUnit()),GetUnitY(GetTriggerUnit()),RADIUS,Filter(function f2))
        endif
        return false
    endfunction

    private function i takes nothing returns nothing
        local trigger t=CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_SPELL_EFFECT)
	call TriggerAddCondition(t,Condition(function c))
    endfunction
endscope

just a guess...
 
Level 3
Joined
May 18, 2009
Messages
30
now works, thanks :), the only error is: every time when cast a spell every unit get paused, for example: 7 units are in pause but in 2 seconds only 4 units get despaused, in 4 seconds 2 more units get despaused and after 6 seconds the last unit get despaused... this is the only error, the rest are fine :)
 
Status
Not open for further replies.
Top