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

Offline capo

  • Friend
  • **
  • Posts: 70
    • View Profile
Yes/No in Teach verb
« on: September 18, 2006, 06:14:31 pm »
Tig made the suggestion, which I think might be the best for now, to use input_to.  Im really confused on how to use input_to inside of a verb.... this is what I have, but it does not work correctly... at all.. Could someone please take a look at this and help me fix it?



code:

/*    /verbs/players/teach.c
 *    teach
 *    teach LIV WRD
 *    created by Capo of Haven_RPG
 */

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

inherit LIB_SENTIENT;
inherit LIB_VERB;

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

mixed can_teach_liv_wrd()
{
    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;
}

void input_to( string string ){
 object target;
 object who;
 who = this_player();

send_messages("", "%^BOLD%^BLUE%^$agent offers to teach $target a spell!", who, target,env);

 if(string == "no")
    {
     send_messages("", "%^BOLD%^BLUE%^$target declines the offer to learn a spell!", who, target,env);
     return 0;
    }

 if(string == "yes")
    {
    send_messages("", "%^BOLD%^BLUE%^$agent offers to teach $target a spell!", who, target,env);
    return 1;
    }

mixed do_teach_liv_wrd(object target, string spell)
{
  mapping myspells;
  string spells;
  object who;

  who = this_player();

  if(!SPELLS_D->GetSpell(spell))
     {
         eventForce("say I'm sorry, that is not a spell I can teach you.");
         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;
     }
     write("You teach your student the spell.");
     return 1;
}


Offline tigwyk

  • Acquaintance
  • *
  • Posts: 45
    • View Profile
Yes/No in Teach verb
« Reply #1 on: September 18, 2006, 07:13:12 pm »
I'm working on a fix for this. I'll post it when I get it working at all. ;)

Offline tigwyk

  • Acquaintance
  • *
  • Posts: 45
    • View Profile
Yes/No in Teach verb
« Reply #2 on: September 18, 2006, 10:50:45 pm »
Okay, I've edited the thing to work properly, except it still doesn't properly ask the user because their input is not accepted, as far as I could see. It does teach properly though. I've commented out the input_to stuff, just so you can paste this in and get the teach verb working properly at first.



LPC code:

/*    /verbs/players/teach.c
 *    teach
 *    teach LIV WRD
 *    created by Capo of Haven_RPG
 *      edited by Tigwyk@LP Heroes [09/18/06]
 */

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

inherit LIB_SENTIENT;
inherit LIB_VERB;

//mixed yes_no( string str, object target );

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

mixed can_teach_liv_str()
{
      
    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 "You have to teach someone.";
}

mixed can_teach_liv()
{
   return "You have to teach something to someone.";
}

/*
mixed yes_no( string str, object target ){
 object who,env;
 who = this_player();
 env = environment(this_player());
 if(str == "no")
    {
     send_messages("decline", "$target_name $target_verb the offer to learn a spell!", who, target,env);
     return 0;
    }

 if(str == "yes")
    {
    send_messages("offer", "$agent_name $agent_verb to teach $target_name a spell!", who, target,env);
    return 1;
    }
}
*/

mixed do_teach_liv_str(object target, string spell)
{
     mapping myspells;
  string spells;
  object who,env;
  env = environment(this_player());
  who = this_player();
 
  debug("do_teach_liv_str() arrived");
 
  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);
     /*
     tell_object(target, "Do you accept? [yes/no]");
     input_to( (: yes_no :), target);
     */
}




Voila. You also need to add this to living.c



LPC code:

mixed direct_teach_liv_str() { return 1; }




Update both, update everything you possibly can, and voila.

Offline capo

  • Friend
  • **
  • Posts: 70
    • View Profile
Yes/No in Teach verb
« Reply #3 on: September 19, 2006, 06:32:25 am »

Thanks a lot, I woke up and started working on this without looking for your reply...  I tried yours out, took out the comments, and this is what happens:



From the teacher's point of view: (continuous, no breaks)



> teach tester orb

DEBUG:  /verbs/players/teach

 "can_teach_liv_str() returning 1"

DEBUG:  /verbs/players/teach

 "do_teach_liv_str() arrived"

You teach Tester a spell!



From the student's point of view:





Capo teaches you a spell!

Do you accept? [yes/no]

yes

Try "help commands" for a list of some commands.



What were we missing?


Offline capo

  • Friend
  • **
  • Posts: 70
    • View Profile
