sliding spell not working

PrisonLove

Hard Realist
Reaction score
78
Okay so I'm creating a spell called rage that causes a unit to run at a target location and knockback and damage all units it comes into contact with.

Current Problems:
Hero goes through doodads

Also, bear in mind that I'm working off of a Mac and do not have ANY third party programs. Everything must be done with the vanilla editor.

Here's the spell:

JASS:
function RageConditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A001'
endfunction

function RageGroupSlide takes nothing returns nothing
    local unit target = GetEnumUnit()
    local integer targetID = GetHandleId(target)
    local real angle = LoadReal(udg_hash, targetID, 0)
    local real kbCount = LoadReal(udg_hash, targetID, 1)
    local timer kbTimer = LoadTimerHandle(udg_hash, targetID, 2)
    local real dist = 20.00
    local real kbTotalDist = 350.00

    if (kbCount < kbTotalDist) then
        call SaveReal(udg_hash, targetID, 1, kbCount + dist)
        call Slide(target, dist, angle, "Objects\\Spawnmodels\\Undead\\ImpaleTargetDust\\ImpaleTargetDust.mdl")
    else
        call PauseTimer(kbTimer)
        call PauseUnit(target, false)
        call DestroyTimer(kbTimer)
        call GroupRemoveUnit(udg_rageDamaged, target)
        call FlushChildHashtable(udg_hash, targetID)
    endif

    set kbTimer = null
    set target = null
endfunction

function RageKnockback takes nothing returns nothing
     call ForGroup(udg_rageDamaged, function RageGroupSlide)
endfunction

function RageGroupFilter takes nothing returns boolean
    local unit caster = udg_globalCaster
    local player owner = GetOwningPlayer(caster)
    local unit target = GetFilterUnit()
    local integer targetID
    local real damageAmount = 100 + ((I2R(GetUnitAbilityLevel(caster, 'A001')) - 1.00) * 50)
    local real angle
    local real angle2
    local real kbCount = 0
    local timer targetTimer = CreateTimer()

    if (GetUnitState(target, UNIT_STATE_LIFE) > 0  and IsUnitType(target, UNIT_TYPE_GROUND) == true and IsUnitEnemy(target, owner) == true and IsUnitInGroup(target, udg_rageDamaged) == false) then
        call GroupAddUnit(udg_rageDamaged, target)
        call UnitDamageTarget(caster, target, damageAmount, false, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS)

        set targetID = GetHandleId(target)
        set angle = GetAngle(GetUnitX(caster), GetUnitY(caster), GetUnitX(target), GetUnitY(target))

        if angle < 0 then
           set angle = angle + 360.
        endif

        set angle2 = GetUnitFacing(caster)

        if angle2 > angle then
             set angle = angle2 - 45.
        elseif angle2 < angle then
             set angle = angle2 + 45.
        endif

        call SaveReal(udg_hash, targetID, 0, angle)
        call SaveReal(udg_hash, targetID, 1, kbCount)
        call SaveTimerHandle(udg_hash, targetID, 2, targetTimer)
        call PauseUnit(target, true)
        call TimerStart(targetTimer, .05, true, function RageKnockback)
    endif

    set caster = null
    set target = null
    return false
endfunction

function RageCallback takes nothing returns nothing
    local timer rageTimer = GetExpiredTimer()
    local integer timerID = GetHandleId(rageTimer)
    local unit caster = LoadUnitHandle(udg_hash, timerID, 0)
    local real angle = LoadReal(udg_hash, timerID, 1)
    local real count = LoadReal(udg_hash, timerID, 2)
    local real totalDist = LoadReal(udg_hash, timerID, 3)
    local real x = GetUnitX(caster)
    local real y = GetUnitY(caster)
    local real dist = 45.00
    local group targetGroup = CreateGroup()
    set udg_globalCaster = caster

    if (count < totalDist) then
        call SaveReal(udg_hash, timerID, 2, count + dist)
        call GroupEnumUnitsInRange(targetGroup, x, y, 175.00, Filter(function RageGroupFilter))
        call SlideKeepOrder(caster, dist, angle, "Objects\\Spawnmodels\\Undead\\ImpaleTargetDust\\ImpaleTargetDust.mdl")
    else
        call PauseTimer(rageTimer)
        call DestroyTimer(rageTimer)
        call PauseUnit(caster, false)
        call FlushChildHashtable(udg_hash, timerID)
    endif

    set rageTimer = null
    set caster = null
    call DestroyGroup(targetGroup)
    set targetGroup = null
