• 🏆 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!

[JASS] Remote Construction

Status
Not open for further replies.
Level 4
Joined
Nov 25, 2008
Messages
76
I have managed this partially but I'm stuck at one point. Here is how the system works: The user selects the castle and right clicks the location that they want to build after they have selected the building they wish to erect then an unselectable peasant appears and builds the wanted building at the targeted location. Only I have a problem here: if the location already contains a building (or anything else that blocks the construction) the trigger still fires. So the question is, how do I make my function check if the given location is buildable or not?

I'm writing the code below in case I couldn't explain it correctly. It probably sucks as I'm very new to this but please bear with me.

JASS:
//Builds the building specified at Building variable on the Target variable location
//Sets the building and target variables to empty after issuing the order
function StartConstruction takes nothing returns nothing
call IssueBuildOrderById(udg_Builder, udg_Building, GetLocationX(udg_Target), GetLocationY(udg_Target))
set udg_Builder_Busy = true
set udg_Target= null
set udg_Building= null
endfunction

//When the castle has been selected and issued a point order, check if there is an existing builder. 
//If there is no builder, create a peasent and designate him as the builder. Then start construction.
//Else, use the existing builder to start the construction.
//Done: If the builder is building something, do not start the construction of a new project.

function Trig_Test_Actions takes nothing returns nothing
    set udg_Target = GetOrderPointLoc()
    if udg_Builder == null then
    call CreateNUnitsAtLocFacingLocBJ( 1, 'hpea', Player(0), GetPlayerStartLocationLoc(Player(0)), udg_Target )
    set udg_Builder=GetLastCreatedUnit()
    call StartConstruction()
    elseif udg_Builder_Busy == false then
    call StartConstruction()
    else
    call DisplayTextToForce(GetPlayersAll(),"Your loyal subjects are busy at the construction site sire. Please wait until they are free.")
    endif
endfunction

//===========================================================================
function InitTrig_Construction takes nothing returns nothing
    set gg_trg_Construction = CreateTrigger(  )
    call TriggerRegisterUnitEvent( gg_trg_Construction, gg_unit_htow_0000, EVENT_UNIT_ISSUED_POINT_ORDER )
    call TriggerAddAction( gg_trg_Construction, function Trig_Test_Actions )
endfunction

Help is really appreciated as I'm dumbfounded on how to progress... +rep will also be given for anything constructive.
 
Level 21
Joined
Aug 21, 2005
Messages
3,699
Perhaps you can even simply add the buildings to the constructionlist of the castle itself, and then detect when a build order is given. e.g. the build order of a Farm is "farm" (or simply the raw data id of a farm, i.e. 'hhou' I think). So whenever the castle is ordered "farm", you know it's trying to construct a farm, but since a castle can't move that order is automatically canceled. Still, you can detect the order and thus can make a peasant build the farm.

Advantages:
- building transparent targetting image
- Need the gold/wood resources before you start building
- can't build on unbuildable ground

Disadvantages:
- only 11 buildings can be built (since a unit can only have 11 structures in the list)
 
Level 4
Joined
Nov 25, 2008
Messages
76
Good point, I haven't thought of that either. If the player does not have enough resources again it will fire the trigger. I tried to do what you said but the 11 buildings deal is too limited. So I made a spellbook that contains dummyspells that corresponds to each building that wish to be built and added that spellbook to the castle. It does check each ability's raw code to determine which structure to be built. Although having transparent image would be nice indeed.

Anyway thanks to Day-Elven I made a condition check which checks for units in range of a location and it works. But now I see I have to make another condition for checking the resources beforehand.

CrashLemon, I'm trying to stop the trigger from firing as there are variable changes once it does and if it changes them even though the action will not happen (construction of the building) then it will be for nothing. Although I can make a debug trigger like that.
 
Status
Not open for further replies.
Top