Help with slide trigger

Evan1993

Ultra Cool Member
Reaction score
30
I've made slide triggers before, however they lag; and they can't so what I want.

In all the slide triggers I’ve made before it pauses the unit so you can't give it orders, however I do want you to be able to give it orders.

So I figured, "Oh! I can just not pause it and everything is fine!" Nope. Now if you give the unit more then one order it tries to make it slider to them both at once at once.

Could anyone please show me how you would make a slide trigger that would make you slide toward the units current order?

Thanks! :)
 

soulreaping

New Member
Reaction score
17
By saying "slide towards the current order" you mean slide in the same angle as the current move, attack, attack-move and a spell orders?
 

Trollvottel

never aging title
Reaction score
262
its easy. just use

a unit is issued an order targeting a point

conditions....

actions:

order triggering unit to stop
set t_loc = Point of issued order
make triggering unit face t_loc
custom script: call RemoveLocation(udg_t_loc)

this would make face it.. and about the laggs.... did you remove the memory leaks? they are evil in periodic events
 

Evan1993

Ultra Cool Member
Reaction score
30
By saying "slide towards the current order" you mean slide in the same angle as the current move, attack, attack-move and a spell orders?

Not spell orders because that would cancel them, I think.

Trollvottel:

Its not that easy, I can't figure out anyway to stop my old trigger.



Here, you can look at my silly trigger. (I hate how badly I did it. :eek:)
Right now it

JASS:

function MoveFast takes nothing returns nothing
    local trigger t = GetTriggeringTrigger() //we need this mainly to load our vars from it.
    local real N = (GetHandleReal(t, "N") + 30.00 )//load all vars we need.
    local unit Caster = GetHandleUnit(t, "caster")
    local location CasterPosition = GetUnitLoc(Caster)
    local real damage = 0
    local location TargetPoint = Location(GetHandleReal(t, "x"), GetHandleReal(t, "y"))
    local real Angle = AngleBetweenPoints(CasterPosition, TargetPoint)
    local location MoveToPoint = PolarProjectionBJ(CasterPosition, 30.00, Angle)
    local real Distance = DistanceBetweenPoints(CasterPosition, TargetPoint)
    local group g = CreateGroup() //group of units to damage
    local unit du //Picked unit to damage, meaning the first unit of the group.
    local boolean bool = false //This tells the main trigger to clean up.
    local effect e //The fire effect that appears on units effected by the spell
    local real flyh = GetHandleReal(t, "flyh")
    local real fd = GetHandleReal(t, "d")
    local unit victim = Caster
    local real manadmg
    local real level = I2R(GetUnitAbilityLevel(Caster, 'A01L'))
    call SetUnitPositionLoc( Caster, MoveToPoint )//move him by 20.
    call SetUnitFacing( Caster,Angle) //make sure he's facing the right way.

    if DistanceBetweenPoints(GetUnitLoc(Caster), TargetPoint) <30  or GetUnitState(Caster, UNIT_STATE_LIFE) <= 0 then //if we got to were we was a goin', then stop; or if yer dead stop too.
        //set e = AddSpecialEffectLoc("AntiMagicBoom2.mdx", PolarProjectionBJ(CasterPosition, 200.00, Angle))
        //set g = GetUnitsInRangeOfLocMatching((250 + ( 50 * I2R(GetUnitAbilityLevel(victim,'A01L')))), TargetPoint, null)
        //loop
       // exitwhen FirstOfGroup(g) == null
      //  set victim = FirstOfGroup(g)
      //  if IsUnitEnemy(victim, GetOwningPlayer(Caster)) == true then
      //  set manadmg = ( GetUnitStateSwap(UNIT_STATE_MANA, victim) / 100.00 )
     //   set manadmg = (manadmg * ( 10.00 * level) )
        //'call DisplayTextToPlayer(Player(0),0,0,R2S(manadmg))
     //   set damage = (((25 * level) + ((10 * level) * (UnitCountBuffsExBJ(bj_BUFF_POLARITY_EITHER, bj_BUFF_RESIST_MAGIC, victim, true, true)))) + manadmg)
        //call DisplayTextToPlayer(Player(0),0,0,R2S(damage))
    //    call UnitDamageTarget(Caster, victim, damage, true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS)
    //    endif
    //    call GroupRemoveUnit(g,victim)
     //   endloop
        call SetUnitFlyHeight( Caster, GetUnitDefaultFlyHeight(Caster), 255.00 )
        set bool = true//Tells main trigger that we are done, and to clean up.
        call SetHandleBoolean(t, "exit", bool)//sends it over to main trigger.
        call PauseUnit(Caster, false )//unpuase caster so you can control him
        call SetUnitPathing( Caster, true )//turn his pathing back on
        call FlushHandleLocals(t)
        set g = null
        set du = null
        set e = null
        set e = null
        //call DisableTrigger( GetTriggeringTrigger() )
    endif
    call SetHandleReal(t, "N", N)//we might not even need this any more.
    set Caster = null//clean up
    set CasterPosition = null
    set TargetPoint = null
    set t = null
