About Store Forum Documentation Contact



Post Reply 
Item don't picked up
Author Message
Ogniok Offline
Member

Post: #1
Item don't picked up
Hi!

I have a problem. In my game I have a code from BM:

Code:
void Player::autoPickUp()
{
   Memc<Game::Obj*> obj;
   Vec test_pos = pos() - Vec(0, ctrl.height() / 2, 0);
   Game::World.objGet(obj, Ball(2, test_pos), OBJ_ITEM);

   REPA(obj)
   {
       if(ItemEC *item = CAST(ItemEC, obj[i]))
       {
         if(item->type2 == ITEM_WEAPON && item->mesh && Dist(test_pos, item->mesh->box * item->matrixScaled()) <= ctrl.radius() + 0.1f)
         {
            this->itemPickUp(*item);
            AddMessage(S + "Picked up " + item->name);
         }
       }
   }
}

When I walk near to the weapon I only see Message "Picked up Simple Gun". Name is right but the weapon still lay on the map and it don't exist in my Inventory.
03-19-2010 11:26 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #2
RE: Item don't picked up
does Player have itemContainer?
did you set Game::World.setObjItem for OBJ_ITEM?
do you meet all other requirements mentioned in the 'pickUp' method comments?
03-20-2010 01:56 AM
Find all posts by this user Quote this message in a reply
Ogniok Offline
Member

Post: #3
RE: Item don't picked up
I have added this code to my game:

Code:
Memx<ItemEC>*   itemContainer()   { Memx<ItemEC> &items = Inv.items; return &items; } //Get item container, this is required by the engine to point to a valid item container for a character
   void itemRemoved(Game::Item &item){ Inv.itemRemoved(item); } //This is called when an item is being removed from the character
   void itemRemoved()                { Inv.itemRemoved(    ); } //This is called when an item has been removed from the character
   void itemAdded  (Game::Item &item){ Inv.itemAdded  (item); } //This is called when an item has been added   to   the character

But when I try to compile this i have an error:

Code:
d:\fps\player.h(27) : error C2555: 'Player::itemContainer': overriding virtual function return type differs and is not covariant from 'EE::Game::Obj::itemContainer'
1>        c:\program files\microsoft visual studio 9.0\vc\include\esenthelengine\game\object.h(26) : see declaration of 'EE::Game::Obj::itemContainer'
(This post was last modified: 03-20-2010 10:45 AM by Ogniok.)
03-20-2010 10:45 AM
Find all posts by this user Quote this message in a reply
Ogniok Offline
Member

Post: #4
RE: Item don't picked up
I have changed my code and now it's compiling. Items are picking up when I walk near to them and Inv.items.elms() returns right number of elements in inventory. But, when I'm opening Inventory Window I don't see any weapon. It's because item.valid() returns false. Alwayes!

Code:
REP(SLOT_NUM) //For all slots
         if(i != SLOT_TEMP) //Skip temporary slot because it's not drawn using 'Image' class
        
            GuiImage &img_back = slot_img[i][0];  //Background image, we use it for accessing its rectangle
            GuiImage &img_item = slot_img[i][1];  //Item image
            Reference<ItemEC> &item = Inv.slot[i]; //Item at slot

         if(!item.valid())  img_item.set(NULL); else //If there is no item then clear the item image slot
         {
            Image *icon = item().icon; //Access item's icon
            img_item.set(icon);        //Set slot image as the item's icon
            if(icon)                   //Set proper scaling
            {
               Vec2 size(icon->x(), icon->y()); size *= PIXEL_SIZE; //Set default size
              
               if(size.x > img_back.rect.w()) size *= img_back.rect.w() / size.x; //Clamp item size to background slot width
               if(size.y > img_back.rect.h()) size *= img_back.rect.h() / size.y; //Clamp item size to background slot height
              
               Rect rect(img_back.rect.center());
               rect.extend(size / 2);
              
               img_item.setRect(rect);
            }
         }
      }
03-20-2010 02:20 PM
Find all posts by this user Quote this message in a reply
Post Reply