• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[General] Event response for building unit?

Status
Not open for further replies.
Level 12
Joined
Nov 3, 2013
Messages
989
  • Untitled Trigger 003
    • Events
      • Unit - A unit Begins construction
    • Conditions
    • Actions
      • Unit - Remove (Triggering unit) from the game
      • Unit - Remove (Constructing structure) from the game
both (Triggering unit) and (Constructing structure) refers to the structure being built, but there doesn't seem like any to get the unit which started building it.

So question: how do I get the building unit when it begins constructing.

Issued order == build crossed my mind but that doesn't mean that it's actually started building...
 
Level 12
Joined
Nov 3, 2013
Messages
989
Yes, human build ability and it only has to detect the initiation.

It's being placed by a dummy unit and then workers with human repair will complete the building.

I were simply going to have the unit variable for the dummy unit switch to the building after it's placed. (note that there's going to be several dummy units placing down buildings at times and it could affect the order in which the buildings are placed)
 

Zwiebelchen

Hosted Project GR
Level 35
Joined
Sep 17, 2009
Messages
7,236
You can always just track the orders of all workers to code this event response by yourself.
The build order stores the worker issued via GetTriggerUnit. So you can basicly store every worker that receives the build order in an array indexed by the rawcode of the structure built, then retrieve the worker that builds the structure manually by reading the array. This will get problems as soon as two workers build the same type of building at the same time, though.
But you can always do a range check between the arrayed workers and the building to find out the correct worker.
 
Level 12
Joined
Nov 3, 2013
Messages
989
You can always just track the orders of all workers to code this event response by yourself.
The build order stores the worker issued via GetTriggerUnit. So you can basicly store every worker that receives the build order in an array indexed by the rawcode of the structure built, then retrieve the worker that builds the structure manually by reading the array. This will get problems as soon as two workers build the same type of building at the same time, though.
But you can always do a range check between the arrayed workers and the building to find out the correct worker.

I don't have any experience with making event responses :c

Until the other day when I realised I couldn't make inner loops if I just used custom scripts in GUI I'd never done anything full jass actually...

Like you said with checking if the unit's in range, that's basically what I were thinking as well.

I thought I'd pick units in range of the building and if GroupEnumUnit == dummy unit[index]

If I could make an actual event for it instead that would be much more preferred though.

PS. I had something like this in mind but I'm not familiar with how to make different functions use each other's variables
JASS:
function Trig_buildSys_build_Func001A takes nothing returns nothing
    loop
        if udg_buildSys_unit_dummy[index] == GetEnumUnit() then
            set udg_buildSys_unit_dummy[index] = u
            loop
                exitwhen i > 2
                call IssueTargetOrderById( udg_buildSys_unit[index * 3 + i], 'Ahrp', udg_buildSys_unit_dummy[index] )
                set i = i + 1
            endloop
            exitwhen true
        endif
        exitwhen index == udg_buildSys_indexMax
        set index = index + 1
    endloop
endfunction

function Trig_buildSys_build_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local real x = GetUnitX(u)
    local real y = GetUnitY(u)
    local location xy = Location( x, y )
    local player p = GetTriggerPlayer()
    local integer index = 0
    local integer i = 0
    call DisplayTextToForce( GetPlayersAll(), R2S(x) + R2S(y) )
    call DisplayTextToForce( GetPlayersAll(), GetUnitName(u) )
    call bj_wantDestroyGroup = true
    call ForGroupBJ( GetUnitsInRangeOfLocAll(128, xy ), function Trig_buildSys_build_Func001A )
endfunction

//===========================================================================
function InitTrig_buildSys_build takes nothing returns nothing
    set gg_trg_buildSys_build = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_buildSys_build, EVENT_PLAYER_UNIT_CONSTRUCT_START )
    call TriggerAddAction( gg_trg_buildSys_build, function Trig_buildSys_build_Actions )
endfunction
 
Level 6
Joined
Mar 17, 2012
Messages
105
I know this is an old thread, but I'm just posting a simpler solution for anyone curious in the future.

  • Crop Speed Bonus
    • Events
      • Unit - A unit Begins casting an ability
    • Conditions
      • (Ability being cast) Equal to Repair (Human)
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Unit-type of (Casting unit)) Equal to |cff00ffffExpansionist|r Farmer
          • (Unit-type of (Target unit of ability being cast)) Equal to Wild Crop
        • Then - Actions
          • Unit - Set (Target unit of ability being cast) construction progress to 90%
        • Else - Actions
          • Do nothing
Disregard the If/Then/Else part, that's specific for my game. The important part is the event and the condition. This trigger just checks for the use of the Repair ability (which is used every time a structure is constructed) and then you can affect the builder by referring to him as the (Casting unit), and the structure as the (Target unit of ability being cast).
 
Status
Not open for further replies.
Top