Author Topic: A bit stumped, object + inventory question  (Read 4680 times)

Offline capo

  • Friend
  • **
  • Posts: 70
    • View Profile
A bit stumped, object + inventory question
« on: January 27, 2008, 12:26:04 PM »
My goal here is to produce something that looks like this:

Quote
> l wand
This is a sample wand to try to test out how difficult it will be
to have an item display invisible inventory objects such as supplies
needed to cast a spell, forge a weapon, pick a lock, etc.  You have the
following sorceror related items needed for casting some spell:


Flint: 0
Energy: 0
Iron: 0

When someone obtains a flint it should look like:

Quote
> l wand
This is a sample wand to try to test out how difficult it will be
to have an item display invisible inventory objects such as supplies
needed to cast a spell, forge a weapon, pick a lock, etc.  You have the
following sorceror related items needed for casting some spell:


Flint: 1
Energy: 0
Iron: 0

Then when someone uses that flint:

Quote
> l wand
This is a sample wand to try to test out how difficult it will be
to have an item display invisible inventory objects such as supplies
needed to cast a spell, forge a weapon, pick a lock, etc.  You have the
following sorceror related items needed for casting some spell:


Flint: 0
Energy: 0
Iron: 0

So far my code looks like this (with the object code for the flint and way to get it already completed):

Code: [Select]
#include <lib.h>
#include <vendor_types.h>
inherit LIB_ITEM;

string *supply;
mapping invent;
int x;
int flint;
int energy;
int iron;

supply = map(filter(all_inventory(this_player()), (: ((int)$1->GetInvis(this_player())) :)), (: (string)$1->GetEquippedShort() :));
invent = ([]);

void create(){
    ::create();
    SetKeyName("wand");
    SetId( ({"wand"}) );
    SetShort("a wand");
    SetLong("This is a sample wand to try to test out how difficult it will be\n"+
        "to have an item display invisible inventory objects such as supplies\n"+
"needed to cast a spell, forge a weapon, pick a lock, etc.  You have the\n"+
"following sorceror related items needed for casting some spell:\n"+
            "\n" +
            "\n" +
"Flint: " + flint + " \n"+
"Energy: " + energy + " \n"+
"Iron: " + iron + " \n"
);
    SetMass(20);
    SetVendorType(VT_TREASURE);
}


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

I know this isn't complete, I was hoping someone could help me figure out how to search an inventory of a player; count a specific number of specific objects, and then return that number.

I, as always, appreciate your help.

Offline capo

  • Friend
  • **
  • Posts: 70
    • View Profile
Re: A bit stumped, object + inventory question
« Reply #1 on: January 27, 2008, 12:47:29 PM »

Now have this:

Code: [Select]
#include <lib.h>
#include <vendor_types.h>
inherit LIB_ITEM;

int x;
int y;
int z;

x = sizeof(filter(all_inventory(this_player()), (: (string)$1->GetName() == "flint" :) ));
y = sizeof(filter(all_inventory(this_player()), (: (string)$1->GetName() == "energy" :) ));
z = sizeof(filter(all_inventory(this_player()), (: (string)$1->GetName() == "iron" :) ));

void create(){
    ::create();
    SetKeyName("wand");
    SetId( ({"wand"}) );
    SetShort("a wand");
    SetLong("This is a sample wand to try to test out how difficult it will be\n"+
            "to have an item display invisible inventory objects such as supplies\n"+
            "needed to cast a spell, forge a weapon, pick a lock, etc.  You have the\n"+
            "following sorceror related items needed for casting some spell:\n"+
            "\n" +
            "\n" +
            "Flint:   " + x + " \n"+
            "Energy:  " + y + " \n"+
            "Iron:    " + z + " \n"
                        );
    SetMass(20);
    SetVendorType(VT_TREASURE);

}

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

Results in these errors:

/realms/capo/area/obj/wand.c line 9: Type mismatch ( unknown vs int ) when initializing x
   
/realms/capo/area/obj/wand.c line 10: Type mismatch ( unknown vs int ) when initializing y
   
/realms/capo/area/obj/wand.c line 11: Type mismatch ( unknown vs int ) when initializing z
   
/realms/capo/area/obj/wand.c line 24: Invalid argument types to '+' ( string vs unknown )
   
/realms/capo/area/obj/wand.c line 25: Invalid argument types to '+' ( string vs unknown )
   
/realms/capo/area/obj/wand.c line 26: Invalid argument types to '+' ( string vs unknown )

Offline capo

  • Friend
  • **
  • Posts: 70
    • View Profile
Re: A bit stumped, object + inventory question
« Reply #2 on: January 27, 2008, 01:20:56 PM »
changed to:

Code: [Select]
#include <lib.h>
#include <vendor_types.h>
inherit LIB_ITEM;


void create()
{
    ::create();

int x;
int y;
int z;

x = sizeof(filter(all_inventory(this_player()), (: (string)$1->GetName() == "flint" :) ));
y = sizeof(filter(all_inventory(this_player()), (: (string)$1->GetName() == "energy" :) ));
z = sizeof(filter(all_inventory(this_player()), (: (string)$1->GetName() == "iron" :) ));

    SetKeyName("wand");
    SetId( ({"wand"}) );
    SetShort("a wand");
    SetLong("This is a sample wand to try to test out how difficult it will be\n"+
            "to have an item display invisible inventory objects such as supplies\n"+
            "needed to cast a spell, forge a weapon, pick a lock, etc.  You have the\n"+
            "following sorceror related items needed for casting some spell:\n"+
            "\n" +
            "\n" +
            "Flint:   " + x + " \n"+
            "Energy:  " + y + " \n"+
            "Iron:    " + z + " \n"
                        );
    SetMass(20);
    SetVendorType(VT_TREASURE);

}

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