endfunction


function Trig_SuperRun_Actions takes nothing returns nothing
    local unit Caster = GetOrderedUnit() //Get casting unit so we can save it for later.
    local location CasterPosition = GetUnitLoc(Caster)// Get the location of the casting unit so we can use it later.
    local location TargetPoint =  GetOrderPointLoc()//Same with the spell target. (this isn't being use atm)
    local real x = GetLocationX(GetOrderPointLoc())//save both the x and y of the target location.
    local real y = GetLocationY(GetOrderPointLoc())// read above ^^
    local real Distance = DistanceBetweenPoints(CasterPosition, TargetPoint)//save both the distance and the angle, so we can use them later.
    local real Angle = AngleBetweenPoints(CasterPosition, TargetPoint)
    local trigger t = CreateTrigger()//these timers run the funtions that make shadows, and the function that moves and damages.
    local timer t2 = CreateTimer()
    if GetOrderPointLoc() == null then
    set TargetPoint = GetUnitLoc(GetOrderTarget())
    endif
    call DisableTrigger(GetTriggeringTrigger())

    call TriggerSleepAction(0.10)
    call UnitAddAbility(Caster,'Amrf')
    call UnitRemoveAbility( Caster,'Amrf')
    call SetUnitAnimation(Caster, "walk")//make him play blade storm animation.
    call SetUnitTimeScalePercent( Caster, 100 )//make it do it in slow motion
    //'call PauseUnit(Caster, true )//Pause him so you cant command him.
    call SetUnitPathing( Caster, false )//Keep him from getting stuck, or colliding.
    call SetHandleHandle(t, "Caster", Caster)//saving all the vars that we need.
    call SetHandleReal(t, "x", x)
    call SetHandleReal(t, "y", y)
    call SetHandleReal(t, "d", Distance)
    call EnableTrigger(GetTriggeringTrigger())

    call SetHandleHandle(t2, "Caster", Caster)
    call TriggerRegisterTimerEventPeriodic( t, 0.03 )// This will run the function "Damage" which moves the caster and deals damage
    call TriggerAddAction( t, function MoveFast )
    //'call TimerStart(t2, 0.11, true, function IllusionEffect)//makes the shadows
    call EnableTrigger( t )
    loop//wait untill spell is done to clean up.
        call TriggerSleepAction(0.5)
        exitwhen GetHandleBoolean(t, "exit") == true
    endloop
    call EnableTrigger(GetTriggeringTrigger())
    call UnitAddAbility(Caster,'Amrf')
    call UnitRemoveAbility( Caster,'Amrf')
    call SetUnitTimeScalePercent( Caster, 100 )//make stop doing it in slow motion
    call SetUnitFlyHeight( Caster, GetUnitDefaultFlyHeight(Caster), 255.00 )
    call PauseTimer(t2)//clean up
    call DestroyTimer(t2)
    set t =null
    set CasterPosition = null
    set TargetPoint = null
