Problems with my slow trigger!

Quakern

New Member
Reaction score
1
Hey there!
I am trying to make a trigger, that everyone in 100 range of the attacked unit (attacking unit=my slow tower), is running 20% slower for 2 seconds.

My trigger now looks like this:
Trigger:
  • Slow
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • (Unit-type of (Attacking unit)) Equal to Frost Tower
    • Actions
      • Custom script: local group udg_slow
      • Custom script: set udg_slow = GetUnitsInRangeOfLocAll(100.00, GetUnitLoc(GetAttackedUnitBJ()))
      • Custom script: call ForGroupBJ( udg_slow,( GetUnitDefaultMoveSpeed(GetEnumUnit()) * ( 80.00 / 100.00 ) ) )
      • Custom script: call TriggerSleepAction( 2 )
      • Custom script: call ForGroupBJ( udg_slow,( GetUnitDefaultMoveSpeed(GetEnumUnit()) ) )
      • Custom script: call DestroyGroup(udg_slow)


I get for some reason error on the wait command and destroy the local variable :S
Anyone knows how to fix this? Or something like this would work? I'm kindy new on this, so im not 100% sure ^^
 

Lehona

New Member
Reaction score
12
Don't name the variable udg_<name>. The prefix udg_ is for global variables which are created with gui.

But I'm not sure whether this is the error.
 

HydraRancher

Truth begins in lies
Reaction score
197
The sleep trigger action (I'm not sure if this is right) I think it has to be 2.00


Remove all the udg's. udg = universal defined global variable. But you're using locals right?
 

Quakern

New Member
Reaction score
1
The sleep trigger action (I'm not sure if this is right) I think it has to be 2.00


Remove all the udg's. udg = universal defined global variable. But you're using locals right?

Yes im using local variables :) I still get error on the wait command, and the destroy command. It says: "Invalid argument type(real)".
My trigger now looks like this:
Trigger:
  • Slow
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • (Unit-type of (Attacking unit)) Equal to Frost Tower
    • Actions
      • Custom script: local group slow
      • Custom script: set slow = GetUnitsInRangeOfLocAll(100.00, GetUnitLoc(GetAttackedUnitBJ()))
      • Custom script: call ForGroupBJ( slow,( GetUnitDefaultMoveSpeed(GetEnumUnit()) * ( 80.00 / 100.00 ) ) )
      • Wait 2.00 seconds
      • Custom script: call ForGroupBJ( slow,( GetUnitDefaultMoveSpeed(GetEnumUnit()) ) )
      • Custom script: call DestroyGroup(slow)
 

cleeezzz

The Undead Ranger.
Reaction score
268
Custom script: call ForGroupBJ( slow,( GetUnitDefaultMoveSpeed(GetEnumUnit()) * ( 80.00 / 100.00 ) ) )
Custom script: call ForGroupBJ( slow,( GetUnitDefaultMoveSpeed(GetEnumUnit()) ) )

you cant use ForGroupBJ like that.. why are you using GUI, your trigger is pretty much JASS
 

Quakern

New Member
Reaction score
1
Custom script: call ForGroupBJ( slow,( GetUnitDefaultMoveSpeed(GetEnumUnit()) * ( 80.00 / 100.00 ) ) )
Custom script: call ForGroupBJ( slow,( GetUnitDefaultMoveSpeed(GetEnumUnit()) ) )

you cant use ForGroupBJ like that.. why are you using GUI, your trigger is pretty much JASS

Like I said, I'm new on this. So im kinda a noob on JASS :p
How should I do it then?:)
 

Weep

Godspeed to the sound of the pounding
Reaction score
400
There are several approaches you could take. If you prefer to stay with more GUI than JASS, and because groups are "agent" type, you can pass the local group off to a global variable so you can access it with a GUI group loop:
Trigger:
  • Untitled Trigger 001
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • (Unit-type of (Attacking unit)) Equal to Footman
    • Actions
      • Custom script: local group slow
      • Set TempPoint = (Position of (Triggering unit))
      • Set TempGroup = (Units within 100.00 of TempPoint)
      • Custom script: call RemoveLocation(udg_TempPoint)
      • Unit Group - Pick every unit in TempGroup and do (Actions)
        • Loop - Actions
          • -------- Stuff --------
      • Custom script: set slow = udg_TempGroup
      • Wait 2.00 seconds
      • Custom script: set udg_TempGroup = slow
      • Unit Group - Pick every unit in TempGroup and do (Actions)
        • Loop - Actions
          • -------- Stuff --------
      • Custom script: call DestroyGroup(slow)
      • Custom script: set slow = null

