/*
 * Hello everyone. This is a mud specfic snip that
 * can be adapted to another mud. Basicly, what this
 * snip is for, is to create involved quests via mprogs
 *
 * This snip is rather involved to get working, requires
 * several new charater data and a close relationship
 * with the coder and builders who will be doing this.
 *
 */

/* To use this snip:

	* Get it working the way you want ;) and working peroid ;)
	* MUST EMAIL ME AT cyhawk@comcast.net
	or AIM CalibanL telling me you are using it
	* MUST GIVE CREDIT IN HELPFILE titled 'gquest'
	  just 4 lines:
		mobprog quest system created by Thri of
		Soulblight.
		telnet://soulblight.slayn.net:5500
		http://soulblight.slayn.net

	* IF i see this code somewhere, and i dont have credit
	  I will be extremely pissed and most likely do something
	  mean and evil to you, including getting you to remove the code.

	* This code took me 24 hours to code, and another 16 to clean up.
	  i EXPECT credit where credit is due. Do not use this snip if you
	  cannot do that simple thing. Even if your mud is 'closed to the public'
	  or your 'just testing it' Email/AIM me and put the helpfile in.
	  Its that easy

	* yes, there are a few things missing from here, you'll figure out
	  what. If your truely stuck, and really need help, ask me. I will
	  see what i can do.

	* If you want to post or release this code anywhere but Kyndig.com
	you must inform me and get my premission. If you got this code
	from anywhere BUT kyndig or my website http://soulblight.slayn.net
	email/aim me and tell me.

	* Put in the helpfile, seriously
	* Tell me, regardless of what your doing with it

	-Thri

 */

/* A quick rundown:

	quest_temp   = What step the player is on in the given quest
		        called by  mprog check  if questtemp $n <step>
	quest_1      = Finished quests. called by mprogs
	               if quest1 $n <quest name>
		        quest name is handled in tables.c
	quest_current = Not covered here. It is a temp holder
	                for the current quest. I have it set up
			  to handle multi-quest mobs to say different
			  things depending on the quest the player is on.

	mprog IF checks:
		questtemp	sentax: if questtemp $n questname
				returns true if quest_temp flag is set.
				example:
					if questtemp $n newbie
						say Your on the newbie quest!
					else
						say You are NOT on the newbie quest.
					endif

		quest1		sentax: if quest1 $n questname
				returns true if quest is finished.
				example:
					if quest1 $n newbie
						say Sorry $n, you have done the newbie quest
					else
						say No $n, you can still do the newbie quest!
					endif

	mob commands:
		qtempstart	sentax:  mob qtempstart $n
				This sets the victim->quest_temp, QUEST_TEMP_ON_QUEST
				Use: To begin a unique quest
				example

				say thank you $n for taking my quest!
				say Go kill that rat!
				mob qtempstart $n

		qtempstep1	sentax: mob qtempset1 $n
				Sets the step1 flag.
				example:

				if questflag step1
					if questflag step2
						say You are on step2
					else
						say You are on step 1
					endif
				else
					say you are not on any step

		questfinish	sentax: mob questfinish $n <quest number>
				will give the reward for finishing the quest
				Note: Requires code edit to function to handle
				each quest.

				example:

				if quest1 $n newbie
					say Im soryr $n, youve done the newbie quest
				else
					say Yep, you compeleted the quest, heres your reward
					mob qtempclear $n
					mob questfinish $n 1
				endif

		qtempcear:	sentax: mob qtempclear $n
				clears all temp flags on $n.

				example: see above

*/






Step 1:

adding quest defines:

Add this to merc.h somewhere


/* ch->Quest_temp Uses for multi-step quests */
#define QUEST_TEMP_ON_QUEST	(A)
#define QUEST_STEP_1		(B)
#define QUEST_STEP_2		(C)
#define QUEST_STEP_3		(D)
#define QUEST_STEP_4		(E)
#define QUEST_STEP_5		(F)
#define QUEST_STEP_6		(G)
#define QUEST_STEP_7		(H)
#define QUEST_STEP_8		(I)
#define QUEST_STEP_9		(J)
#define QUEST_STEP_10	(K)
#define QUEST_FINISH		(L)

/* ch->quest_current: The quest the ch is currently on */
#define QUEST_CUR_NEWBIE	1
#define QUEST_CUR_SEWER	2
#define QUEST_CUR_CAT	3
#define QUEST_CUR_RATS	4


/* Quest 1 Finishes */
#define QUEST_1_NEWBIE	(A)		/* Newbie School quest */
#define QUEST_1_SEWER	(B)		/* Killing the rat king */
#define QUEST_1_CAT		(C)		/* Returning Felix to Alice */
#define QUEST_1_RATS		(D)		/* Cleaning Serena's house of evil rats */


in char_data add..

    long 		 quest_1;
    long 		 quest_temp;
    long 		 quest_current;


Step 2:
save.c

add save features for quest_1, quest_temp, and quest_current, theyre flags.


Step 3:
tables.c

