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

Why there is always a dummy created in the middle of the map? Trigger posted

Status
Not open for further replies.
Level 11
Joined
Oct 11, 2012
Messages
711
Why there is always a dummy created in the middle of the map even when the casting unit is far away from that location and there is no enemy at that location? Can't figure out why..... Thanks guys.
Here are the triggers:

JASS:
function Trig_QT_Conditions takes nothing returns boolean
    return ((GetSpellAbilityId() == 'A00H'))
endfunction

function Trig_QT_001 takes nothing returns boolean
    return IsUnitEnemy(GetFilterUnit(),GetOwningPlayer(GetTriggerUnit())) and GetUnitState(GetFilterUnit(), UNIT_STATE_LIFE) > 0.405 
endfunction

function Trig_QT_002 takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local unit u1
    set u1=FirstOfGroup(udg_zhansha)
    loop 
        exitwhen u1==null
        set u1=FirstOfGroup(udg_zhansha)
        call GroupRemoveUnit(udg_zhansha,u1)
        call RemoveUnit(u1)
    endloop
    call GroupClear(udg_zhansha)
    call PauseTimer(t)
    call DestroyTimer(t)
    set u1 = null
endfunction

function Trig_QT_Actions takes nothing returns nothing
    local timer t = CreateTimer()
    local group g=CreateGroup()
    local unit target = GetSpellTargetUnit()
    local unit dummy
    local unit u
    local integer p = GetPlayerId(GetTriggerPlayer())
    local real x = GetUnitX(target)
    local real y = GetUnitY(target)
    local real x2
    local real y2
    local real a
    local unit u1
    call GroupEnumUnitsInRange(g,x,y,700.00,Condition (function Trig_QT_001))
    set u=FirstOfGroup(g)
    loop
        exitwhen u == null
        set u=FirstOfGroup(g)
        set a=GetUnitFacing(u)
        //Position the dummy behind the enemy unit
        set x2=GetUnitX(u)+ 100. * Cos((a-180)* bj_DEGTORAD)
        set y2=GetUnitY(u)+ 100. * Sin((a-180)* bj_DEGTORAD)
        set dummy=CreateUnit(Player(p),'o001',x2,y2,a)
        call SetUnitAnimation(dummy,"slam")
        call UnitDamageTarget(dummy,u,33.,true,false,ATTACK_TYPE_CHAOS,DAMAGE_TYPE_DEMOLITION,null)
        call GroupAddUnit(udg_zhansha,dummy)
        call GroupRemoveUnit(g,u)
    endloop
    call TimerStart(t,1.00,false,function Trig_QT_002)
    call DestroyGroup(g)
    set target = null
    set g = null    
    set dummy =null
    set t = null
endfunction

//===========================================================================
function InitTrig_QT takes nothing returns nothing
    set gg_trg_QT = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( gg_trg_QT, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition(gg_trg_QT, Condition(function Trig_QT_Conditions))
    call TriggerAddAction(gg_trg_QT, function Trig_QT_Actions)
endfunction
 
Level 22
Joined
Sep 24, 2005
Messages
4,821
JASS:
    set u=FirstOfGroup(g)
    loop
        exitwhen u == null
        set u=FirstOfGroup(g)
I think you should do it like this:
JASS:
    loop
        set u=FirstOfGroup(g)
        exitwhen u == null

bj_DEGTORAD is the right one to use.

Could you also explain what your spell is doing? I can't figure it out.
 
Level 11
Joined
Oct 11, 2012
Messages
711
Can you attach the map?

JASS:
    set u=FirstOfGroup(g)
    loop
        exitwhen u == null
        set u=FirstOfGroup(g)
I think you should do it like this:
JASS:
    loop
        set u=FirstOfGroup(g)
        exitwhen u == null

bj_DEGTORAD is the right one to use.

Could you also explain what your spell is doing? I can't figure it out.

Thanks chobibo and jakeZinc. The problem is solved as chobibo suggested.

@chobibo, when casting this spell, multiple dummies (the same model as the Hero who is casting this spell) will appear behind the enemy units and "slam" them, dealing damage. Its a really simple spell, LOL. I am gonna add "propwindow" and "turnspeed" change so that the units being attacked can not turn back to attack the dummies, and also make this spell a passive one.

Edit: I really want to add Rep to both of you, but the forum system does not allow that at the moment....
 
Level 20
Joined
Aug 13, 2013
Messages
1,696
Well, the spell that you send on me is working fine. maybe the two similar channel abilities collide each other. Anyway even if you set that first of group in below of enumeration is working fine but follow what chobibo ^^.
 
Level 12
Joined
Mar 13, 2012
Messages
1,121
I am gonna add "propwindow" and "turnspeed" change so that the units being attacked can not turn back to attack the dummies.

I dont really understand that. Your dummies do have the locust ability, which makes them invulnerable and untargetable. Fell free to ask more questions :).

Well, the spell that you send on me is working fine. maybe the two similar channel abilities collide each other. Anyway even if you set that first of group in below of enumeration is working fine but follow what chobibo ^^.

The problem with the original code was that on the last loop run u would be null and therefore x2 and y2 will be 0, etc.
 
Level 11
Joined
Oct 11, 2012
Messages
711
I dont really understand that. Your dummies do have the locust ability, which makes them invulnerable and untargetable. Fell free to ask more questions :).



The problem with the original code was that on the last loop run u would be null and therefore x2 and y2 will be 0, etc.

Yup, you are right, the dummies are invulnerable. I want to prevent the targets from running away. :)

Thanks for identifying the problem. +Rep
 
Level 22
Joined
Sep 24, 2005
Messages
4,821
JASS:
function Trig_QT_002 takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local unit u1
    loop
        set u1=FirstOfGroup(udg_zhansha)
        exitwhen u1==null
        call GroupRemoveUnit(udg_zhansha,u1)
        call RemoveUnit(u1)
    endloop
    call GroupClear(udg_zhansha)
    call PauseTimer(t)
    call DestroyTimer(t)
    set u1 = null
    set t = null // <--- HERE
endfunction
You forgot to null your timer variable on the timer callback.
 
Level 11
Joined
Oct 11, 2012
Messages
711
JASS:
function Trig_QT_002 takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local unit u1
    loop
        set u1=FirstOfGroup(udg_zhansha)
        exitwhen u1==null
        call GroupRemoveUnit(udg_zhansha,u1)
        call RemoveUnit(u1)
    endloop
    call GroupClear(udg_zhansha)
    call PauseTimer(t)
    call DestroyTimer(t)
    set u1 = null
    set t = null // <--- HERE
endfunction
You forgot to null your timer variable on the timer callback.

Oops, you are right. >_<
 
Status
Not open for further replies.
Top