Lesson 4: common commands

This lesson is going to be fairly mixed.  It'll mostly be common commands, and I'll throw in a little theory to help with the commands.  At the end, we'll look at the score command, and you all can write your own and send it to me.

Big question:  what the heck is the "->" thing and when do I use it?

Now we get into a little mud theory.  In coding some things, you may have noticed the "inherit BLAH;" bit.  Inheriting is kinda like classifying what you're coding.  For instance:  all living things can fight and emote.  that includes players and monsters.  that code is in the living.c file.  but only players save, quit, etc, so there's a user.c file for them.  so...  the user.c file 'inherits' the living.c, which allows us to fight, and our actual charaters 'inherit' user.c which gives us our user commands.

So what does inheritance have to do with the -> thingy?  well, you can call functions that are in something's inherit file.  in the user inherit file is the set_guild() function.  to access that funcion, I have to say what user (this_player()), and then what funcion I'm calling (set_guild()).  set_guild() needs a string, so here's how it looks all together:

this_player()->set_guild(Nightshady);

here's a few command in the user file you may want to call (most are self explanitory)

query_race()
query_stats(strength)
query_level()
query_guild()
query_gender()
query_cap_name()  (returns their capitalized name)
set_hp()
set_money()
set_sp()
add_hp()
add_money()

and so on...  if you want to remove something, let's say money, just add_money(-100)

some commands you may also need to know to do the score command are:

write("blah");    (writes whatever's in the "s to the current player)

sprintf();      (I know that the current score code uses it, but I wouldn't reccommend it unless you're a sadist :P)

message("info","blah",this_player())   (that does the same thing as the write above...  the last part lets you specify who gets the message)

arrange_string(str, 50)       (this one's kinda hard to explain..  it takes string str, and adds spaces to the end of it so that it equals 50 length (or whatever number you give))
This is useful for making things look nice...  I'll give an example.  let's say I want to do something like in finger and I want it to look like this:

Name: Nightshade           Level: 5000

people's names are going to vary...  so we'll want 21 spaces filled up...  so you'd want to do arrange_string(name, 21); which would add enough spaces to push the "Level:" bit to it's proper place.

------------------------------------------------------------

Ok..  now for the fun part.  YOU get to write the new score command.  I'm going to either combine what people do, or just take the best one and put it into the game.  Here's a tip on making it look really good:

Before you start coding, write out how you want it to look.  for instance:

---------Score------------------
Name: Nightshade
Experience: 0
Quests: 5
--------------------------------
You are drunk off your rocker.
Married: Shy'lo

Strength: 200      Wisdom:       300
Charisma: 9999     Intelligence: 400
blah blah blah blah
----------------------------------

And so on...  Basically, just plan it.  And a tip (I used this for both finger and who):

make a string which will be kinda the "master", and just add to it..  for instance:

string master;

master = "--------Score--------------------\n";
master += "Name: ";
master += this_player->query_cap_name();

and so on...   the += thing adds something to the end of a string.  Also, if you put \n in a string, it starts a new line, but it's still in the same string.  That's about it...  Good luck!

------------------------------------------------------------------

(This is the current code for score for reference.  If you have any questions, just ask me :))

#include <std.h>

inherit DAEMON;

int cmd_score(string str) {
   string rank, foo, name, title, Class, race;
   int sp, max_sp;
   int level, hp, max_hp, mp, max_mp, age;
   int exp, next_exp;

   if(this_player()->query_ghost()) {
        notify_fail("You cannot do that in an immaterial state.\n");
        return 0;
   }
   if(str) {
        notify_fail("See also <skills> and <stats>\n");
        return 0;
   }
   name = (string)this_player()->query_cap_name();
   title = (string)this_player()->query_title();
   Class = (string)this_player()->query_class();
   race = (string)this_player()->query_race();
   level = (int)this_player()->query_level();
   exp = (int)this_player()->query_exp();
   hp = (int)this_player()->query_hp();
   max_hp = (int)this_player()->query_max_hp();
   sp = (int)this_player()->query_sp();
   max_sp = (int)this_player()->query_max_sp();
   mp = (int)this_player()->query_mp();
   max_mp = (int)this_player()->query_max_mp();
   age = time() - (int)this_player()->query_birthday();
    message("status", sprintf("You are %s (%s) (%s)", title,
      (string)this_player()->query_al_title(), 
      (string)this_player()->query_race()), this_player());
   write("You are level " + level + " with " + exp + " experience.");
   write("You have:");
   write(hp+" ("+max_hp+") health points, "+sp+" ("+max_sp+") "+
     "stamina points, and "+mp+" ("+
         max_mp + ") magic points.");
   if((int)this_player()->query_intox()) {
        if((int)this_player()->query_intox() > 420) write("You are FUBAR");
        else if((int)this_player()->query_intox() > 300) 
            write("You are smashed out of your gourd");
        else if((int)this_player()->query_intox() > 180)
            write("You are quite drunk");
        else if((int)this_player()->query_intox() > 90) 
            write("You are drunk");
        else if((int)this_player()->query_intox() > 36) 
            write("You are tipsy");
        else write("You are buzzed");
   }
    else message("info", "You are sober"+
      (this_player()->query_stuffed() ? " and not hungry" : "")+
      (this_player()->query_quenched() ? " and not thirsty" : "")+".",
      this_player());
    if(this_player()->query_poisoning())
      message("info", "You are poisoned.", this_player());
   write("You are " + (18 + (age/4320000)) + " years old.");
   return 1;
}                                            

void help() {
    write("Syntax: <score>\n\n"
          "This command gives you information about your character.\n"
          "See also: status, body, biography, skills, stats, money, inventory\n"
    );
}

