1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. The Lich King demands your service! We've reached the 19th edition of the Icon Contest. Come along and make some chilling servants for the one true king.
    Dismiss Notice
  4. The 4th SFX Contest has started. Be sure to participate and have a fun factor in it.
    Dismiss Notice
  5. The poll for the 21st Terraining Contest is LIVE. Be sure to check out the entries and vote for one.
    Dismiss Notice
  6. The results are out! Check them out.
    Dismiss Notice
  7. Don’t forget to sign up for the Hive Cup. There’s a 555 EUR prize pool. Sign up now!
    Dismiss Notice
  8. The Hive Workshop Cup contest results have been announced! See the maps that'll be featured in the Hive Workshop Cup tournament!
    Dismiss Notice
  9. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

Check if building is currently researching an upgrade?

Discussion in 'Triggers & Scripts' started by xYours Trulyx, Aug 30, 2019.

  1. xYours Trulyx

    xYours Trulyx

    Joined:
    Jan 9, 2016
    Messages:
    946
    Resources:
    0
    Resources:
    0
    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.
     
  2. Pyrogasm

    Pyrogasm

    Joined:
    Feb 27, 2007
    Messages:
    2,905
    Resources:
    1
    Spells:
    1
    Resources:
    1
    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 --------
     
  3. IcemanBo

    IcemanBo

    Joined:
    Sep 6, 2013
    Messages:
    6,179
    Resources:
    22
    Maps:
    3
    Spells:
    11
    Template:
    1
    Tutorials:
    4
    JASS:
    3
    Resources:
    22
    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.
     
  4. IcemanBo

    IcemanBo

    Joined:
    Sep 6, 2013
    Messages:
    6,179
    Resources:
    22
    Maps:
    3
    Spells:
    11
    Template:
    1
    Tutorials:
    4
    JASS:
    3
    Resources:
    22
    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".