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,463
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.
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1

      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