Author Topic: Problem with quest.  (Read 3093 times)

Offline Haldir

  • Acquaintance
  • *
  • Posts: 8
    • View Profile
Problem with quest.
« on: June 22, 2009, 08:29:14 pm »
Hello.

I'm having a problem with a quest that I've been trying to work out for a few hours, using leo.c as an example. Basically, I'm trying to program this room so that when a player types "plant explosives in soil", it checks to see if the explosives (/obj/bomb) are in the player's inventory, and if they are to destroy them and then check to see if the player already has the quest, awarding them if necessary. (I hope that's clear..). (I'm new to Dead Souls, so I'd think probably (and hopefully) this is a simple-ish problem.)

Here's the code I have for the room :
Code: [Select]
#include <lib.h>
#include ROOMS_H

inherit LIB_ROOM;
//int read_sign();
void create() {
    room::create();
    SetClimate("indoors");
    SetAmbientLight(30);
    SetShort("Boring Room");
    SetLong("This is a house which bores you beyond imagine. There is a fireplace, pot of soil, a couch, a table with nothing on it, and another room to the north.");
    SetInventory(([
        "/obj/soil" : 1,
      ]));
    SetExits( ([
        "south" : "/domains/deltov/room/room_four",
        "north" : "/domains/deltov/room/building_room_one.c",
      ]) );
}


int quest(object ob){
    string *quests;
object bomb = present("bomb", this_object());
write("You plant the explosives.");

    quests = ob->GetQuests();
    if(!ob->GetQuest("Boring")){
        ob->AddQuest("Boring","Boring");
        write("You have solved the Bore-Killer Quest. Congratulations!");
        write("I hereby award you 10 quest points, and 2000 experience points!");
        ob->AddQuestPoints(10);
        ob->AddExperiencePoints(2000);
        if(bomb) bomb->eventDestruct();                                                                          
        reload("/domains/deltov/room/building_room_one",0,1);
    }
else{
write("You've already completed this quest");
}
    return 1;
}

int plant(object foo){
int ret;
    object ob, player;
    ob = previous_object();
    player = this_player();
if( !ob || !(ret = plant(foo)) ) return 0;
if(present("/obj/bomb", this_object())){
                call_out("quest", 0, player);
       }
return ret;
}


void init(){
    ::init();
    add_action("plant","plant");
}
« Last Edit: June 22, 2009, 08:30:49 pm by Haldir »

Offline cratylus

  • Your favorite and best
  • Administrator
  • ***
  • Posts: 1024
  • Cratylus@Dead Souls <ds> np
    • View Profile
    • About Cratylus
Re: Problem with quest.
« Reply #1 on: June 22, 2009, 08:51:18 pm »
In the future, please include the exact error you got.

Offhand I see the following problems:

Code: [Select]
    add_action("plant","plant");
That's a perfectly cromulent add_action(), but the definition of the
function it points to starts like this:

Code: [Select]
int plant(object foo){
That's a no-go. From the add_action man page:

Quote
Functions called by a user command will get the rest of the command line
as a string.

For details, type: man add_action

That function will receive the string "explosives in soil". You need to recode that
function to handle that string. Right now it expects an object as an argument,
which is problem 1, but problem 2 is that this function wouldn't know what to
do with the string argument anyway. Right now it would act the same (assuming you
fix the argument) to "plant keyboard on head" and "plant robert".

It also writes "You plant the explosives." whether the player actually has the
explosives or not.


This is a problem:
Code: [Select]
    quests = ob->GetQuests();because you're trying to call GetQuests() on ob, but as we've seen,
ob is actually going to be either a string or 0, not an object. You probably
mean something like:
Code: [Select]
    quests = this_player()->GetQuests();

There may be other problems, but those are the most obvious.

-Crat




Offline Haldir

  • Acquaintance
  • *
  • Posts: 8
    • View Profile
Re: Problem with quest.
« Reply #2 on: June 22, 2009, 09:16:39 pm »
Sorry about not posting the actual problem, I guess I forgot to. Anyway, the problem is that if I type "plant explosives in soil" (now that I fixed that problem, thanks, Cratylus, for pointing that out), nothing happens (other than I am told that I should type 'help creator commands').

Haldir

PS - I changed ob->GetQuests(); etc. to this_player()->GetQuests(); etc. (Again, thanks, Cratylus, for pointing that out)

Offline cratylus

  • Your favorite and best
  • Administrator
  • ***
  • Posts: 1024
  • Cratylus@Dead Souls <ds> np
    • View Profile
    • About Cratylus
Re: Problem with quest.
« Reply #3 on: June 22, 2009, 09:33:28 pm »
PS - I changed ob->GetQuests(); etc. to this_player()->GetQuests(); etc. (Again, thanks, Cratylus, for pointing that out)

You should probably change every

Code: [Select]
ob->
to

Code: [Select]
this_player()->
Since that's probably why nothing is happening.

Also, this_object() refers to the room, not the player, so you probably
want to change that too.

-Crat

Offline Haldir

  • Acquaintance
  • *
  • Posts: 8
    • View Profile
Re: Problem with quest.
« Reply #4 on: June 22, 2009, 09:45:32 pm »
Nope, still not working.

Here's the modified quest function:

Code: [Select]
int quest(){
    string *quests;
object bomb = present("bomb", this_player());
write("You plant the explosives.");

    quests = this_player()->GetQuests();
    if(!this_player()->GetQuest("Boring")){
        this_player()->AddQuest("Boring","Boring");
        write("You have solved the Bore-Killer Quest. Congratulations!");
        write("I hereby award you 10 quest points, and 2000 experience points!");
        this_player()->AddQuestPoints(10);
        this_player()->AddExperiencePoints(2000);
        if(bomb) bomb->eventDestruct();                                                                          
        reload("/domains/deltov/room/building_room_one",0,1);
    }
else{
write("You've already completed this quest");
}
    return 1;
}

And here's the modified plant function:

Code: [Select]
int plant(){
int ret;
    object player;
    ob = previous_object();
    player = this_player();
if( !player || !(ret = plant()) ) return 0;
if(present("/obj/bomb", this_player())){
                call_out("quest", 0, player);
       }
return 1;
}

Offline cratylus

  • Your favorite and best
  • Administrator
  • ***
  • Posts: 1024
  • Cratylus@Dead Souls <ds> np
    • View Profile
    • About Cratylus
Re: Problem with quest.
« Reply #5 on: June 22, 2009, 09:53:25 pm »
Ok. Please post the entire room file.

Also please post the entire /log/runtime file.

-Crat

Offline Haldir

  • Acquaintance
  • *
  • Posts: 8
    • View Profile
Re: Problem with quest.
« Reply #6 on: June 22, 2009, 09:58:27 pm »
First, thanks for tolerating my ongoing problem. Now here are the files:

Room file:
Code: [Select]
#include <lib.h>
#include ROOMS_H

inherit LIB_ROOM;
//int read_sign();
void create() {
    room::create();
    SetClimate("indoors");
    SetAmbientLight(30);
    SetShort("Boring Room");
    SetLong("This is a house which bores you beyond imagine. There is a fireplace, pot of soil, a couch, a table with nothing on it, and another room to the north.");
    SetInventory(([
        "/obj/soil" : 1,
      ]));
    SetExits( ([
        "south" : "/domains/deltov/room/room_four",
        "north" : "/domains/deltov/room/building_room_one.c",
      ]) );
}


int quest(){
    string *quests;
object bomb = present("bomb", this_player());
write("You plant the explosives.");

    quests = this_player()->GetQuests();
    if(!this_player()->GetQuest("Boring")){
        this_player()->AddQuest("Boring","Boring");
        write("You have solved the Bore-Killer Quest. Congratulations!");
        write("I hereby award you 10 quest points, and 2000 experience points!");
        this_player()->AddQuestPoints(10);
        this_player()->AddExperiencePoints(2000);
        if(bomb) bomb->eventDestruct();                                                                           
        reload("/domains/deltov/room/building_room_one",0,1);
    }
else{
write("You've already completed this quest");
}
    return 1;
}

int plant(){
int ret;
    object player;
    //ob = previous_object();
    player = this_player();
if( !player || !(ret = plant()) ) return 0;
if(present("/obj/bomb", this_player())){
                call_out("quest", 0, player);
        }
return 1;
}


void init(){
    ::init();
    add_action("plant","plant explosives in soil");
}

log/runtime file:
Code: [Select]
----------------------------------------------------------------------------
Haldir Needs to Think About This. (FluffOS v2.16-ds05w) starting up on Microsoft Windows NT - Mon Jun 22 20:07:09 2009



Loading preloaded files ...
Initializations complete.

Accepting connections on port 6666.

Running autoexec, please wait...
Autoexec daemon run complete.


---
2009.06.22-17.09,47
*Function for verb 'plant' not found.
Object: <none> (0) at /l\:2282368

---
2009.06.22-17.10,09
*Function for verb 'plant' not found.
Object: <none> (0) at /l\:2282368



Offline cratylus

  • Your favorite and best
  • Administrator
  • ***
  • Posts: 1024
  • Cratylus@Dead Souls <ds> np
    • View Profile
    • About Cratylus
Re: Problem with quest.
« Reply #7 on: June 22, 2009, 10:20:46 pm »
Code: [Select]
#include <lib.h>
#include ROOMS_H

inherit LIB_ROOM;
void create() {
    room::create();
    SetClimate("indoors");
    SetAmbientLight(30);
    SetShort("Boring Room");
    SetLong("This is a house which bores you beyond imagine. There is a fireplace, pot of soil, a couch, a table with nothing on it, and another room to the north.");
    SetInventory(([
                "/obj/soil" : 1,
                ]));
    SetExits( ([
                "south" : "/domains/deltov/room/room_four",
                "north" : "/domains/deltov/room/building_room_one.c",
                ]) );
}


int quest(object player){
    string *quests;
    object bomb = present("bomb", player);
    tell_player(player, "You plant the explosives.");

    quests = player->GetQuests();
    if(!player->GetQuest("Boring")){
        player->AddQuest("Boring","Boring");
        write("You have solved the Bore-Killer Quest. Congratulations!");
        write("I hereby award you 10 quest points, and 2000 experience points!");
        player->AddQuestPoints(10);
        player->AddExperiencePoints(2000);
        if(bomb) bomb->eventDestruct();
        reload("/domains/deltov/room/building_room_one",0,1);
    }
    else{
        write("You've already completed this quest");
    }
    return 1;
}

int plant(string foo){
    int ret;
    object player;
    player = this_player();
    if( !player ) return 0;
    if(!foo || foo != "explosives in soil") return 0;
    if(present("/obj/bomb", this_player())){
        call_out("quest", 0, player);
    }
    return 1;
}


void init(){
    ::init();
    add_action("plant","plant");
}

Offline Haldir

  • Acquaintance
  • *
  • Posts: 8
    • View Profile
Re: Problem with quest.
« Reply #8 on: June 22, 2009, 10:49:48 pm »
Well, it didn't exactly work, but it doesn't give that "help creator commands" message, it just does nothing, which I take as a sign that it is actually acknowledging that 'plant explosives in soil' is different from other commands.

Offline cratylus

  • Your favorite and best
  • Administrator
  • ***
  • Posts: 1024
  • Cratylus@Dead Souls <ds> np
    • View Profile
    • About Cratylus
Re: Problem with quest.
« Reply #9 on: June 22, 2009, 11:07:12 pm »
You'll need to be carrying that bomb for it to work.

-Crat

PS Also, it'll need to have "/obj/bomb" as one of its SetId() elements.

Offline Haldir

  • Acquaintance
  • *
  • Posts: 8
    • View Profile
Re: Problem with quest.
« Reply #10 on: June 23, 2009, 10:37:19 am »
OK, it's finally working (thanks to Cratylus) so here's the working code:

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

inherit LIB_ROOM;
//int read_sign();
void create() {
    room::create();
    SetClimate("indoors");
    SetAmbientLight(30);
    SetShort("Boring Room");
    SetLong("This is a house which bores you beyond imagine. There is a fireplace, pot of soil, a couch, a table with nothing on it, and another room to the north.");
    SetExits( ([
        "south" : "/domains/deltov/room/room_four",
        "north" : "/domains/deltov/room/building_room_one",
      ]) );
    SetInventory(([
        "/obj/soil" : 1,
      ]));
}

int quest(object player){
    string *quests;
    object bomb = present("bomb", player);
    tell_player(player, "You plant the explosives.");

    quests = player->GetQuests();
    if(!player->GetQuest("Boring")){
        player->AddQuest("Boring","Boring");
        write("You have solved the Bore-Killer Quest. Congratulations!");
        write("I hereby award you 10 quest points, and 2000 experience points!");
        player->AddQuestPoints(10);
        player->AddExperiencePoints(2000);
        if(bomb) bomb->eventDestruct();
        reload("/domains/deltov/room/building_room_one",0,1);
    }
    else{
        write("You've already completed this quest");
    }
    return 1;
}

int plant(string foo){
    int ret;
    object player;
    player = this_player();
    if( !player ) return 0;
    if(!foo || foo != "explosives in soil") return 0;
    if(present("bomb", this_player())){
        call_out("quest", 0, player);
    }
    return 1;
}

void init(){
    ::init();
    add_action("plant","plant");
}