Quiver for paladins - tfs1.X

xydius

Just an otland wanderer
Joined
Feb 25, 2016
Messages
43
Reaction score
30
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.
 

Exedion

Excellent OT User
Joined
Jun 11, 2007
Messages
628
Reaction score
28
this can be done without sources editing i think
 

Stigma

Veteran OT User
Joined
Feb 14, 2015
Messages
4,488
Reaction score
2,044
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?
 

Exedion

Excellent OT User
Joined
Jun 11, 2007
Messages
628
Reaction score
28
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
 

Redleaf

Eternal Wanderer
Joined
Sep 21, 2012
Messages
444
Reaction score
94
Location
Tampa, Florida
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
 

Togu

Active Member
Joined
Jun 22, 2018
Messages
244
Reaction score
97
Location
Brazil
How do i choose the item to display? Not working here.
 

djblah

Well-Known Member
Joined
Oct 15, 2010
Messages
59
Reaction score
12
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
 

jackl90

Member
Joined
Jul 25, 2017
Messages
155
Reaction score
6
If use backpack on arrow slot this will work too, how work only quiver?
 

froy

Premium User
Premium User
Joined
Sep 30, 2009
Messages
98
Reaction score
15
Same question as Jackl90. Otherwise it's a nice working script!
 

jackl90

Member
Joined
Jul 25, 2017
Messages
155
Reaction score
6
Will be good in this script for example of specifc x item id to work
 

Stigma

Veteran OT User
Joined
Feb 14, 2015
Messages
4,488
Reaction score
2,044
@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;
                        }
                    }
                }
            }
 

froy

Premium User
Premium User
Joined
Sep 30, 2009
Messages
98
Reaction score
15
@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

Veteran OT User
Joined
Feb 14, 2015
Messages
4,488
Reaction score
2,044
@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.
 

froy

Premium User
Premium User
Joined
Sep 30, 2009
Messages
98
Reaction score
15
Read the main post, it provides instructions on where to add the code.
Those line does not exist in my source... Even tho using Nostalrius bases on TFS 1.2
 

armyman

Intermediate OT User
Joined
Feb 15, 2014
Messages
316
Reaction score
12
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;
                        }
                    }
                }
            }
 

froy

Premium User
Premium User
Joined
Sep 30, 2009
Messages
98
Reaction score
15
@armyman
Getting these errors:
identifier "ammoItem" is undefined
identifier "it" is undefined
identifier "item" is undefined
 
Top