How Do I Refer to the Worker Constructing a Structure?

Squeekems

TH.net Regular
Reaction score
11
I am using the event [ljass]Unit - A unit Begins construction[/ljass] to make this trigger work. I realized I need to refer to the worker unit that is doing the construction. How would I do that?
 

KaerfNomekop

Swim, fishies. Swim through the veil of steel.
Reaction score
613
I don't think there's a reference for that, but you could detect when a unit is issued an order targeting a point and use Triggering unit instead. The building-type would then depend on the issued order.
 

Amn

Member
Reaction score
18
mmmmh, human workers trigger the Repair ability
triggering unit is the worker and target unit of ability being cast is the building

try out
 

Accname

2D-Graphics enthusiast
Reaction score
1,462
Unfortunately there is no way to find the constructing worker accurately. you could try to pick the closest unit to the structures position which has a worker classification. But this will take quite some performance for such a minor issue and is still prone to mistakes since there could be plenty of workers standing around the building, or if the building worker is of the undead race he might very well be somewhere completely else on the map.
 

Sgqvur

FullOfUltimateTruthsAndEt ernalPrinciples, i.e shi
Reaction score
62
Building on top of what KaerfNomekop posted, you just need to make a filter for the orders so that if the worker is ordered to move or some other order it won't fire the event. (I don't think this can be done in gui because for starters I don't think it allows you to use numbers bigger then 999 999 999 and it seams that all buildings have unit id's much bigger than that)

The small caveat is that this fires exactly when the player orders the unit to build the building not when it gets to the actual location and start's building it.
JASS:
// this condition filters the orders
function Trig_get_builder_Conditions takes nothing returns boolean
    return GetIssuedOrderId() > 1500000000 // 'e000' = 1_694_498_816 so I think 1_500_000_000 is good enough
endfunction

function Trig_get_builder_Actions takes nothing returns nothing
    call BJDebugMsg("builder: " + GetUnitName(GetTriggerUnit())) // builder: peasant, wisp, peon or acolyte
endfunction

//===========================================================================
function InitTrig_get_builder takes nothing returns nothing
    set gg_trg_get_builder = CreateTrigger(  )
    
    call TriggerRegisterAnyUnitEventBJ( gg_trg_get_builder, EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER )
    
    call TriggerAddCondition( gg_trg_get_builder, Condition( function Trig_get_builder_Conditions ) )
    
    call TriggerAddAction( gg_trg_get_builder, function Trig_get_builder_Actions )
endfunction


Of course Amn suggestion works too.
 

Squeekems

TH.net Regular
Reaction score
11
I am going to try Amn's suggestion. I try to avoid jass as much as possible. I am terrible with unit orders anyways, so. Here's the trigger I'm working on. I think it is self-explanatory.

Trigger:
  • Restrict Barracks
    • Events
      • Unit - A unit Begins construction
    • Conditions
      • (Unit-type of (Constructing structure)) Equal to Barracks
    • Actions
      • Set TempUnit = (Triggering unit)
      • Set TempGroup[3] = (Units owned by (Owner of (Constructing structure)) of type Peasant)
      • Unit Group - Pick every unit in TempGroup[3] and do (Actions)
        • Loop - Actions
          • Unit - Replace (Picked unit) with a Peasant (No Barracks) using The old unit's relative life and mana
      • Unit - Order TempUnit to Right-Click (Constructing structure)
      • Set TempUnit = No unit
      • Custom script: call DestroyGroup(udg_TempGroup[3])


Also, I was wondering, does [ljass]Set TempUnit = No unit[/ljass] null the variable?

EDIT:

Here is the new trigger I came up with. It does not make the Peasant continue working on the Barracks. I realized it is because TempUnit[0] gets replaced. But, how could I refer to that unit specifically? I am going to replace it separately, and then all of the Peasants owned by the player. Is there some better way to do it?

Trigger:
  • Restrict Barracks
    • Events
      • Unit - A unit Begins casting an ability
    • Conditions
      • (Unit-type of (Target unit of ability being cast)) Equal to Barracks
      • (Ability being cast) Equal to Repair (Human)
      • (Target unit of ability being cast) Not equal to Barracks[((Player number of (Owner of (Triggering unit))) - 1)]
    • Actions
      • Set TempUnit[0] = (Triggering unit)
      • Set TempUnit[1] = (Target unit of ability being cast)
      • Game - Display to (All players) the text: ((Name of TempUnit[0]) + ( and + (Name of TempUnit[1])))
      • Set Barracks[((Player number of (Owner of TempUnit[0])) - 1)] = TempUnit[1]
      • Set TempGroup[3] = (Units owned by (Owner of TempUnit[0]) of type Peasant)
      • Unit Group - Pick every unit in TempGroup[3] and do (Actions)
        • Loop - Actions
          • Unit - Replace (Picked unit) with a Peasant (No Barracks) using The old unit's relative life and mana
      • Unit - Order TempUnit[0] to Human Peasant - Repair TempUnit[1]
      • Custom script: call DestroyGroup(udg_TempGroup[3])


