• 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++ Quiver system source modification attempt

Jaki Maoh

Member
Joined
Sep 13, 2017
Messages
52
Reaction score
12
Hello Community!
I was searching the forum for a way to implement a quiver system and found this post:
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.

View attachment 30370

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.
After following the tutorial and experimenting some things here and there, I tried to make some alterations.
First of all, a little modification to @Infernum 's edit, allowing to add multiple items as different quivers:
C++:
 if (container->getID() == 38218 || 38180) // change quiver id here
then, modified the items.xml file to get the bow to be one handed:
Lua:
<item id="2456" article="a" name="bow">
        <attribute key="weight" value="3100" />
        <attribute key="weaponType" value="distance" />
        <!-- <attribute key="slotType" value="two-handed" /> -->
        <attribute key="ammoType" value="arrow" />
        <attribute key="range" value="6" />
    </item>
and the quiver itself:
Lua:
<item id="38218" article="a" name="brown quiver">
        <attribute key="weight" value="180" />
        <attribute key="containerSize" value="8" />
        <attribute key="description" value="It's a miracle it took so long." />
        <!-- <attribute key="slotType" value="ammo" /> -->
        <attribute key="weaponType" value="shield" />
        <attribute key="speed" value="10" />
    </item>
The attempt was to make the quiver dressable in the "shield slot" instead of the arrow/torch slot.
1635353832937.png
The problem, I believe, is that unless the source is edited in c++ to arrange the code in a way that it is possible to dress the quivers in the shield hand, it will simply not work.
1635353956562.png

Can anyone share some light in this matter?
Thanks in advance,
Jaki
 
Solution
@Jaki Maoh
Im not sure if it would work, but you can try changing CONST_SLOT_AMMO
to CONST_SLOT_RIGHT in the step 3 of the tutorial you followed. (sorry, I'm on phone, it's hard to copy and edit code blocks here). This way, the verification for ammo will be moved to the right hand.

Im not sure if only this change will work but it worth trying.



Edit: and if you declare the quiver as a shield (as you did), I think you'll be able to put it in right hand.
item.cpp
C++:
 else if (it.slotPosition & SLOTP_AMMO) {
            descriptions.emplace_back("Body Position", "Extra Slot");
you need to add ammox or quiver slot. and pass it to hand slot.. then u will go movement / items . / weapons / luascript and add slotp_quiver down ammo and define it as hand slot. then use it in weapons / items.xml
C++:
 else if (it.slotPosition & SLOTP_Quiver) {
            descriptions.emplace_back("Body Position", "hand");
 
Just commenting, I think this is wrong:

if (container->getID() == 38218 || 38180) // change quiver id here



Correct would be
if (container->getID() == 38218 || container->getID() == 38180) // change quiver id here


Explaining: if the itemId is different than 38218, it was returning true for any item (since you are not comparing the constant to anything), so any container would be considered a quiver.
 
item.cpp
C++:
 else if (it.slotPosition & SLOTP_AMMO) {
            descriptions.emplace_back("Body Position", "Extra Slot");
you need to add ammox or quiver slot. and pass it to hand slot.. then u will go movement / items . / weapons / luascript and add slotp_quiver down ammo and define it as hand slot. then use it in weapons / items.xml
C++:
 else if (it.slotPosition & SLOTP_Quiver) {
            descriptions.emplace_back("Body Position", "hand");
Sorry, @Sir Sezago! I wasn't able to follow your instructions at all.
Unfortunatelly did not find anything like the:
C++:
 else if (it.slotPosition & SLOTP_AMMO) {
            descriptions.emplace_back("Body Position", "Extra Slot");
in the item.cpp and even in player.cpp and items.cpp.
Is it possible that my sources are different than yours?
And to get matters worse, this is my first time editing anything in the sources, sorry for the inconvenience.
@drakylucas Thanks for the attention and correction of the one simple line that this newbie tried to add and managed to get wrong😅
Still, if anyone could help me further in this case, it will be much appreciated🤓.
 
@Jaki Maoh
Im not sure if it would work, but you can try changing CONST_SLOT_AMMO
to CONST_SLOT_RIGHT in the step 3 of the tutorial you followed. (sorry, I'm on phone, it's hard to copy and edit code blocks here). This way, the verification for ammo will be moved to the right hand.

Im not sure if only this change will work but it worth trying.



Edit: and if you declare the quiver as a shield (as you did), I think you'll be able to put it in right hand.
 
Last edited:
Solution
Just to register, for the ones that are following along:
-> the bow was changed to be a one handed weapon
-> the arrows are not able to be fired from the arrow slot anymore, only from the shield hand slot
-> but the arrow themselves cannot be dressed there, so a quiver is needed
-> the quiver was modified to be a container that can be dressed in the shield hand
C++:
    // Last edit
        //    Item* ammoItem = inventory[CONST_SLOT_AMMO];
            Item* ammoItem = inventory[CONST_SLOT_RIGHT];           
            /*edit for quiver*/
            if (!ammoItem)
            {
                return nullptr;
            }       
            if (Container* container = ammoItem->getContainer())
            {
                if (container->getID() == 38218 || container->getID() == 38180) // change quiver id here (modified)
                {
                    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*/
            // Last edit
The only thing that is missing IMO is the change that makes the quiver restrictive to arrows and bolts, instead of allowing any items like a common container, but I believe it is pretty good as is by now.

Thanks again for the help! ;)
Jaki
 
Back
Top