• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

C++ help with this code, just to work with one id item

darknelson

Member
Joined
Jun 19, 2011
Messages
190
Solutions
1
Reaction score
15
please help me to edit this code for just work with container id 5089, please bros


Lua:
Item* Player::getAmmunition() const
{
    Item* item = inventory[CONST_SLOT_AMMO];
    if(!item)
        return nullptr;

    if(Container *container = item->getContainer()) {
        Item* weapon = getWeapon();
        const ItemType& it = Item::items[weapon->getID()];
        for(ContainerIterator iter = container->iterator(); iter.hasNext(); iter.advance()) {
            const ItemType& itr = Item::items[(*iter)->getID()];
            if(itr.ammoType == it.ammoType)
                return (*iter);
        }
    }

    return item;
}

this is my try but its not working, please help me

Lua:
Item* Player::getAmmunition() const
{
    Item* item = inventory[CONST_SLOT_AMMO];
    if(!item)
        return nullptr;

    if(Container *container = item->getContainer()) {
        if (container->getID() == 5089];
        Item* weapon = getWeapon();
        const ItemType& it = Item::items[weapon->getID()];
        
        for(ContainerIterator iter = container->iterator(); iter.hasNext(); iter.advance()) {
            const ItemType& itr = Item::items[(*iter)->getID()];
            if(itr.ammoType == it.ammoType)
                return (*iter);
        }
    }

    return item;
}
 
Last edited:
Solution
You will have to declare ITEM_QUIVER in const.h, preferably in item_t, but you can do it anywhere if you like your engine messy. :D
Inside enum just add this line
C++:
ITEM_QUIVER = 5089;

And the rest is here
C++:
Item* Player::getAmmunition() const
{
    Item* item = inventory[CONST_SLOT_AMMO];
    if(!item)
        return nullptr;

    if(Container *container = item->getContainer()) {
        if (item->getID() != ITEM_QUIVER)
            return nullptr;

        Item* weapon = getWeapon();
        const ItemType& it = Item::items[weapon->getID()];
 
        for(ContainerIterator iter = container->iterator(); iter.hasNext(); iter.advance()) {
            const ItemType& itr = Item::items[(*iter)->getID()];
            if(itr.ammoType ==...
You will have to declare ITEM_QUIVER in const.h, preferably in item_t, but you can do it anywhere if you like your engine messy. :D
Inside enum just add this line
C++:
ITEM_QUIVER = 5089;

And the rest is here
C++:
Item* Player::getAmmunition() const
{
    Item* item = inventory[CONST_SLOT_AMMO];
    if(!item)
        return nullptr;

    if(Container *container = item->getContainer()) {
        if (item->getID() != ITEM_QUIVER)
            return nullptr;

        Item* weapon = getWeapon();
        const ItemType& it = Item::items[weapon->getID()];
 
        for(ContainerIterator iter = container->iterator(); iter.hasNext(); iter.advance()) {
            const ItemType& itr = Item::items[(*iter)->getID()];
            if(itr.ammoType == it.ammoType)
                return (*iter);
    }
    return item;
}
 
Last edited:
Solution
Lua:
Item* Player::getAmmunition() const
{
    Item* item = inventory[CONST_SLOT_AMMO];
    if(!item)
        return nullptr;

    if(Container *container = item->getContainer()) {
        if (item->getID() != ITEM_QUIVER)
            return nullptr;

        Item* weapon = getWeapon();
        const ItemType& it = Item::items[weapon->getID()];
 
        for(ContainerIterator iter = container->iterator(); iter.hasNext(); iter.advance()) {
            const ItemType& itr = Item::items[(*iter)->getID()];
            if(itr.ammoType == it.ammoType)
                return (*iter);
    }
    return item;
}

works amazing but u added a ) for misstake, works thanks, please help me in my other thread i make marke as solved rep++
 
Last edited:
Back
Top