add these to tables.c
and to tables.h

extern	const	struct	flag_type	quest_temp_flags[];
extern	const	struct	flag_type	quest_1_flags[];

const struct flag_type quest_1_flags[] = {
    {"newbie", 	A, TRUE},
    {"sewer", 	B, TRUE},
    {"felix", 	C, TRUE},
    {"houseclean", 	D, TRUE},
    {NULL, 0, 0}
};

const struct flag_type quest_temp_flags[] = {
    {"on_quest", 		A, TRUE},
    {"step1", 		B, TRUE},
    {"step2", 		C, TRUE},
    {"step3", 		D, TRUE},
    {"step4", 		E, TRUE},
    {NULL, 0, 0}
};


Step 4:
mob_cmds.c

in mob_cmd_table add the following entries:

    {"qtempclear", do_qtempclear},
    {"qtempstart", do_qtempstart},
    {"questfinish", do_quest_finish},
    {"qtempset1", do_qtempset_step1},



stick this at the bottom


void do_qtempclear (CHAR_DATA * ch, char *argument)
{
    CHAR_DATA *victim;
    char arg[MAX_INPUT_LENGTH];

    argument = one_argument (argument, arg);
    if ((victim = get_char_room (ch, arg)) == NULL)
        return;

    victim->quest_temp = 0;
    logf_old("%s has been quest cleared", ch->name);
    return;

}



void do_qtempstart (CHAR_DATA * ch, char *argument)
{
    CHAR_DATA *victim;
    char arg[MAX_INPUT_LENGTH];
    char arg2[MAX_INPUT_LENGTH];

    argument = one_argument (argument, arg);
    one_argument (argument, arg2);

    if ((victim = get_char_room (ch, arg)) == NULL)
        return;

    SET_BIT (victim->quest_temp, QUEST_TEMP_ON_QUEST);

    return;

}



void do_qtempset_step1 (CHAR_DATA * ch, char *argument)
{
    CHAR_DATA *victim;
    char arg[MAX_INPUT_LENGTH];
    char arg2[MAX_INPUT_LENGTH];

    argument = one_argument (argument, arg);
    one_argument (argument, arg2);

    if ((victim = get_char_room (ch, arg)) == NULL)
        return;

    SET_BIT (victim->quest_temp, QUEST_STEP_1);

    return;

}



void do_quest_finish (CHAR_DATA * ch, char *argument)
{
    CHAR_DATA *victim;
    char arg[MAX_INPUT_LENGTH];
    char arg2[MAX_INPUT_LENGTH];
    char buf[MSL];

    argument = one_argument (argument, arg);
    one_argument (argument, arg2);

    if ((victim = get_char_room (ch, arg)) == NULL)
        return;

	if (!is_number (arg2))
	{
		sprintf(buf, "ERROR: Quest %s is incorrect. This mobile (mob: %s) mobprog is incorrect.\n\r", arg2, ch->short_descr);
		send_to_char(buf, victim);
	       sprintf(buf, "ERROR: Please Note/Fourm post these two lines to Thri.\n\r");
		send_to_char(buf, victim);
	       sprintf(buf, "ERROR: INVALID argument2 (not a number). Mob: %s, Quest %s\n\r", ch->short_descr, arg2);
		send_to_char(buf, victim);
		return;
	}



    switch(atoi (arg2))
    {	default:
		sprintf(buf, "ERROR: Quest %s is incorrect. This mobile (mob: %s) mobprog is incorrect.\n\r", arg2, ch->short_descr);
		send_to_char(buf, victim);
	       sprintf(buf, "ERROR: Please Note/Fourm post these two lines to Thri.\n\r");
		send_to_char(buf, victim);
	       sprintf(buf, "ERROR: INALID QUEST NUMBER. Mob: %s, Quest %s\n\r", ch->short_descr, arg2);
		send_to_char(buf, victim);

	break;

	case 1:
		send_to_char("You have completed the Newbie Quest!\n\r", victim);
		send_to_char("You have recived 50 quest points, and 500 silver.\n\r", victim);
		send_to_char("Use 'GQUEST' to see all quests completed.\n\r", victim);
		SET_BIT (victim->quest_1, QUEST_1_NEWBIE);
		victim->questpoints += 50;
		victim->silver += 500;
	break;

	case 2:
		send_to_char("You have completed the Return of the Rat king Quest!\n\r", victim);
		send_to_char("You have recived 75 quest points, and 750 silver.\n\r", victim);
		send_to_char("Use 'GQUEST' to see all quests completed.\n\r", victim);
		SET_BIT (victim->quest_1, QUEST_1_RATS);
		victim->questpoints += 75;
		victim->silver += 750;
	break;

    }



    return;

}


dont forget to add the declare_do_fun in mob_cmds.h


step 5:
mob_progs.c

at the top add

#define CHK_QUEST_TEMP  (53)
#define CHK_QUEST_1	   (54)

in *fn_keyword add these to the bottom

    "questtemp",			// if questtemp $n questname
    "quest1",				// if quest1 $n questname  (if its COMPLETE)