endfunction

//===========================================================================
function InitTrig_SuperRun takes nothing returns nothing
    set gg_trg_SuperRun = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_SuperRun, EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_SuperRun, EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER )
    call TriggerAddAction( gg_trg_SuperRun, function Trig_SuperRun_Actions )
endfunction
 

darkbeer

Beer is Good!
Reaction score
84
well, if it works its fine, but i never attached handles to a trigger, why dont you attach them to the timer?

( well if anyone could tell me what's better, i would be happy)

btw. using NewGen and structs is much easier :)

well, i would code i like this(not really) but its closest to your trigger xD: and you forgot to remove your locations^^

JASS:
function MoveFast takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local real N = (GetHandleReal(t, "N") + 30.00 )//load all vars we need.
    local unit Caster = GetHandleUnit(t, "caster")
    local location CasterPosition = GetUnitLoc(Caster)
    local real damage = 0
    local location TargetPoint = Location(GetHandleReal(t, "x"), GetHandleReal(t, "y"))
    local real Angle = AngleBetweenPoints(CasterPosition, TargetPoint)
    local location MoveToPoint = PolarProjectionBJ(CasterPosition, 30.00, Angle)
    local real Distance = DistanceBetweenPoints(CasterPosition, TargetPoint)
    local group g = CreateGroup() //group of units to damage
    local unit du //Picked unit to damage, meaning the first unit of the group.
    local boolean bool = false //This tells the main trigger to clean up.
    local effect e //The fire effect that appears on units effected by the spell
    local real flyh = GetHandleReal(t, "flyh")
    local real fd = GetHandleReal(t, "d")
    local unit victim = Caster
    local real manadmg
    local real level = I2R(GetUnitAbilityLevel(Caster, 'A01L'))

    call SetUnitPositionLoc( Caster, MoveToPoint )//move him by 20.
    call SetUnitFacing( Caster,Angle) //make sure he's facing the right way.

    if DistanceBetweenPoints(GetUnitLoc(Caster), TargetPoint) <30  or GetUnitState(Caster, UNIT_STATE_LIFE) <= 0 then //if we got to were we was a goin', then stop; or if yer dead stop too.
        //set e = AddSpecialEffectLoc("AntiMagicBoom2.mdx", PolarProjectionBJ(CasterPosition, 200.00, Angle))
        //set g = GetUnitsInRangeOfLocMatching((250 + ( 50 * I2R(GetUnitAbilityLevel(victim,'A01L')))), TargetPoint, null)
        //loop
       // exitwhen FirstOfGroup(g) == null
      //  set victim = FirstOfGroup(g)
      //  if IsUnitEnemy(victim, GetOwningPlayer(Caster)) == true then
      //  set manadmg = ( GetUnitStateSwap(UNIT_STATE_MANA, victim) / 100.00 )
     //   set manadmg = (manadmg * ( 10.00 * level) )
        //'call DisplayTextToPlayer(Player(0),0,0,R2S(manadmg))
     //   set damage = (((25 * level) + ((10 * level) * (UnitCountBuffsExBJ(bj_BUFF_POLARITY_EITHER, bj_BUFF_RESIST_MAGIC, victim, true, true)))) + manadmg)
        //call DisplayTextToPlayer(Player(0),0,0,R2S(damage))
    //    call UnitDamageTarget(Caster, victim, damage, true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS)
    //    endif
    //    call GroupRemoveUnit(g,victim)
     //   endloop
        call SetUnitFlyHeight( Caster, GetUnitDefaultFlyHeight(Caster), 255.00 )
        set bool = true//Tells main trigger that we are done, and to clean up.
        call SetHandleBoolean(t, "exit", bool)//sends it over to main trigger.
        call PauseUnit(Caster, false )//unpuase caster so you can control him
        call SetUnitPathing( Caster, true )//turn his pathing back on
        set g = null
        set du = null
        set e = null
        set e = null
    endif
    call SetHandleReal(t, "N", N)//we might not even need this any more.
    set Caster = null//clean up
    call RemoveLocation(CasterPosition)
    call RemoveLocation(TargetPoint)
    set CasterPosition = null
    set TargetPoint = null
    set t = null
