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

[Trigger] how do i order a unit to build something?

Status
Not open for further replies.
Level 8
Joined
Dec 1, 2010
Messages
316
how do i order a unit to build something? [SOLVED]

So ive started working on something (for personal use)
and am trying to make some quests.

so basicly what i'm trying to do is order some peasants owned by a computer
to build a townhall near a gold mine after ive killed some bandit leader near that gold mine.

so this is what i tried, and don't really know why it does not work or how i can solve this (keep in mind that i am a noob with triggers)
  • Events
    • Unit - Alchemist 0017 <gen> Dies
  • Actions
    • Unit - Order Peasant 0201 <gen> to build a Guard Tower at (Center of Region 003 <gen>)
    • Unit - Order Peasant 0202 <gen> to build a Guard Tower at (Center of Region 002 <gen>)
    • Unit - Order Peasant 0204 <gen> to build a Guard Tower at (Center of Region 005 <gen>)
    • Unit - Order Peasant 0203 <gen> to build a Guard Tower at (Center of Region 004 <gen>)
    • Unit - Order Peasant 0200 <gen> to build a Town Hall at (Center of Region 001 <gen>)
 
Last edited:
Level 24
Joined
Aug 1, 2013
Messages
4,657
Be aware that the resources of that player has to be able to support the construction.
Also building a town hall to close to a gold mine is not allowed because of the short time that peasants would have to walk.

Also, fix leaks.
Locations leak so you have to place the center of those regions in a variable and use "call RemoveLocation(udg_<variablename>)" in a custom script each time to remove it.
Example:
  • Actions
    • Set TempLocation[0] = (Center of Region 003 <gen>)
    • Unit - Order Peasant 0201 <gen> to build a Guard Tower at TempLocation[0]
    • Custom script: call RemoveLocation(udg_TempLocation[0])
    • -------- - --------
    • Set TempLocation[0] = (Center of Region 002 <gen>)
    • Unit - Order Peasant 0202 <gen> to build a Guard Tower at TempLocation[0]
    • Custom script: call RemoveLocation(udg_TempLocation[0])
    • -------- - --------
    • Set TempLocation[0] = (Center of Region 005 <gen>)
    • Unit - Order Peasant 0204 <gen> to build a Guard Tower at TempLocation[0]
    • Custom script: call RemoveLocation(udg_TempLocation[0])
    • -------- - --------
    • Set TempLocation[0] = (Center of Region 004 <gen>)
    • Unit - Order Peasant 0203 <gen> to build a Guard Tower at TempLocation[0]
    • Custom script: call RemoveLocation(udg_TempLocation[0])
    • -------- - --------
    • Set TempLocation[0] = (Center of Region 001 <gen>)
    • Unit - Order Peasant 0200 <gen> to build a Town Hall at TempLocation[0]
    • Custom script: call RemoveLocation(udg_TempLocation[0])
 
Level 8
Joined
Dec 1, 2010
Messages
316
i have never worked with custom scripts or variables so i don't really know how it works, but if i make the trigger exactly the way you just did will it work?

i am reading something about variables (not really understanding it that well) but what kind of variable should i make? and as for the custom script, do i have to download jass and write more then "call RemoveLocation(udg_<variablename>)?
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
Well, the actual post was about the first two lines :D
"Be aware that the resources of that player has to be able to support the construction.
Also building a town hall to close to a gold mine is not allowed because of the short time that peasants would have to walk."


But to answer your other question, no you dont have to download anything at all.
JASS is a code language that is used even by placing GUI actions in triggers.
GUI Triggers are simply an easy way to use JASS.
Variables are boxes with a name and a content.
The name of the box must be unique at all times.
The content of the box can be anything that is actually something.
Variables like an Integer (round number), Real (aka float) (number with possibility of decimals), Boolean (something like a switch, TRUE or FALSE), String (a piece of text) are very basic variables.
You can make almost everything out of those variables.
Other variables like, Unit (an actual unit in the game), Player (reference of a player (human or pc)), Sound (something that plays in-game), etc, etc, etc, etc, etc are variables that refer to something that is in-game.

To create variables in WC3, you press the hotkey [ctrl] + while being in the trigger editor.
Or you just click on this button:
wMugcXC.png


Variables are an easy way to store data (or something) that you want the game to remember.
Like remember the location the unit was when he did someting, or remember the owning player of a unit that died... or whatever.

Some variables are only used because they are more efficient or easier to use than a direct link to your object.
For example, I want to point to the player color of the owning player of the nearest living unit of the triggering unit that is facing the center of the map.
Then I can, everytime when I want to use it, recalculate who that unit is, but what better, easier, less action needing, is, is that I calculate it one time and place that unit in a variable, so everytime that I want that unit again, I can just look it up in my variable.

Variables that are only used to point to an object but not to remember things are called temporary variables (dunno actually if that is real but we use it :D).
I write my temporary variables like this: TempUnit, TempPlayer, TempLocation, TempSound, TempReal, TempInteger, TempBoolean, TempString, etc, etc, etc.
Every trigger can use these variables as long as they do not want to remember the contents of it.
For example, you dont want to remember the locations but you have to store them in a variable, so you use tempvariables.

Variables can also be a list of variables (of the same type).
These variables are an array.
Arrays in WC3 have a size of 8192.
So one Real Array is actually 8192 Real Variables.
In most coding languages, you can even make an array of arrays... of arrays of arrays of arrays, etc.
So you have a Real Array Array Array Array Array which (calculated in sizes of 8192 (even though the size of an array is much bigger than that)) gives you a total of 36,893,488,147,419,103,232 Real Variables... you can imagine the possibilities.
You can see that pointing to an array variable itself is not enough to get the content you want.
In this case, you also need an index that is used, because index 1, might very probably have a different content than index 2 of that same variable.
To point to an Array Variable, you do this: <variablename>[<indexnumber>]
Example:
TempReal[100], TempReal[1], TempReal[2], etc.
(Arrays start at index 0 and end in WC3 at index 8191.)

