Earthwolf's "Add a wear-slot" text v1.0 earthwolf@anti-social.com Table Of Contents ----------------- 1. Introduction 2. Your step-by-step 3. How to contact me INTRODUCTION ------------ You'll all have to excuse any inability I show in writing code snippet tutorials, this is my first :-). Being new to coding I'm not yet great at fixing patches, modifying other's snippets, etc. It was because of the trouble I had of modifying my Circle30bpl17 source by following other people's instructions that I set out to learn everything from scratch. I'm sure it's the best thing you can do for yourself: Learn how to add things yourself, without other's tutorials. Now that I think about it, it doesn't make sense while I'm writing this. Anyway, this is a relatively simple process for beginners. Read on and enjoy! NOTE: I'm not sure how well this will work for distributions other than Circle30bpl17 STEP-BY-STEP How to add Wear-Slots ---------------------------------- Although CircleMUD has many wear slots, it's always fun to add your own. I can think of some great wear-slots that I'd rather not mention :-). For this tutorial, we'll be adding one for the ankle. Not even for both, just one. After reading this you should be able to add as many as you see fit. files used (in alphtabetical order): act.item.c, constants.c, objsave.c, structs.h Modifications to act.item.c -------------------------- Goto line 1165 and you should see the following code: {"$n grabs $p.", "You grab $p."} }; That is the line for the description of what you and others will see when you HOLD something. Since our ankle slot is new we'll just put it after the hold one. So, add a comma to the bracket after the hold strings, and then add what people and you will see when you wear your anklet. The code will now look like this: {"$n grabs $p.", "You grab $p."}, {"$n fastens $p around $s ankle.", "You fasten $p around your ankle."} }; Make sure that you leave the "};" At the very end. If you did not know, when the game is running variables with a '$' before them will be replaced with some differant text. For example, $n is replaced with the user's name and $p is replaced with what the item is called. Ok, now head on down to line 1185 were you'll see a big block of code looking like this: int wear_bivectors[] = { ITEM_WEAR_TAKE, ITEM_WEAR_FINGER, ITEM_WEAR_FINGER, ITEM_WEAR_NECK ITEM_WEAR_NECK, ITEM_WEAR_BODY, ITEM_WEAR_HEAD, ITE_WEAR_LEGS, ITE_WEAR_FEET, ITEM_WEAR_HANDS, ITEM_WEAR_ARMS, ITE_WEAR_SHIELD, ITEM_WEAR_ABOUT, ITEM_WEAR_WAIST, ITEM_WEAR_WRIST, ITEM_WEAR_WRIST, ITEM_WEAR_WIELD, ITEM_WEAR_TAKE }; Again, all we want to do is add more to this array. SLAP down a comma after ITEM_WEAR_TAKE and add yourself an ITEM_WEAR_ANKLE. Your code should magically now look like this: int wear_bivectors[] = { ITEM_WEAR_TAKE, ITEM_WEAR_FINGER, ITEM_WEAR_FINGER, ITEM_WEAR_NECK ITEM_WEAR_NECK, ITEM_WEAR_BODY, ITEM_WEAR_HEAD, ITE_WEAR_LEGS, ITE_WEAR_FEET, ITEM_WEAR_HANDS, ITEM_WEAR_ARMS, ITE_WEAR_SHIELD, ITEM_WEAR_ABOUT, ITEM_WEAR_WAIST, ITEM_WEAR_WRIST, ITEM_WEAR_WRIST, ITEM_WEAR_WIELD, ITEM_WEAR_TAKE, ITEM_WEAR_ANKLE }; You see we just added our ankle information ITEM_WEAR_ANKLE to the end of an already existing array. Ready to do it again? Well, jump on down to line number 1211 where we'll append the the big string array. You should already see this: "You're already holding something\r\n" }; You want to change this to: "You're already holding something\r\n", "You've already got something around your ankle\r\n" }; The MUD knows what's up now if you try to wear an anklet twice. Because of the code above all of the newbies shall be told. Ok, now go down to line 1260 and we'll just slide our ankle into the end like we always do. (that didn't sound right) "\r!RESERVED!", "\r!RESERVED!", "\n" }; So, to not have a crash we'll just change the code above to this code below: "\r!RESERVED!", "\r!RESERVED!", "ankle", "\n" }; Well now that you have that done we must add some error checking to the MUD to keep on making sure the MUD doesn't try to wear to anklets on the same slot: if (CAN_WEAR(obj, ITEM_WEAR_WRIST)) where = WEAR_WRIST_R; } else { We're just going to add some of our ankle code to this. You might of already guessed, but all we need to do is make the code so it looks like this: if (CAN_WEAR(obj, ITEM_WEAR_WRIST)) where = WEAR_WRIST_R; if (CAN_WEAR(obj, ITEM_WEAR_ANKLE)) where = WEAR_ANKLE; } else { We be done with act.item.c! Modifications to constants.c ---------------------------- If you didn't think that was very hard, then you'll get through the rest of this fine. We'll just be adding some strings to some existing arrays so that the MUD will notify us about what we're doing when we try to wear something on our ankle. Ok, jump on down to line 264 where we'll add some more stuff after that ol' hold slot friend of ours. On line 264 you'll see some code that looks like this: " ", " " }; We just want to plug in another slot for the ankle. Simply modify your code to look like what's below, and don't forget the comma! " ", " ", " " }; By now you should be getting the picture, but if you don't then that's ok. Our next step is very very similar to the last one. Warp on down to line 289 and you'll see some code look'n just like 'dis: "Wielded", "Held", "\n" }; We want to jump inbetween the "Held" and the "\n" to make ourselves an ankle sandwhich. We be jammin now! Use that voodoo that you do and change your code to "Wielded", "Held", "Worn around ankle", "\n" }; Don't worry, we're getting there. Go to line 340 and you'll see some very similar code: "WIELD", "HOLD", "\n" }; Ok, let's just put our ankle slot after the HOLD slot like we've been doing. Your code will now look like this: "WIELD", "HOLD", "ANKLE" "\n" }; Oh my GOD, we did it! Well almost, you're now done with constants.c. There's still some more to go. If you need to get up, stretch out, play some Bob Marley, and do some Tai Chi or something. Modifying objsave.c, Friend or Foe? ----------------------------------- Just by noticing the name of this file, I'm guessing that this is what helps the computer save information about objects :-). The only thing that we're going to be worrying about is helping the MUD know if you can actually wear the obj on your ankle or not. Scroll down all the way to line 162. There you'll see a bunch of similar blocks of code for each differant wear-slot. For easy installation we're gonna stick our code right after the WEAR_LEGS info because it doesn't really matter. case WEAR_LEGS: if (!CAN_WEAR(obj, ITEM_WEAR_LEGS)) location == LOC_INVENTORY; break; case WEAR_FEET: So, with simple text editing program change the code above to look like the code below: case WEAR_LEGS: if (!CAN_WEAR(obj, ITEM_WEAR_LEGS)) location = LOCINVENTORY; break; case WEAR_ANKLE: if (!CAN_WEAR(obj, ITEM_WEAR_ANKLE)) location = LOC_INVENTORY; break; case WEAR_FEET: Didn't really take much to modify objsave.c did it? We only have one more file to edit before you and your faithful mortals can start wearing stuff on your ankle! Modifying structs.h "It's structurific!" ---------------------------------------- Remember all of those WEAR_ANKLE and ITEM_WEAR_ANKLE flags we've been throwing around so haphazzardly? Well, we're actually going to define them now. NOTE: It's better to define things first :-) I now you're ready to implement, so cruise on down to line 127 where all of the cool code hangs out. There you'll see some code like this: #define WEAR_WIELD 16 #define WEAR_HOLD 17 #define NUM_WEARS 18 We're not only going to through in our ankle slot, but also increment the NUM_WEARS constant. So, modify your code to the following, remembering to change NUM_WEARS: #define WEAR_WIELD 16 #define WEAR_HOLD 17 #define WEAR_ANKLE 18 #define NUM_WEARS 19 We're now ready for our last bit of code modification, and I can't beleave I've already written a 258 line text file! Boy the time has been passing quickly hasn't it? For your last addition go on down to line 321 where you should see the following code: #define ITEM_WEAR_HOLD (1 << 14) /* Can be held */ Just change that to this and you're done: #define ITEM_WEAR_HOLD (1 << 14) /* Can be held */ #define ITEM_WEAR_ANKLE (1 << 15) Ok, you're completely done adding the wear slots now! When you're editing your objects from now on set your War Bivector as 'p' to make the equipment for your ankle. (without the quotes) HOW TO CONTACT ME ----------------- As I'm sure you've noticed, adding wear slots was a really easy thing to do. As for all you newbie coders like myself though, it's a great excersize for more familiarizing yourself with the CircleMUD code. If you still have any questions, or I made a mistake just e-mail me or go to my website. My website will be updated with tutorials I write. earthwolf@anti-social.com http://www.geocities.com/earthwolf_0