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:
The messy JASS code.
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
- Events
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'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) <= 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't get maxed out. Pushing them back by 1000.
if (udg_NumSlider > 2000) then
set a = udg_NumSlider - 1000
loop
exitwhen a > 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 > 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) <= 0) then
call Trig_SuperSlide_Finish(bj_forLoopAIndex)
endif
if (GetUnitState(target, UNIT_STATE_LIFE) <= 0) then
call Trig_SuperSlide_Finish(bj_forLoopAIndex)
endif
// If the caster arrives at the target, do stuff.
if (distance < 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 > 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 > 0) then
set damagegroup = GetUnitsInRangeOfLocAll(damageradius, movepoint)
call ForGroup(damagegroup, function Trig_SuperSlide_DealDamage)
call DestroyGroup(damagegroup)
endif
endif
// Sliding isn'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'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) <= 0) then
call Trig_SuperSlide_Finish(bj_forLoopAIndex)
endif
if (distance < distancemin) then
if (udg_SlidePointDamage[bj_forLoopAIndex]) then
if (damageradius > 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 > 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>