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 poll for Hive's 12th Concept Art Contest is up! Go cast your vote for your favourite genie!
    Dismiss Notice
  4. Travel to distant realms and encounter scenes unknown to the common folk. The Greatest of Adventures is upon us with the 8th Cinematic Contest. Join in on a fun ride.
    Dismiss Notice
  5. The 18th Icon Contest is ON! Choose any ingame unit and give him/her Hero abilities. Good luck to all.
    Dismiss Notice
  6. Contestants are to create a scene set in the Stone Age. Come and see what you can come up with. We wish you the best of luck!
    Dismiss Notice
  7. Colour outside the lines! Techtree Contest #13 is a go. The contest is optionally paired.
    Dismiss Notice
  8. Greetings cerebrates, our Swarm needs new spawners that will have numerous children. Join the HIVE's 31st Modeling Contest - Spawners and Spawned! The contest is optionally paired.
    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.

[Trigger] Autoclosing spellbook abilities when they cast

Discussion in 'Triggers & Scripts' started by darwin, Jan 17, 2018.

  1. darwin

    darwin

    Joined:
    Aug 30, 2004
    Messages:
    893
    Resources:
    2
    Maps:
    2
    Resources:
    2
    My heroes have a spellbook Hero ability that lets them cast multiple spells. When they cast these spells, I want to automatically close the book so they can see their regular spells and move, patrol, stop, hold position, and so on.

    Originally I did this:

    • Spell Book Fix
      • Events
        • Unit - A unit owned by Player 7 (Green) Begins channeling an ability
      • Conditions
        • Or - Any (Conditions) are true
          • Conditions
            • (Ability being cast) Equal to Borean's Grace tranquility
            • (Ability being cast) Equal to Consume Fires
            • (Ability being cast) Equal to Consume Fire 2
            • (Ability being cast) Equal to Crushing Wave channel
            • (Ability being cast) Equal to Earthen Sanctuary Inferno (Neutral Hostile)
            • (Ability being cast) Equal to Earthen Sanctuary Inferno (Neutral Hostile) 2
            • (Ability being cast) Equal to Quake impale
            • (Ability being cast) Equal to Fire Shield
            • (Ability being cast) Equal to Fire Shield 2
            • (Ability being cast) Equal to Gail of Wind rocket effect = 1
            • (Ability being cast) Equal to Hurricane
            • (Ability being cast) Equal to Kiss of the Witch fan of knives
            • (Ability being cast) Equal to Lightning Rune
            • (Ability being cast) Equal to Lamune's Dazzling Scouts
            • (Ability being cast) Equal to Magnetic Rock (Neutral Hostile)
            • (Ability being cast) Equal to Magnetic Rock (Neutral Hostile) 2
            • (Ability being cast) Equal to Mists of Obscurement (aqua)
            • (Ability being cast) Equal to Pyroclasm acid bomb 1
            • (Ability being cast) Equal to Pyroclasm acid bomb 2
            • (Ability being cast) Equal to Pyromantic Siege (Neutral Hostile 2)
            • (Ability being cast) Equal to Sandstorm
            • (Ability being cast) Equal to Sandstorm (snow)
            • (Ability being cast) Equal to Smoke Screen channel
            • (Ability being cast) Equal to Spirit Link Mirin Meld
            • (Ability being cast) Equal to Touch of the Witch Roar(Morph)
            • (Ability being cast) Equal to Twister Gate (Neutral Hostile)
            • (Ability being cast) Equal to Water Barrier (more powerful)
      • Actions
        • Game - Force Player 7 (Green) to press Escape/Cancel


    It worked surprisingly well, except if the player cast one of those spells at a great distance and then selected another unit, at which point the trigger would make them press ESC causing other problems.

    I recalled that there is an order you can give to a unit to make them open a spellbook. I used it in my Battle for Tatooine map. Does anyone know if there is a custom order I can give to CLOSE a spellbook? I'm looking for something like this:

    • Custom script: call IssueImmediateOrderById (udg_triggeringUnit, 852608)
     
  2. _Guhun_

    _Guhun_

    Joined:
    Jun 12, 2010
    Messages:
    339
    Resources:
    7
    Spells:
    6
    Tutorials:
    1
    Resources:
    7
    I think the easiest fix would be to enumerate the units selected by the player. If the casting unit is not selected, then don't press Esc. That can still lead to some unwanted situations if the player has multiple units selected, though. You can check if the unit is the only one selected, but that will make it so the spellbook isn't closed even if it the highlighted unit in the player's selection.

    Another possible solution would be: Detect the order of the ability, instead of when the unit starts casting it. This way, even if the unit casts the ability far away, Esc is instantly pressed. Though I'm not sure this can work with abilities based off of item abilities.
     
  3. darwin

    darwin

    Joined:
    Aug 30, 2004
    Messages:
    893
    Resources:
    2
    Maps:
    2
    Resources:
    2
    I can try that second one; but I would have thought this was possible with just an order. There is a "Cancel" button there... and if there's an order to open a spellbook, why not one to close it?

    There is another problem with the ESC key as well which is that it doesn't work if the player is holding down ALT to see unit life bars.

    I tried adding and removing the spellbook ability, but that seems to cancel the spell before it takes place; and it removes cooldowns.
     
  4. _Guhun_

    _Guhun_

    Joined:
    Jun 12, 2010
    Messages:
    339
    Resources:
    7
    Spells:
    6
    Tutorials:
    1
    Resources:
    7
    I tried catching an order event for opening/closing a spellbook, but it doesn't return anything.

    • Untitled Trigger 001
      • Events
        • Unit - A unit Is issued an order with no target
        • Unit - A unit Is issued an order targeting a point
        • Unit - A unit Is issued an order targeting an object
      • Conditions
      • Actions
        • Game - Display to (All players) the text: (String((Issued order)))
        • Custom script: call BJDebugMsg(I2S(GetIssuedOrderId()))


    So I'm not sure how people figured out that custom order to open a spellbook, but it seems like it requires more extensive testing (maybe brute force?).

    I can't think of an alternative to pressing Esc right now, I know that unselecting and then selecting the unit again won't work.
     
  5. darwin

    darwin

    Joined:
    Aug 30, 2004
    Messages:
    893
    Resources:
    2
    Maps:
    2
    Resources:
    2
    That's funny; I literally just wrote out that trigger you pasted and was about to test for the order myself.

    On older post suggested this for cancelling a building, but it hasn't worked yet:

    • Custom script: call IssueImmediateOrderById (udg_triggeringUnit, 851976)


    I could just leave it so the player has to manually press ESC to get back to their main spells, but it is annoying. The ESC trigger (particularly with your detect whether the unit is selected trigger) might still be the best unless anyone else has an idea.
     
  6. Tasyen

    Tasyen

    Joined:
    Jul 18, 2010
    Messages:
    1,253
    Resources:
    16
    Tools:
    2
    Maps:
    2
    Spells:
    7
    Tutorials:
    4
    JASS:
    1
    Resources:
    16
    Some other Idea to close the book would be to add & Remove an empty Spellbook skill on spellcasting.
     
  7. BloodSoul

    BloodSoul

    Joined:
    May 10, 2009
    Messages:
    736
    Resources:
    2
    Spells:
    2
    Resources:
    2
    Tasyen's idea is the easiest to do. It won't interfere with any other unit.
     
    Last edited: Jan 17, 2018
  8. _Guhun_

    _Guhun_

    Joined:
    Jun 12, 2010
    Messages:
    339
    Resources:
    7
    Spells:
    6
    Tutorials:
    1
    Resources:
    7
    Indeed, I just tested Tasyen's idea and it worked like a charm. You won't even have to change the events and conditions for your original trigger, just add an empty spell book then remove it.

    This will still make it so the spell book remains open when a unit is ordered to cast a spell out of range, but then you just have to change the event and conditions to apply to orders instead, if you don't want that behavior.
     
  9. darwin

    darwin

    Joined:
    Aug 30, 2004
    Messages:
    893
    Resources:
    2
    Maps:
    2
    Resources:
    2
    Beautiful guys! +rep all around