endfunction


function Trig_SuperRun_Actions takes nothing returns nothing
    local unit Caster = GetTriggerUnit() //Get casting unit so we can save it for later.
    local location CasterPosition = GetUnitLoc(Caster)// Get the location of the casting unit so we can use it later.
    local location TargetPoint =  GetOrderPointLoc()//Same with the spell target. (this isn't being use atm)
    local real x = GetLocationX(GetOrderPointLoc())//save both the x and y of the target location.
    local real y = GetLocationY(GetOrderPointLoc())// read above ^^
    local real Distance = DistanceBetweenPoints(CasterPosition, TargetPoint)//save both the distance and the angle, so we can use them later.
    local real Angle = AngleBetweenPoints(CasterPosition, TargetPoint)
    local timer t = CreateTimer()

    if GetOrderPointLoc() == null then
         set TargetPoint = GetUnitLoc(GetOrderTarget())
    endif

    call TriggerSleepAction(0.10)
    call UnitAddAbility(Caster,'Amrf')
    call UnitRemoveAbility( Caster,'Amrf')
    call SetUnitAnimation(Caster, "walk")//make him play blade storm animation.
    call SetUnitTimeScalePercent( Caster, 100 )//make it do it in slow motion
    //'call PauseUnit(Caster, true )//Pause him so you cant command him.
    call SetUnitPathing( Caster, false )//Keep him from getting stuck, or colliding.
    call SetHandleHandle(t, "Caster", Caster)//saving all the vars that we need.
    call SetHandleReal(t, "x", x)
    call SetHandleReal(t, "y", y)
    call SetHandleReal(t, "d", Distance)

    call SetHandleHandle(t, "Caster", Caster)
    call TimerStart(t, 0.03, true, function MoveFast)
    loop//wait untill spell is done to clean up.
        call TriggerSleepAction(0.5)
        exitwhen GetHandleBoolean(t, "exit") == true
    endloop
    call FlushHandleLocals(t) // importatn move this here
    call UnitAddAbility(Caster,'Amrf')
    call UnitRemoveAbility( Caster,'Amrf')
    call SetUnitTimeScalePercent( Caster, 100 )//make stop doing it in slow motion
    call SetUnitFlyHeight( Caster, GetUnitDefaultFlyHeight(Caster), 255.00 )
    call PauseTimer(t)//clean up
    call DestroyTimer(t)
    set t =null
    call RemoveLocation(CasterPosition) //cleans the leaks
    call RemoveLocation(TargetPoint) //cleans the leaks
    set CasterPosition = null
    set TargetPoint = null
endfunction

//===========================================================================
function InitTrig_SuperRun takes nothing returns nothing
    set gg_trg_SuperRun = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_SuperRun, EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_SuperRun, EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER )
    call TriggerAddAction( gg_trg_SuperRun, function Trig_SuperRun_Actions )
endfunction


your trigger doesnt stop, because you flush the locals just after setting the boolean to true, so the main trigger will never get that boolean and always be working.....
JASS:
set bool = true//Tells main trigger that we are done, and to clean up.
        call SetHandleBoolean(t, "exit", bool)//sends it over to main trigger.
        call PauseUnit(Caster, false )//unpuase caster so you can control him
        call SetUnitPathing( Caster, true )//turn his pathing back on
        call FlushHandleLocals(t)//move this to main trigger!!!!!!
 

Evan1993