endfunction

function RageActions takes nothing returns nothing
    local unit caster = GetTriggerUnit()
    local real x1 = GetUnitX(caster)
    local real y1 = GetUnitY(caster)
    local real x2 = GetSpellTargetX()
    local real y2 = GetSpellTargetY()
    local real angle = GetAngle(x1, y1, x2, y2)
    local real totalDist = Distance(x1, y1, x2, y2)
    local real count = 0.00
    local timer rageTimer = CreateTimer()
    local integer timerID = GetHandleId(rageTimer)

    call SaveUnitHandle(udg_hash, timerID, 0, caster)
    call SaveReal(udg_hash, timerID, 1, angle)
    call SaveReal(udg_hash, timerID, 2, count)
    call SaveReal(udg_hash, timerID, 3, totalDist)

    call PauseUnit(caster, true)
    call TimerStart(rageTimer, 0.03, true, function RageCallback)
    
    set caster = null
    set rageTimer = null
endfunction

//===========================================================================
function InitTrig_Rage takes nothing returns nothing
    local trigger trigRage = CreateTrigger( )
    call TriggerRegisterAnyUnitEventBJ(trigRage, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(trigRage, Condition(function RageConditions))
    call TriggerAddAction(trigRage, function RageActions)
endfunction


And here are some function declared in the header that I used in this spell:

JASS:
//================================================================

function PolarProjectX takes real x, real dist, real angle returns real
    return x + dist * Cos(angle * bj_DEGTORAD)
endfunction

function PolarProjectY takes real y, real dist, real angle returns real
    return y + dist * Sin(angle * bj_DEGTORAD)
endfunction

function GetAngle takes real x1, real y1, real x2, real y2 returns real
    return bj_RADTODEG * Atan2(y2 - y1, x2 - x1)
endfunction

function Distance takes real x1, real y1, real x2, real y2 returns real
    local real dx = x2 - x1
    local real dy = y2 - y1
    return SquareRoot(dx * dx + dy * dy)
endfunction

//================================================================

function SafeX takes real x returns real
    if (x > udg_maxX) then
        return udg_maxX
    elseif (x < udg_minX) then
        return udg_minX
    else
        return x
    endif
endfunction

function SafeY takes real y returns real
    if (y > udg_maxY) then
        return udg_maxY
    elseif (y < udg_minY) then
        return udg_minY
    else
        return y
    endif
endfunction

//================================================================

function SlideKeepOrder takes unit target, real dist, real angle, string fx returns nothing
    local real x = GetUnitX(target)
    local real y = GetUnitY(target)
    local real x2 = SafeX(PolarProjectX(x, dist, angle))
    local real y2 = SafeY(PolarProjectY(y, dist, angle))
    call DestroyEffect(AddSpecialEffect(fx, x, y))
    call SetUnitX(target, x2)
    call SetUnitY(target, y2)
endfunction

//================================================================

function Slide takes unit target, real dist, real angle, string fx returns nothing
    local real x = GetUnitX(target)
    local real y = GetUnitY(target)
    local real x2 = SafeX(PolarProjectX(x, dist, angle))
    local real y2 = SafeY(PolarProjectY(y, dist, angle))
    call DestroyEffect(AddSpecialEffect(fx, x, y))
    call SetUnitPosition(target, x2, y2)
endfunction

//================================================================


Extra Info, from the comments section of the Trigger:

Code:
Hashtable info: Hashtable = udg_hash
  Index (timerID,0) reserved for unit "caster"
  Index (timerID,1) reserved for real "angle"
  Index (timerID,2) reserved for real "count"
  Index (timerID,3) reserved for real "totalDist"

Hashtable info: Hashtable = udg_hash
  Index (targetID,0) reserved for real "angle"
  Index (targetID,1) reserved for real "kbcount"
  Index (targetID,2) reserved for timer "kbTimer"

Thanks for any help.
 

Dinowc

don't expect anything, prepare for everything
Reaction score
223
you're right

that code is a complete mess

first of all, remove the TriggerSleepAction() and never use it again

instead, count the seconds remaining in RageExecution function and when it reaches 0.5, pause and destroy the timer

this:
JASS:
local real x = GetUnitX(target)
local real y = GetUnitX(target)

should be:
JASS:
local real x = GetUnitX(target)
local real y = GetUnitY(target)

that's the reason why he moves 270 degrees

also use X/Y coordinates, not locations

and why are you creating a new group every time? use one group and recycle (clear) it on every timer callback

and you can't refer to the expired timer in GroupActions() function... make a global timer variable for that
same for GetTriggerUnit() in RageGroupFilter() function

there are probably many more errors, but don't have time to look at the whole code

btw, why are you doing so complicated stuff already? you wont learn it faster like it...
 

PrisonLove

Hard Realist
Reaction score
78
I updated the code.
Now there's a new problem:

The hero slides, but no damage is done. Also, the hero doesn't slide through anybody, he stops when he hits a unit. It would be preferable to allow him to slide through units, but not anything else, such as terrain and doodads (destructibles would be fine). Any and all help is appreciated.
 

Dinowc

don't expect anything, prepare for everything
Reaction score
223
instead of me trying to find errors in your code, I've made the whole spell with plain Jass (using vanilla editor, was a pain in the ass xd)

JASS:
function PolarX takes real dist, real angle returns real
    return dist * Cos(angle * bj_DEGTORAD)
endfunction

function PolarY takes real dist, real angle returns real
    return dist * Sin(angle * bj_DEGTORAD)
endfunction

function Distance takes real x1, real y1, real x2, real y2 returns real
    local real dx = x2 - x1
    local real dy = y2 - y1
    return SquareRoot(dx * dx + dy * dy)
endfunction

function GetAngle takes real x1, real y1, real x2, real y2 returns real
    return bj_RADTODEG * Atan2(y2 - y1, x2 - x1)
endfunction

function SafeX takes real x returns real
    if x > udg_MaxX then
        return udg_MaxX
    else
        return x
    endif

    if x < udg_MinX then
        return udg_MinX
    else
        return x
    endif
endfunction

function SafeY takes real y returns real
    if y > udg_MaxY then
        return udg_MaxY
    else
        return y
    endif

    if y < udg_MinY then
        return udg_MinY
    else
        return y
    endif
endfunction

function slide_knock takes nothing returns nothing
    local unit picked = GetEnumUnit()
    local integer id = GetHandleId(picked)
    local real angle = LoadReal(udg_hash, id, 0)
    local real dist = LoadReal(udg_hash, id, 1)

    call SetUnitX(picked, SafeX(GetUnitX(picked) + PolarX(dist, angle)))
    call SetUnitY(picked, SafeY(GetUnitY(picked) + PolarY(dist, angle)))
    call DestroyEffect(AddSpecialEffectTarget("Objects\\Spawnmodels\\Undead\\ImpaleTargetDust\\ImpaleTargetDust.mdl", picked, "origin"))

    set dist = dist * 0.9

    call SaveReal(udg_hash, id, 1, dist)

    if dist <= 10 then
        call FlushChildHashtable(udg_hash, id)
        call GroupRemoveUnit(udg_KnockbackGroup, picked)
        call PauseUnit(picked, false)
        
        set udg_Count = udg_Count - 1

        if udg_Count <= 0 then
           call PauseTimer(udg_Timer)
        endif
     endif

     set picked = null 
endfunction

function slide_knockback takes nothing returns nothing
    call ForGroup(udg_KnockbackGroup, function slide_knock)
endfunction

function slide_filter takes nothing returns boolean
    local unit picked = GetFilterUnit()
    local player p = GetOwningPlayer(udg_Caster)
    local integer id
    local real angle
    local real angle2

    if IsUnitType(picked, UNIT_TYPE_DEAD) == false and IsUnitEnemy(picked, p) == true and IsUnitInGroup(picked, udg_Damaged) == false then
        call UnitDamageTarget(udg_Caster, picked, 100 + ((GetUnitAbilityLevel(udg_Caster, 'A000') - 1) * 50), false, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS)
        call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Other\\Stampede\\StampedeMissileDeath.mdl" , picked, "chest"))
        call GroupAddUnit(udg_KnockbackGroup, picked)
        call GroupAddUnit(udg_Damaged, picked)

        set id = GetHandleId(picked)
        set angle = GetAngle(GetUnitX(udg_Caster), GetUnitY(udg_Caster), GetUnitX(picked), GetUnitY(picked))

        if angle < 0 then
           set angle = angle + 360.
        endif

        set angle2 = GetUnitFacing(udg_Caster)

        if angle2 > angle then
             set angle = angle2 - 45.
        elseif angle2 < angle then
             set angle = angle2 + 45.
        endif
             
        call SaveReal(udg_hash, id, 0, angle)
        call SaveReal(udg_hash, id, 1, 40.)

        call PauseUnit(picked, true)
     
        if udg_Count == 0 then
           call TimerStart(udg_Timer, 0.03125, true, function slide_knockback)
        endif

        set udg_Count = udg_Count + 1
    endif
  
    set picked = null
    set p = null
    return false
endfunction

function slide_callback takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local integer id = GetHandleId(t)
    local unit caster = LoadUnitHandle(udg_hash, id, 0)
    local real x = GetUnitX(caster)
    local real y = GetUnitY(caster)
    local real count = LoadReal(udg_hash, id, 1) + 40.
    local real dist = LoadReal(udg_hash, id, 2)
    local real angle = LoadReal(udg_hash, id, 3)
    local group g = LoadGroupHandle(udg_hash, id, 4)

    call SetUnitX(caster, SafeX(x + PolarX(40., angle)))
    call SetUnitY(caster, SafeY(y + PolarY(40., angle)))
    call SaveReal(udg_hash, id, 1, count)

    set udg_Caster = caster
    set udg_Damaged = g
    call GroupEnumUnitsInRange(udg_DamageGroup, GetUnitX(caster), GetUnitY(caster), 150., Filter(function slide_filter))
    set udg_Caster = null
    set udg_Damaged = null

    call DestroyEffect(AddSpecialEffectTarget("Objects\\Spawnmodels\\Undead\\ImpaleTargetDust\\ImpaleTargetDust.mdl", caster, "origin"))

    if count >= dist then
        call FlushChildHashtable(udg_hash, id)
        call GroupClear(g)
        call DestroyGroup(g)
        call PauseTimer(t)
        call DestroyTimer(t)
        call PauseUnit(caster, false)
        call SetUnitAnimation(caster, "stand")
        call IssueImmediateOrder(caster, "stop")
    endif

    set g =null
    set caster = null
    set t = null
endfunction

function slide_actions takes nothing returns nothing
    local unit caster = GetTriggerUnit()
    local real x1 = GetUnitX(caster)
    local real y1 = GetUnitY(caster)  
    local real x2 = GetSpellTargetX()
    local real y2 = GetSpellTargetY()
    local real count = 0.
    local real dist = Distance(x1, y1, x2, y2)
    local real angle = GetAngle(x1, y1, x2, y2)
    local group g = CreateGroup()
    local timer t = CreateTimer()
    local integer id = GetHandleId(t)

    call SaveUnitHandle(udg_hash, id, 0, caster)
    call SaveReal(udg_hash, id, 1, count)
    call SaveReal(udg_hash, id, 2, dist)
    call SaveReal(udg_hash, id, 3, angle)
    call SaveGroupHandle(udg_hash, id, 4, g)
    call TimerStart(t, 0.03125, true, function slide_callback)

    call PauseUnit(caster, true)
    call SetUnitAnimation(caster, "channel")

    set caster = null
    set t = null
endfunction

function slide_conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A000'
endfunction

//===========================================================================
function InitTrig_Slide takes nothing returns nothing
    local trigger t = CreateTrigger()

    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(t, Condition(function slide_conditions))
    call TriggerAddAction(t, function slide_actions)

    set udg_MaxX = GetRectMaxX(GetPlayableMapRect()) - 50.
    set udg_MaxY = GetRectMaxY(GetPlayableMapRect()) - 50.
    set udg_MinX = GetRectMinX(GetPlayableMapRect()) + 50.
    set udg_MinY = GetRectMinY(GetPlayableMapRect()) + 50.

    set udg_Timer = CreateTimer()
    set udg_KnockbackGroup = CreateGroup()
    set udg_DamageGroup = CreateGroup()
    set udg_hash = InitHashtable()
    set t = null
endfunction


here's the test map (it sucks because it's not configurable)
 

