Welcome to the Builder Academy

Question How to Add a Wear Slot

More
11 Jun 2012 03:01 #23 by Rumble
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 writingcode snippet tutorials, this is my first :-). Being new tocoding 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 with 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 looking just like this:

"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 reallyeasy 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 please e-mail me at: earthwolf@anti-social.com

Rumble
The Builder Academy
tbamud.com 9091
rumble@tbamud.com

Please Log in or Create an account to join the conversation.

More
12 Jul 2014 06:06 - 12 Jul 2014 06:42 #4954 by Papaya Pete
Replied by Papaya Pete on topic How to Add a Wear Slot
I know this is an older thread, but thought maybe others have had the same problem as I have had in adding new wear slots.

Everything seems to work out really well; I added in a wear slot for backpacks. Sometimes, however, it crashes when I try to wear it. Other times, it will allow me to wear it just fine. I know this is vague, but any ideas or leads on how to resolve this issue? I likely forgot something...

Edit: So I messed around a bit more. My suggestion is adding the dual wielding snippet found on the old circlemud ftp site AFTER you put in every other new wear slot you add. It seems that was the problem. It seems to be working fine now.
Last edit: 12 Jul 2014 06:42 by Papaya Pete.

Please Log in or Create an account to join the conversation.

More
06 Jun 2020 19:22 #8761 by angrboda6
Replied by angrboda6 on topic How to Add a Wear Slot
Do you not have to edit the oasis/olc files?

Please Log in or Create an account to join the conversation.

More
06 Jun 2020 21:42 #8762 by WhiskyTest
Replied by WhiskyTest on topic How to Add a Wear Slot
Hey, necro! :D

No dude, when you increase the NUM_WEARS this is how the OLC stuff figures out how many different wear slots are available when you are creating items.

Please Log in or Create an account to join the conversation.

Time to create page: 0.180 seconds