Yes/No in Teach verb
« Reply #4 on: September 19, 2006, 06:36:28 am »

Ah hah... yes_no is pointing to the teacher, not the student:





> teach tester buffer

DEBUG:  /verbs/players/teach

 "can_teach_liv_str() returning 1"

DEBUG:  /verbs/players/teach

 "do_teach_liv_str() arrived"

You teach Tester a spell!

no

Tester declines the offer to learn a spell!



Capo teaches you a spell!

Do you accept? [yes/no]

You decline the offer to learn a spell!


Offline capo

  • Friend
  • **
  • Posts: 70
    • View Profile
Yes/No in Teach verb
« Reply #5 on: September 19, 2006, 03:05:28 pm »

Hmm.. All of my efforts to switch the actual yes/no choice (rather than just the text) to the target have failed.



Any idears?


Offline cratylus

  • Your favorite and best
  • Administrator
  • ***
  • Posts: 1022
  • Cratylus@Dead Souls <ds> np
    • View Profile
    • About Cratylus
Yes/No in Teach verb
« Reply #6 on: September 19, 2006, 03:17:48 pm »
Arr! Be ye sure the lead/follow code be not a good example?

Offline capo

  • Friend
  • **
  • Posts: 70
    • View Profile
Yes/No in Teach verb
« Reply #7 on: September 19, 2006, 03:29:18 pm »
Avast! Im not sure how to use the lead/follow with this.  It be a slimey barnacle!

Offline cratylus

  • Your favorite and best
  • Administrator
  • ***
  • Posts: 1022
  • Cratylus@Dead Souls <ds> np
    • View Profile
    • About Cratylus
Yes/No in Teach verb
« Reply #8 on: September 19, 2006, 03:39:43 pm »

If I understand you correctly, you want an action from player 1

to give player 2 a prompt, "accept? yes/no"



I would suggest that input_to is not a nice way to do it,

even if it were possible. I could walk up to someone

I don't like while they're busy and then jam them up with

my offer, which hoses up their next command.



Fortunately, it doesn't look like input_to is something you can

use conveniently here, so that option isn't really available.



When you want to follow someone, they have the option

of "leading" you. If you "follow bert", and then bert

types "lead ernie", then it's less likely bert will accidentally

lose ernie while running around.



This is a kind of "offer/response" code that is much more

polite. It doesn't force the recipient to have the next command

be yes/no.



Similarly, the party system enables you to invite someone to

join the party. They have a set period of time to accept, otherwise

they lose the opportunity.



Again, an offer/response system that works, but doesn't

inconvenience the second person.



I would urge you to examine the code for the verbs lead,

follow, and party, to see how things are done there.


Offline capo

  • Friend
  • **
  • Posts: 70
    • View Profile
Yes/No in Teach verb
« Reply #9 on: September 19, 2006, 04:21:07 pm »

Crat,  I know you feel very strongly that I should use the party/lead system, it's just that I look at it and it makes absolutely no sense to me with what I want to do.  



GAH! Just frustrated with this.


Offline capo

  • Friend
  • **
  • Posts: 70
    • View Profile
Yes/No in Teach verb
« Reply #10 on: September 19, 2006, 04:39:58 pm »
Gah, frustration! Im not sure how to form the "teaching party", make it disband after the skill is taught, AND more importantly I do not know what syntax I should use for the rules....  If you could help me out here I would greatly appreciate it.  This is what I have so far:



code:



#pragma save_binary

#include <lib.h>
#include <daemons.h>
#include "include/party.h"

inherit LIB_VERB;

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

int livings_are_remote() { return 1; }

mixed can_teach_wrd_wrd(string cmd, string party)
   {
    if( !cmd || !party ) return 0;
    if(cmd == "invite")
   {
   if(!party || !present(party,environment(this_player())))
   {
       return "That person isn't here.";
   }
   if(!living(present(party,environment(this_player()))))
   {
       return "That is not a living thing.";
   }
    }
    switch(cmd)
   {
    case "start":
   return (mixed)PARTY_D->CanCreateParty(this_player(), party);

    case "accept":
   return (mixed)PARTY_D->CanJoinParty(this_player(), party);

    default:
   return "It doesn't work that way.";
    }
}

mixed can_party_wrd_liv(string cmd) {
    if( !cmd ) return 0;    
    switch(cmd) {
    case "invite":
   return 1;

    default:
   return "That is an unknown party action.";
    }
}

