10 Sep, 2006, Midboss wrote in the 1st comment:
Votes: 0
Okay, here's my first tutorial, and it's gonna be pretty simple. I assume you have enough knowledge to compile and run your MUD in the first place. Anyway, I'll be teaching you to add a new skill to your ROM-based MUD! First off, open the file merc.h in your favorite text editor (I personally use 'nano' in my shell and EditPlus 2 if I'm using FTP),and find something that looks like this (note that the number may or may not be different):

#define MAX_SKILL          150


What you want to do, is increment the value by one. So, assuming the value WAS 150, that line should now read:

#define MAX_SKILL          151


Now, in the file const.c, find the skill_table. If you search for skill_type you should go right to it. Anywhere in the table that suits your organizational tastes, you need to add a skill entry. EXISTING skill entries should look something like this:

{
"second attack", {30, 24, 12, 5}, {10, 8, 5, 3},
spell_null, TAR_IGNORE, POS_FIGHTING,
&gsn_second_attack, SLOT (0), 0, 0,
"", "!Second Attack!", ""},


So, let's assume the skill you want to add is… Fourth attack. Preferably below the "third attack" entry in the skill table, you add a bit of code something like the last, but with the proper values changed, like so:

{
"fourth attack", {53, 53, 38, 25}, {0, 0, 12, 6},
spell_null, TAR_IGNORE, POS_FIGHTING,
&gsn_fourth_attack, SLOT (0), 0, 0,
"", "!Fourth Attack!", ""},


A brief explanation of the above skill entry: the first bit is the name of the skill, of course. The two arrays of numbers following it are the level required by each class, and the amount of trains it costs to gain, as well as the difficulty to improve, respectively. The 'spell_null' in these skills would be changed to a spell_fun pointer if the skill in question were magical, but since this isn't, we'll leave that alone for now.

The 'TAR_IGNORE' is also a value used only be spells, as is 'SLOT (0)', the two 0s following it, and the POS_FIGHTING. POS_FIGHTING here refers to the minimum position the character can be in to cast the spell, which doesn't matter in this case, but by setting it to POS_FIGHTING, if this WERE a spell, players could cast the spell while standing, or while fighting. I won't go into detail on the TAR_IGNORE part here, perhaps in another tutorial. The SLOT() macro was meant for object loading, but to my knowledge, isn't really used by anything in ROM, as most of the oldstyle objects are gone. The following zeros are the minimum (base) mana cost of the spell, and the wait time (lag) incurred by casting it (most also use this for skills, but again, this is a passive skill, so the point is moot). The wait time, by default, is in quarter seconds, so a wait time of 12 would incur 3 seconds of lag.

Now, you also may have noticed that there is an odd string in the bottom line. That string is for the wear off message of any skill that adds a status effect – previous coders, and many of us newer coders, put something that doesn't really make sense there on non-status changing skills, to arouse a player's attention should something go awry.

Okay, so it wasn't brief at all. Enough rambling, ONWARD I SAY!

Now that you have the skill added to the skill table, if you wish for any class to learn it by default, scroll down until you find the group_table, and look for that particular class' default skillset, usually named something like "warrior default". Just for reference, "warrior default" in my stock QuickMUD looks like so:
{
"warrior default", {-1, -1, -1, 40},
{"weaponsmaster", "shield block", "bash", "disarm", "enhanced damage",
"parry", "rescue", "third attack"}
},

In order to add the skill to the group, you would simply add a comma at the end, followed by the skill's exact name from the skill_table in quotation marks. Remember: If your compiler complains later about something in the group_table, incremement the value MAX_IN_GROUP, in merc.h (which is usually somewhere near MAX_SKILL), by one until it stops complaining.

Now, you're done with const.c. Open up db.h and, once more, merc.h. I'm sure you remember the line we added to the skill_table with the text &gsn_fourth_attack on it? If you have any programming knowledge, which you probably should, you know that that has to come from somewhere, so it's time to define it. Search for the following chunk of code, or one like it, in db.c:

sh_int gsn_second_attack;
sh_int gsn_third_attack;


Now, add another line after the gsn_third_attack line, so that the same block looks like this:

sh_int gsn_second_attack;
sh_int gsn_third_attack;
sh_int gsn_fourth_attack;


Back in merc.h, you need to find similar code; a block that reads something like:

extern    sh_int    gsn_second_attack;
extern sh_int gsn_third_attack;


And of course, change it to look like this:

extern    sh_int    gsn_second_attack;
extern sh_int gsn_third_attack;
extern sh_int gsn_fourth_attack;


At this point, after a clean compile, the skill would exist, but it wouldn't DO anything. Can't have that, now, can we? So, let's open up fight.c. Look for the function multi_hit, and in particular, this block of code (or one a hell of a lot like it):

chance = get_skill (ch, gsn_third_attack) / 4;

if (IS_AFFECTED (ch, AFF_SLOW))
chance = 0;;

if (number_percent () < chance)
{
one_hit (ch, victim, dt);
check_improve (ch, gsn_third_attack, TRUE, 6);
if (ch->fighting != victim)
return;
}


Now, below that, add a very similar block, modified for our new skill, fourth attack. The new block should look about like this:

chance = get_skill (ch, gsn_fourth_attack) / 6;

if (IS_AFFECTED (ch, AFF_SLOW))
chance = 0;

if (number_percent () < chance)
{
one_hit (ch, victim, dt);
check_improve (ch, gsn_fourth_attack, TRUE, 7);
if (ch->fighting != victim)
return;
}


NOW, still within your source directory, do a 'make clean', and then 'make', to get a fresh compile. When it's done, reboot (or copyover, if you have it installed) your MUD. You should now have a working 'Fourth Attack' skill, and a better understanding (presuming you're a total newbie) of how to expand your MUD's skillsets.

I know it's not the best tutorial, but don't flame too hard. Save the flames for something more worthy, like… My incessant ranting about pie! Booyah! I even made a tutorial into a post about pie, eat that! …no pun intended.
0.0/1