First JASS trigger, need help finding the problem.

Summoned

New Member
Reaction score
51
UPDATE: Really weird effect from the activating trigger, seems to make every spell target the center of the map.

Note: not trying to create a sliding system, just trying to get used to JASS.

The problem I'm encountering is when I try to trigger the unit to slide, what ends up happening is the unit slides 1 step toward the center of the map, no matter where I target the spell, then the sliding ends (unit even gets unpaused, etc.). Are the variables somehow being screwed up?

Trigger to activate sliding:
Trigger:
  • Slide1
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Slide1 (Druid)
    • Actions
      • Unit - Pause (Triggering unit)
      • Unit - Turn collision for (Triggering unit) Off
      • Set NumSlider = (NumSlider + 1)
      • Set SlideCaster[NumSlider] = (Triggering unit)
      • Set SlideDistanceMin[NumSlider] = 50.00
      • Set SlideSpeed[NumSlider] = 600.00
      • Set SlideToPoint[NumSlider] = (Target point of ability being cast)
      • Set SlideTreeKill[NumSlider] = True


The messy JASS code.
JASS:
// These globals are actually declared via the Variables editor in WE.
// Just putting them here so JassCraft doesn't freak out.
globals
    integer udg_NumSlider //Default 0, keeps count of how many units are sliding
    group udg_SlideDamaged = CreateGroup() //Default empty, for damage function
    boolean array udg_SlideEffectAllies //Default false, for damage function
    boolean array udg_SlideEffectAll //Default false, for damage function
    boolean array udg_SlidePoolShot //Default false, for damage function
    boolean array udg_SlideTargetDamage //Default false, single target damage
    boolean array udg_SlideTargetKnockback //Default false, single target knockback
    boolean array udg_SlidePointDamage //Default false, aoe damage at destination
    boolean array udg_SlideRadiusDamage //Default false, aoe damage while sliding
    boolean array udg_SlideTreeKill //Default true, destroys trees while sliding
    boolean array udg_SlideDamageOnce //Default false, for damage function
    boolean array udg_SlideSuicide //Default false, for damage function
    unit array udg_SlideCaster //Default null, the unit that does the sliding
    unit array udg_SlideToTarget //Default null, used if the sliding is homing toward a unit
    location array udg_SlideToPoint //Default null, used if the sliding is going to a point
    real array udg_SlideSpeed //Default 200, the speed that the sliding goes
    real array udg_SlideEffectRadius //Default 0, radius of damage/knockbacks if applicable
    real array udg_SlideDamage //Default 0, amount of damage done
    real array udg_SlideDistanceMin //Default 0, how far from the target point the sliding unit will stop at
    real array udg_SlideDistance //Default 0, keeps track of how far the unit has slid, used for further knockbacks if applicable
endglobals



// Kills trees.
function Trig_SuperSlide_TreeKill takes nothing returns nothing
    call KillDestructable(GetEnumDestructable())
endfunction



// When a sliding finishes, all variables are flushed and the sliding unit fixed up.
function Trig_SuperSlide_Finish takes integer b returns nothing
    call PauseUnit(udg_SlideCaster<b>, false)
    call SetUnitPathing(udg_SlideCaster<b>, true)
    call ResetUnitAnimation(udg_SlideCaster<b>)            
    set udg_SlideCaster<b> = null
    set udg_SlideToTarget<b> = null
    set udg_SlideTreeKill<b> = true
    set udg_SlideSpeed<b> = 200
    set udg_SlidePoolShot<b> = false
    set udg_SlideEffectRadius<b> = 0
    set udg_SlideEffectAllies<b> = false
    set udg_SlideEffectAll<b> = false
    set udg_SlideDamage<b> = 0
    set udg_SlideDistanceMin<b> = 0
    set udg_SlideDamageOnce<b> = false
    set udg_SlideSuicide<b> = false
    set udg_SlideTargetDamage<b> = false
    set udg_SlideTargetKnockback<b> = false
    set udg_SlidePointDamage<b> = false
    set udg_SlideRadiusDamage<b> = false
    call RemoveLocation(udg_SlideToPoint<b>)
endfunction



// Deals damage and causes additional knockbacks.
function Trig_SuperSlide_DealDamage takes nothing returns nothing
    local location castpoint
    local location targetpoint
    local real angle
    