EDIT2:

Here is the version of the trigger that I have working.

Trigger:
  • Restrict Barracks
    • Events
      • Unit - A unit Begins casting an ability
    • Conditions
      • (Unit-type of (Target unit of ability being cast)) Equal to Barracks
      • (Ability being cast) Equal to Repair (Human)
      • (Target unit of ability being cast) Not equal to Barracks[((Player number of (Owner of (Triggering unit))) - 1)]
    • Actions
      • Set TempUnit[1] = (Target unit of ability being cast)
      • Unit - Replace (Triggering unit) with a Peasant (No Barracks) using The old unit's relative life and mana
      • Set TempUnit[0] = (Last replaced unit)
      • Game - Display to (All players) the text: ((Name of TempUnit[0]) + ( and + (Name of TempUnit[1])))
      • Set Barracks[((Player number of (Owner of TempUnit[0])) - 1)] = TempUnit[1]
      • Wait 0.10 seconds
      • Set TempGroup[3] = (Units owned by (Owner of TempUnit[0]) of type Peasant)
      • Unit Group - Pick every unit in TempGroup[3] and do (Actions)
        • Loop - Actions
          • Unit - Replace (Picked unit) with a Peasant (No Barracks) using The old unit's relative life and mana
      • Unit - Order TempUnit[0] to Human Peasant - Repair TempUnit[1]
      • Custom script: call DestroyGroup(udg_TempGroup[3])


I am going to try and get it to have the player select the unit after it is replaced if the the player had the it selected.
 

Sgqvur

FullOfUltimateTruthsAndEt ernalPrinciples, i.e shi
Reaction score
62
>Also, I was wondering, does Set TempUnit = No unit null the variable?

Well you can check that, if you go to "Edit/Convert to Custom Text" and if you want to revert back to gui press Ctrl+Z or you can make a copy of the trigger and covert it to custom text. But you don't have to null global (variables created in the Variables Dialog) because they will be resigned the next time the event happens in general.

>But, how could I refer to that unit specifically?

Using Last replaced unit I think.
 

Squeekems

TH.net Regular
Reaction score
11
Thanks for the information, guys. Here is the final product:

Trigger:
  • Restrict Barracks
    • Events
      • Unit - A unit Begins casting an ability
    • Conditions
      • (Unit-type of (Target unit of ability being cast)) Equal to Barracks
      • (Ability being cast) Equal to Repair (Human)
      • (Target unit of ability being cast) Not equal to Barracks[((Player number of (Owner of (Triggering unit))) - 1)]
    • Actions
      • Set TempUnit[1] = (Target unit of ability being cast)
      • For each (Integer A) from 0 to 5, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Triggering unit) is selected by (Player(((Integer A) + 1)))) Equal to True
            • Then - Actions
              • Set BarracksSelected[(Integer A)] = True
            • Else - Actions
      • Unit - Replace (Triggering unit) with a Peasant (No Barracks) using The old unit's relative life and mana
      • Set TempUnit[0] = (Last replaced unit)
      • For each (Integer A) from 0 to 5, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • BarracksSelected[(Integer A)] Equal to True
            • Then - Actions
              • Selection - Add TempUnit[0] to selection for (Player(((Integer A) + 1)))
              • Set BarracksSelected[(Integer A)] = False
            • Else - Actions
      • Game - Display to (All players) the text: ((Name of TempUnit[0]) + ( and + (Name of TempUnit[1])))
      • Set Barracks[((Player number of (Owner of TempUnit[0])) - 1)] = TempUnit[1]
      • Wait 0.10 seconds
      • Set TempGroup[3] = (Units owned by (Owner of TempUnit[0]) of type Peasant)
      • Unit Group - Pick every unit in TempGroup[3] and do (Actions)
        • Loop - Actions
          • Unit - Replace (Picked unit) with a Peasant (No Barracks) using The old unit's relative life and mana
      • Unit - Order TempUnit[0] to Human Peasant - Repair TempUnit[1]
      • Custom script: call DestroyGroup(udg_TempGroup[3])
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top