• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!

SImple question needing simple answer

Status
Not open for further replies.
Level 9
Joined
Jul 20, 2009
Messages
427
What action to order training unit to stop training?Coz order triggering unit to stop won't work.

  • Untitled Trigger 002 Copy
    • Events
      • Unit - A unit Begins training a unit
    • Conditions
      • (Unit-type of (Trained unit)) Equal to Farmer
    • Actions
      • Set Temp_Group = (Random 1 units from P1man)
      • Unit Group - Pick every unit in Temp_Group and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Number of units in Temp_Group) Equal to 0
            • Then - Actions
              • Unit - Order (Triggering unit) to Stop
            • Else - Actions
 
Level 9
Joined
Jul 20, 2009
Messages
427
Unit enters playable map
unit type of entering unit=man
add entering unit to P1man
P1man=units owned by player of type man
Temp_group=random 1 unit from P1
Pick every unit in temp group,if there's no unit man orders the training unit to stop..
 
Ah now I get it.
You can order the unit to Cancel.
JASS:
call IssueImmediateOrderById( GetTriggerUnit( ), 851976 )
call IssueImmediateOrderById( GetTriggerUnit( ), 0xD0008 )
This will force the building to hit Cancel the moment it starts training a unit.

But note, that if a played trains the same unit in a row meaning the unit training query, it won't work.

Edit:

JASS:
function CancelTrain_Actions takes nothing returns nothing
    local group g = GetUnitsOfTypeIdAll( 'hfoo' )
    local unit temp
    local integer unitCount = 0
    local integer cancel = 0
    loop
        set temp = FirstOfGroup( g )
        exitwhen temp == null or unitCount >= 1
        set unitCount = unitCount + 1
        call GroupRemoveUnit( g, temp )
    endloop
    call DestroyGroup( g )
    set g = null
    if unitCount > 0 then
        loop
            exitwhen cancel >= 7
            call IssueImmediateOrderById( GetTriggerUnit( ), 851976 )
            set cancel = cancel + 1
        endloop
    endif
endfunction

//===========================================================================
function InitTrig_CancelTrain takes nothing returns nothing
    local trigger CancelTrain = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( CancelTrain, EVENT_PLAYER_UNIT_TRAIN_START )
    call TriggerRegisterAnyUnitEventBJ( CancelTrain, EVENT_PLAYER_UNIT_TRAIN_FINISH )
    call TriggerAddAction( CancelTrain, function CancelTrain_Actions )
    set CancelTrain = null
endfunction
 
Either of them, they do the same.
  • CancelTrain
    • Events
      • Unit - A unit Begins training a unit
    • Conditions
    • Actions
      • Set tempGroup = (Random 1 units from (Units owned by Player 1 (Red) of type Footman))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Number of units in tempGroup) Equal to 0
        • Then - Actions
          • Custom script: call IssueImmediateOrderById( GetTriggerUnit( ), 851976 )
        • Else - Actions
      • Custom script: call DestroyGroup( udg_tempGroup )
 
Level 9
Joined
Jul 20, 2009
Messages
427
It works now but would that script also work if for example I set conditions on what unit type of the trained unit is?
 
Status
Not open for further replies.
Top