mixed do_party_wrd(string cmd)
{
    switch(cmd) {
    case "disband":
   return (mixed)PARTY_D->eventRemoveParty(this_player());

    case "leave":
   return (mixed)PARTY_D->eventLeaveParty(this_player());
    }
}

mixed do_party_wrd_wrd(string cmd, string party) {
    switch(cmd) {
    case "start":
   return (mixed)PARTY_D->eventCreateParty(this_player(), party);

    case "accept":
   return (mixed)PARTY_D->eventJoinParty(this_player(), party);
    }
}

mixed do_party_wrd_liv(string cmd, object targ)
{
    mixed foo;
    mapping myspells;
    string spells;
    object who,env;
   object target;
   string spell;
    env = environment(this_player());
    who = this_player();
   myspells = target->GetSpellBook();
   
   switch(cmd)
   {
    case "invite":
   foo = (mixed)PARTY_D->CanInviteMember(this_player(), targ);
   if(!SPELLS_D->GetSpell(spell))
      {
         write("You can't teach that.");
         return 1;
      }
    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;
        }
   break;
    default:
   return "You fail to do that.";
       }
}



Offline cratylus

  • Your favorite and best
  • Administrator
  • ***
  • Posts: 1022
  • Cratylus@Dead Souls <ds> np
    • View Profile
    • About Cratylus
Yes/No in Teach verb
« Reply #11 on: September 19, 2006, 04:51:56 pm »

Ok, then make it simpler.



Player 1 (foo) types: teach bleh to bar



Player 2 (bar) sees: Foo wants to teach you bleh.



Player 2 types: learn bleh from foo



And then the lesson begins.



The quickest, off the cuff way that occurs to me

is something like this:



the teach verb adds this property to foo:



foo->SetProperty("teaching" , ({ "bar","bleh", time() }));



meaning "I am offering to teach bleh to bar, and began at this time"



the verb also sends the meesage to bar telling him

what foo is trying to do.l



Bar can then "learn bleh from foo". The learn

verb would do something like



mixed *Lesson = teacher->GetProperty("teaching");



if(Lesson[0] != this_player()->GetName()) write("no");

etc and so on.

After the appropriate checks, then the learn verb would

initiate the learning preocess by triggering your new

Teach Someone Something function, whereverit is you put it.



The time() thing is so you can set a limit on how long that

offer is valid, and of course, you'll want to make sure

the dudes are in the same room, etc.



This is a general, rough idea of a simple way to do it.



Does that make sense?



Offline capo

  • Friend
  • **
  • Posts: 70
    • View Profile
Yes/No in Teach verb
« Reply #12 on: September 19, 2006, 08:27:45 pm »
It makes sense, but Im still not getting it code wise... This is what I have so far, could you please correct it?



code:


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

inherit LIB_SENTIENT;
inherit LIB_VERB;

//mixed yes_no( string str, object target );

static void create()
{
    verb::create();
    SetVerb("teach");
    SetRules("","STR to LIV");
    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)
{
    class teach this_session;
    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)
{
    class teach this_session;
    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 capo

  • Friend
  • **
  • Posts: 70
    • View Profile
Yes/No in Teach verb
« Reply #13 on: September 20, 2006, 07:21:04 am »
I've been working on it more with no sucess, but a lot of errors, any ideas?



code:


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

inherit LIB_SENTIENT;
inherit LIB_VERB;

static void create()
{
    verb::create();
    SetVerb("teach");
    SetRules("","STR to LIV");
    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)
{
    class teach this_session;
    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)
{
    class teach this_session;
    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 capo

  • Friend
  • **
  • Posts: 70
    • View Profile
Yes/No in Teach verb
« Reply #14 on: September 20, 2006, 07:32:02 am »
Hmm these are the errors I get:



> update teach.c

/verbs/players/teach.c line 43: Undefined class 'teach'

   

/verbs/players/teach.c line 47: Undefined variable 'Teach'

   

/verbs/players/teach.c line 48: No class in scope has no member 'Invited'

   

/verbs/players/teach.c line 48: Illegal lvalue

   

/verbs/players/teach.c line 49: Undefined variable 'RemoveInvitiation'

   

/verbs/players/teach.c line 49: syntax error

   

With this code:



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)
{
    class teach this_session;
    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)
{
    class teach this_session;
    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);
}





Heeeelp. :'-(