PrisonLove

Hard Realist
Reaction score
78
Thanks a lot, although I really would have preferred the errors to be pointed out, as this helps me learn better. This spell is a real learning experience for me. I find I learn better by trying difficult tasks, which is why I started learning timers with a fairly complex (at least in my opinion) spell.

For example I didn't know these existed:



That's why I was using locations. With these I won't have to use locations again.

Also, the GetAngle function you created was another thing which I didn't know how to construct.

Sorry you needed to use the vanilla editor, but I personally think it's more rewarding to do things the hard way.

Edit: Sorry, it appears I have to wait to give you rep. I'll do it as soon as possible.

Edit2: Hmm, it seems that your spell allows the unit to go over cliffs and through doodads. How would I prevent this? I only want him to charge through unit, and possibly destructibles, not doodads and cliffs.
 

PrisonLove

Hard Realist
Reaction score
78
Ok so I've updated the code in the first post. Currently the hero slides but the enemies get knocked back at an awkward angle and don't take any damage. Also the hero goes over cliffs and through doodads, which I don't want it to do.


Current Problems:
Hero goes over cliffs and through doodads
Enemy units get knocked back at an odd angle
Enemy units do not take damage


Any help from anyone to fix these issues would be much appreciated.

As a side note, all global variables are properly declared.
 