leads to:

/realms/capo/area/obj/wand.c line 10: Reserved type name unexpected.
   
/realms/capo/area/obj/wand.c line 10: syntax error
   
/realms/capo/area/obj/wand.c line 14: Illegal LHS
   
/realms/capo/area/obj/wand.c line 15: Undefined variable 'y'
   
/realms/capo/area/obj/wand.c line 15: Illegal lvalue
   
/realms/capo/area/obj/wand.c line 16: Undefined variable 'z'

Offline capo

  • Friend
  • **
  • Posts: 70
    • View Profile
Re: A bit stumped, object + inventory question
« Reply #3 on: January 27, 2008, 01:32:17 PM »
The fun continues!

Code: [Select]
#include <lib.h>
#include <vendor_types.h>
inherit LIB_ITEM;

void create()
{
    ::create();
    SetKeyName("wand");
    SetId( ({"wand"}) );
    SetShort("a wand");
    SetLong("This is a sample wand to try to test out how difficult it will be\n"+
            "to have an item display invisible inventory objects such as supplies\n"+
            "needed to cast a spell, forge a weapon, pick a lock, etc.  You have the\n"+
            "following sorceror related items needed for casting some spell:\n"+
            "\n" +
            "\n" +
            "Flint:   " + x + " \n"+
            "Energy:  " + y + " \n"+
            "Iron:    " + z + " \n"
                        );
    SetMass(20);
    SetVendorType(VT_TREASURE);

}

void init()
{
    ::init();

    int x = sizeof(filter(all_inventory(this_player()), (: (string)$1->GetName() == "flint" :) ));
    int y = sizeof(filter(all_inventory(this_player()), (: (string)$1->GetName() == "energy" :) ));
    int z = sizeof(filter(all_inventory(this_player()), (: (string)$1->GetName() == "iron" :) ));

}


Offline capo

  • Friend
  • **
  • Posts: 70
    • View Profile
Re: A bit stumped, object + inventory question
« Reply #4 on: January 27, 2008, 01:32:42 PM »
With these errors:

/realms/capo/area/obj/wand.c line 17: Undefined variable 'x'
   
/realms/capo/area/obj/wand.c line 18: Undefined variable 'y'
   
/realms/capo/area/obj/wand.c line 19: Undefined variable 'z'
   
/realms/capo/area/obj/wand.c line 30: Reserved type name unexpected.
   
/realms/capo/area/obj/wand.c line 30: syntax error
   
/realms/capo/area/obj/wand.c line 30: Illegal LHS

Offline tigwyk

  • Acquaintance
  • *
  • Posts: 45
    • View Profile
Re: A bit stumped, object + inventory question
« Reply #5 on: January 27, 2008, 01:45:33 PM »
Here we go.

Code: [Select]
#include <lib.h>
#include <vendor_types.h>
inherit LIB_ITEM;

string GetNewLong();

void create(){
    ::create();
    SetKeyName("wand");
    SetId( ({"wand"}) );
    SetShort("a wand");
    SetLong((: GetNewLong :));
    SetMass(20);
    SetVendorType(VT_TREASURE);

}

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

string GetNewLong(){
int x,y,z;
x = sizeof(filter(all_inventory(this_player()), (: (string)lower_case($1->GetName()) == "flint" :) ));
y = sizeof(filter(all_inventory(this_player()), (: (string)lower_case($1->GetName()) == "energy" :) ));
z = sizeof(filter(all_inventory(this_player()), (: (string)lower_case($1->GetName()) == "iron" :) ));
return "This is a sample wand to try to test out how difficult it will be\n"+
            "to have an item display invisible inventory objects such as supplies\n"+
            "needed to cast a spell, forge a weapon, pick a lock, etc.  You have the\n"+
            "following sorceror related items needed for casting some spell:\n"+
            "\n" +
            "\n" +
            "Flint:   " + x + " \n"+
            "Energy:  " + y + " \n"+
            "Iron:    " + z + " \n";
}

Offline Nulvect

  • BFF
  • ***
  • Posts: 127
    • View Profile
Re: A bit stumped, object + inventory question
« Reply #6 on: January 28, 2008, 05:45:10 PM »
One minor thing: once you get done with the testing, you'll probably want to make the wand only show the available "ammo" if it's in the inventory of this_player().

Offline capo

  • Friend
  • **
  • Posts: 70
    • View Profile
Re: A bit stumped, object + inventory question
« Reply #7 on: January 29, 2008, 06:29:32 AM »
Hmm... Im not sure I get you, it appears to do that now.

Offline Nulvect

  • BFF
  • ***
  • Posts: 127
    • View Profile
Re: A bit stumped, object + inventory question
« Reply #8 on: February 01, 2008, 01:09:49 PM »
The way that wand is coded right now, if it is on the ground and you look at it, it will show you the ammo you are carrying. The same thing will happen any time you see its long description, such as if a player shows it to you from his own inventory (if you have that command) or if you are browsing at a shop.

Offline capo

  • Friend
  • **
  • Posts: 70
    • View Profile
Re: A bit stumped, object + inventory question
« Reply #9 on: February 01, 2008, 06:00:26 PM »

It seems that you are partly right.  If Player A has it in his inventory and shows it to Player B, Player B will get to see what Player A has as far as inventory goes.  If the item is on the floor both will get to see what is in their inventory for that object's ammo//

Any ideas on how to supress it if it's on the floor and not in someone's inventory?

Offline Nulvect

  • BFF
  • ***
  • Posts: 127
    • View Profile
Re: A bit stumped, object + inventory question
« Reply #10 on: February 01, 2008, 06:34:58 PM »
Only show the ammo part...
Code: [Select]
if (this_player() == environment(this_object()) && query_verb() == "look")
...and it should work right in every case I can think of.