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

The Theory Behind Spellbooks

Level 21
Joined
Mar 27, 2012
Messages
3,232
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.
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:

JASS:
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.
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:
Level 21
Joined
Mar 27, 2012
Messages
3,232
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.

If more people dislike the centered text, then I can change it. Also looked over the whole thing again and fixed some minor typos.
 
Level 14
Joined
Sep 28, 2011
Messages
968
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
 

Attachments

  • dfg0.w3x
    12.5 KB · Views: 201
Last edited:
Level 21
Joined
Mar 27, 2012
Messages
3,232
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.
 
Level 14
Joined
Sep 28, 2011
Messages
968
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.
 

Attachments

  • dfg.w3x
    12.5 KB · Views: 184
Level 21
Joined
Mar 27, 2012
Messages
3,232
I have mentioned how to do that in the section where I comment about the tutorial on TheHelper.
In short, unless you add abilities during the game you don't need to make them permanent. Instead just make a copy of your spellbook ability for the alternate form.
 
Level 3
Joined
Aug 11, 2012
Messages
52
Now, I want to use a spellbook to level up attributes. When heroes level up, they gain 5 skill points they can invest in attributes of their choosing. With the max level of 100, they'd gain 503 (with the first level granting 3 points) skill points for their attributes. I want to do it this way to avoid the level 500 (In case they want to dump all points into STR or something fun like that) of each add attribute skill. Would spellbooks be a way to remedy this?
 
Level 21
Joined
Mar 27, 2012
Messages
3,232
I think it belongs in a separate thread. Anyways, I don't see how spellbooks can fix this. You'd still need the same amount of abilities no matter the method, because spellbooks can only be added once afaik.
What would fix it is adding stats in a way that doesn't require the ability itself to level up.
E.g, make a dummy ability that can be cast, but doesn't do anything on its own(based on channel, for instance). When that ability is cast you check the amount of remaining skillpoints and add the stat with this action:
  • Untitled Trigger 001
    • Events
    • Conditions
    • Actions
      • Hero - Modify Strength of (Last created unit): Add 10
 
Level 3
Joined
Aug 11, 2012
Messages
52
I think it belongs in a separate thread.

If I knew spellbooks were not the way to go, I'd have made my own thread. Sorry about that!

What would fix it is adding stats in a way that doesn't require the ability itself to level up.

Would I have to "delevel" the ability to restore it in the abilities button? I've got the dummy ability to grant the point when the ability is leveled. The trigger fires when they level it up, then it will grant the corresponding point then delevel the ability. Sound good?
 
Level 3
Joined
Aug 11, 2012
Messages
52
Have you ever played The Black Road? I'm trying to create a stat system much like that. Where players determine where their points go and not the game.
 
Top