Author Topic: Yes/No in Teach verb  (Read 6542 times)

Offline capo

  • Friend
  • **
  • Posts: 70
    • View Profile
Yes/No in Teach verb
« Reply #15 on: September 20, 2006, 07:45:46 am »
Per Detah's suggestion I began to switch to mappings: (Still no love though)



code:


#include <lib.h>
#include <daemons.h>
#include <position.h>

inherit LIB_SENTIENT;
inherit LIB_VERB;

mapping teach;

static void create()
{
    verb::create();
    SetVerb("teach");
    SetRules("","STR to LIV");
    teach = ([]);
    SetErrorMessage("Syntax: teach <%^BOLD%^%^CYAN%^ability%^RESET%^> to (%^BOLD%^%^ORANGE%^player%^RESET%^)");
    SetHelp("Syntax: teach <%^BOLD%^%^CYAN%^ability%^RESET%^> to (%^BOLD%^%^ORANGE%^player%^RESET%^)\n"
      "This command allows you to teach another player an ability, spell, or skill.\n\n");
}

mixed can_teach_str_to_liv()
{
    int pos = this_player()->GetPosition();

    if( (int)this_player()->GetParalyzed() ) {
        return "You cannot move!";
    }
    if( pos == POSITION_SITTING || pos == POSITION_LYING &&
      !RACES_D->GetLimblessCombatRace(this_player()->GetRace()) ){
        return "You cannot teach in that position!";
    }
    debug("can_teach_liv_str() returning 1");
    return 1;
  }

mixed can_teach()
{
        return "Syntax: teach <%^BOLD%^%^CYAN%^ability%^RESET%^> to (%^BOLD%^%^ORANGE%^player%^RESET%^)\n";
}

mixed eventTeachPlayer(object who, object target)
{
    mapping teach;
    string name;

    name = (string)who->GetTeach();
    this_session = teach[name];
    this_session->Invited += ({ target });
    call_out((: RemoveInvitiation :), 60, name, target);
    targ->eventPrint("You have been invited to learn an ability you have one minute to
                         "accept.", MSG_SYSTEM);
    return 1;
}

mixed eventAccept(object who, string name)
{
    mapping teach;
    mixed tmp;

    this_session = teach[name];
    this_session->Invited -= ({ who });
    this_session->Members += ({ who });
    CHAT_D->eventSendChannel("", name, (string)who->GetName() +
      " has accepted the offer to teach the skill");
    return do_teach_str_to_liv;
}

mixed do_teach_str_to_liv(object target, string spell)
{
  mapping myspells;
  string spells;
  object who,env;
  env = environment(this_player());
  who = this_player();

  if(!SPELLS_D->GetSpell(spell))
     {
         write("You can't teach that.");
         return 1;
     }

    myspells = target->GetSpellBook();

        if(myspells[spell])
         {
          write("Your student already knows that spell.");
          return 1;
     }
    if(!target->eventLearnSpell(spell))
     {
          write("Your student is incapable of learning that spell.");
          return 1;
          return 1;
     }
     send_messages("teach", "$agent_name $agent_verb $target_name a spell!", who, target,env);
}

Offline Aransus

  • Acquaintance
  • *
  • Posts: 2
    • View Profile
Yes/No in Teach verb
« Reply #16 on: September 20, 2006, 08:09:24 am »

A couple of things to keep in mind if you're converting from classes to mappings...



Definition:



(class) class teach this_session;

(mapping) mapping this_session = ([ ]); (not mapping teach)



Manipulation:



(class) this_session->Invited -= ({ who });

(mapping) this_session["Invited"] -= ({ who });



That's not going to fix everything, but it's a couple things worth noting for now. If you don't initialize the mappings, you'll get funky errors when you try to manipulate them.



-- Aransus


Offline capo

  • Friend
  • **
  • Posts: 70
    • View Profile
Yes/No in Teach verb
« Reply #17 on: September 20, 2006, 10:04:12 am »
Reqested code:



remove invitation



code:

static void RemoveInvitiation(string name, object who) {
    if( !teach[name] ) return;
    if( member_array(who, ((class teach)Teach[name])->Invited) == -1 )
        return;
    ((class teach)Teach[name])->Invited -= ({ who });
}







From living.c

code:


mixed direct_teach_liv_str() { return 1; }

mixed getteach(){ return 1;}


Lost and confusedly yours!

Offline capo

  • Friend
  • **
  • Posts: 70
    • View Profile
Yes/No in Teach verb
« Reply #18 on: September 20, 2006, 10:08:59 am »
code:


#include <lib.h>
#include <daemons.h>
#include <position.h>

inherit LIB_SENTIENT;
inherit LIB_VERB;

