• 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
 
I think only you know about this @WibbenZ not much people here know about source edits (C++) here
When you have time, could you take a look on GitHub - Fir3element/3777 ?
It's so useful

No offence but I try to stay away from 0.x, as I said try to debug and find what the problem might be and ill try to help you, but I really don't feel like download a 0.4 datapack, source code, compiler, libs etc etc etc
If it was 1.x I could have helped you right away since I got the things I need ready :p

There should be someone who still works alot on 0.x but I have pretty much given up on them.
 
When i shot 3 times with 2 arrows (yes the last one arrow is not removing)

Its printing:
Code:
AMMOACTION_REMOVECOUNT 1AMMOACTION_REMOVECOUNT 2COUNT > 1AMMOACTION_REMOVECOUNT 1AMMOACTION_REMOVECOUNT 2COUNT < 0AMMOACTION_REMOVECOUNT 1AMMOACTION_REMOVECOUNT 2COUNT < 0[0:9:20.350] Paladin has logged out.

Why do i need to relog to print?

weapons.cpp
hastebin
 
When i shot 3 times with 2 arrows (yes the last one arrow is not removing)

Its printing:
Code:
AMMOACTION_REMOVECOUNT 1AMMOACTION_REMOVECOUNT 2COUNT > 1AMMOACTION_REMOVECOUNT 1AMMOACTION_REMOVECOUNT 2COUNT < 0AMMOACTION_REMOVECOUNT 1AMMOACTION_REMOVECOUNT 2COUNT < 0[0:9:20.350] Paladin has logged out.

Why do i need to relog to print?

weapons.cpp
hastebin

So it works except that the last arrow is not getting removed?
 
So it works except that the last arrow is not getting removed?

The script is not working, but if your question was about if i had more then 1 arrows like 2,3,100, yes, it's was removing that amount, only last do not remove (i didnt had arrows in my bp on that test)
 
The script is not working, but if your question was about if i had more then 1 arrows like 2,3,100, yes, it's was removing that amount, only last do not remove (i didnt had arrows in my bp on that test)

So if you have 0 arrows in your backpack it won't remove the last?
If you have more in your backpack it will refill?

As I said it's hard to say since I can't test it
 
So if you have 0 arrows in your backpack it won't remove the last?
If you have more in your backpack it will refill?

As I said it's hard to say since I can't test it
Sorry to don't express myself right:
I'm not in my computer right now, but i remember:

1 if i had 0 arrows in my backpack it won't remove the last one
2 if i had in my backpack some it remove but wont recharge (not sure this second one)
 
When i shot 3 times with 2 arrows (yes the last one arrow is not removing)

Its printing:
Code:
AMMOACTION_REMOVECOUNT 1AMMOACTION_REMOVECOUNT 2COUNT > 1AMMOACTION_REMOVECOUNT 1AMMOACTION_REMOVECOUNT 2COUNT < 0AMMOACTION_REMOVECOUNT 1AMMOACTION_REMOVECOUNT 2COUNT < 0[0:9:20.350] Paladin has logged out.

Why do i need to relog to print?

weapons.cpp
hastebin

bump
 
Is anybody know how to fix this?


When i shot 3 times with 2 arrows (yes the last one arrow is not removing)

Its printing:
Code:
AMMOACTION_REMOVECOUNT 1AMMOACTION_REMOVECOUNT 2COUNT > 1AMMOACTION_REMOVECOUNT 1AMMOACTION_REMOVECOUNT 2COUNT < 0AMMOACTION_REMOVECOUNT 1AMMOACTION_REMOVECOUNT 2COUNT < 0[0:9:20.350] Paladin has logged out.

Why do i need to relog to print?

weapons.cpp
hastebin


Sorry to don't express myself right:
I'm not in my computer right now, but i remember:

1 if i had 0 arrows in my backpack it won't remove the last one
2 if i had in my backpack some it remove but wont recharge (not sure this second one)

Is anybody know how to fix this?


When i shot 3 times with 2 arrows (yes the last one arrow is not removing)

Its printing:
Code:
AMMOACTION_REMOVECOUNT 1AMMOACTION_REMOVECOUNT 2COUNT > 1AMMOACTION_REMOVECOUNT 1AMMOACTION_REMOVECOUNT 2COUNT < 0AMMOACTION_REMOVECOUNT 1AMMOACTION_REMOVECOUNT 2COUNT < 0[0:9:20.350] Paladin has logged out.