Dinowc

don't expect anything, prepare for everything
Reaction score
223
Hero goes over cliffs and through doodads

change this:
JASS:
function SlideKeepOrder takes unit target, real dist, real angle, string fx returns nothing
    local real x = GetUnitX(target)
    local real y = GetUnitY(target)
    local real x2 = SafeX(PolarProjectX(x, dist, angle))
    local real y2 = SafeY(PolarProjectY(y, dist, angle))
    call DestroyEffect(AddSpecialEffect(fx, x, y))
    call SetUnitX(target, x2)
    call SetUnitY(target, y2)
endfunction

to this:
JASS:
function SlideKeepOrder takes unit target, real dist, real angle, string fx returns nothing
    local real x = GetUnitX(target)
    local real y = GetUnitY(target)
    local real x2 = SafeX(PolarProjectX(x, dist, angle))
    local real y2 = SafeY(PolarProjectY(y, dist, angle))
    call DestroyEffect(AddSpecialEffect(fx, x, y))
    if GetTerrainCliffLevel(x2, y2) == GetTerrainCliffLevel(x, y) then
          call SetUnitX(target, x2)
          call SetUnitY(target, y2)
    endif
endfunction


checking for destructables is a bit more complicated

you should do that in GUI and convert it to see how it looks

Enemy units get knocked back at an odd angle