Ultra Cool Member
Reaction score
30
Better. . .

Ok, that is a lot better.

However, it still has a problem or two. I want it to slide towards the units CURRENT order, not the way it is right now.

Right now if you give the unit an order it will start sliding towards it, then you give the unit another order and it tries to slide towards them both!

After 6-10 orders the unit goes crazy :rolleyes:

Also, I'd love it if you could show me how to make this trigger with structs, I've never used them before. :eek:
 

darkbeer

Beer is Good!
Reaction score
84
sure thing^^, well i would code it something like this xD

JASS:
scope Slide
private constant function Periode takes nothing returns real
    return 0.03125
endfunction

private constant function Speed takes nothing returns real
    return 20.00
endfunction

globals
    private timer SlideTimer = CreateTimer()
    private integer SlideTotal = 0
    private SlideData array Data
endglobals

struct SlideData
    unit u = null
    real dx = 0
    real dy = 0
    integer ticks = 0
endstruct

private function SlideLoop takes nothing returns nothing
    local SlideData dat
    local integer i = 0
    
    loop
        exitwhen i == SlideTotal
        set dat = Data<i>
        if dat.ticks == 0 then
            call dat.destroy()
            set Data<i> = Data[SlideTotal - 1]
            set SlideTotal = SlideTotal - 1
            set i = i - 1
        else
            set dat.ticks = dat.ticks - 1
            call SetUnitPosition(dat.u , GetUnitX(dat.u) + dat.dx, GetUnitY(dat.u) + dat.dy)
        endif
        set i = i + 1
    endloop
    
    if SlideTotal == 0 then
        call PauseTimer(SlideTimer)
    endif
endfunction

private function Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local real X = GetUnitX(u)
    local real Y = GetUnitY(u)
    local real targX = GetOrderPointX()
    local real targY = GetOrderPointY()
    local unit targ = GetOrderTargetUnit()
    local real angle
    local real distance
    local real dx = targX - X
    local real dy = targY - Y
    local integer i = 0
    local SlideData dat
    
    if targ != null then
        set targX = GetUnitX(targ)
        set targY = GetUnitY(targ)
    endif
    
    set dx = targX - X
    set dy = targY - Y
    set angle = Atan2(targY - Y, targX - X)
    set distance = SquareRoot(dx * dx + dy * dy)
    
    loop
        exitwhen i == SlideTotal
        set dat = Data<i>
        if u == dat.u then
            set dat.dx = Speed() * Cos(angle)
            set dat.dy = Speed() * Sin(angle)
            set dat.ticks = R2I(distance / Speed())
            
            set u = null
            set targ = null
            
            return
        endif
        set i = i + 1
    endloop
    
    set dat = SlideData.create()
    
    set dat.ticks = R2I(distance / Speed())
    set dat.u = u
    set dat.dx = Speed() * Cos(angle)
    set dat.dy = Speed() * Sin(angle)
    
    set Data[SlideTotal] = dat
    
    if SlideTotal == 0 then
        call TimerStart(SlideTimer, Periode(), true, function SlideLoop)
    endif
    
    set SlideTotal = SlideTotal + 1
    
    set u = null
    set targ = null
    
endfunction

//===========================================================================
function InitTrig_Slide takes nothing returns nothing
    local trigger t = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER )
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER )    
    call TriggerAddAction( t, function Actions )
    set t = null
endfunction
endscope

</i></i></i>


Note: Made this within 15 minutes, so i didnt really implent mcuh, ask when sth is unclear or you want to add something to the code, btw. i forgot to set unit pathing to off -.-

demo map attached
 

Evan1993

Ultra Cool Member
Reaction score
30
Even better

Thanks!

EDIT: LOL, I know why now.
I never removed old trigger, so they were fighting. Sorry about that. :eek:


+rep
 
Reaction score
333
The SetUnitX and SetUnitY natives allow you to move a unit without checking pathing or interfering with its orders.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top