| 10-30-2008, 03:38 AM | #1 |
Hello, I'll need to implent a "Reactivator" function, that sends units that are standing around back to their waypoints. In other words: Take all units in the map with current order = stop and with player controller = computer and do something. Well, my first quick and dirty approach looks like this: JASS:function Trig_Troops_ReActivator_Callback takes nothing returns nothing local boolean tempBool = true if ( not ( GetUnitCurrentOrder(GetEnumUnit()) == udg_OrderStop ) ) then set tempBool = false endif if ( not ( GetPlayerController(GetOwningPlayer(GetEnumUnit())) == MAP_CONTROL_COMPUTER ) ) then set tempBool = false endif if ( tempBool ) then call OrderUnitToNextWaypoint(GetEnumUnit()) endif endfunction function Trig_Troops_ReActivator_Actions takes nothing returns nothing local group TempGroup set TempGroup = GetUnitsInRectAll(GetPlayableMapRect()) call ForGroup( TempGroup, function Trig_Troops_ReActivator_Callback ) call DestroyGroup( TempGroup ) set TempGroup = null endfunction Well, I'm quite unhappy with this code because it doesn't seem to be very efficient. Any suggestions are very appreciated. |
| 10-30-2008, 06:08 AM | #2 |
first of all, there are [ jass ] (without whitespaces) tags. Use those if you want to share Jass code. okay: your script is inefficient, and very hard to understand (not (cond) -> set to false; if not false then do...). JASS:function Trig_Troops_ReActivator_Condition takes nothing returns boolean return GetUnitCurrentOrder(GetFilterUnit()) != OrderId("move") and GetPlayerController(GetOwningPlayer(GetFilterUnit())) == MAP_CONTROL_COMPUTER // change order "move" into the order you are giving the units on their way to the waypoints. endfunction function Trig_Troops_ReActivator_Callback takes nothing returns nothing call OrderUnitToNextWaypoint(GetEnumUnit()) endfunction function Trig_Troops_ReActivator_Actions takes nothing returns nothing local group TempGroup = CreateGroup() call GroupEnumUnitsInRect(TempGroup, bj_mapInitialPlayableArea, Condition(function Trig_Troops_ReActivator_Condition)) // store the condition in a global if you have JNGP call ForGroup( TempGroup, function Trig_Troops_ReActivator_Callback ) call DestroyGroup( TempGroup ) set TempGroup = null endfunction Im not sure if you are experiencing any problems with your script, but here's a more optimized one plus some other changes (order comparison, group handling). |
| 10-30-2008, 01:54 PM | #3 |
Thanks a lot! That's exactly what I needed. I guess I never used conditions in jass before.. |
