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

Compiling Help to add Auto Recharge Ammo in 0.4

kennyubuntu

Member
Joined
May 20, 2016
Messages
150
Reaction score
13
I trying to use this function: Feature - Auto recharge ammo
From @Joe Rod that when you hit your last bolt,arrow... And if u have more ammo it auto recharge
I love the idea and tried to use in my source code, but its not compiling...
What i'm doing wrong?

Code:
weapons.cpp: In member function ‘virtual void Weapon::onUsedAmmo(Player*, Item*, Tile*) const’:
weapons.cpp:445:38: error: ‘class Player’ has no member named ‘getItemTypeCount’
       uint32_t playerCount = player->getItemTypeCount(item->getID(), -1);
                                      ^
weapons.cpp:452:19: error: ‘class Player’ has no member named ‘removeItemOfType’
           player->removeItemOfType(item->getID(), removeCount, item->getSubType
                   ^
weapons.cpp:457:35: error: ‘MESSAGE_STATUS_SMALL’ was not declared in this scope
           player->sendTextMessage(MESSAGE_STATUS_SMALL, ss.str());
                                   ^
weapons.cpp:467:8: error: jump to case label [-fpermissive]
   case AMMOACTION_REMOVECHARGE:
        ^
weapons.cpp:442:13: note:   crosses initialization of ‘uint32_t count’
    uint32_t count = item->getItemCount();
             ^
weapons.cpp:471:8: error: jump to case label [-fpermissive]
   case AMMOACTION_MOVE:
        ^
weapons.cpp:442:13: note:   crosses initialization of ‘uint32_t count’
    uint32_t count = item->getItemCount();
             ^
weapons.cpp:475:8: error: jump to case label [-fpermissive]
   case AMMOACTION_MOVEBACK:
        ^
weapons.cpp:442:13: note:   crosses initialization of ‘uint32_t count’
    uint32_t count = item->getItemCount();
             ^
weapons.cpp:478:3: error: jump to case label [-fpermissive]
   default:
   ^
weapons.cpp:442:13: note:   crosses initialization of ‘uint32_t count’
    uint32_t count = item->getItemCount();
             ^
weapons.cpp:438:8: warning: enumeration value ‘AMMOACTION_NONE’ not handled in switch [-Wswitch]
  switch(ammoAction)
        ^
weapons.cpp:438:8: warning: enumeration value ‘AMMOACTION_REMOVECHARGE’ not handled in switch [-Wswitch]
weapons.cpp:438:8: warning: enumeration value ‘AMMOACTION_MOVE’ not handled in switch [-Wswitch]
weapons.cpp:438:8: warning: enumeration value ‘AMMOACTION_MOVEBACK’ not handled in switch [-Wswitch]
Makefile:547: recipe for target 'weapons.o' failed
make[1]: *** [weapons.o] Error 1
make[1]: *** Waiting for unfinished jobs....
mv -f .deps/waitlist.Tpo .deps/waitlist.Po
mv -f .deps/vocation.Tpo .deps/vocation.Po

weapons.cpp
hastebin

weapons.h
hastebin
 
weapons.cpp
Try, replace function Weapon::eek:nUsedAmmo with:
C++:
void Weapon::decrementItemCount(Item* item)
{
    uint16_t count = item->getItemCount();
    int32_t newCount = std::max((int32_t)0, ((int32_t)item->getItemCount()) - 1);
    if (count > 1) {
        g_game.transformItem(item, item->getID(), newCount);
    }
}


void Weapon::onUsedAmmo(Player* player, Item* item, Tile* destTile) const
{
    if(!g_config.getBool(ConfigManager::REMOVE_WEAPON_AMMO))
        return;
    switch(ammoAction)
    {
       
case AMMOACTION_REMOVECOUNT:
            count = item->getItemCount();
            if (count - 1 == 0)
            {
               uint32_t playerCount = player->__getItemTypeCount(item->getID(), -1);
               playerCount--;
           
               if (playerCount > 0)
               {
                   int32_t removeCount = std::max<int32_t>(1, std::min<int32_t>(100, playerCount));            
                   g_game.transformItem(item, item->getID(), removeCount);
                   g_game.removeItemOfType(player, item->getID(), removeCount, item->getSubType());
                   break;
               }
            }
            Weapon::decrementItemCount(item);
           break;

        case AMMOACTION_REMOVECHARGE:
            g_game.transformItem(item, item->getID(), std::max((int32_t)0, ((int32_t)item->getCharges()) - 1));
            break;
        case AMMOACTION_MOVE:
            g_game.internalMoveItem(player, item->getParent(), destTile, INDEX_WHEREEVER, item, 1, NULL, FLAG_NOLIMIT);
            break;
        case AMMOACTION_MOVEBACK:
            break;
        default:
            if(item->hasCharges())
                g_game.transformItem(item, item->getID(), std::max((int32_t)0, ((int32_t)item->getCharges()) - 1));
            break;
    }
}


player.h
After: friend class ProtocolGame;
Add: friend class Weapon;

weapons.h
C++:
static void decrementItemCount(Item* item);
 
Last edited:
Where should i put this part in weapons.h?
static void decrementItemCount(Item* item);

I have the same question... Is it here?

class WeaponDistance : public Weapon
{
public:
WeaponDistance(LuaInterface* _interface);
virtual ~WeaponDistance() {}

virtual bool configureWeapon(const ItemType& it);

virtual int32_t playerWeaponCheck(Player* player, Creature* target) const;

virtual bool useWeapon(Player* player, Item* item, Creature* target) const;
virtual int32_t getWeaponDamage(const Player* player, const Creature* target, const Item* item, bool maxDamage = false) const;

protected:
virtual void onUsedAmmo(Player* player, Item* item, Tile* destTile) const;
virtual bool getSkillType(const Player* player, const Item* item, skills_t& skill, uint32_t& skillpoint) const;
static void decrementItemCount(Item* item);

int32_t hitChance, maxHitChance, breakChance, ammoAttackValue;
};
 
After
C++:
AmmoAction_t ammoAction;
        CombatParams params;

Script not tested. Tell me how it works. I will try to make it work perfectly.

Wont compile:
Code:
weapons.cpp: In member function ‘virtual void Weapon::onUsedAmmo(Player*, Item*, Tile*) const’:
weapons.cpp:449:10: error: ‘count’ was not declared in this scope
          count = item->getItemCount();
          ^
weapons.cpp:449:10: note: suggested alternative:
In file included from /usr/include/c++/5/algorithm:62:0,
                 from /usr/include/boost/function/detail/prologue.hpp:13,
                 from /usr/include/boost/function.hpp:24,
                 from otpch.h:34,
                 from weapons.cpp:17:
/usr/include/c++/5/bits/stl_algo.h:3959:5: note:   ‘std::count’
     count(_InputIterator __first, _InputIterator __last, const _Tp& __value)
     ^

Line 449:
count = item->getItemCount();
 
C++:
count = item->getItemCount();
V
C++:
uint16_t count = item->getItemCount();

Code:
weapons.cpp: In member function ‘virtual void Weapon::onUsedAmmo(Player*, Item*, Tile*) const’:
weapons.cpp:465:14: error: jump to case label [-fpermissive]
         case AMMOACTION_REMOVECHARGE:
              ^
weapons.cpp:449:19: note:   crosses initialization of ‘uint16_t count’
          uint16_t count = item->getItemCount();
                   ^
weapons.cpp:468:14: error: jump to case label [-fpermissive]
         case AMMOACTION_MOVE:
              ^
weapons.cpp:449:19: note:   crosses initialization of ‘uint16_t count’
          uint16_t count = item->getItemCount();
                   ^
weapons.cpp:471:14: error: jump to case label [-fpermissive]
         case AMMOACTION_MOVEBACK:
              ^
weapons.cpp:449:19: note:   crosses initialization of ‘uint16_t count’
          uint16_t count = item->getItemCount();
                   ^
weapons.cpp:473:9: error: jump to case label [-fpermissive]
         default:
         ^
weapons.cpp:449:19: note:   crosses initialization of ‘uint16_t count’
          uint16_t count = item->getItemCount();
                   ^
weapons.cpp:446:11: warning: enumeration value ‘AMMOACTION_NONE’ not handled in switch [-Wswitch]
     switch(ammoAction)
           ^
weapons.cpp:446:11: warning: enumeration value ‘AMMOACTION_REMOVECHARGE’ not handled in switch [-Wswitch]
weapons.cpp:446:11: warning: enumeration value ‘AMMOACTION_MOVE’ not handled in switch [-Wswitch]
weapons.cpp:446:11: warning: enumeration value ‘AMMOACTION_MOVEBACK’ not handled in switch [-Wswitch]
Makefile:547: recipe for target 'weapons.o' failed
make[1]: *** [weapons.o] Error 1
 
Code:
weapons.cpp: In member function ‘virtual void Weapon::onUsedAmmo(Player*, Item*, Tile*) const’:
weapons.cpp:465:14: error: jump to case label [-fpermissive]
         case AMMOACTION_REMOVECHARGE:
              ^
weapons.cpp:449:19: note:   crosses initialization of ‘uint16_t count’
          uint16_t count = item->getItemCount();
                   ^
weapons.cpp:468:14: error: jump to case label [-fpermissive]
         case AMMOACTION_MOVE:
              ^
weapons.cpp:449:19: note:   crosses initialization of ‘uint16_t count’
          uint16_t count = item->getItemCount();
                   ^
weapons.cpp:471:14: error: jump to case label [-fpermissive]
         case AMMOACTION_MOVEBACK:
              ^
weapons.cpp:449:19: note:   crosses initialization of ‘uint16_t count’
          uint16_t count = item->getItemCount();
                   ^
weapons.cpp:473:9: error: jump to case label [-fpermissive]
         default:
         ^
weapons.cpp:449:19: note:   crosses initialization of ‘uint16_t count’
          uint16_t count = item->getItemCount();
                   ^
weapons.cpp:446:11: warning: enumeration value ‘AMMOACTION_NONE’ not handled in switch [-Wswitch]
     switch(ammoAction)
           ^
weapons.cpp:446:11: warning: enumeration value ‘AMMOACTION_REMOVECHARGE’ not handled in switch [-Wswitch]
weapons.cpp:446:11: warning: enumeration value ‘AMMOACTION_MOVE’ not handled in switch [-Wswitch]
weapons.cpp:446:11: warning: enumeration value ‘AMMOACTION_MOVEBACK’ not handled in switch [-Wswitch]
Makefile:547: recipe for target 'weapons.o' failed
make[1]: *** [weapons.o] Error 1

Post weapons.cpp
C++:
void Weapon::decrementItemCount(Item* item)
{
    uint16_t count = item->getItemCount();
    int32_t newCount = std::max((int32_t)0, ((int32_t)item->getItemCount()) - 1);
    if (count > 1) {
        g_game.transformItem(item, item->getID(), newCount);
    }
}

void Weapon::onUsedAmmo(Player* player, Item* item, Tile* destTile) const
{
    if (!g_config.getBool(ConfigManager::REMOVE_WEAPON_AMMO)) {
        return;
    }

    switch(ammoAction) {
        case AMMOACTION_REMOVECOUNT:
            uint16_t count = item->getItemCount();
            if (count - 1 == 0) {
                uint32_t playerCount = player->__getItemTypeCount(item->getID(), -1);
                playerCount--;

                if (playerCount > 0) {
                    int32_t removeCount = std::max<int32_t>(1, std::min<int32_t>(100, playerCount));            
                    g_game.transformItem(item, item->getID(), removeCount);
                    g_game.removeItemOfType(player, item->getID(), removeCount, item->getSubType());
                    break;
                }
            }
            Weapon::decrementItemCount(item);
            break;

        case AMMOACTION_REMOVECHARGE:
            g_game.transformItem(item, item->getID(), std::max((int32_t)0, ((int32_t)item->getCharges()) - 1));
            break;

        case AMMOACTION_MOVE:
            g_game.internalMoveItem(player, item->getParent(), destTile, INDEX_WHEREEVER, item, 1, NULL, FLAG_NOLIMIT);
            break;

        case AMMOACTION_MOVEBACK:
            break;

        default:
            if (item->hasCharges()) {
                g_game.transformItem(item, item->getID(), std::max((int32_t)0, ((int32_t)item->getCharges()) - 1));
            }
            break;
    }
}

Cleaned the code abit
 
Thank you @WibbenZ , but it's not working:

Post weapons.cpp
C++:
void Weapon::decrementItemCount(Item* item)
{
    uint16_t count = item->getItemCount();
    int32_t newCount = std::max((int32_t)0, ((int32_t)item->getItemCount()) - 1);
    if (count > 1) {
        g_game.transformItem(item, item->getID(), newCount);
    }
}

void Weapon::onUsedAmmo(Player* player, Item* item, Tile* destTile) const
{
    if (!g_config.getBool(ConfigManager::REMOVE_WEAPON_AMMO)) {
        return;
    }

    switch(ammoAction) {
        case AMMOACTION_REMOVECOUNT:
            uint16_t count = item->getItemCount();
            if (count - 1 == 0) {
                uint32_t playerCount = player->__getItemTypeCount(item->getID(), -1);
                playerCount--;

                if (playerCount > 0) {
                    int32_t removeCount = std::max<int32_t>(1, std::min<int32_t>(100, playerCount));          
                    g_game.transformItem(item, item->getID(), removeCount);
                    g_game.removeItemOfType(player, item->getID(), removeCount, item->getSubType());
                    break;
                }
            }
            Weapon::decrementItemCount(item);
            break;

        case AMMOACTION_REMOVECHARGE:
            g_game.transformItem(item, item->getID(), std::max((int32_t)0, ((int32_t)item->getCharges()) - 1));
            break;

        case AMMOACTION_MOVE:
            g_game.internalMoveItem(player, item->getParent(), destTile, INDEX_WHEREEVER, item, 1, NULL, FLAG_NOLIMIT);
            break;

        case AMMOACTION_MOVEBACK:
            break;

        default:
            if (item->hasCharges()) {
                g_game.transformItem(item, item->getID(), std::max((int32_t)0, ((int32_t)item->getCharges()) - 1));
            }
            break;
    }
}

Cleaned the code abit

Code:
weapons.cpp:433:43: error: no ‘void Weapon::decrementItemCount(Item*)’ member function declared in class ‘Weapon’
 void Weapon::decrementItemCount(Item* item)
                                           ^
In file included from weapons.h:28:0,
                 from weapons.cpp:18:
player.h: In member function ‘virtual void Weapon::onUsedAmmo(Player*, Item*, Tile*) const’:
player.h:1100:20: error: ‘virtual uint32_t Player::__getItemTypeCount(uint16_t, int32_t) const’ is protected
   virtual uint32_t __getItemTypeCount(uint16_t itemId, int32_t subType = -1) co
                    ^
weapons.cpp:452:84: error: within this context
           uint32_t playerCount = player->__getItemTypeCount(item->getID(), -1);
                                                                              ^
weapons.cpp:462:13: error: ‘decrementItemCount’ is not a member of ‘Weapon’
             Weapon::decrementItemCount(item);
             ^
weapons.cpp:465:14: error: jump to case label [-fpermissive]
         case AMMOACTION_REMOVECHARGE:
              ^
weapons.cpp:450:22: note:   crosses initialization of ‘uint16_t count’
             uint16_t count = item->getItemCount();
                      ^
weapons.cpp:469:14: error: jump to case label [-fpermissive]
         case AMMOACTION_MOVE:
              ^
weapons.cpp:450:22: note:   crosses initialization of ‘uint16_t count’
             uint16_t count = item->getItemCount();
                      ^
weapons.cpp:473:14: error: jump to case label [-fpermissive]
         case AMMOACTION_MOVEBACK:
              ^
weapons.cpp:450:22: note:   crosses initialization of ‘uint16_t count’
             uint16_t count = item->getItemCount();
                      ^
weapons.cpp:476:9: error: jump to case label [-fpermissive]
         default:
         ^
weapons.cpp:450:22: note:   crosses initialization of ‘uint16_t count’
             uint16_t count = item->getItemCount();
                      ^
weapons.cpp:448:11: warning: enumeration value ‘AMMOACTION_NONE’ not handled in switch [-Wswitch]
     switch(ammoAction) {
           ^
weapons.cpp:448:11: warning: enumeration value ‘AMMOACTION_REMOVECHARGE’ not handled in switch [-Wswitch]
weapons.cpp:448:11: warning: enumeration value ‘AMMOACTION_MOVE’ not handled in switch [-Wswitch]
weapons.cpp:448:11: warning: enumeration value ‘AMMOACTION_MOVEBACK’ not handled in switch [-Wswitch]
Makefile:547: recipe for target 'weapons.o' failed
make[1]: *** [weapons.o] Error 1

weapons.cpp
hastebin
 
Thank you @WibbenZ , but it's not working:



Code:
weapons.cpp:433:43: error: no ‘void Weapon::decrementItemCount(Item*)’ member function declared in class ‘Weapon’
 void Weapon::decrementItemCount(Item* item)
                                           ^
In file included from weapons.h:28:0,
                 from weapons.cpp:18:
player.h: In member function ‘virtual void Weapon::onUsedAmmo(Player*, Item*, Tile*) const’:
player.h:1100:20: error: ‘virtual uint32_t Player::__getItemTypeCount(uint16_t, int32_t) const’ is protected
   virtual uint32_t __getItemTypeCount(uint16_t itemId, int32_t subType = -1) co
                    ^
weapons.cpp:452:84: error: within this context
           uint32_t playerCount = player->__getItemTypeCount(item->getID(), -1);
                                                                              ^
weapons.cpp:462:13: error: ‘decrementItemCount’ is not a member of ‘Weapon’
             Weapon::decrementItemCount(item);
             ^
weapons.cpp:465:14: error: jump to case label [-fpermissive]
         case AMMOACTION_REMOVECHARGE:
              ^
weapons.cpp:450:22: note:   crosses initialization of ‘uint16_t count’
             uint16_t count = item->getItemCount();
                      ^
weapons.cpp:469:14: error: jump to case label [-fpermissive]
         case AMMOACTION_MOVE:
              ^
weapons.cpp:450:22: note:   crosses initialization of ‘uint16_t count’
             uint16_t count = item->getItemCount();
                      ^
weapons.cpp:473:14: error: jump to case label [-fpermissive]
         case AMMOACTION_MOVEBACK:
              ^
weapons.cpp:450:22: note:   crosses initialization of ‘uint16_t count’
             uint16_t count = item->getItemCount();
                      ^
weapons.cpp:476:9: error: jump to case label [-fpermissive]
         default:
         ^
weapons.cpp:450:22: note:   crosses initialization of ‘uint16_t count’
             uint16_t count = item->getItemCount();
                      ^
weapons.cpp:448:11: warning: enumeration value ‘AMMOACTION_NONE’ not handled in switch [-Wswitch]
     switch(ammoAction) {
           ^
weapons.cpp:448:11: warning: enumeration value ‘AMMOACTION_REMOVECHARGE’ not handled in switch [-Wswitch]
weapons.cpp:448:11: warning: enumeration value ‘AMMOACTION_MOVE’ not handled in switch [-Wswitch]
weapons.cpp:448:11: warning: enumeration value ‘AMMOACTION_MOVEBACK’ not handled in switch [-Wswitch]
Makefile:547: recipe for target 'weapons.o' failed
make[1]: *** [weapons.o] Error 1

weapons.cpp
hastebin

Could you post weapons.h aswell?
 
Give this a try, should work

weapons.cpp OTS.ME - Paste - 563081

Code:
In file included from weapons.h:28:0,
                 from weapons.cpp:18:
player.h: In member function ‘virtual void Weapon::onUsedAmmo(Player*, Item*, Tile*) const’:
player.h:1100:20: error: ‘virtual uint32_t Player::__getItemTypeCount(uint16_t, int32_t) const’ is protected
   virtual uint32_t __getItemTypeCount(uint16_t itemId, int32_t subType = -1) co
                    ^
weapons.cpp:443:84: error: within this context
           uint32_t playerCount = player->__getItemTypeCount(item->getID(), -1);
                                                                              ^
Makefile:547: recipe for target 'weapons.o' failed
make[1]: *** [weapons.o] Error 1
 
Code:
In file included from weapons.h:28:0,
                 from weapons.cpp:18:
player.h: In member function ‘virtual void Weapon::onUsedAmmo(Player*, Item*, Tile*) const’:
player.h:1100:20: error: ‘virtual uint32_t Player::__getItemTypeCount(uint16_t, int32_t) const’ is protected
   virtual uint32_t __getItemTypeCount(uint16_t itemId, int32_t subType = -1) co
                    ^
weapons.cpp:443:84: error: within this context
           uint32_t playerCount = player->__getItemTypeCount(item->getID(), -1);
                                                                              ^
Makefile:547: recipe for target 'weapons.o' failed
make[1]: *** [weapons.o] Error 1

OTS.ME - Paste - 563082
 
Now it's compiling, but when i tried to test in game (with a bow+arrow) i used 2 arrows, when arrows going to 0 the auto recharge dont happen, not work :(

weapons.cpp (L 440~460)
hastebin

weapons.h (L 84)
hastebin

player.h (L 1249)
hastebin

Well I don't have the ability to compile 0.4 servers atm maybe @buchaLL does?

But try to debug it first to see what parts of the code is executed etc
 
Back
Top