• 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] Simple Jass spell

Status
Not open for further replies.
Level 6
Joined
Sep 13, 2008
Messages
261
I am learning Jass and I would appreciate it, if someone could make this work for me.

I want it to pause units in area giving them pause(stun) effect, then wait x seconds based on a global variable number, then simply unpause them and remove the effect. Must be MUI when done and have as few leaks as possible.

Heres what I got.
JASS:
function Trig_ArcaneFlash_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'A004' ) ) then
        return false
    endif
    return true
endfunction

function Trig_ArcaneFlash_Func003A takes nothing returns nothing
    local effect e=null
    call PauseUnitBJ( true, GetEnumUnit() )
    call AddSpecialEffectTargetUnitBJ( "overhead", GetEnumUnit(), "Abilities\\Spells\\Human\\Thunderclap\\ThunderclapTarget.mdl" )
    set e=bj_lastCreatedEffect
    call TriggerSleepAction( ( I2R(udg_Player1skills[1]) / 2.00 ) )
    call PauseUnitBJ( false, GetEnumUnit() )
    call DestroyEffectBJ( e )
endfunction

function Trig_ArcaneFlash_Actions takes nothing returns nothing
    set udg_TempPoint[1] = GetUnitLoc(GetSpellAbilityUnit())
    set bj_wantDestroyGroup = true
    call ForGroupBJ( GetUnitsInRangeOfLocAll(300.00, GetUnitLoc(GetSpellAbilityUnit())), function Trig_ArcaneFlash_Func003A )
    call RemoveLocation(udg_TempPoint[1])
endfunction

//===========================================================================
function InitTrig_ArcaneFlash takes nothing returns nothing
    set gg_trg_ArcaneFlash = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_ArcaneFlash, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_ArcaneFlash, Condition( function Trig_ArcaneFlash_Conditions ) )
    call TriggerAddAction( gg_trg_ArcaneFlash, function Trig_ArcaneFlash_Actions )
endfunction

Currently It stuns them and adds the effect, but doesn't unstun or remove the effect.
 
Level 6
Joined
Sep 13, 2008
Messages
261
Tried your suggestion and I can't get it to work either. If someone could just write the spell for me it would help greatly.

mine I get undeclared variable e error.

JASS:
function Trig_ArcaneFlash2_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'A004' ) ) then
        return false
    endif
    return true
endfunction

function Trig_ArcaneFlash2_Func002A takes nothing returns nothing
    local effect e=null
    call AddSpecialEffectTargetUnitBJ( "overhead", GetEnumUnit(), "Abilities\\Spells\\Human\\Thunderclap\\ThunderclapTarget.mdl" )
    set e=bj_lastCreatedEffect
    call PauseUnitBJ( true, GetEnumUnit() )
endfunction

function Trig_ArcaneFlash2_Func004A takes nothing returns nothing
    call DestroyEffectBJ( e )
    call PauseUnitBJ( false, GetEnumUnit() )
endfunction

function Trig_ArcaneFlash2_Actions takes nothing returns nothing
    local group g=null
    set udg_TempPoint[1] = GetUnitLoc(GetSpellAbilityUnit())
    call GroupAddGroup( GetUnitsInRangeOfLocAll(250.00, udg_TempPoint[1]), g )
    set g=bj_groupLastCreatedDest
    call ForGroupBJ( g, function Trig_ArcaneFlash2_Func002A )
    call TriggerSleepAction( ( I2R(udg_Player1skills[1]) / 2.00 ) )
    call ForGroupBJ( g, function Trig_ArcaneFlash2_Func004A )
    call DestroyGroup(g)
    call RemoveLocation(udg_TempPoint[1])
endfunction

//===========================================================================
function InitTrig_ArcaneFlash2 takes nothing returns nothing
    set gg_trg_ArcaneFlash2 = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_ArcaneFlash2, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_ArcaneFlash2, Condition( function Trig_ArcaneFlash2_Conditions ) )
    call TriggerAddAction( gg_trg_ArcaneFlash2, function Trig_ArcaneFlash2_Actions )
endfunction

When I remove variable e, there seems to be no effect on the ability at all. So someone please write me this simple spell.
 
Last edited:
Level 5
Joined
Dec 18, 2007
Messages
205
Sorry, but I think you just convert GUI -> JASS and this is really bad. You should learn writing triggers directly in JASS, so you can prevent lots of unneeded triggers. Just an example:

