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

[JASS] Can someone fix this?

Status
Not open for further replies.
Level 3
Joined
Dec 24, 2006
Messages
68
Well, im not so good jasser, so im asking you to help me. This spells summons x units and then it should order them to attack target of ability being cast and get removed after x time, though they dont get removed, they dont even attack the target, just random units.

JASS:
function Trig_Ancestral_Call_Conditions takes nothing returns boolean
   return GetSpellAbilityId() == 'A00G'
endfunction

function Trig_Ancestral_Call_Actions takes nothing returns nothing

        local unit a = GetSpellAbilityUnit()
        local group g
        local integer i=0
        local unit pickedunit

        set g = CreateGroup()

        loop
              set i = i + 1
              exitwhen i >  GetUnitAbilityLevelSwapped('A00G', a)
              call GroupAddUnit(g, CreateUnit(GetOwningPlayer(a) , 'oshm', GetUnitX(a) , GetUnitY(a) , 0))
              call IssueTargetOrder( GetLastCreatedUnit(), "attack", GetSpellTargetUnit() )
        endloop
        call PolledWait(0.50)
loop
            exitwhen FirstOfGroup(g)  == null
            set pickedunit = FirstOfGroup(g) 
            call RemoveUnit(pickedunit)
            call GroupRemoveUnit(g, pickedunit)
            set pickedunit=null
        endloop

endfunction

//===========================================================================
function InitTrig_Ancestral_Call takes nothing returns nothing
    set gg_trg_Ancestral_Call = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Ancestral_Call, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Ancestral_Call, Condition( function Trig_Ancestral_Call_Conditions ) )
    call TriggerAddAction( gg_trg_Ancestral_Call, function Trig_Ancestral_Call_Actions )
endfunction
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
CreateUnit() doesn't set bj_lastCreatedUnit.

Try changing it to

local unit temp

[loop]
set temp = CreateUnit(bleh)

then using temp to do your stuff

Also, use UnitApplyTimedLife( someUnit, 'BTlf', 1 ) to clean them up (with SetUnitExploded( someUnit, true ) and having them have no Art-Special, or a 'death' art of your choice) instead of the wait. Finally, use GetUnitAbilityLevel instead of GetUnitAbilityLevelSwapped
 
Level 11
Joined
Oct 13, 2005
Messages
233
Though if you follow PurlePoot's instructions, what I'm going to say won't be necessary to your code, but it's good to know. In the second loop, you're removing the picked unit from the game and then trying to remove the unit from the group. You should instead do it the other way around. Also, I notice you'll have 2 FirstOfGroup calls per loop in the second one. Instead, set a unit to the FirstOfGroup and then the exitwhen statement should exit when that unit is == null.
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
to follow up on wyrm's instructions, a loop like that (if you chose to go about this that way) would look like

JASS:
loop
    set u = FirstOfGroup( g )
    exitwhen u == null
    call GroupRemoveUnit( g, u )
    call RemoveUnit( u )
endloop

Though

JASS:
call SetUnitExploded( u, true )
call UnitApplyTimedLife( u, 'BTlf', 1 )

Is still a much cleaner way to do it than the wait + loop, for reasons like

-a non-variable wait time before the unit is killed
-you don't need a group
-you don't need the wait
 
Level 3
Joined
Dec 24, 2006
Messages
68
if i get it right, i should get something like this?
JASS:
function Trig_Ancestral_Call_Conditions takes nothing returns boolean
   return GetSpellAbilityId() == 'A00G'
endfunction

function Trig_Ancestral_Call_Actions takes nothing returns nothing

        local unit a = GetSpellAbilityUnit()
        local unit b = GetSpellTargetUnit()
        local unit temp
        local integer i = 0

        loop
              set i = i + 1
              exitwhen i >  GetUnitAbilityLevel( a, 'A00G' )
              set temp = CreateUnit(GetOwningPlayer(a) , 'oshm', GetUnitX(a) , GetUnitY(a) , 0)
              call IssueTargetOrder( temp, "attack", b )
              call UnitApplyTimedLife( temp, 'BTlf', 1 )
              call SetUnitExploded( temp, true )
        endloop
endfunction

//===========================================================================

function InitTrig_Ancestral_Call takes nothing returns nothing
    set gg_trg_Ancestral_Call = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Ancestral_Call, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Ancestral_Call, Condition( function Trig_Ancestral_Call_Conditions ) )
    call TriggerAddAction( gg_trg_Ancestral_Call, function Trig_Ancestral_Call_Actions )
endfunction

Edit: just tested it, works fine, thenks for help ;)

1 more question regarding this ability, how can i create units around the caster in random position within 300 area?
is that correct?
JASS:
          set temp = CreateUnitAtLoc( GetOwningPlayer(a), 'oshm', OffsetLocation(GetUnitLoc(a), GetRandomReal(0, 300.00), GetRandomReal(0.00, 300.00)), 0 )
 
Last edited:
Level 11
Joined
Oct 13, 2005
Messages
233
Yes, but you'll be leaking a location each time you do that. You are calling GetUnitLoc(a) without removing that location. The best way to do this would be with using x/y coordinates instead of locations for the whole thing:
JASS:
set caster_x = GetUnitX(a)
set caster_y = GetUnitY(a)

// Later on...

set temp = CreateUnit(GetOwningPlayer(a), 'oshm', caster_x + GetRandomReal(-300., 300.), caster_y + GetRandomReal(-300., 300.), 0.)
 
Level 3
Joined
Dec 24, 2006
Messages
68
what type of locals are caster_x/y ? location? WE gave me 3 errors, 2 of them were "Type missmatch in assigment" and other one was " Invalid type for specified operator " when using location
 
Status
Not open for further replies.
Top