home » builders » builder's lessons » quest bits tutorial
Quest bits tutorial
Quest bits run from 0 to 32. In order to understand quest bits it is good to be able to understand the binary number system. Each bit has an on and off position, just as binary digits do. In order to determine the step number for a bit, you would calculate the decimal number from the binary number or vise versa.
So for instance you have an 8 step quest. You would need to use 3 bits, assuming that the quest is done in order. So the quest bits would start at 0 and run for 3 bits. So to check if a characters quest is completed with the final eigth step you would do:
if quest(0, 3, $n) == 8
For further explanation, here is a brief set of possible quest sets.
|
if quest(0, 3, $n) == 0 if quest(0, 3, $n) == 1 if quest(0, 3, $n) == 2 if quest(0, 3, $n) == 3 if quest(0, 3, $n) == 4 if quest(0, 3, $n) == 5 if quest(0, 3, $n) == 6 if quest(0, 3, $n) == 7 |
You can see how the number of possible steps climbs quickly, so you don't need many bits to do a full quest.
If you have a second quest in the area and you have used (0, 3, $n) as your first quest set, the second quest set can begin at (3,x,$n) where x is the number of bits you need to complete your second quest. Notice that (3,x,$n)==1 has no spaces. The spaces are not necessary for the code to work, but can be helpful when looking for possible problems in your code.
Quest Bits Tutorial by Grimace
Grimace (Area Creator from Mortal Realms Mud) has wrote the following tutorial for MRMud. We use the same quest bits system, so it applies to here as well:
Think of quest bits as a set of 32 switches that can be on or off. Let's take the simplest case. If you have ONE switch, it can either be off or on. You could write a simple quest where once the user has said "Grimace forever!", the mob changes the switch from 0 to 1 (off to on). Since you have 32 such switches to use, just use the first one (offset = 0, ie: at the beginning): mpmset $n quest 0 1 1. In this case the offset is 0, the quest is using only 1 bit of width (1 switch) and the value is 1 ("ON"). Pretty easy, eh? It might look like this:
>speech_prog p Grimace forever!~ say Damned straight. mpmset $n quest 0 1 1 ~
Now say you want a quest with FOUR steps. Well, binary tells us that we can get 4 unique numbers from TWO switches (A off, B off; A on, B off; A off, B on; A on, B on). So... let's tack this quest on after the first. Since we've already used 1 switch for the first quest, we'll need an offset of 1 so we start at the second bit. Since we want 4 unique positions, we need 2 switches, so the width will be 2. The values will range from 0 to 3, so it'll look like this: mpmset $n quest 1 2 1 or mpmset $n quest 1 2 2, etc., all the way up to mpmset $n quest 1 2 3. It'll screw it up if you try to set the value greater than 3. Here's an example:
>give_prog i9700~ if quest(1,2,$n) == 0 say Aha. That's a nice... item... you have there. Bring me a few more. mpmset $n quest 1 2 1 else if quest(1,2,$n) == 1 say Two items. That's spiffy. I need another. mpmset $n quest 1 2 2 else if quest(1,2,$n) == 2 say THREE wonderful items. Mu ha ha ha. Here's your reward. cast 'change sex' $n mpmset $n quest 1 2 3 else if quest(1,2,$n) == 3 say I don't need any more of those. Go away. endif endif endif endif ~
Getting the hang of it? You can divide the 32 switches into whatever pieces you want. You can have 32 1-bit quests (on/off) or you can have 1 32-bit quest (2^32 = billions of values) or anything in between. Simply decide how many steps you need, then figure out how many switches you'd need to group together to get that number of values, then pick a non-overlapping offset value to set aside a chunk of your 32 switches for this particular quest. (By the way, the equation to figure out how many bits you need for a certain number of steps is this: 2^#bits = #steps. It's better to set aside way too many and not use them than to set aside not enough. I tend to make my quests 4 bits wide as a rule. 16 steps is a nice round number unless you want to do silly stuff like count mobs killed, like in mist city... So you'd have three 16-step quests like a 0 4 quest, and a 4 4 quest, and a 8 4 quest, with values from 0 to 15, and then maybe a couple flags like 9 1 and 10 1, with values of 0 and 1 only.
Other notes:
- All bits for every char start in the "off" position (value = 0).
- Every pc and each mob has a unique set of 32 switches for each area. If you set or check quest bits, it will automatically use the bits from the area the mob or pc is from, even if it's for an item or mob from another area. Objects however only check the area they are currently in so they should use questr.
- Generally a mob_prog will have a bunch of nested "if else" statements (remember an "endif" for EACH "if") which check the quest bits, perform some cool slight of hand, and then set the quest bits. It's a generic formula.
Feel free to ask any member of the area administration if you have any questions. Quest bits are cool. Use them everywhere.
- Grimace