• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

Detect Next/Current Order

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,584
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,584
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:
  • Actions
    • Set Variable MyBuilding = (The building unit)
    • Custom script: call CancelTrainingFront( udg_MyBuilding )
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.
 
Last edited:

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,584
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:

TimerUtils: www.wc3c.net/showthread.php?t=101322
Table: www.hiveworkshop.com/forums/jass-resources-412/snippet-new-table-188084/

Those might be some outdated links.

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.
 
Level 7
Joined
Sep 4, 2016
Messages
116
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
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,584
Why not just create a script used for it exclusively? Libraries also run their code before "everything" else.

I imagine the demo map has a folder you can copy with everything setup already. Shouldn't be much harder than copying and pasting that.
 
Top