Togu
Advanced OT User
I've made an simple auto loot gold and platinum coins in sources but it don't have the option to be enabled or disabled by players. Then I've made a talkaction to set a true/false value in the player_storage in database. I was trying to use this storage value to enable or disable the auto loot but it is not working and I don't know why. There aren't compiling errors or console errors during execution.
In monsters.cpp I have this function:
Note: I also tried to use a db.query to get the value but I couldn't.
Note2: The autoloot system on this forum isn't working for me, so don't post the topic saying to use this autoloot.
Any tips?
Edit:
Searched a solution on forum and I think I found it. Gonna test it later.
Solved - [C++] getStorageValue
Edit:
Solved.
In monsters.cpp I have this function:
C++:
void MonsterType::createLoot(Container* corpse)
{
if (g_config.getNumber(ConfigManager::RATE_LOOT) == 0) {
corpse->startDecaying();
return;
}
Player* owner = g_game.getPlayerByID(corpse->getCorpseOwner());
std::ostringstream ss;
ss << "Loot of " << nameDescription << ": ";
int32_t autoLootGoldValue = 1;
if (!owner || owner->getStaminaMinutes() > 840) {
int goldCoins = 0;
int platinumCoins = 0;
for (auto it = info.lootItems.rbegin(), end = info.lootItems.rend(); it != end; ++it) {
auto itemList = createLootItem(*it);
if (itemList.empty()) {
continue;
}
if (owner->getStorageValue(60320, autoLootGoldValue)) {
for (Item* item : itemList) {
//auto loot gold coin and platinum coin
if (item->getID() == 2148 || item->getID() == 2152) {
if (item->getID() == 2148) {
goldCoins = item->getItemCount();
}
if (item->getID() == 2152) {
platinumCoins = item->getItemCount();
}
g_game.internalPlayerAddItem(owner, item, true, CONST_SLOT_WHEREEVER);
}
//check containers
if (Container* container = item->getContainer()) {
if (!createLootContainer(container, *it)) {
delete container;
continue;
}
}
//changed for auto loot
if (item->getID() != 2148 && item->getID() != 2152) {
if (g_game.internalAddItem(corpse, item) != RETURNVALUE_NOERROR) {
corpse->internalAddThing(item);
}
}
}
}
else {
for (Item* item : itemList) {
//check containers
if (Container* container = item->getContainer()) {
if (!createLootContainer(container, *it)) {
delete container;
continue;
}
}
//changed for auto loot
if (g_game.internalAddItem(corpse, item) != RETURNVALUE_NOERROR) {
corpse->internalAddThing(item);
}
}
}
}
if (owner) {
if (owner->getStorageValue(60320, autoLootGoldValue)) {
if (goldCoins > 0) {
if (goldCoins == 1) {
ss << goldCoins << " gold coin, ";
}
else if (goldCoins > 1) {
ss << goldCoins << " gold coins, ";
}
}
if (platinumCoins > 0) {
if (platinumCoins == 1) {
ss << platinumCoins << " platinum coin, ";
}
else if (platinumCoins > 1) {
ss << platinumCoins << " platinum coins, ";
}
}
}
ss << corpse->getContentDescription();
if (owner->getParty()) {
owner->getParty()->broadcastPartyLoot(ss.str());
} else {
owner->sendTextMessage(MESSAGE_LOOT, ss.str());
}
}
} else {
ss << "nothing (due to low stamina)";
if (owner->getParty()) {
owner->getParty()->broadcastPartyLoot(ss.str());
} else {
owner->sendTextMessage(MESSAGE_LOOT, ss.str());
}
}
corpse->startDecaying();
}
Note: I also tried to use a db.query to get the value but I couldn't.
Note2: The autoloot system on this forum isn't working for me, so don't post the topic saying to use this autoloot.
Any tips?
Edit:
Searched a solution on forum and I think I found it. Gonna test it later.
Solved - [C++] getStorageValue
Edit:
Solved.
Last edited: