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

Feature Auto recharge ammo

Joe Rod

Discord: joerod1
Joined
Mar 16, 2011
Messages
499
Solutions
2
Reaction score
172
GitHub
joerod1
Hi, with this modification your ammo slot will be refilled if you have enough ammo on your equipment.

go to weapon.cpp and find:
case WEAPONACTION_REMOVECOUNT:
before "Weapon::decrementItemCount(item);" paste this
C++:
uint32_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));            
       bool test = player->removeItemOfType(item->getID(), removeCount, -1, true);
       if (test)  
       {
           g_game.transformItem(item, item->getID(), removeCount);
           std::ostringstream ss;
         
           ss << "Your " << item->getPluralName() << " were charged.";
         
           player->sendTextMessage(MESSAGE_STATUS_SMALL, ss.str());
              break;
       }  
     
   }
}

now on player.h
after "friend class ProtocolGameBase;"
put this:
C++:
friend class Weapon;

Tested on OTX, however it will work on TFS 1.X i guess

Next updates (only if i get enough feedback):
  • Enable/Disable on config

Enjoy it and report bugs :)
 
Last edited by a moderator:
Did not work, alot of compile errors.

Code:
/var/otss/src/weapons.cpp: In member function ‘void Weapon::onUsedWeapon(Player*, Item*, Tile*) const’:
/var/otss/src/weapons.cpp:472:8: error: jump to case label [-fpermissive]
   case WEAPONACTION_REMOVECHARGE: {
        ^
/var/otss/src/weapons.cpp:448:10: error:   crosses initialization of ‘uint32_t count’
uint32_t count = item->getItemCount();
          ^
/var/otss/src/weapons.cpp:480:8: error: jump to case label [-fpermissive]
   case WEAPONACTION_MOVE:
        ^
/var/otss/src/weapons.cpp:448:10: error:   crosses initialization of ‘uint32_t count’
uint32_t count = item->getItemCount();
          ^
/var/otss/src/weapons.cpp:484:3: error: jump to case label [-fpermissive]
   default:
   ^
/var/otss/src/weapons.cpp:448:10: error:   crosses initialization of ‘uint32_t count’
uint32_t count = item->getItemCount();
          ^
/var/otss/src/weapons.cpp:446:9: error: enumeration value ‘WEAPONACTION_NONE’ not handled in switch [-Werror=switch]
  switch (action) {
         ^
/var/otss/src/weapons.cpp:446:9: error: enumeration value ‘WEAPONACTION_REMOVECHARGE’ not handled in switch [-Werror=switch]
/var/otss/src/weapons.cpp:446:9: error: enumeration value ‘WEAPONACTION_MOVE’ not handled in switch [-Werror=switch]
cc1plus: all warnings being treated as errors
CMakeFiles/tfs.dir/build.make:1967: recipe for target 'CMakeFiles/tfs.dir/src/weapons.cpp.o' failed
make[2]: *** [CMakeFiles/tfs.dir/src/weapons.cpp.o] Error 1
CMakeFiles/Makefile2:122: recipe for target 'CMakeFiles/tfs.dir/all' failed
make[1]: *** [CMakeFiles/tfs.dir/all] Error 2
Makefile:76: recipe for target 'all' failed
make: *** [all] Error 2
 
In my opinion using ammo from bp is better way than auto 'ammo slot' refill.
 
Amazing idea!
What did a making 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
 
Amazing idea!
What did a making 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

Are you sure you are using OTX or tfs? everything looks different on your file
 
thats why it doesnt work mate, u are using an older version

btw if someone has some sort of issues compiling because of uint32_t count and some errors about the next case statement just copy that uint32_t count and paste it before the switch statement so it looks like this

C++:
uint32_t count;
    switch (action) {
        case WEAPONACTION_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);
                   player->removeItemOfType(item->getID(), removeCount, item->getSubType());
                   std::ostringstream ss;
            
                   ss << "Your " << item->getPluralName() << " were charged.";
            
                   player->sendTextMessage(MESSAGE_STATUS_SMALL, ss.str());
            
                   break;
               }
            
            }
            Weapon::decrementItemCount(item);
            break;

