Author Topic: advance attached to an item in the inventory  (Read 2941 times)

Offline WilliamOfKingmud

  • Acquaintance
  • *
  • Posts: 4
    • View Profile
advance attached to an item in the inventory
« on: May 27, 2009, 07:59:57 pm »
I am trying to have the functionality of "ask dirk to advance" on an item "ask seal to advance".

It is not necessarily important to have to ask the seal to advance. if I could set it to an action done by the player such as polish seal that would be great.

the code I have is taken directly from dirk and is...
Code: [Select]
// The advancemet item.
// this item allows you to ask it to advance your level.

#include <lib.h>
#include <vendor_types.h>
#include <daemons.h>
#include <function.h>
#ifndef REQUIRE_QUESTING
#define REQUIRE_QUESTING 1
#endif

inherit LIB_ITEM;


int AdvanceDude(mixed arg);
mapping advancement, Levels;
int counter;


static void create(){
    ::create();
    SetKeyName("An intricate looking seal");
    SetId( ({"seal","symbol",}) );
    SetAdjectives( ({"intricate"}) );
    SetShort("The test Seal");
    SetLong("TEST SEAL");
    SetPreventDrop(0);
    SetMass(2);
    set_heart_beat(1);
    counter = 0;
    Levels = PLAYERS_D->GetLevelList();
    advancement = ([]);   
}



void init(){
    ::init();
    add_action("lvlAdvance","advance");
    if(living(environment())){
        victim = environment();
    }
}

int AdvanceDude(mixed arg){
    int level,xp,qp;
    int desired_level,required_xp,required_qp;
    mixed *statlist;
    mapping this_stat;
    int statclass, statlevel, i;

    statlist = this_player()->GetStats();

    if(this_player()->GetKeyName() == "guest"){
        this_object()->eventForce("say I don't promote temporary players.");
        return 1;
    }

    if(!level = this_player()->GetLevel()){
        this_object()->eventForce("say You are confusing me.");
        return 1;
    }

    if(level > 19){
        this_object()->eventForce("say Whoa there, big "
                "stuff. Advancement past level 20 is the "
                "purview of the Trans-Human Elder Guild. "
                "I'm sorry but I can't help you.");
        return 1;
    }

    xp = this_player()->GetExperiencePoints();
    if(!qp = this_player()->GetQuestPoints()) qp = 0;
    desired_level = level+1;
    required_xp = advancement[desired_level]["xp"];
    if(!required_qp = advancement[desired_level]["qp"]) required_qp = 0;
    if(!REQUIRE_QUESTING) required_qp = 0;
    this_object()->eventForce("say Level "+desired_level+" "
            "with the title of \""+advancement[desired_level]["title"]+"\" "
            "requires "+required_xp+" experience points and "+
            required_qp+" quest points.");

    if( xp > required_xp-1 && qp > required_qp-1){
        this_object()->eventForce("say Congratulations! "
                "You are promoted to level "+desired_level+" and "
                "have earned the name "+this_player()->GetName()+" "
                +advancement[desired_level]["title"]+".");

        this_player()->ChangeLevel(desired_level);
        this_player()->AddTrainingPoints(desired_level);
        this_player()->AddTitle(advancement[desired_level]["title"]);
        this_player()->RemoveTitle(advancement[desired_level-1]["title"]);

        this_player()->save_player((string)this_player()->GetKeyName());

        if(level == MAX_NEWBIE_LEVEL){
            write("\nDirk raises his hand and sternly points to you.\n");            say("\nDirk raises his hand and sternly points to "+
                    this_player()->GetName()+".\n");
            this_object()->eventForce("say "+this_player()->GetName()+","+
                    " you are no longer a newbie. From now on, you will need"+
                    " a light source to see in the dark. From now on, you will"+
                    " not understand languages you haven't learned. You have"+                    " earned this promotion, and now face the future as a"+
                    " real adventurer.");
        }

        return 1;
    }
    else this_object()->eventForce("say I'm sorry, "+
            this_player()->GetName()+", but you have not "
            "fulfilled all the requirements of level "+
            desired_level+". Please come back and try "
            "again once you have fulfilled them.");
    return 0;}
string GetLevelTitle(int level){
    if(!level) level = 1;
    return advancement[level]["title"];
}