JASS:
call GroupAddGroup( GetUnitsInRangeOfLocAll(250.00, udg_TempPoint[1]), g )
    set g=bj_groupLastCreatedDest

just use

JASS:
set g=GetUnitsInRangeOfLocAll(250.,udg_TempPoint[1])

because in the upper function you use a global variable but u set it to the other group and that leaks, although you have that local.
 
Level 22
Joined
Dec 31, 2006
Messages
2,216
I think this should work (Haven't tested it)

JASS:
function ArcaneFlash2_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A004'
endfunction

function ArcaneFlash2 takes nothing returns nothing
    local unit u = GetSpellAbilityUnit()
    local group g = CreateGroup()
    local group g2 = CreateGroup()
    local real x = GetUnitX(u)
    local real y = GetUnitY(u)
    local unit u2
    call GroupEnumUnitsInRange(g, x, y, 250., null)
    loop
        set u2 = FirstOfGroup(g)
        exitwhen u2 == null
        call GroupRemoveUnit(g, u2)
        call GroupAddUnit(g2, u2)
        call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Human\\Thunderclap\\ThunderclapTarget.mdl", u2, "overhead"))
        call PauseUnit(u2, true)
        set u2 = null
    endloop
    call DestroyGroup(g)
    set g = null
    call TriggerSleepAction( ( I2R(udg_Player1skills[1]) / 2.00 ) )
    loop
        set u2 = FirstOfGroup(g2)
        exitwhen u2 == null
        call PauseUnit(u2, false)
        set u2 = null
    endloop
    call DestroyGroup(g2)
    set g2 = null
    set u = null
endfunction

//===========================================================================
function InitTrig_ArcaneFlash2 takes nothing returns nothing
    set gg_trg_ArcaneFlash2 = CreateTrigger( )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_ArcaneFlash2, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_ArcaneFlash2, Condition( function ArcaneFlash2_Conditions ) )
    call TriggerAddAction( gg_trg_ArcaneFlash2, function ArcaneFlash2 )
endfunction
 
Level 6
Joined
Sep 13, 2008
Messages
261
I think this should work (Haven't tested it)

JASS:
function ArcaneFlash2_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A004'
endfunction

function ArcaneFlash2 takes nothing returns nothing
    local unit u = GetSpellAbilityUnit()
    local group g = CreateGroup()
    local group g2 = CreateGroup()
    local real x = GetUnitX(u)
    local real y = GetUnitY(u)
    local unit u2
    call GroupEnumUnitsInRange(g, x, y, 250., null)
    loop
        set u2 = FirstOfGroup(g)
        exitwhen u2 == null
        call GroupRemoveUnit(g, u2)
        call GroupAddUnit(g2, u2)
        call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Human\\Thunderclap\\ThunderclapTarget.mdl", u2, "overhead"))
        call PauseUnit(u2, true)
        set u2 = null
    endloop
    call DestroyGroup(g)
    set g = null
    call TriggerSleepAction( ( I2R(udg_Player1skills[1]) / 2.00 ) )
    loop
        set u2 = FirstOfGroup(g2)
        exitwhen u2 == null
        call PauseUnit(u2, false)
        set u2 = null
    endloop
    call DestroyGroup(g2)
    set g2 = null
    set u = null
endfunction

//===========================================================================
function InitTrig_ArcaneFlash2 takes nothing returns nothing
    set gg_trg_ArcaneFlash2 = CreateTrigger( )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_ArcaneFlash2, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_ArcaneFlash2, Condition( function ArcaneFlash2_Conditions ) )
    call TriggerAddAction( gg_trg_ArcaneFlash2, function ArcaneFlash2 )
endfunction

I fixed the minor syntax errors etc and tried the script. It did not work right.
I permanently stunned the unites and the special effect was created and instantly destroyed. I still need someone to write a code or fix this one. This one looks like it should work to me, but I only started Jass yesterday.
 
Level 22
Joined
Dec 31, 2006
Messages
2,216
Oops... I made a little mistake...
Here's the new code:
JASS:
function ArcaneFlash2_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A004'
endfunction

