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. Don’t forget to sign up for the Hive Cup. There’s a 555 EUR prize pool. Sign up now!
    Dismiss Notice
  4. The Hive Workshop Cup contest results have been announced! See the maps that'll be featured in the Hive Workshop Cup tournament!
    Dismiss Notice
  5. Units have been turned into heroes in our latest Icon Contest! Vote for the best icon set at the Icon Contest #18 Poll!
    Dismiss Notice
  6. The poll for Hive's 12th Concept Art Contest is up! Go cast your vote for your favourite genie!
    Dismiss Notice
  7. The raddest synthwave tracks were chosen - Check out our Music Contest #12 - Results and congratulate the winners!
    Dismiss Notice
  8. 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.

The Theory Behind Spellbooks

Discussion in 'General Mapping Tutorials' started by Xonok, Jan 12, 2013.

  1. Xonok

    Xonok

    Joined:
    Mar 27, 2012
    Messages:
    3,042
    Resources:
    8
    Spells:
    3
    Tutorials:
    5
    Resources:
    8
    An in-depth explanation on spellbooks

    This is everything that I know about them.

    Table of Contents:
    • Introduction
    • Definition
    • How spellbooks work
    • Bugs
    • TheHelper about spellbooks(and what's wrong)
    • Facts
    • Wrong
    • Links


    Introduction

    The first tutorial about spellbooks I ever saw was the one in thehelper. However, it made me question a few things that andrewgosu assumed.
    Due to that I constantly kept thinking about spellbooks for half a year.
    Eventually I realized what was wrong. This is included here.
    However, I didn't really think of publishing anything, since I thought that people can figure those things out themselves.

    Time went on and on. People constantly asked the same questions and often got the same(wrong) answers. This has been annoying to me.
    So now I have decided to end the peoples' ignorance.

    Note that this tutorial is not meant to teach you how to do everything with them, but only the mechanics behind them. Thus, I will not show every way of using them here, only tell. If I showed everything this tutorial would become very long.

    Definition


    Basic: Spellbook is an ability that allows a unit to replace the abilities in its command card.

    How spellbooks work

    When a unit gets a spellbook then the abilities are added, as long as another spellbook with the same ID hasn't added them already. .
    When the spellbook gets removed, then the game checks if the spellbook contains a certain ability. If yes, then the ability will be removed.

    Bugs

    The "collision" bug:
    When you "open" a spellbook, then the spellbook ability itself is not checked. What is checked is its base order ID. That means that if you use multiple spellbooks with the same base order ID, then they share abilities.

    The morphing bug:
    When a unit with a spellbook morphs(bear form, chaos, chemical rage) to a unit that has the same abilities, then those abilities are not transferred(why add an ability that the unit already has?). That's because spellbooks weren't originally implemented in warcraft and thus the game doesn't check for abilities "in" the spellbook. I say "in" because spellbooks do NOT actually contain the abilities.
    How to counter this bug?
    You simply make another spellbook with the exact same abilities, name, limits, etc. The only thing different is that it is just a separate ability.

    The spellbook disable bug
    When you disable a spellbook, like this:
    • Player - Disable Spell Book for Player 1 (Red)

    Then the game plays a trick on you.
    Since spellbooks don't really contain the abilities(they are added separately), then any abilities inside the spellbook are still on the unit.
    HOWEVER, since the spellbook hides all abilities "in" it, then you won't see them before you "open" the spellbook. That means that you can have passive abilities without an icon. In theory it also allows to cast hidden actives with triggers.
    • Unit - Order (Triggering unit) to Human Sorceress - Slow (Target unit of ability being cast)

    ALSO, combined with the spellbook disable and "collision" bug it allows for more.
    Since disabling abilities doesn't remove them(only hides and turns off), then you can use disabled spellbooks to add abilities to other spellbooks.

    The Spellbook close... thing:
    When your unit has a spellbook opened and you add another spellbook with the same ID, then the spellbook closes.
    Possible use: Forcefully closing spellbooks.

    The spellbook inventory bug:
    Imagine a hero unit with usual hero inventory. This unit has 6 item slots.
    What if you would add a spellbook with another(or the same) inventory ability?
    Well, the answer is: You get 6 more slots.
    The slots added this way work like sheets. Each ability has a separate sheet of slots - you can't make 6 slots by adding 2 abilities of 3 slots each.
    This bug can be used to create systems for extended inventory, where each item still works as normal, except that unseen items can't be used.
    However, the downside is that taking away items from secret slots doesn't remove them from the hero, so they can't be picked up and they still give the stat bonuses to the hero.
    Solution: Delete the item and create a new one.

    Ability slot bug:
    When multiple abilities are added to the same slot in a spellbook, then their positions change. This also applies to simply adding abilities to units.
    However, with spellbooks there is the distinct difference, that when usually you can just change the ability position in object editor, then in a spellbook you can not.
    Furthermore, the position changes apply to that ability in all spellbooks, not just that one.
    The way to fix it is here.
    Explanation(might be wrong)
    Abilities in a spellbook are always added from left to right and from up to down. The object editor positions do not matter. Furthermore, since spellbooks on a unit are actually stored through the base order ID and not the rawcode of the spellbook, then shared spellbooks also collide here.
    For instance, if you add the first spellbook that has 3 abilities, then the abilities are put in slots 0-2.
    When you now add another spellbook, with another 3 abilities, then it will once again try to put them in slots 0-2, but the positions collide, which creates havoc.


    ----------

    TheHelper about spellbooks

    ------
    TheHelper
    ------
    My explanation

    http://www.thehelper.net/threads/how-to-make-spellbooks.27637/
    This is the only other tutorial about spellbooks that I know of. It is wrong in a few things.
    Pasted:
    ------
    WHY DO MY SPELLS DISAPPEAR FROM THE SPELLBOOK AFTER TRANSFORMATION/METAMORPHISM ETC.

    This is because the abilities inside the spellbook are not permanent; they are gained via a spellbook.

    To fix this issue, you must make the ability permanent. The only way is to use a piece of custom script because the action is not accessible via GUI:

    Code (vJASS):
    call UnitMakeAbilityPermanent(whichUnit, true, abilCode)

    Replace whichUnit with the unit who has the ability and abilCode with the raw code of the ability.
    ------
    This assumes that the game re-adds abilities each time that a unit morphs. This is not true, because a specific unit's abilities are tied to the unit instance, which does not change upon morphing.
    So, the MakeAbilityPermanent function is actually fighting the consequences, not the cause. What you really should do is making a copy of the spellbook for the morphed unit.
    ------
    HOW TO CAST SPELLS INSIDE A SPELLBOOK WITH TRIGGERS

    There is no way to do that because there is no way to open the spellbook with triggers.
    ------
    That is not true, because spellbooks are never really opened. They are an ability that shows/hides abilities.
    That's also why you can't open it. But you can(probably) order the unit to use the spellbook ability.
    Casting spells inside a spellbook IS possible, but you simply won't know if they are in it.
    EXAMPLE:
    • Unit - Order (Triggering unit) to Human Sorceress - Slow (Target unit ofability being cast)


    EDIT: I've now got new information, thanks to envenger, Derdan and this thread:http://www.hiveworkshop.com/forums/world-editor-help-zone-98/prevent-spell-book-closing-236871/
    It turns out, that if you assign a hotkey to the spellbook and then order the player to press that key, like this:
    • Game - Force Player 1 (Red) to press the key A

    Then the spellbook actually is opened.
    Note that you should still make sure that player has this unit selected, and no other, to prevent unwanted effects.
    Other way
    With a little thinking I came to the conclusion that it's also possible to close all spellbooks, with 2 simple actions.
    • Selection - Clear selection for Player 1 (Red)
    • Selection - Select (Triggering unit) for Player 1 (Red)

    However, it should still be noted that this way requires you to use a wait, which can complicate the trigger a lot in some cases.


    ----------

    Facts
    *All abilities in a spellbook are contained in an array.
    *When a spellbook is added to a unit the game checks for any abilities under the spellbook's base order ID, NOT rawcode. that's why spellbooks "collide".
    *All abilities added by spellbooks are tagged. The tag tells which spellbook the ability belongs to. However, it only remembers the order ID, not the rawcode of the spellbook.
    *Spellbook abilities are stored in a separate list that is associated with the ability rawcode.
    *A spellbook can contain from 0-12 abilities. If the minimum is set lower than maximum and there are not enough slots for all abilities, then the abilities inside the spellbook are random. You can counter this by setting both minimum and maximum to 11.
    *Even hero skills can be added to spellbooks and it will still be possible to level them like normally. However, they start at level 1.
    *If a spellbook contains more than 11 abilities, then the cancel button might get pushed off the command card.
    *Abilities in spellbooks don't fully collide with abilities in other spellbooks, even when the order IDs are the same. This means that you can have multiples of the same castable ability on the same unit, without any major bugs. Explanation

    Wrong
    has been claimed, but proven false.
    *When a spellbook is removed, then the game removes all other spellbooks that have the same ID. Proof

    Links
    http://www.hiveworkshop.com/forums/trigger-gui-editor-tutorials-279/mysteries-spellbook-33039/
    http://www.clancbs.com/downloads_seperate.php?id=348
    http://www.wc3c.net/showthread.php?t=80186
    http://www.hiveworkshop.com/forums/general-mapping-tutorials-278/set-spell-ui-position-spellbook-240242/

    If you know anything more about them, then please tell.
    Also, if you want help on using them, then just ask. I am sure that I can show how to do quite about anything.
     
    Last edited: Jul 1, 2014
  2. Almia

    Almia

    Joined:
    Apr 24, 2012
    Messages:
    4,861
    Resources:
    35
    Spells:
    30
    Tutorials:
    4
    JASS:
    1
    Resources:
    35
    Can you add some.............err............colors.To make it attractive.
     
  3. Xonok

    Xonok

    Joined:
    Mar 27, 2012
    Messages:
    3,042
    Resources:
    8
    Spells:
    3
    Tutorials:
    5
    Resources:
    8
    Where exactly would you propose I add them?
     
  4. edo494

    edo494

    Joined:
    Apr 16, 2012
    Messages:
    3,855
    Resources:
    5
    Spells:
    1
    JASS:
    4
    Resources:
    5
    make the section names a lot bigger, so they are more visible, maybe color them a little bit
     
  5. Xonok

    Xonok

    Joined:
    Mar 27, 2012
    Messages:
    3,042
    Resources:
    8
    Spells:
    3
    Tutorials:
    5
    Resources:
    8
    Done...
    ... and I've also made it a bit more colorful.
     
  6. Almia

    Almia

    Joined:
    Apr 24, 2012
    Messages:
    4,861
    Resources:
    35
    Spells:
    30
    Tutorials:
    4
    JASS:
    1
    Resources:
    35
    Now,it looks good.Okay + rep
     
  7. PurgeandFire

    PurgeandFire

    Code Moderator

    Joined:
    Nov 11, 2006
    Messages:
    7,427
    Resources:
    18
    Icons:
    1
    Spells:
    4
    Tutorials:
    9
    JASS:
    4
    Resources:
    18
    Great study. I don't like the centered text (it is a bit difficult to read), but that is personal preference.

    It seems to be solid information though, and I remember testing a couple of your claims a while back (with success). Approved.
     
  8. Xonok

    Xonok

    Joined:
    Mar 27, 2012
    Messages:
    3,042
    Resources:
    8
    Spells:
    3
    Tutorials:
    5
    Resources:
    8
    If more people dislike the centered text, then I can change it. Also looked over the whole thing again and fixed some minor typos.
     
  9. deathismyfriend

    deathismyfriend

    Joined:
    Oct 24, 2012
    Messages:
    6,532
    Resources:
    14
    Spells:
    12
    Tutorials:
    2
    Resources:
    14
    its odd with everything being centered but i dont mind it.
     
  10. Xonok

    Xonok

    Joined:
    Mar 27, 2012
    Messages:
    3,042
    Resources:
    8
    Spells:
    3
    Tutorials:
    5
    Resources:
    8
  11. noob

    noob

    Joined:
    Sep 28, 2011
    Messages:
    685
    Resources:
    0
    Resources:
    0
    An spell book property(works weird) is that if you have A B and C (all spell books with the same order id) and that you give to each of them an variation of summon tentacle(for example but it can works in an buggy way if it is an ability who check again unit abilities again after being cast by doing thing like if all abilities were on the unit out of an spell book for choosing the effect) Then you can see in any of those the three summon which is normal but then when you click one of them it cast this ability(not the usual comportment abilities of the same kind have outside of the spell books) because it thinks "hey the user wants to use this ability who is alone in an spell book so he surely wants this one" because he looks only in spell book the spell belongs initially and considers all others are disabled but then the ui knows the truth and highlight all the abilities of the same kind but if the ability does something who makes him check again the unit abilities he can decide to have the effect it would have if all abilities were outside of the spell book (happens with build tiny tower who checks again when the unit goes to his destination and then act like if he was not fooled even if he displayed the building you selected he builds the one of the ability who have priority)
    Here is an attachment who shows how it works with inferno
     

    Attached Files:

    • dfg0.w3x
      File size:
      12.5 KB
      Views:
      134
    Last edited: Jul 10, 2014
  12. Xonok

    Xonok

    Joined:
    Mar 27, 2012
    Messages:
    3,042
    Resources:
    8
    Spells:
    3
    Tutorials:
    5
    Resources:
    8
    Tried out the testmap. Conclusions:

    1. If the abilities are in different hidden spellbooks, then casting them through one that is shown will not have the usual bug of a random one being cast.
    2. Doing it this way causes a visual bug that makes it look like a different ability than you casted is still active.
     
  13. noob

    noob

    Joined:
    Sep 28, 2011
    Messages:
    685
    Resources:
    0
    Resources:
    0
    At the same time indicate it can works weirdly if you use some abilities like build tiny tower.(the trick will work half only as it will seems like if you casted the one you selected until you click where you want to put the building then it will create the building he likes the most and not the one he shown you)
    Tiny tower bug is an important example of bug as it prevents you to make an advanced build ability like many users would want to do with this trick.
    example map of when the trick screw up.
     

    Attached Files:

    • dfg.w3x
      File size:
      12.5 KB
      Views:
      125
  14. Xonok

    Xonok

    Joined:
    Mar 27, 2012
    Messages:
    3,042
    Resources:
    8
    Spells:
    3
    Tutorials:
    5
    Resources:
    8
    So the trick only works properly with some abilities.
     
  15. Xonok

    Xonok

    Joined:
    Mar 27, 2012
    Messages:
    3,042
    Resources:
    8
    Spells:
    3
    Tutorials:
    5
    Resources:
    8
    Today I came across a few things that make me question previous beliefs.
    The attached map proves that removing a spellbook doesn't remove all others with the same ID.
     

    Attached Files:

  16. noob

    noob

    Joined:
    Sep 28, 2011
    Messages:
    685
    Resources:
    0
    Resources:
    0
    Update the table of contents it does not refers to the wrong section.
     
  17. Xonok

    Xonok

    Joined:
    Mar 27, 2012
    Messages:
    3,042
    Resources:
    8
    Spells:
    3
    Tutorials:
    5
    Resources:
    8
    Good point. Done.
     
  18. Kyrbi0

    Kyrbi0

    Joined:
    Jul 29, 2008
    Messages:
    7,880
    Resources:
    1
    Models:
    1
    Resources:
    1
    This needs more publicity.
     
  19. Xonok

    Xonok

    Joined:
    Mar 27, 2012
    Messages:
    3,042
    Resources:
    8
    Spells:
    3
    Tutorials:
    5
    Resources:
    8
    You are welcome to refer to it.
     
  20. DracoL1ch

    DracoL1ch

    Joined:
    Dec 12, 2010
    Messages:
    1,758
    Resources:
    2
    Tutorials:
    2
    Resources:
    2
    you can as well make abilities inside spellbook permanent so they won't disappear at morphing