Variable types are pretty much 2 things:
1, a raw piece of data.
Pretty much Integer, Real, Boolean and String.
These variables have a specific value.
2, a pointer to an object instance.
An object is pretty much something out of the game.
An actual unit, player, ability, sound, race, etc, etc, etc.
In variable types, it is pretty much everything except those 4 other variable types.
Objects have multiple sets of data that belong to that object.
A location for example is made out of two reals (two coordinates) that lead to a location.

Objects however are created into the data storage that WC3 uses in your RAM.
And you only use it that one time, so you dont want to keep that data in there at all.
(It will be removed when WC3 closes the map but you want it to be removed immediately.)
To do that, you must use a function that is not able to be called in GUI.
This function is named "RemoveLocation". To call this function, you have to write "call RemoveLocation(<yourlocation>)" where <yourlocation> is the location you want to be removed from the memory.
Because GUI has no action that does it, you have to use a custom script to use this function.
Also because you want to remove the location that is used in your build order action, you have to store it in a variable because otherwise, you would create another new location which pretty much removes the point of calling this function. (tell me if you see that joke :D)

One more thing to have in mind is that GUI variables (created using the normal variable maker) have a prefix.
So when your variable is called "MyUnit", your actual variable's name is "udg_MyUnit".
So when you remove your location "MyLocation", you do "call RemoveLocation(udg_MyLocation)".

If anyone else can clear this out a bit more then feel free to do so.
 
Level 8
Joined
Dec 1, 2010
Messages
316
woa, thank you for explaining that, i have learned alot more about what variables are and what they do.
so i need to create a variable and set it in the actions pannel?
but what type of variable do i need to create in the wc3 variable editor?

i did not find out how i make a templocation variable.
do i have to write code to do so? or can i do it out of the wc3 variable editor?

so i'm inside the variable editor right now, what kind of stuff do i need to set here? in order to create a working temporary variable?
kec9bl.jpg


anyway thanks for all your help up to now, your really being helpfull to me :p
((EDIT: so i tried my best to make it the way you did, and started by only letting them make the townhall, just to test it i will add in a screenshot as it gave an error, i noticed i do not have the [0] after templocation, should i change that? anyway screen shot below is how it looks ))

2n9fasx.jpg
 
Level 8
Joined
Dec 1, 2010
Messages
316
Okay OMG this is awesome,
for the first time it did work!
however i think it doesnt work when i am standing on the place he wanted to build it so i'm going to try to add a reapeating to the command every 3 seconds.
Anyway HUGE thanks for all this help.
your getting rep :p
I must be honest to say that it took me a long time to really understand what you were saying, but in the end i did learn something from it wich is just awesome.
Man i'm freaking happy now,

and to awnser your question, i didnt see it as a joke, but somehow after reading that i did laugh about it lel

anyway i'm gonna give you some well deserved rep!
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
Uhm... yea sorry missed the part where you asked which types you needed :D
And Location (which is Point in GUI) is actually one of the hard ones to find because of it's different names.
In GUI, it is called "Point".

Also, you can edit posts instead of making new posts... it is kind of annoying and even against the site rules.
As you seem to know how to do it so we will just proceed.

The [0] part is when you tick the "array" checkbox when you create or edit a variable.
That will make the variable an array and will automatically create an index part whenever you use it in GUI.

However for now it is not necessary to have the variable as an array so it doesnt really matter... yet.
It is just something easy to have when you need multiple temp variables of the same type... instead of making a TempLocation1, TempLocation2, TempLocation3, etc, etc, etc, like I did before I knew arrays (which is spamming your variable box massively sometimes), you can create one single array TempLocation instead :D
But as I said, it doesnt really matter.

When I use the <> thingies, I mean that those including the text between it is a placeholder. (So it should be replaced by something fitting that is explained inside the tags.)
I dont really know what to use better though...

About the joke...
"because otherwise, you would create another new location which pretty much removes the point of calling this function. (tell me if you see that joke :D)"
It "removes" the "point" (aka location) of calling the "RemoveLocation()" function.



But to sum up the solutions again...
1, Make sure the player has enough resources.
2, Make sure that the buildings dont overlap. (Too close to each other.)
3, Make sure that the town hall is not too close to the gold mine.
I think that units wont really matter at this point as units will walk away from the construction site.
 
Level 8
Joined
Dec 1, 2010
Messages
316
Also, you can edit posts instead of making new posts... it is kind of annoying and even against the site rules.
As you seem to know how to do it so we will just proceed.


Ok i did not know this and i'll keep it in in mind.

However for now it is not necessary to have the variable as an array so it doesnt really matter... yet.
It is just something easy to have when you need multiple temp variables of the same type... instead of making a TempLocation1, TempLocation2, TempLocation3, etc, etc, etc, like I did before I knew arrays (which is spamming your variable box massively sometimes), you can create one single array TempLocation instead :D
But as I said, it doesnt really matter.


Thank you for telling me, would 'nt have figured this out by myself.

did get it working properly in game, and have already made some triggers i wouldnt have been able to make 2 days ago using variables (pretty much use them for everything now so ty again :D)

About the joke...

got it (i think)

Anyway, this can be closed now as the problem has been solved.
thanks again for your help.
 
Status
Not open for further replies.
Top