Why do i need to relog to print?

weapons.cpp
hastebin


Sorry to don't express myself right:
I'm not in my computer right now, but i remember:

1 if i had 0 arrows in my backpack it won't remove the last one
2 if i had in my backpack some it remove but wont recharge (not sure this second one)

bump
 
Last edited by a moderator:
I got 2 bugs when i shot the last arrow:

1) if i had 0 arrows in my backpack it won't remove the last one
2) if i had in my backpack some it remove but wont recharge (not sure this second one)

weapons.cpp:
hastebin

Anybody know how to fix this?
It's too important to me :(
And so useful a lot people will use...

I got 2 bugs when i shot the last arrow:

1) if i had 0 arrows in my backpack it won't remove the last one
2) if i had in my backpack some it remove but wont recharge (not sure this second one)

weapons.cpp:
hastebin

Anybody know how to fix this?
It's too important to me :(
And so useful a lot people will use...
 
Last edited by a moderator:
bump

I made this organized post with all code, prints and errors because thats how i can help, idk how to fix but i would like to have it too:

Errors:

2 bugs when shot the last arrow:

1) if i had 0 arrows in my backpack it won't remove the last one
2) if i had in my backpack some it remove but wont recharge

Codes:


weapons.cpp (Line 440~460):
hastebin

weapons.h (L 84)
hastebin

player.h (L 1249)
hastebin

Prints:

1) With 1 arrow in my arrow slot and 0 arrows in my backpack (infinity hit bug)
Print this:
Code:
[10:26:21.208] Paladin has logged in.
AMMOACTION_REMOVECOUNT 1AMMOACTION_REMOVECOUNT 2COUNT < 0AMMOACTION_REMOVECOUNT 1AMMOACTION_REMOVECOUNT 2COUNT < 0AMMOACTION_REMOVECOUNT 1AMMOACTION_REMOVECOUNT 2COUNT < 0AMMOACTION_REMOVECOUNT 1AMMOACTION_REMOVECOUNT 2COUNT < 0AMMOACTION_REMOVECOUNT 1AMMOACTION_REMOVECOUNT 2COUNT < 0AMMOACTION_REMOVECOUNT 1AMMOACTION_REMOVECOUNT 2COUNT < 0AMMOACTION_REMOVECOUNT 1AMMOACTION_REMOVECOUNT 2COUNT < 0AMMOACTION_REMOVECOUNT 1AMMOACTION_REMOVECOUNT 2COUNT < 0[10:28:05.936] Paladin has logged out.

2) With 1 arrow on arrow slot and 30 in my backpack, when i shot one time remove the arrow but dont recharge and print this:
Code:
[10:29:34.432] Paladin has logged in.
AMMOACTION_REMOVECOUNT 1AMMOACTION_REMOVECOUNT 2COUNT < 0[10:30:30.813] Paladin has logged out.

Is anybody know how to fix this, it's so useful?

I made this organized post with all code, prints and errors because thats how i can help, idk how to fix but i would like to have it too:

Errors:

2 bugs when shot the last arrow:

1) if i had 0 arrows in my backpack it won't remove the last one
2) if i had in my backpack some it remove but wont recharge

Codes:


weapons.cpp (Line 440~460):
hastebin

weapons.h (L 84)
hastebin

player.h (L 1249)
hastebin

Prints:

1) With 1 arrow in my arrow slot and 0 arrows in my backpack (infinity hit bug)
Print this:
Code:
[10:26:21.208] Paladin has logged in.
AMMOACTION_REMOVECOUNT 1AMMOACTION_REMOVECOUNT 2COUNT < 0AMMOACTION_REMOVECOUNT 1AMMOACTION_REMOVECOUNT 2COUNT < 0AMMOACTION_REMOVECOUNT 1AMMOACTION_REMOVECOUNT 2COUNT < 0AMMOACTION_REMOVECOUNT 1AMMOACTION_REMOVECOUNT 2COUNT < 0AMMOACTION_REMOVECOUNT 1AMMOACTION_REMOVECOUNT 2COUNT < 0AMMOACTION_REMOVECOUNT 1AMMOACTION_REMOVECOUNT 2COUNT < 0AMMOACTION_REMOVECOUNT 1AMMOACTION_REMOVECOUNT 2COUNT < 0AMMOACTION_REMOVECOUNT 1AMMOACTION_REMOVECOUNT 2COUNT < 0[10:28:05.936] Paladin has logged out.