that solved i for me, nice mod btw
 
thats why it doesnt work mate, u are using an older version

btw if someone has some sort of issues compiling because of uint32_t count and some errors about the next case statement just copy that uint32_t count and paste it before the switch statement so it looks like this

C++:
uint32_t count;
    switch (action) {
        case WEAPONACTION_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);
                   player->removeItemOfType(item->getID(), removeCount, item->getSubType());
                   std::ostringstream ss;
           
                   ss << "Your " << item->getPluralName() << " were charged.";
           
                   player->sendTextMessage(MESSAGE_STATUS_SMALL, ss.str());
           
                   break;
               }
           
            }
            Weapon::decrementItemCount(item);
            break;

that solved i for me, nice mod btw

What did i made wrong? I'm sorry idk a damn about this
weapons.cpp
hastebin

Code:
weapons.cpp: In member function ‘virtual void Weapon::onUsedAmmo(Player*, Item*, Tile*) const’:
weapons.cpp:442:13: error: ‘count’ was not declared in this scope
             count = item->getItemCount();
             ^
weapons.cpp:442:13: 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)
     ^
weapons.cpp:445:47: error: ‘class Player’ has no member named ‘getItemTypeCount’
                uint32_t playerCount = player->getItemTypeCount(item->getID(), -1);
                                               ^
weapons.cpp:452:28: error: ‘class Player’ has no member named ‘removeItemOfType’
                    player->removeItemOfType(item->getID(), removeCount, item->getSubType());
                            ^
weapons.cpp:457:44: error: ‘MESSAGE_STATUS_SMALL’ was not declared in this scope
                    player->sendTextMessage(MESSAGE_STATUS_SMALL, ss.str());
                                            ^
weapons.cpp:463:13: error: ‘decrementItemCount’ is not a member of ‘Weapon’
             Weapon::decrementItemCount(item);
             ^
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
 
What did i made wrong? I'm sorry idk a damn about this
weapons.cpp
hastebin

Code:
weapons.cpp: In member function ‘virtual void Weapon::onUsedAmmo(Player*, Item*, Tile*) const’:
weapons.cpp:442:13: error: ‘count’ was not declared in this scope
             count = item->getItemCount();
             ^
weapons.cpp:442:13: 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)
     ^
weapons.cpp:445:47: error: ‘class Player’ has no member named ‘getItemTypeCount’
                uint32_t playerCount = player->getItemTypeCount(item->getID(), -1);
                                               ^
weapons.cpp:452:28: error: ‘class Player’ has no member named ‘removeItemOfType’
                    player->removeItemOfType(item->getID(), removeCount, item->getSubType());
                            ^
weapons.cpp:457:44: error: ‘MESSAGE_STATUS_SMALL’ was not declared in this scope
                    player->sendTextMessage(MESSAGE_STATUS_SMALL, ss.str());
                                            ^
weapons.cpp:463:13: error: ‘decrementItemCount’ is not a member of ‘Weapon’
             Weapon::decrementItemCount(item);
             ^
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
this mod as the first post says is for otx(based on tfs) and tfs 1.x so your ot version uses different functions, also you forgot uint32_t count; before switch (action) but as i said before it wont matter because your server is different
 
this mod as the first post says is for otx(based on tfs) and tfs 1.x so your ot version uses different functions, also you forgot uint32_t count; before switch (action) but as i said before it wont matter because your server is different

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

   uint32_t count;
   switch(ammoAction)
   {
       case AMMOACTION_REMOVECOUNT:
           // auto ammo refill (Joe Rod)
            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);
                   player->removeItemOfType(item->getID(), removeCount, item->getSubType());
                   std::ostringstream ss;
           
                   ss << "Your " << item->getPluralName() << " were charged.";
           
                   player->sendTextMessage(MESSAGE_STATUS_SMALL, ss.str());
           
                   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;
   }
}
 
Back
Top