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

Check if building is currently researching an upgrade?

Status
Not open for further replies.
Hey.

Is there any way to check if a building is researching an upgrade? No, I'm not asking for these:
  • Events
    • Unit - A unit Begins research
    • Unit - A unit Cancels research
    • Unit - A unit Finishes research
I'm looking for something like this:
  • Condition - Is Unit Researching {Upgrade} == True
There's nothing like that condition in the editor. Only events can detect researches.
 
Level 39
Joined
Feb 27, 2007
Messages
5,010
No, you'd have to track this information yourself. Not particularly difficult with a hashtable.
  • Events
    • Time - Elapsed game time is 0.50 seconds
  • Conditions
  • Actions
    • Hashtable - Create a hashtable
    • Set TechHash = (Last created hashtable)
  • Events
    • Unit - A unit begins research
  • Conditions
  • Actions
    • Set Tech = (Researched tech type)
    • Custom script: set udg_TechInt = udg_Tech //necessary because GUI doesn't 'know' rawcodes are integers....
    • Hashtable - Save TechInt as 0 of Key(Triggering Unit) in TechHash
  • Events
    • Unit - A unit finishes research
    • Unit - A unit Cancels research
    • -------- if the cancel event isn't run when a unit dies you'll need this event too --------
  • Conditions
  • Actions
    • Hashtable - Clear all child hashtables of child Key(Triggering Unit) in TechHash
  • -------- to get the currently researching tech of a unit --------
  • Set TechInt = Load 0 of Key(THE UNIT) in TechHash
  • Custom script: set udg_Tech = udg_TechInt
  • If (All conditions are true) then do (then actions) else do (else actions)
    • If - Conditions
      • TechInt not equal to 0
    • Then - Actions
      • -------- unit is researching Tech --------
    • Else - Actions
      • -------- unit isn't researching anything --------
 
But I think the cancel event would fire if any research from training queue gets canceled, not only if it's the currently trained research.

  • You could try if new natives, to retrive for example a researche's tooltip would return an empty string for invalid research's id.
    OR
  • Researches start their rawcode usually with 'R'. You might check if currently trained object has 'R' in first place.
    To make it a bit easier we also could check if value is between 'R000' and 'S000', which I will do in the example below.

To get currently trained object id you can use TrainingDetection v3.1a.

To take usage of TrainingDetection, it could look like following. 2 variables needed:
  • Unit variable "Unit"
  • Boolean variable "IsResearching"
  • Set Unit = (< YourUnit >)
  • Custom script: set udg_IsResearching = ( IAbsBJ(GetCurrentTrainedObjectId(udg_Unit) - 'R000') < ( 'S000' - 'R000') )
The "IsResearching" boolean is true/false, respectively.
 
Forget my post above. The cancel might be at any position in queue, but I forgot that researches are unique, so you can't train multiple same researches at once.

Pyrogasm's "cancel/finish" trigger does only need an additinal check, which ensures that it's the same Research that cancels/finishes that was stored into hashtable at the "begins research" trigger, and not a random research from training queue.

The check can just be "(Load 0 of (Key (<UNIT>)) from TechHash) Not equal to 0".
 
Status
Not open for further replies.
Top