2) With 1 arrow on arrow slot and 30 in my backpack, when i shot one time remove the arrow but dont recharge and print this:
Code:
[10:29:34.432] Paladin has logged in.
AMMOACTION_REMOVECOUNT 1AMMOACTION_REMOVECOUNT 2COUNT < 0[10:30:30.813] Paladin has logged out.

Is anybody know how to fix this, it's so useful?

bump

bump
 
Last edited by a moderator:
bump

I made this organized post with all code, prints and errors because thats how i can help, idk how to fix but i would like to have it too:

Errors:

2 bugs when shot the last arrow:

1) if i had 0 arrows in my backpack it won't remove the last one
2) if i had in my backpack some it remove but wont recharge

Codes:


weapons.cpp (Line 440~460):
hastebin

weapons.h (L 84)
hastebin

player.h (L 1249)
hastebin

Prints:

1) With 1 arrow in my arrow slot and 0 arrows in my backpack (infinity hit bug)
Print this:
Code:
[10:26:21.208] Paladin has logged in.
AMMOACTION_REMOVECOUNT 1AMMOACTION_REMOVECOUNT 2COUNT < 0AMMOACTION_REMOVECOUNT 1AMMOACTION_REMOVECOUNT 2COUNT < 0AMMOACTION_REMOVECOUNT 1AMMOACTION_REMOVECOUNT 2COUNT < 0AMMOACTION_REMOVECOUNT 1AMMOACTION_REMOVECOUNT 2COUNT < 0AMMOACTION_REMOVECOUNT 1AMMOACTION_REMOVECOUNT 2COUNT < 0AMMOACTION_REMOVECOUNT 1AMMOACTION_REMOVECOUNT 2COUNT < 0AMMOACTION_REMOVECOUNT 1AMMOACTION_REMOVECOUNT 2COUNT < 0AMMOACTION_REMOVECOUNT 1AMMOACTION_REMOVECOUNT 2COUNT < 0[10:28:05.936] Paladin has logged out.

2) With 1 arrow on arrow slot and 30 in my backpack, when i shot one time remove the arrow but dont recharge and print this:
Code:
[10:29:34.432] Paladin has logged in.
AMMOACTION_REMOVECOUNT 1AMMOACTION_REMOVECOUNT 2COUNT < 0[10:30:30.813] Paladin has logged out.

Is anybody know how to fix this, it's so useful?



bump

Ty! BUMP
 
bump

bump

bump

bump

I made this organized post with all code, prints and errors because thats how i can help, idk how to fix but i would like to have it too:

Errors:

2 bugs when shot the last arrow:

1) if i had 0 arrows in my backpack it won't remove the last one
2) if i had in my backpack some it remove but wont recharge

Codes:


weapons.cpp (Line 440~460):
hastebin

weapons.h (L 84)
hastebin

player.h (L 1249)
hastebin

Prints:

1) With 1 arrow in my arrow slot and 0 arrows in my backpack (infinity hit bug)
Print this:
Code:
[10:26:21.208] Paladin has logged in.
AMMOACTION_REMOVECOUNT 1AMMOACTION_REMOVECOUNT 2COUNT < 0AMMOACTION_REMOVECOUNT 1AMMOACTION_REMOVECOUNT 2COUNT < 0AMMOACTION_REMOVECOUNT 1AMMOACTION_REMOVECOUNT 2COUNT < 0AMMOACTION_REMOVECOUNT 1AMMOACTION_REMOVECOUNT 2COUNT < 0AMMOACTION_REMOVECOUNT 1AMMOACTION_REMOVECOUNT 2COUNT < 0AMMOACTION_REMOVECOUNT 1AMMOACTION_REMOVECOUNT 2COUNT < 0AMMOACTION_REMOVECOUNT 1AMMOACTION_REMOVECOUNT 2COUNT < 0AMMOACTION_REMOVECOUNT 1AMMOACTION_REMOVECOUNT 2COUNT < 0[10:28:05.936] Paladin has logged out.

