Well, I took the liberty and fixed your system for you.
There ya go:
JASS:
function Trig_walk_speed_Actions takes nothing returns boolean
local unit u
local real def
local location loc
local location loc_tar
local real z1
local real z2
call GroupEnumUnitsInRect( udg_MoveGroup, bj_mapInitialPlayableArea, null )
loop
set u = FirstOfGroup( udg_MoveGroup )
exitwhen u == null
if not IsUnitType( u , UNIT_TYPE_STRUCTURE ) and not IsUnitType( u , UNIT_TYPE_FLYING ) then
set def = GetUnitDefaultMoveSpeed(u)
set loc = GetUnitLoc(u)
set loc_tar = PolarProjectionBJ( loc, 10.00, GetUnitFacing(u))
set z1 = GetLocationZ(loc)
set z2 = GetLocationZ(loc_tar)
if z1 < z2 then
call SetUnitMoveSpeed( u, def - (z2 - z1)*20 )
elseif z1 > z2 then
call SetUnitMoveSpeed( u, def + (z1 - z2)*10 )
else
call SetUnitMoveSpeed( u, def )
endif
call RemoveLocation(loc)
call RemoveLocation(loc_tar)
endif
call GroupRemoveUnit( udg_MoveGroup, u )
endloop
set loc_tar = null
set loc = null
return false
endfunction
//===========================================================================
function InitTrig_walk_speed takes nothing returns nothing
set gg_trg_walk_speed = CreateTrigger( )
call TriggerRegisterTimerEventPeriodic( gg_trg_walk_speed, 0.1 )
call TriggerAddCondition( gg_trg_walk_speed, Condition(function Trig_walk_speed_Actions) )
endfunction
You can improve it further from here
The speed change is configured by changing the
*20
and
*10
to something else.
I could've made it configurable by a variable, but it would've required vJASS. And I saw that you've made it in WE, so I didn't convert it to vJASS.
What I did:
1) Made the trigger run every 0.1 seconds, instead of every 0.02 seconds
2) Changed the "action" to "condition"
3) Started assigning the values to variables, instead of calling functions to get the values every time you need them.
4) Using First of Group method to do the loop, instead of "For Group", and stopped leaking a unit group every 0.02 seconds (50 groups leaked every second)
5) Doing the speed change, based on the unit's default speed, instead of on its "current" speed, thus now it works well with items/abilities, and it doesn't increase/decrease the unit's speed to max/min allowed, instead - it sets it to some value, based on the steepness of the hill.
6) Stopped changing the movespeed of structures, and flying units.
7) Moved the 'if's inside the main function, instead of calling external functions to do the check.
8) Started clearing location leaks.
And that's about all I did