function ArcaneFlash2 takes nothing returns nothing
    local unit u = GetSpellAbilityUnit()
    local location l = GetSpellTargetLoc()
    local group g = CreateGroup()
    local group g2 = CreateGroup()
    local real x = GetLocationX(l)
    local real y = GetLocationY(l)
    local unit u2
    local effect array e
    local integer i = 0
    call RemoveLocation(l)
    call GroupEnumUnitsInRange(g, x, y, 250., null)
    loop
        set u2 = FirstOfGroup(g)
        exitwhen u2 == null
        if u2 != u then
            call GroupRemoveUnit(g, u2)
            call GroupAddUnit(g2, u2)
            set e[i] = AddSpecialEffectTarget("Abilities\\Spells\\Human\\Thunderclap\\ThunderclapTarget.mdl", u2, "overhead")
            call PauseUnit(u2, true)
            set i = i + 1
        else
        endif
        set u2 = null
    endloop
    call DestroyGroup(g)
    set g = null
    call TriggerSleepAction( ( I2R(udg_Player1skills[1]) / 2.00 ) )
    loop
        set u2 = FirstOfGroup(g2)
        exitwhen u2 == null
        set i = i - 1
        call DestroyEffect(e[i])
        set e[i] = null
        call PauseUnit(u2, false)
        set u2 = null
    endloop
    call DestroyGroup(g2)
    set g2 = null
    set u = null
endfunction

//===========================================================================
function InitTrig_ArcaneFlash2 takes nothing returns nothing
    set gg_trg_ArcaneFlash2 = CreateTrigger( )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_ArcaneFlash2, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_ArcaneFlash2, Condition( function ArcaneFlash2_Conditions ) )
    call TriggerAddAction( gg_trg_ArcaneFlash2, function ArcaneFlash2 )
endfunction
 
Level 6
Joined
Sep 13, 2008
Messages
261
The new code doesn't seem to work at all. I noticed that you changed to spell target location, so I changed it back to postion of caster, but either way the script doesn't seem to do anything in game. So I still need the code.

If anyone can show me how to debug his code and find the problem that would help too.

Nvmd I fixed his script he just put some things in the wrong places.
 
Last edited:
Level 6
Joined
Sep 13, 2008
Messages
261
In order to get your script to function properly I had to change your script to this
JASS:
function ArcaneFlash2_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A004'
endfunction
function ArcaneFlash2 takes nothing returns nothing
    local unit u = GetSpellAbilityUnit()
    local group g = CreateGroup()
    local group g2 = CreateGroup()
    local real x = GetUnitX(u)
    local real y = GetUnitY(u)
    local unit u2
    local effect array e
    local integer i = 0
    call GroupEnumUnitsInRange(g, x, y, 250., null)
    loop
        set u2 = FirstOfGroup(g)
        exitwhen u2 == null
        if u2 != u then
            call GroupRemoveUnit(g, u2)
            call GroupAddUnit(g2, u2)
            set e[i] = AddSpecialEffectTarget("Abilities\\Spells\\Human\\Thunderclap\\ThunderclapTarget.mdl", u2, "overhead")
            call PauseUnit(u2, true)
            set i = i + 1
        else
            call GroupRemoveUnit(g, u2)
        endif
    endloop
    call DestroyGroup(g)
    set g = null
    call TriggerSleepAction( ( GetHeroLevel(GetSpellAbilityUnit()) / 4.00 ) )
    loop
        set u2 = FirstOfGroup(g2)
        exitwhen u2 == null
        call GroupRemoveUnit(g2, u2)
        set i = i - 1
        call DestroyEffect(e[i])
        set e[i] = null
        call PauseUnit(u2, false)
    endloop
    call DestroyGroup(g2)
    set g2 = null
    set u = null
    set u2 = null
endfunction
//===========================================================================
function InitTrig_ArcaneFlash takes nothing returns nothing
    set gg_trg_ArcaneFlash = CreateTrigger( )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_ArcaneFlash, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_ArcaneFlash, Condition( function ArcaneFlash2_Conditions ) )
    call TriggerAddAction( gg_trg_ArcaneFlash, function ArcaneFlash2 )
endfunction

I think the problem was in your first loop. The else function needed to remove the caster from the group or the loop got stuck, because he stayed the first unit in the group.

Thank you for all your help The_Reborn_Devil. I learned alot from your script.
 
Status
Not open for further replies.
Top