mapping teach;

static void create()
{
    verb::create();
    SetVerb("teach");
    SetRules("","STR to LIV");
    teach = ([]);
    SetErrorMessage("Syntax: teach <%^BOLD%^%^CYAN%^ability%^RESET%^> to (%^BOLD%^%^ORANGE%^player%^RESET%^)");
    SetHelp("Syntax: teach <%^BOLD%^%^CYAN%^ability%^RESET%^> to (%^BOLD%^%^ORANGE%^player%^RESET%^)\n"
      "This command allows you to teach another player an ability, spell, or skill.\n\n");
}

mixed can_teach_str_to_liv()
{
    int pos = this_player()->GetPosition();

    if( (int)this_player()->GetParalyzed() ) {
        return "You cannot move!";
    }
    if( pos == POSITION_SITTING || pos == POSITION_LYING &&
      !RACES_D->GetLimblessCombatRace(this_player()->GetRace()) ){
        return "You cannot teach in that position!";
    }
    debug("can_teach_liv_str() returning 1");
    return 1;
  }

mixed can_teach()
{
        return "Syntax: teach <%^BOLD%^%^CYAN%^ability%^RESET%^> to (%^BOLD%^%^ORANGE%^player%^RESET%^)\n";
}

mixed eventTeachPlayer(object who, object target)
{
    mapping teach;
    string name;

    name = (string)who->GetTeach();
    this_session = teach[name];
    this_session->Invited += ({ target });
    call_out((: RemoveInvitiation :), 60, name, target);
    targ->eventPrint("You have been invited to learn an ability you have one minute to
                         "accept.", MSG_SYSTEM);
    return 1;
}

mixed eventAccept(object who, string name)
{
    mapping teach;
    mixed tmp;

    this_session = teach[name];
    this_session->Invited -= ({ who });
    this_session->Members += ({ who });
    CHAT_D->eventSendChannel("", name, (string)who->GetName() +
      " has accepted the offer to teach the skill");
    return do_teach_str_to_liv;
}

mixed do_teach_str_to_liv(object target, string spell)
{
  mapping myspells;
  string spells;
  object who,env;
  env = environment(this_player());
  who = this_player();

  if(!SPELLS_D->GetSpell(spell))
     {
         write("You can't teach that.");
         return 1;
     }

    myspells = target->GetSpellBook();

        if(myspells[spell])
         {
          write("Your student already knows that spell.");
          return 1;
     }
    if(!target->eventLearnSpell(spell))
     {
          write("Your student is incapable of learning that spell.");
          return 1;
     }
     send_messages("teach", "$agent_name $agent_verb $target_name a spell!", who, target,env);
}





Offline tigwyk

  • Acquaintance
  • *
  • Posts: 45
    • View Profile
Yes/No in Teach verb
« Reply #19 on: September 20, 2006, 10:30:29 am »
Aha, Capo, in living.c you've got getteach(), but I believe functions are case sensitive, so you have to make sure it's GetTeach(). That may fix some things.

Offline cratylus

  • Your favorite and best
  • Administrator
  • ***
  • Posts: 1022
  • Cratylus@Dead Souls <ds> np
    • View Profile
    • About Cratylus
Yes/No in Teach verb
« Reply #20 on: September 20, 2006, 11:23:11 am »
I'm posting 4 files that will demonstrate the general idea
behind a call and response verb pair. This is not intended to
be seen as production quality code. This is demonstration
code. It doesn't check for things, doesn't account for whatifs.
It's a demonstration of functionality. It even probably has bugs.

if you put this code in yer mud, make sure to add

code:
inherit "/lib/teach";
inherit "/lib/learn";



to /lib/living.c

then: update -r /lib/creator

If it works, relogin any characters that will be tested.
Relogin your test char first.




/lib/learn.c

code:
#include <lib.h>

int direct_learn_str_from_liv(){ return 1;}
int direct_learn_to_str_from_liv(){ return 1;}

int CanLearn(){
    return 1;
}

int eventLearn(object who, string what){
    if(!CanLearn()){
   write("You can't learn that.");
   return 0;
    }
    who->eventTeach(this_player(),what);
    return 1;
}


/lib/teach.c

code:
#include <lib.h>

private static mapping Teaching = ([]);
private static int OfferExpires = 60;

int direct_teach_str_to_liv(){ return 1;}
int direct_teach_liv_to_str(){ return 1;}

int CanTeach(){
    return 1;
}

int eventOfferTeaching(object who, string what){
    if(!CanTeach()){
   write("You can't teach that.");
   return 0;
    }
    tell_player(who,this_object()->GetName()+" offers to teach you "+what+".");
    Teaching[who] = ({ what, time() });
    return 1;
}