// Makes sure the damage/knockback won&#039;t affect the sliding target, structures, or corpses.
    if (IsUnit(GetEnumUnit(), udg_SlideCaster[bj_forLoopAIndex])) then
        return
    endif
    if (IsUnitType(GetEnumUnit(), UNIT_TYPE_STRUCTURE)) then
        return
    endif
    if (GetUnitState(GetEnumUnit(), UNIT_STATE_LIFE) &lt;= 0) then
        return
    endif
    
// Whether allies, enemies, or both are affected can be edited.
    if (IsUnitAlly(GetEnumUnit(), GetOwningPlayer(udg_SlideCaster[bj_forLoopAIndex]))) then
        if (not udg_SlideEffectAllies[bj_forLoopAIndex]) then
            if (not udg_SlideEffectAll[bj_forLoopAIndex]) then
                return
            endif
        endif
    elseif (udg_SlideEffectAllies[bj_forLoopAIndex]) then
        if (not udg_SlideEffectAll[bj_forLoopAIndex]) then
            return
        endif    
    endif
    
// Preliminary setup.
    set castpoint = GetUnitLoc(udg_SlideCaster[bj_forLoopAIndex])
    set targetpoint = GetUnitLoc(GetEnumUnit())
    set angle = AngleBetweenPoints(castpoint, targetpoint)

// Checks to see if the chained knockbacks are active.
    if (udg_SlidePoolShot[bj_forLoopAIndex]) then
        set udg_NumSlider = udg_NumSlider + 1
        call PauseUnit(GetEnumUnit(), true)
        call SetUnitPathing(GetEnumUnit(), false)
        set udg_SlideCaster[udg_NumSlider] = GetEnumUnit()
        set udg_SlideToPoint[udg_NumSlider] = PolarProjectionBJ(castpoint, (udg_SlideDistance[bj_forLoopAIndex] / 2), angle)
        set udg_SlideSpeed[udg_NumSlider] = udg_SlideSpeed[bj_forLoopAIndex] / 1.5
        set udg_SlidePoolShot[udg_NumSlider] = true
        set udg_SlidePointDamage[udg_NumSlider] = true
        set udg_SlideEffectRadius[udg_NumSlider] = 100
        set udg_SlideEffectAllies[udg_NumSlider] = true
    endif
    call RemoveLocation(castpoint)
    call RemoveLocation(targetpoint)
    
// Deals damage.
    call UnitDamageTarget(udg_SlideCaster[bj_forLoopAIndex], GetEnumUnit(), udg_SlideDamage[bj_forLoopAIndex], true, false, ATTACK_TYPE_HERO, DAMAGE_TYPE_UNIVERSAL, WEAPON_TYPE_WHOKNOWS)

// Checks to see if the sliding unit is meant to die after contact (i.e. missile effects).    
    if (udg_SlideSuicide[bj_forLoopAIndex]) then
        call KillUnit(udg_SlideCaster[bj_forLoopAIndex])
    endif

// Checks to see if the target should get temporary immunity after taking damage.
    if (udg_SlideDamageOnce[bj_forLoopAIndex]) then
        if (IsUnitInGroup(GetEnumUnit(), udg_SlideDamaged)) then
            return
        endif
        call GroupAddUnit(udg_SlideDamaged, GetEnumUnit())
    endif
endfunction



// Main function.
function Trig_SuperSlide_Actions takes nothing returns nothing

// Declaring some variables easier to write than udg_SlideCaster[bj_forLoopAIndex].
    local integer a
    local integer b
    local unit caster
    local unit target
    local location castpoint
    local location targetpoint
    local location movepoint
    local group damagegroup = CreateGroup()
    local real angle
    local real distance
    local real distancemin
    local real speed
    local real damageradius
    local real damage

// Makes sure the arrays don&#039;t get maxed out. Pushing them back by 1000.
    if (udg_NumSlider &gt; 2000) then
        set a = udg_NumSlider - 1000
        loop
            exitwhen a &gt; udg_NumSlider
            set b = a - 1000
            set udg_SlideCaster<b> = udg_SlideCaster[a]
            set udg_SlideToTarget<b> = udg_SlideToTarget[a]
            set udg_SlideToPoint<b> = udg_SlideToPoint[a]
            set udg_SlideTreeKill<b> = udg_SlideTreeKill[a]
            set udg_SlideSpeed<b> = udg_SlideSpeed[a]
            set udg_SlidePoolShot<b> = udg_SlidePoolShot[a]
            set udg_SlideEffectRadius<b> = udg_SlideEffectRadius[a]
            set udg_SlideDamage<b> = udg_SlideDamage[a]
            set udg_SlideDistanceMin<b> = udg_SlideDistanceMin[a]
            set udg_SlideDamageOnce<b> = udg_SlideDamageOnce[a]
            set udg_SlideSuicide<b> = udg_SlideSuicide[a]
            set udg_SlideTargetDamage<b> = udg_SlideTargetDamage[a]
            set udg_SlideTargetKnockback<b> = udg_SlideTargetKnockback[a]
            set udg_SlidePointDamage<b> = udg_SlidePointDamage[a]
            set udg_SlideRadiusDamage<b> = udg_SlideRadiusDamage[a]
            call Trig_SuperSlide_Finish(a)
            set a = a + 1
        endloop
        set udg_NumSlider = udg_NumSlider - 1000
    endif