Up to this point it will allow me to update it successfully. I realize I will run into other complications once I get it to go into int AdvanceDude(mixed arg){

My concern at this point is that I can't get it to make the call to run the AdvanceDude code. The way it is accomplished on dirk is with
Code: [Select]
SetCommandResponses( ([
                "advance": (: AdvanceDude :)
                ]) );

This will not work with my item because it is not inheriting LIB_SENTIENT; which I have alos tried but get the error too many global vars.
 
I am sure there is a simple way to make a call to AdvanceDude that I am not thinking of any feed back on this would be welcome.

Offline Nulvect

  • BFF
  • ***
  • Posts: 127
    • View Profile
Re: advance attached to an item in the inventory
« Reply #1 on: May 27, 2009, 08:56:22 pm »
If you change this line inside init():
Code: [Select]
    add_action("lvlAdvance","advance");

To this:
Code: [Select]
    add_action("AdvanceDude","advance");

It should work. Check your man page for add_action, but basically, this makes it so when you type "advance blah" it calls AdvanceDude("blah"). (Just "advance" will send it an empty string which is fine in this case.) The AdvanceDude function returns 1 to mean it was the correct command and the mud should stop processing, or 0 to mean it was the wrong command and the mud should continue looking for the advance command elsewhere.

As you hinted, you'll need to change all those eventForce() lines to write()s or message()s. You should probably use return notify_fail("You can't advance!\n") rather than plain old return 0, to give a default failure message.

One last thing: Dead Souls has a very nice verb system which you should probably look into, especially if any of the above sounded weird to you. The add_action system is fraught with problems, and verbs generally get around them.

Offline WilliamOfKingmud

  • Acquaintance
  • *
  • Posts: 4
    • View Profile
Re: advance attached to an item in the inventory
« Reply #2 on: May 27, 2009, 10:46:03 pm »
great thanks!! that worked I was able to get it to advance the level. I replaced all occurrences of eventForce with write but I do not get any messages at all. is there something I am missing?

Offline Nulvect

  • BFF
  • ***
  • Posts: 127
    • View Profile
Re: advance attached to an item in the inventory
« Reply #3 on: May 28, 2009, 12:36:55 am »
My best guess is that you're doing this_object()->write(). If this is the case, just use write(). If not, I don't know.

Offline WilliamOfKingmud

  • Acquaintance
  • *
  • Posts: 4
    • View Profile
Re: advance attached to an item in the inventory
« Reply #4 on: May 28, 2009, 10:24:25 am »
ok I got the write messages to work they were missing the \n s. you can see it in the code below. is there any reason why this would not work for a normal player but would work for my creator?

Code: [Select]
include <daemons.h>
#include <function.h>
#ifndef REQUIRE_QUESTING
#define REQUIRE_QUESTING 1
#endif

inherit LIB_ITEM;


int AdvanceDude(mixed arg);
mapping advancement, Levels;
int counter;


static void create(){
    int i;
    ::create();
    SetKeyName("An intricate looking seal");
    SetId( ({"seal","symbol",}) );
    SetAdjectives( ({"intricate"}) );
    SetShort("The test Seal");
    SetLong("TEST SEAL");
    SetPreventDrop(0);
    SetMass(2);
    set_heart_beat(1);
    counter = 0;    Levels = PLAYERS_D->GetLevelList();
    advancement = ([]);
   
    for(i=0;i<21;i++){
        advancement[i] = Levels[i];
    }   
}



void init(){
    ::init();
    add_action("AdvanceDude","advance");
   
}

int AdvanceDude(mixed arg){
    int level,xp,qp;
    int desired_level,required_xp,required_qp;
    mixed *statlist;
    mapping this_stat;
    int statclass, statlevel, i;

    statlist = this_player()->GetStats();

    if(this_player()->GetKeyName() == "guest"){
        write("say I don't promote temporary players.");
        return 1;
    }

    if(!level = this_player()->GetLevel()){
        write("\nContact and admin.\n");
        return 1;
    }

    //if(level > 19){
      //  write("\n Whoa there, big "
        //        "stuff. Advancement past level 20 is the "
          //      "purview of the Trans-Human Elder Guild. "
            //    "I'm sorry but I can't help you.");
        //return 1;
    //}
   
    xp = this_player()->GetExperiencePoints();
    if(!qp = this_player()->GetQuestPoints()) qp = 0;
    desired_level = level+1;
    required_xp = advancement[desired_level]["xp"];
    if(!required_qp = advancement[desired_level]["qp"]) required_qp = 0;
    if(!REQUIRE_QUESTING) required_qp = 0;
        write("\nLevel "+desired_level+" with the title of \""+advancement[desired_level]["title"]+"\" requires "+required_xp+" experience points and "+required_qp+" quest points.\n");
    if( xp > required_xp-1 && qp > required_qp-1){
        write("\nCongratulations! You are promoted to level "+desired_level+" and have earned the name "+this_player()->GetName()+""+advancement[desired_level]["title"]+".\n");

        this_player()->ChangeLevel(desired_level);
        this_player()->AddTrainingPoints(desired_level);
        this_player()->AddTitle(advancement[desired_level]["title"]);
        this_player()->RemoveTitle(advancement[desired_level-1]["title"]);

        this_player()->save_player((string)this_player()->GetKeyName());

        if(level == MAX_NEWBIE_LEVEL){
            write("\nThe KingSeal Pulses and grows.\n");           
            write("\n"+this_player()->GetName()+", you are no longer a newbie. From now on, you will need a light source to see in the dark.");

//From now on, you will"+
                    //" not understand languages you haven't learned. You have"+ " earned this promotion, and now face the future as a"+  " real adventurer.");
        }

        return 1;
    }
    else write("\nI'm sorry, "+this_player()->GetName()+", but you have not fulfilled all the requirements of level "+ desired_level+". Please try again once you have fulfilled them.\n");
    return 0;}
string GetLevelTitle(int level){
    if(!level) level = 1;
    return advancement[level]["title"];
}

works fine with my admin. but when I type in advance with a players character I get the type help commands error. any thoughts?