This won't leak the group even though it destroys "slow" instead of "TempGroup" because we made "slow" point to the same actual group in memory. There's still only one unit group being used.

To actually use the ForGroup JASS command, you need to make a separate function for your actions; you can't just specify it in the ForGroup command itself. You'll pretty much need to convert the whole trigger to JASS to accomplish this:

JASS:
function Slow_Conditions takes nothing returns boolean
    return GetUnitTypeId(GetAttacker()) == &#039;hfoo&#039; //&#039;hfoo&#039; is the rawcode for a Footman.  Substitute for your frost tower.
endfunction

function RestoreUnit_Callback takes nothing returns nothing
    call SetUnitMoveSpeed(GetEnumUnit(), GetUnitDefaultMoveSpeed(GetEnumUnit()))
endfunction

function SlowUnit_Callback takes nothing returns nothing
    call SetUnitMoveSpeed(GetEnumUnit(), GetUnitDefaultMoveSpeed(GetEnumUnit())*0.8)
endfunction

function Slow_Actions takes nothing returns nothing
    local group slow = CreateGroup()
    call GroupEnumUnitsInRange(slow, 100.00, GetUnitX(GetTriggerUnit()), GetUnitY(GetTriggerUnit()), null)
    call ForGroup(slow, function SlowUnit_Callback)
    call TriggerSleepAction(2.)
    call ForGroup(slow, function RestoreUnit_Callback)
    call DestroyGroup(slow)
    set slow = null
endfunction

//===========================================================================
function InitTrig_Untitled_Trigger_001 takes nothing returns nothing
    set gg_trg_Untitled_Trigger_001 = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Untitled_Trigger_001, EVENT_PLAYER_UNIT_ATTACKED )
    call TriggerAddCondition( gg_trg_Untitled_Trigger_001, Condition( function Slow_Conditions ) )
    call TriggerAddAction( gg_trg_Untitled_Trigger_001, function Slow_Actions )
endfunction

FYI, I've de-GUI'd that a bit, using [ljass]GroupEnumUnitsInRange[/ljass] instead of [ljass]GetUnitsInRangeOfLocAll[/ljass].

There are yet other ways to approach this, but it should get you started.

------------------

Also FYI, this method isn't very safe. If a unit is slowed, and then hit again before the first slow has ended, the first slow period will restore the unit's movement speed before the second slow should wear off. I'll leave it as an exercise for you to think about how to account for that...
 

Quakern

New Member
Reaction score
1
Thanks Weep! :) That worked :D
My trigger now looks like this:
Trigger:
  • Slow
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • (Unit-type of (Attacking unit)) Equal to Frost Tower
    • Actions
      • Custom script: local group slow
      • Set TempPointSlow = (Position of (Attacked unit))
      • Set TempGroup = (Units within 200.00 of TempPointSlow)
      • Custom script: call RemoveLocation(udg_TempPointSlow)
      • Unit Group - Pick every unit in TempGroup and do (Actions)
        • Loop - Actions
          • Unit - Set (Picked unit) movement speed to ((Default movement speed of (Picked unit)) x (80.00 / 100.00))
      • Custom script: set slow = udg_TempGroup
      • Wait 2.00 seconds
      • Custom script: set udg_TempGroup = slow
      • Unit Group - Pick every unit in TempGroup and do (Actions)
        • Loop - Actions
          • Unit - Set (Picked unit) movement speed to (Default movement speed of (Picked unit))
      • Custom script: call DestroyGroup(slow)
      • Custom script: set slow = null
 

Laiev

Hey Listen!!
Reaction score
188
Trigger:
  • Slow
    • Set TempGroup = (Units within 200.00 of TempPointSlow)


TempGroup = group = leak

Trigger:
  • Slow
    • Set TempGroup = (Units within 200.00 of TempPointSlow)
    • Custom script: set udg_TempGroup = slow


set group which you don't destroy before set AGAIN = leak
 

Weep

Godspeed to the sound of the pounding
Reaction score
400
TempGroup = group = leak
set group which you don't destroy before set AGAIN = leak
Incorrect. In fact, destroying TempGroup would prevent the trigger from working after the wait.
This won't leak the group even though it destroys "slow" instead of "TempGroup" because we made "slow" point to the same actual group in memory. There's still only one unit group being used.
 

Laiev

Hey Listen!!
Reaction score
188
Incorrect. In fact, destroying TempGroup would prevent the trigger from working after the wait.

You don't destroy the group, you just set other group to value of that group, then you just destroy the newest group, leaving one alive. So you leak.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top