// This part SHOULD make a unit slide forward. Want to use a global counter here due to other functions.
    set bj_forLoopAIndex = 1
    loop
        exitwhen bj_forLoopAIndex &gt; udg_NumSlider
        
// First part takes effect if the unit is meant to slide to a target (homing).
        if (udg_SlideToTarget[bj_forLoopAIndex] != null) then
        
// Most globals should be fairly obvious. udg_SlideEffectRadius affects knockbacks and damage.
            set caster = udg_SlideCaster[bj_forLoopAIndex]
            set target = udg_SlideToTarget[bj_forLoopAIndex]
            set speed = udg_SlideSpeed[bj_forLoopAIndex]   
            set damage = udg_SlideDamage[bj_forLoopAIndex]
            set damageradius = udg_SlideEffectRadius[bj_forLoopAIndex]
            set castpoint = GetUnitLoc(caster)
            set targetpoint = GetUnitLoc(target)
            set distance = DistanceBetweenPoints(castpoint, targetpoint)

// DistanceMin refers to where a normal slide will end in comparison to the target.
            set distancemin = udg_SlideDistanceMin[bj_forLoopAIndex]
            set angle = AngleBetweenPoints(castpoint, targetpoint)

// If either caster or target is dead, the sliding ends automatically.
            if (GetUnitState(caster, UNIT_STATE_LIFE) &lt;= 0) then
                call Trig_SuperSlide_Finish(bj_forLoopAIndex)
            endif
            if (GetUnitState(target, UNIT_STATE_LIFE) &lt;= 0) then
                call Trig_SuperSlide_Finish(bj_forLoopAIndex)
            endif
            
// If the caster arrives at the target, do stuff.            
            if (distance &lt; distancemin) then
            
// If set to damage the target, deal damage.
                if (udg_SlideTargetDamage[bj_forLoopAIndex]) then
                    call UnitDamageTarget(caster, target, damage, true, false, ATTACK_TYPE_HERO, DAMAGE_TYPE_UNIVERSAL, WEAPON_TYPE_WHOKNOWS)
                endif
                
// If set to knock the target back, do it here.
                if (udg_SlideTargetKnockback[bj_forLoopAIndex]) then
                    set udg_NumSlider = udg_NumSlider + 1
                    call PauseUnit(target, true)
                    call SetUnitPathing(target, false)
                    set udg_SlideCaster[udg_NumSlider] = target
                    set udg_SlideToPoint[udg_NumSlider] = PolarProjectionBJ(castpoint, (udg_SlideDistance[bj_forLoopAIndex] / 2), angle)
                    set udg_SlideSpeed[udg_NumSlider] = speed / 1.5
                    set udg_SlidePoolShot[udg_NumSlider] = true
                    set udg_SlideEffectAllies[udg_NumSlider] = true
                endif
                
// If set to damage all units near the target, do it here.
                if (udg_SlidePointDamage[bj_forLoopAIndex]) then
                    if (damageradius &gt; 0) then
                        set damagegroup = GetUnitsInRangeOfLocAll(damageradius, movepoint)
                        call ForGroup(damagegroup, function Trig_SuperSlide_DealDamage)
                        call DestroyGroup(damagegroup)
                    endif
                endif
                
// Ends the sliding.
                call Trig_SuperSlide_Finish(bj_forLoopAIndex)
            endif
            
// If nothing ends the sliding by now, try to keep sliding along...
            set movepoint = PolarProjectionBJ(castpoint, speed/20, angle)
            
// Unless the terrain is impassable.
            if (not IsTerrainPathableBJ(movepoint, PATHING_TYPE_WALKABILITY)) then
                call Trig_SuperSlide_Finish(bj_forLoopAIndex)
            endif
            
// Destroys those pesky trees in the way. This is set to false for projectiles.
            if (udg_SlideTreeKill[bj_forLoopAIndex]) then
                call EnumDestructablesInCircleBJ(damageradius, movepoint, function Trig_SuperSlide_TreeKill)
            endif
            
