Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
Simple question: Is there a way to detect a units next order or queued orders?
For context, I'm trying to detect training commands on a building training heroes.
Info: The system provides information about objects being trained. It also allows you to loop through the current training queue, and saves the amount object types that were entirely trained by a unit. Now it also provides funtion to get remaining time of a unit being trained. Credits: Bribe...
A complex solution, but a solution nonetheless. Appreciated.
In hopes of potentially acquiring a simpler solution to my problem, is there a way to detect the order a unit is currently carrying out?
Yes, it's a function called Current Order which returns a String:
Conditions
(Current order of (Triggering unit)) Equal to (Order(stop))
Also, TrainingDetection is pretty simple to use:
vJASS:
GetCurrentTrainedObjectId takes unit whichbuilding returns integer
GetLastTrainedObjectId takes unit whichbuilding returns integer
GetBuildTimeRemaining takes unit whichbuilding returns real
// It will return the remaining time for a unit being trained.
// Sadly the native only works for normal units, not for heroes.
// For anything but a normal unit it will return 0.
// The slot number might not be identical with the true position in order-queue.
// Only the size number is identical. But the true slot positon might change.
// With knowing the size you might loop through the queue each get each element.
GetTrainingQueueSize takes unit whichbuilding returns integer
GetTrainedObjectId takes unit whichbuilding, integer whichslot returns integer
ReOrderTrainingQueue takes unit building returns nothing
// ReOrder will internally stop and start trainings to simulate cancel at front,
// be aware of that. After cleaning the queue, all units will have correct position in queue.
// (works with GetCleanTrainingQueue, see later)
CancelTrainingBack takes unit building returns nothing
// Back works same as using order native with CANCEL-id
CancelTrainingFront takes unit building returns nothing
// Front will internally stop and start trainings to simulate cancel at front, be aware of that.
CountFinishedUnits takes unit whichbuilding returns integer
CountFinishedTechs takes unit whichbuilding returns integer
CountFinishedUpgrades takes unit whichbuilding returns integer
GetCleanTraningQueue takes unit building, boolean keepFirst returns nothing
// After calling it the building will have all traingings canceled.
// set keepFirst "true" to avoid cancelling the first unit being trained.
Those are all of the functions that you would use. The first text you see in all white is the function name (GetCurrentTrainedObjectId), the next line after that which says "takes" tells you what variables you need to put into the (parenthesis) of said function. The greyed out text in front of the double slashes // is literally a comment from the author of this code. It's no different than the Comment action that we often use in the Trigger Editor to leave ourselves notes. After "takes" you can see "returns" which tells you what variable type gets returned back to you (if any) after the function is finished running, which you could then store in a variable of the same variable type. For example, GetTrainingQueueSize returns the number of units being trained, which is an Integer value. So you could store that in an Integer variable like so:
Actions
Set Variable MyBuilding = (The building unit)
Custom script: set udg_MyInteger = GetTrainingQueueSize( udg_MyBuilding )
MyInteger is an Integer variable that you would create in the Variable Editor. You can reference it like any other Integer variable after setting it's value in the Custom Script.
Here's another example, let's say that we wanted to tell our building to cancel the first unit being trained:
This orders the building to cancel the first unit being trained (the one in the front of the training queue).
This system could probably solve your problem in a couple of Actions. All it takes is basic knowledge of how functions work in Jass, which is pretty easy to learn, especially with how many tutorials are on Hive.
I appreciate the explanation. I am used to C++, but not JASS. I don't imagine any function names will be the same, but should I be worried about how this might interact with other custom script code I have for the map?
The code is inside of a Library, which as far as I understand will prevent naming conflicts as any code inside of a library is given a unique prefix. However, the system also requires two other systems:
You'll likely run into issues if you have imported these systems already. However, that's not too difficult to fix, just don't import what you already have. The only other issue I can imagine would be version related, where you have an old outdated version or maybe a newer version of one of more of these systems that uses different syntax.
I tried to implement it at the end of the code I have, and I get a series of compile errors, starting with several "Expected end of line" errors, starting at the line before the library starts. I thought it might be the comment I added, and made some adjustments, but it doesn't seem to work.
Code:
//... previous code
endfunction
// == == == == == == == == == == == == == == == == == == == ==
// Other Custom Scripts
//
library TrainingDetection initializer Init/* v3.1a -- www.hiveworkshop.com/threads/trainingdetection.248978/
Information
The system provides information about objects being trained.
It also allows you to loop through the current training queue,
and saves the amount object types that were entirely trained by a unit.
Objects are: Units, Researches/Techs, Upgrades
*/ requires /*
// ... code continues
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.