Login
User Name:

Password:



Register

Forgot your password?
do_owhere recursive
Author: Khonsu
Submitted by: Khonsu
Changes list / Addchange
Author: Khonsu
Submitted by: Khonsu
6Dragons mp3 sound pack
Author: Vladaar
Submitted by: Vladaar
AFKMud 2.2.3
Author: AFKMud Team
Submitted by: Samson
SWFOTEFUSS 1.5
Author: Various
Submitted by: Samson
Users Online
AhrefsBot, Google

Members: 0
Guests: 22
Stats
Files
Topics
Posts
Members
Newest Member
489
3,791
19,644
596
Elwood

Today's Birthdays
There are no member birthdays today.
» SmaugMuds » Codebases » AFKMud Support & Development » Quest point code for AfkMud
Forum Rules | Mark all | Recent Posts

Quest point code for AfkMud
< Newer Topic :: Older Topic >

Pages:<< prev 1 next >>
Post is unread #1 Aug 28, 2012 10:03 am   Last edited Aug 28, 2012 11:53 am by Sherm
Go to the top of the page
Go to the bottom of the page

Sherm
Fledgling
GroupMembers
Posts33
JoinedDec 20, 2010

 
So I have been working on adding quest points to AfkMud code this is was has worked for me. I am add this to make Afk better and will be working towards getting the questmaster code working with Afk also.

Here is what i have done. If anyone see and glaring mistakes please let me know.

In Character.h

Find int version;

Add int quest_points;

Find bool backtracking; /* Unsafe landing flag */

Under that add
int quest_points; /*adding in quest points ###8-21-12*/

In Character.cpp in the char_data::char_data()

Find this->perm_lck = 13;

Add this->quest_points = 0; right under lck.

Find int char_data::GET_AC( )

Right under that add

int char_data::get_quest_points( )
{
return this->quest_points ;
}

In player.cpp

