|------------------------------------------------------------------| | Basic Class Restricted Guild Code | | By Chuck Reed of Dark Horizon - pentrel.com 6001 | | with much appreciated contributions from Siv of cyberenet.net:400| |------------------------------------------------------------------| Introduction: ------------- This is a VERY step by step document as it is intended for newbie coders looking to implement a guild system based on class. What the file does exactly is, it takes the mob special procedure (guild) and makes a series of checks to see if a PC trying to practice or level is able to. I have changed the way leveling works for this code so that characters do not gain levels simply by gaining enough exp. They must go to their guild and let their guild master advance them (the "gain" command is what I use). There are two main things you should know before using this: 1) This is meant to work only with a formula for exp and not the crazy stock code of tables and arrays. If you still have that, you must substitute exp_to_level(ch) with some sort of titles[] function. 2) I am not responsible for anything that goes wrong with your code. You use this on your own free will. Blah blah blah blah! Now, let's begin. ***********************Edit your structs.h file****************************** Add a this anywhere in the file (except inside of something!): struct new_guild_info { int guild_room; int class; } ********************************Edit your class.c file***************** Add a new array for any guilds you want to have. For example, if you have only two guilds right now for thieves and paladins, here is what it would look like: struct new_guild_info guilds[] = { {3045, CLASS_THIEF}, {3048, CLASS_PALADIN}, {-1,-1} }; Since this isn't going to be just a cut paste job for this array, I'll tell you what it means. It calls for the structure of new_guild_info making the first argument called guild_room and the second class. The number inside the {}'s should be the room of the guild while the CLASS_BLAH should be the class definition that you want to be able to practice/level there. Anytime a new guild is added, this MUST BE UPDATED. **Edit your spec_procs.c file*********************************************** Under the last external variable listed, add: struct new_guild_info guilds[]; Search for the guild special procedure. It looks like this "SPECIAL(guild)" with no quotes. Now, delete every line until the next SPECIAL (stock is dump). Insert the following where this special used to be: SPECIAL(guild) { int found, skill_num, percent,i; extern struct spell_info_type spell_info[]; extern struct int_app_type int_app[]; found = FALSE; if (IS_NPC(ch)) return 0; if (!CMD_IS("practice") && !CMD_IS("gain")) return 0; for(i=0;guilds[i].class != -1;i++) if (GET_CLASS(ch) == guilds[i].class && world[ch->in_room].number == guilds[i].guild_room) { found = TRUE; break; } if(CMD_IS("practice") && found == TRUE) { skip_spaces(&argument); if (!*argument) { list_skills(ch); return 1; } if (GET_PRACTICES(ch) <= 0) { send_to_char("You do not seem to be able to practice now.\r\n", ch); return 1; } skill_num = find_skill_num(argument); if (skill_num < 1 || GET_LEVEL(ch) < spell_info[skill_num].min_level[(int) GET_CLASS(ch)]) { sprintf(buf, "You do not know of that %s.\r\n", SPLSKL(ch)); send_to_char(buf, ch); return 1; } if (GET_SKILL(ch, skill_num) >= LEARNED(ch)) { send_to_char("You are already learned in that area.\r\n", ch); return 1; } send_to_char("You practice for a while...\r\n", ch); GET_PRACTICES(ch)--; percent = GET_SKILL(ch, skill_num); percent += MIN(MAXGAIN(ch), MAX(MINGAIN(ch), int_app[GET_INT(ch)].learn)); SET_SKILL(ch, skill_num, MIN(LEARNED(ch), percent)); if (GET_SKILL(ch, skill_num) >= LEARNED(ch)) send_to_char("You are now learned in that area.\r\n", ch); return 1; } if(CMD_IS("gain") && found == TRUE) { if(GET_EXP(ch) < exp_to_level(ch)) { send_to_char("You need more experience to level.\r\n", ch); return 0; } if(GET_EXP(ch) >= exp_to_level(ch) && GET_LEVEL(ch) >= LVL_IMMORT - 1) { send_to_char("You can't gain anymore levels!\r\n", ch); return 0; } if(GET_LEVEL(ch) < LVL_IMMORT - 1 && GET_EXP(ch) >= exp_to_level(ch)) { GET_LEVEL(ch) += 1; advance_level(ch); send_to_char("You gain a level!\r\n", ch); return 1; } else return FALSE; } else return FALSE; } **Edit your act.other.c*********************************************** Under the last external variable listed, add: struct new_guild_info guilds[]; Add a new command under one of the already existing ones with this code: ACMD(do_gain) { int i, found; for(i=0;guilds[i].class != -1;i++) if(GET_CLASS(ch) == guilds[i].class && world[ch->in_room].number == guilds[i].guild_room) found = TRUE; else found = FALSE; if (!found) send_to_char("Not here!\r\n", ch); } *******Edit your interpreter.c file************************************** Add ACMD(do_gain) somewhere in the list of all the ACMD(do_blah) commands. Add : {"gain", POS_STANDING, do_gain, 0, 0}, somewhere in the Master list of commands. *****Edit your limits.c file*********************************************** replace the existing gain_exp function with this one: void gain_exp(struct char_data * ch, int gain) { char buf[128]; if (!IS_NPC(ch) && ((GET_LEVEL(ch) < 1 || GET_LEVEL(ch) >= LVL_IMMORT - 1))) return; if (IS_NPC(ch)) { GET_EXP(ch) += gain; return; } if (gain > 0) { gain = MIN(max_exp_gain, gain); GET_EXP(ch) += gain; } if (gain < 0) { gain = MAX(-max_exp_loss, gain); GET_EXP(ch) += gain; } if (GET_EXP(ch) < 0) GET_EXP(ch) = 0; } Now replace the existing gain_exp_regardless function with this one: void gain_exp_regardless(struct char_data * ch, int gain) { GET_EXP(ch) += gain; if (GET_EXP(ch) < 0) GET_EXP(ch) = 0; } /*************************************************************************/ That should be all. Exit all of your files and compile. There is always the possibility that I have left SOMETHING out so mail me at creed@i-55.com if you have any troubles. Here are some things to note: 1) When any guilds are added, you must add the proper data to the guilds[] array in class.c. 2) All new guildmasters must have the guild special procedure assigned to them in spec_assign.c. 3) As always, your code IS NOT MINE! So things may conflict and things may not go exactly as they have for me. Just mail me and I'll see if I can help. Chuck Reed mailto:creed@i-55.com