Author Topic: Read and Write on Parchment  (Read 1498 times)

Offline Nilrin

  • Friend
  • **
  • Posts: 85
    • View Profile
Read and Write on Parchment
« on: December 20, 2014, 09:04:23 AM »
Someone asked me how I did this, for some silly reason...

Anyway, this lets you write using stationary and a writing utensil.

Here's the verb write.c:

Code: [Select]
/*    /verbs/players/write.c
 *    from the Rebirth Library
 *    created by Nilrin
 */

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

inherit LIB_VERB;

static void create() {
    verb::create();
    SetVerb("write");
    SetRules("on OBJ with OBJ");
    SetErrorMessage("Write on what with what?");
    SetHelp("Syntax: write on <item> with <item>\n\n"
            "Allows you to write something on the specified object using the specified writing tool."
            "\nSee also:");
}

int end_write(object ob1, string tmp){
    if(ob1 && tmp){
        ob1->SetFileSource(tmp);
    }
    send_messages("stop","$agent_name $agent_verb writing on $target_name.",this_player(),ob1,"subject_env",0,({ "visual" }));
    return 1;
}

mixed can_write_on_obj_with_obj() {
    if( this_player()->GetParalyzed() ) {
        return "You cannot do anything!";
    }
    return this_player()->CanManipulate();
}

mixed do_write_on_obj_with_obj(object ob1, object ob2){
        string file = ob1->GetFileSource();

        if(file){
            this_player()->eventEdit(file, (: end_write, ob1 :));
            send_messages("begin","$agent_name $agent_verb writing on $target_name.",this_player(),ob1,"subject_env",0,({ "visual" }));
        }
        else{
            string dir = "/doc/writings/";
            string tmp;

            if(!directory_exists(dir)){
                mkdir(dir);
            }

            tmp = dir + ob1->GetKeyName() + sizeof(get_dir(dir));

            this_player()->eventEdit(tmp, (: end_write, ob1, tmp :));
            send_messages("begin","$agent_name $agent_verb writing on $target_name.",this_player(),ob1,"subject_env",0,({ "visual" }));
        }
    return 1;
}

And here is parchment.c

Code: [Select]
#include <lib.h>
#include <vendor_types.h>
#include <damage_types.h>

inherit LIB_ITEM;
inherit LIB_PERSIST;
inherit LIB_READ;

public string file_source;

string GetFileSource(){
    return file_source;
}

string SetFileSource(string str){
    file_source = str;
    SetLong("This is a sheet of parchment. It has been made from the skin of an animal and stretch out extremely thin, to the point of being partially transparent.\nThe parchment has something written on it.");
    return str;
}

eventRead(){
    if(file_source && file_exists(file_source)){
        this_player()->eventPage(file_source);
        send_messages("read","$agent_name $agent_verb $target_name.",this_player(),this_object(),"subject_env",0,({ "visual","exclude_subject" }));
    }
    else{
        write("There is nothing written on it.");
    }
    return 1;
}

void create(){
    item::create();
    SetKeyName("parchment");
    SetId(({"parchment","sheet of parchment","sheet"}));
    SetShort("a sheet of parchment");
    SetLong("This is a sheet of parchment. It has been made from the skin of an animal and stretch out extremely thin, to the point of being partially transparent.");
    SetMass(1);
    SetVendorType(VT_TREASURE);
    SetRead((: eventRead :));
    AddSave( ({ "file_source" }) );
}

void init(){
    ::init();
}

int direct_write_on_obj_with_obj(object ob1, object ob2){
    return 1;
}

Whatever you want to use as a writing utensil, just have:

int indirect_write_on_obj_with_obj(object ob1, object ob2){
    return 1;
}

Also, you'll want to change the send_messages() functions to whatever your message handler/print to screen thingie is.

Pretty simple really.

Offline Lash

  • Acquaintance
  • *
  • Posts: 42
    • View Profile
Re: Read and Write on Parchment
« Reply #1 on: December 22, 2014, 03:55:01 AM »
I was just looking for this! Thanks!

Offline Gogron

  • Acquaintance
  • *
  • Posts: 3
    • View Profile
Re: Read and Write on Parchment
« Reply #2 on: December 26, 2014, 05:00:20 PM »
Same here, you saved me a lot of frustration :D