Jump to content
  • 0

[HELP]New function: Counting items


Dumik

Question

Hello everybody,

 

i have a problem with new funtion in error log i have this:

char_item.cpp: In member function 'bool CHARACTER::helpCountBeltSpecifyItem(DWORD, int) const':
char_item.cpp:6422: error: invalid conversion from 'const CHARACTER* const' to 'CHARACTER*'
char_item.cpp:6422: error:   initializing argument 1 of 'static bool CBeltInventoryHelper::IsItemInSlotBeltInventory(CHARACTER*, DWORD, int)'

this is the function from char_item.cpp

int CHARACTER::CountBeltSpecifyItem(DWORD vnum) const
{
    int	count = 0;
    LPITEM item;
    LPITEM beltItem = GetWear(WEAR_BELT);  
    
    if (beltItem != NULL) // if belt is equip
    {
        for (int i = BELT_INVENTORY_SLOT_START; i < BELT_INVENTORY_SLOT_END; ++i)
        {
            if (!helpCountBeltSpecifyItem(vnum, i))
            {
                continue;
            }
            else
            {
                count += item->GetCount();
            }
        }
    }
    
    return count;
}

bool CHARACTER::helpCountBeltSpecifyItem(DWORD vnum, int i) const
{
line 6422   ->if (CBeltInventoryHelper::IsItemInSlotBeltInventory(this, vnum, i))
        return true;
    else
        return false;
}

belt_inventory_helper.cpp

    static bool IsItemInSlotBeltInventory(LPCHARACTER pc, DWORD vnum, int target_cell)
    {
        if(pc == NULL)
            return false;
        if(vnum == NULL)
        {
            pc->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("ERROR! [belt_inventory_helper] No vnum specified!"));
            return false;
        }
        if(target_cell == NULL)
        {
            pc->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("ERROR! [belt_inventory_helper] No target cell specified!"));
            return false;
        }
        
        LPITEM beltInventoryItem = pc->GetInventoryItem(target_cell); //pc->GetInventoryItem(i)
        if(beltInventoryItem->GetVnum())
            return true;
        return false;
    }

Thanks for any help

 

Link to comment
  • Answers 1
  • Created
  • Last Reply

Top Posters For This Question

Top Posters For This Question

1 answer to this question

Recommended Posts

  • 0

Because you are in a const function, you are not allowed to modify this, yet you are passing it to a function that treats it as a plain CHARACTER pointer, not constant. That is what you can't do.

 

Remove the const at the end of the declaration helpCountBeltSpecifyItem.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.