Find ch->printf( "%sPracs: %s%-15d %sFavor :

And change it to be

ch->printf( "%sPracs: %s%-15d %sFavor : %s%-15d %s Quest Points: %s%-15d\r\n\r\n",
s2, s3, ch->pcdata->practice, s2, s3, ch->pcdata->favor, s2, s3, ch->pcdata->quest_points );

in save.cpp

find fprintf( fp, "Condition %d %d %d\n", ch->pcdata->condition[0], ch->pcdata->condition[1], ch->pcdata->condition[2] );

then add fprintf( fp, "QuestPoints %d\n", ch->pcdata->quest_points); // ### added quest points to characters pfile

then find void fread_char( char_data * ch, FILE * fp, bool preload, bool copyover ) and go down to the case 'Q': right below the Qbit add in

if( !str_cmp( word, "QuestPoints" ) )
{
line = fread_line( fp );
sscanf( line, "%d", &x1 );
ch->pcdata->quest_points = x1;

break;
}

In act_wiz.cpp (this is where I added the command do add and remove quest points)
Under the last CMDF add

CMDF(do_qpset) {
string arg1, arg2, arg3;
char_data *victim;
string origarg = argument;
int value = 0;

ch->set_color(AT_IMMORT);


// adding data to args
argument = one_argument(argument, arg1);
argument = one_argument(argument, arg2);
argument = one_argument(argument, arg3);

// need to change arg3 from string to interger

value = atoi(arg3.c_str());


// checking to make sure the player is online
if (!(victim = ch->get_char_world(arg1))) {
ch->print("They don't seem to be around.\r\n");
return;
}
// mobs should not be able to set quest points
if (ch->isnpc()) {
ch->print("Mob's can't qpset\r\n");
return;
}


if (arg1.empty() || arg2.empty()) {
ch->print("Syntax: qpset \r\n");
ch->print("Example qpset Player1 add, will just add one to quest points\r\n\n");
ch->print("Syntax: qpset #\r\n");
ch->print("Example qpset Player1 add 5, will add five to quest points\r\n\n");
return;
}

if (!str_cmp(arg2, "add")) {
if (arg3.empty()) {
victim->pcdata->quest_points = victim->pcdata->quest_points + 1;
ch->printf("Setting one quest point on %s.\r\n", victim->name);
victim->save();
return;

}
else if ((value < 1) || (value > 1000)) {
ch->printf("You must enter a number between 1 and 1000");
return;
} else {
victim->pcdata->quest_points = value + victim->pcdata->quest_points;
ch->printf("Setting %d quest points on %s.\r\n", value, victim->name);
victim->save();
return;
}
} else if (!str_cmp(arg2, "remove")) {
if (arg3.empty()) {
victim->pcdata->quest_points = victim->pcdata->quest_points - 1;
ch->printf("Removing one quest point from %s.\r\n", victim->name);
victim->save();
return;
} else if ((value < 1) || (value > 1000)) {
ch->printf("You must enter a number between 1 and 1000");
return;
} else {

victim->pcdata->quest_points = victim->pcdata->quest_points - value;
ch->printf("Removing %d quest points from %s.\r\n", value, victim->name);
victim->save();
return;
}
} else {
ch->print("Syntax: qpset \r\n");
ch->print("Example qpset Player1 add, will just add one to quest points\r\n\n");
ch->print("Syntax: qpset #\r\n");
ch->print("Example qpset Player1 add 5, will add five to quest points\r\n\n");
return;
}

return;
}

Then go to the system folder and find commands.dat
Then right below pclist add

#COMMAND
Name qpset
Code do_qpset
Position dead
Level 101
Log normal
Flags ghost
End

You can change the level to be whatever you want it to be for your mud

Post is unread #2 Aug 28, 2012 2:21 pm   
Go to the top of the page
Go to the bottom of the page

Sherm
Fledgling
GroupMembers
Posts33
JoinedDec 20, 2010

 
If anyone finds a mistake here let me know.

Post is unread #3 Sep 3, 2012 2:25 pm   Last edited Sep 3, 2012 2:29 pm by Andril
Go to the top of the page
Go to the bottom of the page

Andril
Magician
GroupMembers
Posts147
JoinedJun 9, 2009

 
In which class, pc_data or char_data, are you sticking quest_points? You don't specify, and in fact seem to be saying add it in two places.
This is a problem as you're adding the quest_points, when loading a char, to pc_data, also setting them to pc_data in do_qpset, but getting
the amount from char_data. Make up your mind.
It would probably make sense to put it in pc_data, but if you're going to do that make sure your get_quest_points function in char_data is pulling
that value from pcdata somehow. And also checking for whether or not the ch in question is a mob.

Also, your loading addition, use the KEY macro, not that sscanf stuff.

The following version of your do_qpset command is more dealing with style than any real errors in the code itself.
CMDF(do_qpset) {
   // If you're going to outright forbid mobs from doing this, not saying you shouldn't,
   // then you should probably check here, before doing any other work, just to prevent
   // any unnecessary function calls and stuff. Save your CPU cycles. -- Andril

   // mobs should not be able to set quest points 
   if (ch->isnpc()) {
      ch->print("Mob's can't qpset\r\n";
      return;
   }

   /*string origarg = argument;*/ // What was the point of this? It's not used anywhere -- Andril

   ch->set_color(AT_IMMORT);

   // Personal pet peeve of mine, the multiple args are not, usually, necessary.
   // Or you have more than are needed, both of which is the state in this case.
   // Simply move the calls to one_argument to appropriate spots based on what
   // you're checking next.
   // See the C++ Faq, item 27.7 -- Andril

   // Get target player first. If the target doesn't exist it doesn't matter
   // what you supply as arguments, you won't be going any further anyway...
   string arg;
   argument = one_argument(argument, arg);

   char_data *victim;
   // checking to make sure the player is online 
   if (!(victim = ch->get_char_world(arg))) {
      ch->print("They don't seem to be around.\r\n";
      return;
   }

   argument = one_argument(argument, arg);  // Reuse arg. Already have target player.
   /*argument = one_argument(argument, arg2);*/ // Why bother with an arg2? Just use argument.

   // You say that number of quest points is optional, but you give a bad syntax error message if it's not provided
   if (arg.empty() /*|| argument.empty()*/ ) {
      ch->print("Syntax: qpset  \r\n";
      ch->print("Example qpset Player1 add, will just add one to quest points\r\n\n";
      ch->print("Syntax: qpset   #\r\n";
      ch->print("Example qpset Player1 add 5, will add five to quest points\r\n\n";
      return;
   }

   // I would suggest thinking about checking for whether argument is a number or not first
   // Not strictly necessary though I guess.
   int value = 1; // default add/remove number if no value supplied -- Andril
   if( is_number(argument) )
      value = atoi(argument.c_str());

   // Check if you have a valid value amount here. There was no need to do this
   // more than once as you were. -- Andril
   if ( value < 1 || value > 1000 ) {
      ch->printf("You must enter a number between 1 and 1000";
      return;
   }

   if (!str_cmp(arg1, "add") {
      // We've already guaranteed we have a valid amount to add. Why do two separate checks? -- Andril
      /*victim->pcdata->quest_points = value + victim->pcdata->quest_points;*/ // Blech! :)
      victim->pcdata->quest_points += value; // Much cleaner. Nothing wrong with the above, just not as nice -- Andril
      ch->printf("Setting %d quest points on %s.\r\n", value, victim->name);
      victim->save();
   } else if (!str_cmp(arg1, "remove") {
      victim->pcdata->quest_points -= value;

      // Make sure their quest point count doesn't go negative. Important! -- Andril
      if( victim->pcdata->quest_points < 0 )
         victim->pcdata->quest_points = 0;

      ch->printf("Removing %d quest points from %s.\r\n", value, victim->name);
      victim->save();
   } else {
      ch->print("Syntax: qpset  \r\n";
      ch->print("Example qpset Player1 add, will just add one to quest points\r\n\n";
      ch->print("Syntax: qpset   #\r\n";
      ch->print("Example qpset Player1 add 5, will add five to quest points\r\n\n";
   }
   // None of the return statements were, strictly speaking, necessary due to the
   // use of the if else chain. Doesn't hurt, but again, if you're going to do things
   // this way it's not needed. Especially not the final one. You do not need a
   // return statement at the end of a void function. -- Andril
}


Strip out all of my comments and the code is, IMO, much cleaner overall. Less useless stuff and much more concise. Yours had 81 lines total, mine has 56.
Just some things to keep in mind really. Your version should work with no problems as far as I can tell, you're just needlessly doing a lot of stuff multiple times.

Edit:
Also, "\r\n\n" is bad. Stick another \r in there, in the error messages, so it's \r\n\r\n.

Post is unread #4 Sep 4, 2012 7:01 am   
Go to the top of the page
Go to the bottom of the page

Sherm
Fledgling
GroupMembers
Posts33
JoinedDec 20, 2010

 
Thanks for the input Andril. Thanks for the advice.

Pages:<< prev 1 next >>