do they get knocked back backwards sometimes?

add these lines (like I did with my spell)

JASS:
if angle < 0 then
      set angle = angle + 360.
endif

set angle2 = GetUnitFacing(caster)

if angle2 > angle then
      set angle = angle2 - 45.
elseif angle2 < angle then
      set angle = angle2 + 45.
endif


JASS:
if (IsUnitType(target, UNIT_TYPE_DEAD) == false  and IsUnitType(target, UNIT_TYPE_GROUND) == true and IsUnitEnemy(target, owner) == true and IsUnitInGroup(target, udg_rageDamaged) == false) then
      call GroupAddUnit(udg_rageDamaged, target)
      call UnitDamageTarget(caster, target, damageAmount, false, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS)

      set targetID = GetHandleId(target)
      set angle = GetAngle(GetUnitX(caster), GetUnitY(caster), GetUnitX(target), GetUnitY(target))

      // here.......

      call SaveReal(udg_hash, targetID, 0, angle)
      call SaveReal(udg_hash, targetID, 1, kbCount)
      call SaveTimerHandle(udg_hash, targetID, 2, targetTimer)
      call PauseUnit(target, true)
      call TimerStart(targetTimer, .05, true, function RageKnockback)
endif


also, declare the angle2 variable in the function

Enemy units do not take damage