int eventTeach(object who, string what){
    if(!CanTeach()){
   write("They can't teach that.");
   return 0;
    }
    if(!Teaching[who]){
   write("They're not interested in teaching you anything.");
   return 0;
    }
    if(time() - Teaching[who][1] > OfferExpires){
   write("It's too late. Their offer to teach you expired.");
   map_delete(Teaching,who);
   return 0;
    }
    if( !who->eventLearnSpell(what) ) {
   write("You are not prepared for that spell!");
   return 0;
    }

    who->eventPrint(this_object()->GetName() + " touches your forehead and gives "
      "you knowledge of " + what + ".");
    environment()->eventPrint(this_object()->GetName() + " touches " +
      possessive_noun(who) +
      " forehead and gives " +
      objective(who) + " knowledge of " +
      what + ".", who);
    map_delete(Teaching,who);
    return 1;
}


/verbs/players/learn.c

code:
#include <lib.h>
#include <daemons.h>
#include <position.h>

inherit LIB_VERB;

static void create()
{
    verb::create();
    SetVerb("learn");
    SetRules("","STR from LIV","to STR from LIV");
    SetErrorMessage("Syntax: learn <%^BOLD%^%^CYAN%^ability%^RESET%^> to (%^BOLD%^%^ORANGE%^player%^RESET%^)");
    SetHelp("Syntax: learn <%^BOLD%^%^CYAN%^ability%^RESET%^> to (%^BOLD%^%^ORANGE%^player%^RESET%^)\n"
      "This command allows you to learn from another player an ability, spell, or skill.\n\n");
}

mixed can_learn_str_from_liv(string str, object ob)
{
    int pos = this_player()->GetPosition();
    if( (int)this_player()->GetParalyzed() ) {
   return "You cannot move!";
    }
    if( pos == POSITION_LYING &&
      !RACES_D->GetLimblessCombatRace(this_player()->GetRace()) ){
   return "You cannot learn in that position!";
    }
    return 1;
}

mixed can_learn_to_str_from_liv(string str, object ob){
    return can_learn_str_from_liv(str, ob);
}

mixed can_learn()
{
    return "Syntax: learn <%^BOLD%^%^CYAN%^ability%^RESET%^> from (%^BOLD%^%^ORANGE%^player%^RESET%^)\n";
}

mixed do_learn_str_from_liv(string spell, object target){
    this_player()->eventLearn(target,spell);
    return 1;
}

mixed do_learn_to_str_from_liv(string spell, object target){
    return do_learn_str_from_liv(spell,target);
}


/verbs/players/teach.c
code:
#include <lib.h>
#include <daemons.h>
#include <position.h>

inherit LIB_VERB;

static void create()
{
    verb::create();
    SetVerb("teach");
    SetRules("","STR to LIV","LIV to STR");
    SetErrorMessage("Syntax: teach <%^BOLD%^%^CYAN%^ability%^RESET%^> to (%^BOLD%^%^ORANGE%^player%^RESET%^)");
    SetHelp("Syntax: teach <%^BOLD%^%^CYAN%^ability%^RESET%^> to (%^BOLD%^%^ORANGE%^player%^RESET%^)\n"
      "This command allows you to teach another player an ability, spell, or skill.\n\n");
}

mixed can_teach_str_to_liv(string str, object ob)
{
    int pos = this_player()->GetPosition();
    if( (int)this_player()->GetParalyzed() ) {
   return "You cannot move!";
    }
    if( pos == POSITION_SITTING || pos == POSITION_LYING &&
      !RACES_D->GetLimblessCombatRace(this_player()->GetRace()) ){
   return "You cannot teach in that position!";
    }
    return 1;
}

mixed can_teach_liv_to_str(object ob, string str){
    return can_teach_str_to_liv(str, ob);
}

mixed can_teach()
{
    return "Syntax: teach <%^BOLD%^%^CYAN%^ability%^RESET%^> to (%^BOLD%^%^ORANGE%^player%^RESET%^)\n";
}

mixed do_teach_str_to_liv(string spell, object target){
    this_player()->eventOfferTeaching(target,spell);
    write("You offer to teach "+spell+" to "+target->GetName()+".");
    tell_player(target,this_player()->GetName()+" offers to teach you "+spell+".");
    return 1;
}

mixed do_teach_liv_to_str(object target, string spell){
    return do_teach_str_to_liv(spell,target);
}

Offline capo

  • Friend
  • **
  • Posts: 70
    • View Profile
Yes/No in Teach verb
« Reply #21 on: September 20, 2006, 12:13:11 pm »
Perfect, I can definately work with this! Thank you!