in cmd_eval
find:
 * Case 4: Keyword, actor and value

add these two somewhere in the switch statement

        case CHK_QUEST_TEMP:
            return (lval_char != NULL
                    && IS_SET (lval_char->quest_temp,
                               flag_lookup (buf, quest_temp_flags)));

        case CHK_QUEST_1:
            return (lval_char != NULL
                    && IS_SET (lval_char->quest_1,
                               flag_lookup (buf, quest_1_flags)));





Ok your all set up.
Here is an example on how to do this in mprogs.

The quest:	Its a newbie quest, basicly, Molly, the newbie priestess
asks if you can do something for her. when the player says 'QUEST'
she will tell them about her apprentice Gilly, and that shes missing.
Gilly is in a ruined temple to the north.
Once you find gilly, she decides she doesnt want to return, and
gives the player a ribbon to give to molly as proof she is ok.
Once the player gives the ribbon to molly, she finds out, and
then rewards the player for making sure Gilly is safe. She
also loads and gives the key to the door out of the newbie place.

This is a 1 step quest


// Molly Greeting
// grall 100
// Handles greetings based on where they are in the quest
// Also asks the player if they want to partake on the quest



if questtemp $n on_quest
	if questtemp $n step1
		say $n! Have you found Gilly yet?
		say Please help find her quickly.
		mob cast heal $n
	else
		say Welcome back to the temple $n.
		mob cast heal $n
	endif
else
	if quest1 $n newbie
		say Welcome back $n, I thank you for telling me where Gilly has gone.
		mob cast heal $n
	else
		say Welcome stranger, to the Temple of Thri. My duty here is to heal and
		say protect adventurers like yourself. I offer then standard healing services to all.
		say just type '{yHEAL{G' to see a list of spells I can cast on you.
		say Oh, I hate to bother you, but there is a small matter in which I need
		say some assistance on. Please, if you can help, just say '{YQUEST{G'.
	endif
endif



// 'quest' from molly
// Speech trigger 'quest'
// Gives the key to the $n
// and tells here about the quest
// also begins the quest

if questtemp $n on_quest
	if questtemp $n step1
		say What $n? Let me tell you agian what has happened.
		say My Apprentice, Gilly has left the temple without saying
		say anything. Please, find her, and bring her back safely.
		say Here is another key to the Northern ruins.
		mob oload 7806
		give key $n
	else
		smile $n
		say Thank you $n, but you are already on a quest.
	endif
else
	if quest1 $n newbie
		say I am sorry $n, but I do not have any other tasks avaible
		say for you. I do know, however, that there is a small
		say Rat problem in the city of Vandagard. Talk to Charles
		say the Captian of the Vandagard Guard about it for more
		say Information.
	else
		say Good. I am glad you are willing to help.
		say It all began two months ago. My apprentice Gilly and I had a falling out of sorts.
		say She stormed out of the Temple. Normaly when she does this, she returns in a few days
		say after she has cooled off. But this time, she has not returned. I am fearful the worst
		say has happened. I suspect the Goblins that have taken up residence in the northern
		say Ruins had something to do with her not returning. Please, go to the northern ruins
		say and bring Gilly back safely. I will give you a key to open the northern gates.
		say If you need to remember your quest, just say 'QUEST' agian.
		say Thri's speed young $n. Bring her back to me.
		mob oload 7806
		give key $n
		mob qtempstart $n
		mob qtempset1 $n
	endif
endif

// END quest
// give ribbon molly

// handles giving the quest out.
// Calls $n a fake if they try to do it agian.

if quest1 $n newbie
	say I am sorry $n. But this obvious FAKE ribbon from gilly
	say will not earn you more credit... Please leave.
else
	say I see....
	say A long time ago, i took gilly in. Her perants were killed in the
	say Thalosian wars. I taught her everything she knows. To me, she was
	say my own daughter of flesh and blood. It pains me to know this.
	say but at least she is safe. Thank you $n.
	mob oload 7809
	mob oload 7810
	say Your time here is now complete. It is time to make your mark in
	say the world $n. Please, take this key and token. The key unlocks
	say the door to the west, which leads to a portal to the world.
	say The token is for your help finding Gilly. Just '{YEAT{g' the token
	say when you have a chance. Another command is also avaible to you,
	say '{YGQUEST{G'. This command is a list of your deeds in the world.
	say Good luck $n, may your god be with you.
	give token $n
	give key $n
	mob qtempclear $n
	mob questfinish $n 1
endif


// Greet on Gilly
// Gives ribbon to $n
say thank Thri you have rescued me.
say I see, Molly sent you to find me
say ...
mob oload 7808
say No, i will not go back with you. I no longer
say wish to be a priestess of Thri. I never did.
say Give molly this ribbon, she will know what it means.
say Its time to make my own mark in this world, not follow someone elses
say footsteps. I will be ok on my own now, thank you $n.
say Just give her the ribbon, she will know what it means.
give ribbon $n
give rib $n