I think it's because you can't refer to triggering unit in RageGroupFilter() function

store the caster in a global variable (like I did with udg_Caster)

OR

JASS:
local real damageAmount = 100 + ((GetUnitAbilityLevel(caster, 'A000') - 1) * 50)

shouldn't that be:
JASS:
local real damageAmount = 100 + ((GetUnitAbilityLevel(caster, 'A001') - 1) * 50)

?

also, your code is still very messy... why are you creating a new timer for every picked unit? that might cause heavy lags

read the code in my spell carefully and try to understand it (it's not perfect, but it's good enough)

I find I learn better by trying difficult tasks

that's weird because it never worked for me xd
 

PrisonLove

Hard Realist
Reaction score
78
That was a good catch with the ability ID. But damage still isn't being done :banghead:

Anyway I updated the first post with the latest trigger and it still isn't working properly.

I have a theory that the caster unit is being passed into the RageGroupSlide function, which is why his movement is glitchy. This is why I think this.

When I change the equality comparison in the if statement, which is:
[ljass]if (kbCount < kbTotalDist) then[/ljass]
to this instead:
[ljass]if (kbCount > kbTotalDist) then[/ljass]

it effectively disables that function. Once this is done the caster moves through objects and units and slides smoothly, but the enemy units do not get knocked back. So, I need to find a way to fix this. If someone thinks the cause may be different then please let me know.

Edit:
I think it's because you can't refer to triggering unit in RageGroupFilter() function

store the caster in a global variable (like I did with udg_Caster)
Won't that make it not MUI?

Edit2:
do they get knocked back backwards sometimes?

add these lines (like I did with my spell)

JASS:
if angle &lt; 0 then
      set angle = angle + 360.
endif

set angle2 = GetUnitFacing(caster)

if angle2 &gt; angle then
      set angle = angle2 - 45.
elseif angle2 &lt; angle then
      set angle = angle2 + 45.
endif

It's more like they stick to the caster instead of being knocked back. Just out of curiosity, what does that particular piece of code do?

Sorry there are so many questions.
 

Dinowc

don't expect anything, prepare for everything
Reaction score
223
Won't that make it not MUI?

the group enumeration runs the actions instantly and the udg_Caster variable is nulled after that, so no

It's more like they stick to the caster instead of being knocked back. Just out of curiosity, what does that particular piece of code do?

to make the units knocked back only in front of the caster (in a cone of 90°) I added the +-45 to the angle, depending on angle between the caster and the target

the GetAngle() function sometimes returns a negative angle, so it's wise to add 360. to it when that occurs, because -45° == 315°, but -45 != 315