2) With 1 arrow on arrow slot and 30 in my backpack, when i shot one time remove the arrow but dont recharge and print this:
Code:
[10:29:34.432] Paladin has logged in.
AMMOACTION_REMOVECOUNT 1AMMOACTION_REMOVECOUNT 2COUNT < 0[10:30:30.813] Paladin has logged out.

Is anybody know how to fix this, it's so useful?


bump
 
Last edited by a moderator:
Code:
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) {
                player->removeSlotItem(CONST_SLOT_AMMO, 1)
                uint32_t playerCount = player->getItemCount(item->getID());
               

                if (playerCount > 0) {
                        if (playerCount > 100) {
                            player->removeItem(item->getID(), 100);
                            player->addSlotItem(CONST_SLOT_AMMO, item->getID(), 100);
                            break;
                        }
                        if (playerCount < 100 and playerCount > 0) {
                            player->removeItem(item->getId(), playerCount);
                            player->addSlotItem(CONST_SLOT_AMMO, item->getId(), playerCount);
                            break;
                        }
                    break;
                }
            }

            if (count > 1) {
                int32_t newCount = std::max((int32_t)0, ((int32_t)item->getItemCount()) - 1);
                g_game.transformItem(item, item->getID(), newCount);
            }
            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;
        }
    }
}
 
Code:
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) {
                player->removeSlotItem(CONST_SLOT_AMMO, 1)
                uint32_t playerCount = player->getItemCount(item->getID());
             

                if (playerCount > 0) {
                        if (playerCount > 100) {
                            player->removeItem(item->getID(), 100);
                            player->addSlotItem(CONST_SLOT_AMMO, item->getID(), 100);
                            break;
                        }
                        if (playerCount < 100 and playerCount > 0) {
                            player->removeItem(item->getId(), playerCount);
                            player->addSlotItem(CONST_SLOT_AMMO, item->getId(), playerCount);
                            break;
                        }
                    break;
                }
            }

            if (count > 1) {
                int32_t newCount = std::max((int32_t)0, ((int32_t)item->getItemCount()) - 1);
                g_game.transformItem(item, item->getID(), newCount);
            }
            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;
        }
    }
}

Code:
weapons.cpp: In member function ‘virtual void Weapon::onUsedAmmo(Player*, Item*, Tile*) const’:
weapons.cpp:446:25: error: ‘class Player’ has no member named ‘removeSlotItem’
                 player->removeSlotItem(CONST_SLOT_AMMO, 1)
                         ^
weapons.cpp:446:40: error: ‘CONST_SLOT_AMMO’ was not declared in this scope
                 player->removeSlotItem(CONST_SLOT_AMMO, 1)
                                        ^
weapons.cpp:450:21: error: ‘playerCount’ was not declared in this scope
                 if (playerCount > 0) {
                     ^
weapons.cpp:452:37: error: ‘class Player’ has no member named ‘removeItem’
                             player->removeItem(item->getID(), 100);
                                     ^
weapons.cpp:453:37: error: ‘class Player’ has no member named ‘addSlotItem’
                             player->addSlotItem(CONST_SLOT_AMMO, item->getID(), 100);
                                     ^
weapons.cpp:457:37: error: ‘class Player’ has no member named ‘removeItem’
                             player->removeItem(item->getId(), playerCount);
                                     ^
weapons.cpp:457:54: error: ‘class Item’ has no member named ‘getId’
                             player->removeItem(item->getId(), playerCount);
                                                      ^
weapons.cpp:458:37: error: ‘class Player’ has no member named ‘addSlotItem’
                             player->addSlotItem(CONST_SLOT_AMMO, item->getId(), playerCount);
                                     ^
weapons.cpp:458:72: error: ‘class Item’ has no member named ‘getId’
                             player->addSlotItem(CONST_SLOT_AMMO, item->getId(), playerCount);
                                                                        ^
mv -f .deps/waitlist.Tpo .deps/waitlist.Po
Makefile:547: recipe for target 'weapons.o' failed
make[1]: *** [weapons.o] Error 1

weapons.cpp
hastebin
 
Back
Top