// Nothing stopping the sliding? Move one more step forward.
            call SetUnitPositionLoc(caster, movepoint)
            
// Adds to the total distance already travelled, this is used to determine how far chain knockbacks go.
            set udg_SlideDistance[bj_forLoopAIndex] = udg_SlideDistance[bj_forLoopAIndex] + (speed / 20)
            
// This option allows damaging and knocking back things along the way while sliding.
            if (udg_SlideRadiusDamage[bj_forLoopAIndex]) then    
                if (damageradius &gt; 0) then
                    set damagegroup = GetUnitsInRangeOfLocAll(damageradius, movepoint)
                    call ForGroup(damagegroup, function Trig_SuperSlide_DealDamage)
                    call DestroyGroup(damagegroup)
                endif
            endif
            
// Sliding isn&#039;t finished yet, but local variables have to be removed.
            set caster = null
            set target = null
            call RemoveLocation(castpoint)
            call RemoveLocation(targetpoint)
            call RemoveLocation(movepoint)
            call DestroyGroup(damagegroup)
            
// This next portion is almost an exact same copy as the above, except it&#039;s sliding to a point.
        elseif (udg_SlideToPoint[bj_forLoopAIndex] != null) then
            set caster = udg_SlideCaster[bj_forLoopAIndex]
            set speed = udg_SlideSpeed[bj_forLoopAIndex]   
            set damage = udg_SlideDamage[bj_forLoopAIndex]
            set damageradius = udg_SlideEffectRadius[bj_forLoopAIndex]
            set castpoint = GetUnitLoc(caster)
            set targetpoint = udg_SlideToPoint[bj_forLoopAIndex]
            set distance = DistanceBetweenPoints(castpoint, targetpoint)
            set distancemin = udg_SlideDistanceMin[bj_forLoopAIndex]
            set angle = AngleBetweenPoints(castpoint, targetpoint)
            if (GetUnitState(caster, UNIT_STATE_LIFE) &lt;= 0) then
                call Trig_SuperSlide_Finish(bj_forLoopAIndex)
            endif            
            if (distance &lt; distancemin) then
                if (udg_SlidePointDamage[bj_forLoopAIndex]) then
                    if (damageradius &gt; 0) then
                        set damagegroup = GetUnitsInRangeOfLocAll(damageradius, movepoint)
                        call ForGroup(damagegroup, function Trig_SuperSlide_DealDamage)
                        call DestroyGroup(damagegroup)
                    endif
                endif
                call Trig_SuperSlide_Finish(bj_forLoopAIndex)
            endif
            set movepoint = PolarProjectionBJ(castpoint, speed/20, angle)
            if (not IsTerrainPathableBJ(movepoint, PATHING_TYPE_WALKABILITY)) then
                call Trig_SuperSlide_Finish(bj_forLoopAIndex)
            endif
            if (udg_SlideTreeKill[bj_forLoopAIndex]) then
                call EnumDestructablesInCircleBJ(damageradius, movepoint, function Trig_SuperSlide_TreeKill)
            endif
            call SetUnitPositionLoc(caster, movepoint)
            set udg_SlideDistance[bj_forLoopAIndex] = udg_SlideDistance[bj_forLoopAIndex] + (speed / 20)
            if (udg_SlideRadiusDamage[bj_forLoopAIndex]) then    
                if (damageradius &gt; 0) then
                    set damagegroup = GetUnitsInRangeOfLocAll(damageradius, movepoint)
                    call ForGroup(damagegroup, function Trig_SuperSlide_DealDamage)
                    call DestroyGroup(damagegroup)
                endif
            endif
            set caster = null
            call RemoveLocation(castpoint)
            call RemoveLocation(targetpoint)
            call RemoveLocation(movepoint)
            call DestroyGroup(damagegroup)
        endif
        set bj_forLoopAIndex = bj_forLoopAIndex + 1
    endloop
endfunction



// Setting up/executing the trigger every 0.05 seconds.
function InitTrig_SuperSlide takes nothing returns nothing
    set gg_trg_SuperSlide = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_SuperSlide, 0.05 )
    call TriggerAddAction( gg_trg_SuperSlide, function Trig_SuperSlide_Actions )
endfunction</b></b></b></b></b></b></b></b></b></b></b></b></b></b></b></b></b></b></b></b></b></b></b></b></b></b></b></b></b></b></b></b></b></b></b>
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      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