Sorry there are so many questions.

there's a bigger chance for ppl to answer to them if you have a smaller and easier-to-read code
ppl are too lazy (including me) for going trough all that and explain everything xd

always add a BJDebugMsg("write anything here...") code at unsure places (where you think the error occurs)
that helps a lot in debugging (as the name of the BJ says ^^)

so for example, put that line under the call UnitDamageTarget() to be sure that it checks for correct units and that it runs every other action in the block
 

PrisonLove

Hard Realist
Reaction score
78
the group enumeration runs the actions instantly and the udg_Caster variable is nulled after that, so no

That did it, it now works as intended except for one thing. The hero slides through doodads. Any suggestions on how to prevent this?

Thank you so much for your help by the way!
 

Dinowc

don't expect anything, prepare for everything
Reaction score
223
The hero slides through doodads. Any suggestions on how to prevent this?

first, you need a rect because the native that checks for destructibles needs it
also create a global boolean variable

just create the rect on init with this:
JASS:
set udg_Rect = Rect(-75., -75., 75., 75.)

then put these lines in the callback function (before the if (count < totalDist) then):
JASS:
call MoveRectTo(udg_Rect, x, y)
call EnumDestructablesInRect(udg_Rect, Filter(function CheckTrees), null)


and make a function named CheckTrees

JASS:
function CheckTrees takes nothing returns boolean
    local destructable d = GetFilterDestructable()
    if GetDestructableLife(d) &gt; 0 then
        set udg_Boolean = false
    endif
    set d = null
    return false
endfunction


and keep checking for udg_Boolean in callback function
if it becomes false, then set count = totalDist (to pause and destroy the timer) and then immediately set it to true
 

PrisonLove

Hard Realist
Reaction score
78
Okay that works for destructibles, but not regular doodads, like rocks and trees and such. How can I make it work for those? Is it possible?
 

the Immortal

I know, I know...
Reaction score
51
JASS:
    globals //use var editor
        item udg_PathItem
        rect udg_PathRect    //region
        item array udg_PathItems
        integer udg_PathItemCount
    endglobals
    
    function Path_HideItems takes nothing returns boolean
        if IsItemVisible(GetFilterItem()) then
            set udg_PathItems[udg_PathItemCount] = GetFilterItem()
            call SetItemVisible(udg_PathItems[udg_PathItemCount], false)
            set udg_PathItemCount = udg_PathItemCount + 1
        endif
        return false
    endfunction
    
    function CanWeStepHere takes real x, real y returns boolean
        local real ix
        local real iy

        if udg_PathItem == null then
            set udg_PathItem = CreateItem(&#039;ciri&#039;, 0, 0)
            set udg_PathRect = Rect(0, 0, 128, 128)
        endif

        call MoveRectTo(udg_PathRect, x, y)
        call EnumItemsInRect(udg_PathRect, null, function Path_HideItems)
        
        call SetItemPosition(udg_PathItem, x, y)
        set ix = GetItemX(udg_PathItem)
        set iy = GetItemY(udg_PathItem)
        call SetItemVisible(udg_PathItem, false)
        
        loop
            exitwhen udg_PathItemCount == 0
            set udg_PathItemCount = udg_PathItemCount - 1
            call SetItemVisible(udg_PathItems[udg_PathItemCount], true)
        endloop
        return (ix-x) * (ix-x) + (y-iy) * (y-iy) &lt;= 100    //10^2
    endfunction

if CanWeStepHere(x, y) then blahblah

There was a similar one at wc3c, but I couldn't find it when I needed it, so I made this one. Should work flawlessly.

edit: no vjass
 

the Immortal

I know, I know...
Reaction score
51
Didn't see that. Still, updated the post with pure JASS version, and I believe it is still useful since the IsTerrainPathable method has a (big) flaw - it seems to ignore destructibles and buildings.

And I found the original thread - the resource is there plus some further explanations at 4th page of it for those interested.
 
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

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top