Author Topic: Read Menu questions:  (Read 2570 times)

Offline Ashon

  • Acquaintance
  • *
  • Posts: 24
    • View Profile
    • http://talosmud.wordpress.com/
Read Menu questions:
« on: June 27, 2008, 11:43:30 am »
straight out of pub.c in Yslrim:

Code: [Select]
int readMenu(object who, string str) {
    string array tmp2 = ({});
    string array tmp = ({ sprintf("%:-20s %:-7s", "Drink", "Cost") });
    object ob = present("lars");

    if( !ob ) { // lars is dead!
        this_player()->eventPrint("The menu is too bloodstained to read.");
        return 1;
    }
    foreach(string *item in keys(ob->GetMenuItems())) {
        tmp += ({ sprintf("%:-20s %d electrum", capitalize(item[0]),
            to_int(ob->GetCost(item))) });
    }
    foreach(string element in tmp){
        element = translate(element,  this_player()->GetLanguageLevel("Edhellen"));
        tmp2 += ({ element });
    }
    tmp = tmp2;
    // show the menu a page at a time
    this_player()->eventPage(tmp, MSG_SYSTEM); // MSG_SYSTEM means ignore blocking
    return 1;

Which is called from this little gem in the main room definition:
Code: [Select]
SetRead("menu", (: readMenu :));

So what I need to do is be able to pass the bar keeps name into the function so that it can be inherited into any and all "Inns".

Offline chaos

  • BFF
  • ***
  • Posts: 291
  • Job, school, social life, sleep. Pick 2.5.
    • View Profile
    • Lost Souls
Re: Read Menu questions:
« Reply #1 on: June 27, 2008, 01:03:28 pm »
I suggest a module configuration point rather than an argument to readMenu().

Offline Ashon

  • Acquaintance
  • *
  • Posts: 24
    • View Profile
    • http://talosmud.wordpress.com/
Re: Read Menu questions:
« Reply #2 on: June 27, 2008, 04:20:07 pm »
Thanks to the responses from Kalinash I was able to hack this together: bar.c for all your menu reading needs.
Code: [Select]
/*  /lib/bar.c
 *  From the Talos Object Library
 *  Added Functionality for Bars/Pubs to Read Menu Item
 *  So that it doesn't have to be re-coded each time.
 *  Version: 1.0
 *  Last Modified: 06/27/08
 *  Ashon
 */
 
#include <lib.h>
#include <message_class.h>


mixed barkeep_check(){
    object *livs = get_livings(this_object());
    object barkeep;
    if(sizeof(livs))
        foreach(object liv in livs){
        if(inherits(LIB_BARKEEP,liv)) {
write(liv->GetShort());
write(liv->GetNativeLanguage());
return liv;
}

    }
    return 0;
}

int ReadMenu(object who, string str) {
   
string array tmp2 = ({});
    string array tmp = ({ sprintf("%s \t\t\t\t%s", "Item", "Cost") });
object ob = barkeep_check();
if( !ob ) { // Barkeep
    who->eventPrint("The menu is too bloodstained to read.");
return 1;
}
   
    foreach(string *item in keys(ob->GetMenuItems())) {
if ( strlen(item[0]) > 20 ) {
tmp += ({ sprintf("%s \t%d silver", capitalize(item[0]),
to_int(ob->GetCost(item))) });
}
else if ( strlen(item[0]) > 10 ){
tmp += ({ sprintf("%s \t\t%d silver", capitalize(item[0]),
to_int(ob->GetCost(item))) });
}
else {
tmp += ({ sprintf("%s \t\t\t\t\t%d silver", capitalize(item[0]),
to_int(ob->GetCost(item))) });
}
   }

    foreach(string element in tmp){
if ( nullp(ob->GetNativeLanguage())) {
element = translate(element,  this_player()->GetLanguageLevel(ob->GetNativeLanguage()));
tmp2 += ({ element });
}
        else {
element = translate(element,  this_player()->GetLanguageLevel("Common"));
tmp2 += ({ element });
}
    }
    tmp = tmp2;


    // show the menu a page at a time
    this_player()->eventPage(tmp, MSG_SYSTEM); // MSG_SYSTEM means ignore blocking
    return 1;