• 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!

Quiver for paladins - tfs1.X

xydius

Just an otland wanderer
Joined
Feb 25, 2016
Messages
41
Reaction score
37
Hello fellow otlanders heres a little edit i did for my custom ot and i felt like sharing it.

First of all what is a quiver? A quiver is a container where u can put your arrows/bolts and use them while equiped with a bow/crossbow like show in the picture below.

quiver demo.png

EDIT

  1. First go to your source files and look for player.cpp
  2. Then look for
    Code:
    Item* Player::getWeapon(slots_t slot, bool ignoreAmmo) const
    mine was at line 230 so your should be around that line also.
  3. In that function look for
    Code:
    if (it.ammoType != AMMO_NONE) {
                Item* ammoItem = inventory[CONST_SLOT_AMMO];
    and right below that just add
    Code:
    /*edit for quiver*/
                if (!ammoItem)
                {
                    return nullptr;
                }
               
                if (Container* container = ammoItem->getContainer())
                {
                    for (ContainerIterator iter = container->iterator(); iter.hasNext(); iter.advance())
                    {
                        const ItemType& itr = Item::items[(*iter)->getID()];
                        if (itr.ammoType == it.ammoType)
                        {
                            item = (*iter);
                            return item;
                        }
                    }
                }
                /*end of edit*/
  4. Thats it LoL.
  5. To add an item to add as a quiver remember to edit it with an itemEditor so it can work as a container and add the attribute to the item like this
    Code:
    <attribute key="containerSize" value="20" />
    and that should do.
FAQ
Q.- do you "bla bla bla" for tfs 0.4?
A.- No, i dont. Move on already guys.
 
i do that loooong time ago

never said you couldn't do it, it's not as flexible to set up, you most likely had to script each weapon to get it to pull the ammo out of the quiver
probably have to do it every time you make a new weapon, which is the reason why it's more flexible (and easier) to create something in c++
not everything is so godly in lua only, why would you use an embeddable language and completely ignore the parent language?
 
never said you couldn't do it, it's not as flexible to set up, you most likely had to script each weapon to get it to pull the ammo out of the quiver
probably have to do it every time you make a new weapon, which is the reason why it's more flexible (and easier) to create something in c++
not everything is so godly in lua only, why would you use an embeddable language and completely ignore the parent language?

Yeah i see now, thanks for the feature
 

See the very bottom of his post. You can always link this thread in a support thread of your own and see if anyone would help you convert it, but doesn't seem like the thread starter is interested in coding for outdated servers (rightfully so).

FAQ
Q.- do you "bla bla bla" for tfs 0.4?
A.- No, i dont. Move on already guys.

Regards,
Cody
 
How do i choose the item to display? Not working here.
 

I hope I'm not wrong but the only thing I see that changes in tfs 0.4.0

nullptr ------> c++11
NULL -------> TFS 0.4.0
IN PLAYER.CPP -------> TFS 0.4.0

C++:
Item* ammoItem = getInventoryItem(SLOT_AMMO);

down this line you hit this

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

item = (*iter); ------------------->
YOU WANT ON THIS LINE THERE IS AN ERRO BY THE *

I have not tested
 
Same question as Jackl90. Otherwise it's a nice working script!
 
@jackl90 @froy
C++:
            if (Container* container = ammoItem->getContainer())
            {
                if (container->getID() == 1999) // change quiver id here
                {
                    for (ContainerIterator iter = container->iterator(); iter.hasNext(); iter.advance())
                    {
                        const ItemType& itr = Item::items[(*iter)->getID()];
                        if (itr.ammoType == it.ammoType)
                        {
                            item = (*iter);
                            return item;
                        }
                    }
                }
            }
 
@Stigma

I'm using TFS 1.2 Nostalrius and cannot seem to add that code.. might be that the sources are totaly diffrent..
I'm not really familiar with C++ at all..
is there somewhere in this where I could enter that code?





Code:
/**

Item* Player::getInventoryItem(slots_t slot) const
{
    if (slot < CONST_SLOT_FIRST || slot > CONST_SLOT_LAST) {
        return nullptr;
    }
    return inventory[slot];
}

void Player::addConditionSuppressions(uint32_t conditions)
{
    conditionSuppressions |= conditions;
}

void Player::removeConditionSuppressions(uint32_t conditions)
{
    conditionSuppressions &= ~conditions;
}

Item* Player::getWeapon() const
{
    Item* item = inventory[CONST_SLOT_LEFT];
    if (item && item->getWeaponType() != WEAPON_NONE && item->getWeaponType() != WEAPON_SHIELD && item->getWeaponType() != WEAPON_AMMO) {
        return item;
    }

    item = inventory[CONST_SLOT_RIGHT];
    if (item && item->getWeaponType() != WEAPON_NONE && item->getWeaponType() != WEAPON_SHIELD && item->getWeaponType() != WEAPON_AMMO) {
        return item;
    }

    return nullptr;
}

Item* Player::getAmmunition() const
{
    return inventory[CONST_SLOT_AMMO];
}

int32_t Player::getArmor() const
{
    int32_t armor = 0; // base armor

    static const slots_t armorSlots[] = { CONST_SLOT_HEAD, CONST_SLOT_NECKLACE, CONST_SLOT_ARMOR, CONST_SLOT_LEGS, CONST_SLOT_FEET, CONST_SLOT_RING };
    for (slots_t slot : armorSlots) {
        Item* inventoryItem = inventory[slot];
        if (inventoryItem) {
            armor += inventoryItem->getArmor();
        }
    }

    if (armor > 1) {
        armor = rand() % (armor >> 1) + (armor >> 1);
    }

    return armor;
}

void Player::getShieldAndWeapon(const Item*& shield, const Item*& weapon) const
{
    shield = nullptr;
    weapon = nullptr;

    for (uint32_t slot = CONST_SLOT_RIGHT; slot <= CONST_SLOT_LEFT; slot++) {
        Item* item = inventory[slot];
        if (!item) {
            continue;
        }

        switch (item->getWeaponType()) {
            case WEAPON_NONE:
            break;

            case WEAPON_SHIELD: {
                if (!shield || item->getDefense() > shield->getDefense()) {
                    shield = item;
                }
                break;
            }

            default: { // weapons that are not shields
                weapon = item;
                break;
            }
        }
    }
}
 
Last edited:
@Stigma

I'm using TFS 1.2 Nostalrius and cannot seem to add that code.. might be that the sources are totaly diffrent..
I'm not really familiar with C++ at all..
is there somewhere in this where I could enter that code?





Code:
/**

Item* Player::getInventoryItem(slots_t slot) const
{
    if (slot < CONST_SLOT_FIRST || slot > CONST_SLOT_LAST) {
        return nullptr;
    }
    return inventory[slot];
}

void Player::addConditionSuppressions(uint32_t conditions)
{
    conditionSuppressions |= conditions;
}

void Player::removeConditionSuppressions(uint32_t conditions)
{
    conditionSuppressions &= ~conditions;
}

Item* Player::getWeapon() const
{
    Item* item = inventory[CONST_SLOT_LEFT];
    if (item && item->getWeaponType() != WEAPON_NONE && item->getWeaponType() != WEAPON_SHIELD && item->getWeaponType() != WEAPON_AMMO) {
        return item;
    }

    item = inventory[CONST_SLOT_RIGHT];
    if (item && item->getWeaponType() != WEAPON_NONE && item->getWeaponType() != WEAPON_SHIELD && item->getWeaponType() != WEAPON_AMMO) {
        return item;
    }

    return nullptr;
}

Item* Player::getAmmunition() const
{
    return inventory[CONST_SLOT_AMMO];
}

int32_t Player::getArmor() const
{
    int32_t armor = 0; // base armor

    static const slots_t armorSlots[] = { CONST_SLOT_HEAD, CONST_SLOT_NECKLACE, CONST_SLOT_ARMOR, CONST_SLOT_LEGS, CONST_SLOT_FEET, CONST_SLOT_RING };
    for (slots_t slot : armorSlots) {
        Item* inventoryItem = inventory[slot];
        if (inventoryItem) {
            armor += inventoryItem->getArmor();
        }
    }

    if (armor > 1) {
        armor = rand() % (armor >> 1) + (armor >> 1);
    }

    return armor;
}

void Player::getShieldAndWeapon(const Item*& shield, const Item*& weapon) const
{
    shield = nullptr;
    weapon = nullptr;

    for (uint32_t slot = CONST_SLOT_RIGHT; slot <= CONST_SLOT_LEFT; slot++) {
        Item* item = inventory[slot];
        if (!item) {
            continue;
        }

        switch (item->getWeaponType()) {
            case WEAPON_NONE:
            break;

            case WEAPON_SHIELD: {
                if (!shield || item->getDefense() > shield->getDefense()) {
                    shield = item;
                }
                break;
            }

            default: { // weapons that are not shields
                weapon = item;
                break;
            }
        }
    }
}
Read the main post, it provides instructions on where to add the code.
 
Hello, @froy.

Look for
C++:
Item* Player::getAmmunition() const

After
C++:
return inventory[CONST_SLOT_AMMO];

Put the code there.
C++:
            if (Container* container = ammoItem->getContainer())
            {
                if (container->getID() == 1999) // change quiver id here
                {
                    for (ContainerIterator iter = container->iterator(); iter.hasNext(); iter.advance())
                    {
                        const ItemType& itr = Item::items[(*iter)->getID()];
                        if (itr.ammoType == it.ammoType)
                        {
                            item = (*iter);
                            return item;
                        }
                    }
                }
            }
 
@armyman
Getting these errors:
identifier "ammoItem" is undefined
identifier "it" is undefined
identifier "item" is undefined
 
Back
Top