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?
 
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.
 
mmmmh, human workers trigger the Repair ability
triggering unit is the worker and target unit of ability being cast is the building

try out
 
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.
 
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.
 
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.
 
>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.
 
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.
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    News portal has been retired. Main page of site goes to Headline News forum now
  • The Helper The Helper:
    I am working on getting access to the old news portal under a different URL for those that would rather use that for news before we get a different news view.
  • Ghan Ghan:
    Easily done
    +1
  • The Helper The Helper:
    https://www.thehelper.net/pages/news/ is a link to the old news portal - i will integrate it into the interface somewhere when i figure it out
  • Ghan Ghan:
    Need to try something
  • Ghan Ghan:
    Hopefully this won't cause problems.
  • Ghan Ghan:
    Hmm
  • Ghan Ghan:
    I have converted the Headline News forum to an Article type forum. It will now show the top 20 threads with more detail of each thread.
  • Ghan Ghan:
    See how we like that.
  • The Helper The Helper:
    I do not see a way to go past the 1st page of posts on the forum though
  • The Helper The Helper:
    It is OK though for the main page to open up on the forum in the view it was before. As long as the portal has its own URL so it can be viewed that way I do want to try it as a regular forum view for a while
  • Ghan Ghan:
    Yeah I'm not sure what the deal is with the pagination.
  • Ghan Ghan:
    It SHOULD be there so I think it might just be an artifact of having an older style.
  • Ghan Ghan:
    I switched it to a "Standard" article forum. This will show the thread list like normal, but the threads themselves will have the first post set up above the rest of the "comments"
  • The Helper The Helper:
    I don't really get that article forum but I think it is because I have never really seen it used on a multi post thread
  • Ghan Ghan:
    RpNation makes more use of it right now as an example: https://www.rpnation.com/news/
  • The Helper The Helper:
  • The Helper The Helper:
    What do you think Tom?
  • tom_mai78101 tom_mai78101:
    I will have to get used to this.
  • tom_mai78101 tom_mai78101:
    The latest news feed looks good

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top