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

Need help with JASS trigger

Status
Not open for further replies.
Level 22
Joined
Feb 3, 2009
Messages
3,292
Hello, i'm trying to make a spell in JASS. It works almost perfectly...
The spell is based of Haunt from Spectre in Dota. Here is the problem:
It works perfectly exept that 3 or 2 illusions always stay by caster, and the others do the job the way they should...

The JASS trigger:

JASS:
globals
unit x
unit illusion
group done
endglobals

function SpectralKill takes nothing returns nothing
call RemoveUnit(GetEnumUnit())
endfunction

function Group2E takes nothing returns boolean
    return ( IsUnitIllusionBJ(GetFilterUnit()) == true )
endfunction

function Group2D takes nothing returns boolean
    return ( GetUnitTypeId(GetFilterUnit()) == 'E000' )
endfunction

function Group2A takes nothing returns boolean
    return GetBooleanAnd( Group2E (), Group2D ())
endfunction

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

function Group1A takes nothing returns boolean
return ( IsUnitEnemy(GetFilterUnit(), GetOwningPlayer(x)) == true )
endfunction

function Group1B takes nothing returns boolean
return ( IsUnitType(GetFilterUnit(), UNIT_TYPE_HERO) == true) 
endfunction


function Group1 takes nothing returns boolean
    return GetBooleanAnd( Group1A (), Group1B () )
endfunction


function Actions takes nothing returns nothing
local group illusions
local group heroes
local integer count
local unit dummy
local unit y
local real yx
local real yy
set x = GetTriggerUnit()
set heroes = GetUnitsInRectMatching(GetEntireMapRect(), Condition(function Group1))
set count = CountUnitsInGroup(heroes)
loop
exitwhen count <= 0
call TriggerSleepAction(0.01)
set dummy = CreateUnitAtLoc( GetOwningPlayer(x), 'h001' , GetRectCenter(GetPlayableMapRect()), 0.00 )
call IssueTargetOrderById(dummy, 852274, x)
call UnitApplyTimedLifeBJ( 5.00, 'BTLF', dummy )
set dummy = null
set count = count - 1
endloop
call TriggerSleepAction(0.01)
set illusions = GetUnitsInRectMatching(GetEntireMapRect(), Condition(function Group2A))
set count = CountUnitsInGroup(heroes)
loop
exitwhen count <= 0
call TriggerSleepAction(0.01)
set y = FirstOfGroup(heroes)
set illusion = FirstOfGroup(illusions) 
set yx = GetUnitX(y)
set yy = GetUnitY(y)
call SetUnitPosition(illusion, yx, yy)
call IssueTargetOrderBJ( illusion, "attack", y )
call UnitApplyTimedLifeBJ( 5.00, 'BTLF', illusion )
call GroupRemoveUnit(heroes, y)
call GroupRemoveUnit(illusions, illusion)
set y = null
set dummy = null
set count = count - 1
endloop
set y = null
set x = null
set dummy = null
call DestroyGroup (illusions)
call DestroyGroup (heroes)
call DestroyGroup (done)
endfunction

//===========================================================================
function InitTrig_Haunt takes nothing returns nothing
    local trigger Haunt = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( Haunt, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( Haunt, Condition(function Conditions ) )
    call TriggerAddAction( Haunt, function Actions )
endfunction


The map (if you can fix, fix in the map and post please):

EDIT: Ahh ffs it doesn't let me upload, gues i'll need the trigger in JASS tags then and i'll copy paste...
 
Last edited:
Level 5
Joined
Dec 18, 2007
Messages
205
well actually, i dont have the time to look through the whole code, but you are using a lot of unnecessary code

like this:

JASS:
function Group1A takes nothing returns boolean
return ( IsUnitEnemy(GetFilterUnit(), GetOwningPlayer(x)) == true )
endfunction

function Group1B takes nothing returns boolean
return ( IsUnitType(GetFilterUnit(), UNIT_TYPE_HERO) == true)
endfunction

function Group1 takes nothing returns boolean
    return GetBooleanAnd( Group1A (), Group1B () )
endfunction

this could be done in 1 fucntion using

JASS:
function Group1 takes nothing returns boolean
    return IsUnitEnemy(GetFilterUnit(), GetOwningPlayer(x)) and IsUnitType(GetFilterUnit(), UNIT_TYPE_HERO)
endfunction

additionally: why are you using waits?

and why don't you add your created illusions to a group instead of creating them and AFTERWARDS adding them to a group by checking the unit types on the map? this destroy the MUI effect even a little.

or even easier: create the illusion dummy, save the attacked unit for each dummy, then add the 5 sec timer. with another timer starting simultaneously check if the attacked unit for the dummy is dead, then kill the dummy before the 5 seconds are over.

such a loop for example

JASS:
loop
exitwhen count <= 0
call TriggerSleepAction(0.01)
set dummy = CreateUnitAtLoc( GetOwningPlayer(x), 'h001' , GetRectCenter(GetPlayableMapRect()), 0.00 )
call IssueTargetOrderById(dummy, 852274, x)
call UnitApplyTimedLifeBJ( 5.00, 'BTLF', dummy )
set dummy = null
set count = count - 1
endloop

better becomes
JASS:
loop
exitwhen count <= 0
set dummy = CreateUnitAtLoc( GetOwningPlayer(x), 'h001' , GetRectCenter(GetPlayableMapRect()), 0.00 ) // leaing a location btw
call IssueTargetOrderById(dummy, 852274, x)
call UnitApplyTimedLifeBJ( 5.00, 'BTLF', dummy )
//save dummy to the group
set count = count - 1
endloop
then you dont need to write the second loop.

i'll look through the code once again if i have the time. i cannot tell you why there is this error atm. maybe i'll do in the future a spectre-haunt trigger.

greetings
 
Level 22
Joined
Feb 3, 2009
Messages
3,292
Do you mind using the same trigger which is used in dota?

I won't open the map just to take the trigger from icefrog if that's what you ment

You should probably explain what Haunt does, since many of us don't play dota.

Well... When used it summons an illusion on every enemy hero on the map and the illusion attacks him, after the timer which in dota is level 1 = 4
2 = 5 3 = 6 they are gone.
 
Status
Not open for further replies.
Top