Ir para conteúdo

Featured Replies

  • 3 weeks later...
  • Respostas 16
  • Visualizações 5k
  • Created
  • Última resposta

Top Posters In This Topic

Most Popular Posts

  • Uns dos problemas das maiorias dos otserv casual que estão online é o autoloot, alguns com erros e defeito na checagem dos containers e sempre consumindo muito por ser em lua fazendo checagens de tile

  • O erase tem q usar iterator, tente usa assim void Player::removeAutoLoot(uint16_t id) { if(checkAutoLoot(id)) { return; } std::list<uint16_t>::iterator it = AutoLoot.begin(); for(;

  • Wonsr Narutibia
    Wonsr Narutibia

    Opa amigo, fiz uns testes aqui e percebi que o problema estava na checagem também. Mas de resto está tudo certo.   void Player::removeAutoLoot(uint16_t id) { if(!checkAutoLoot(id)) return;

Posted Images

Postado
Em 25/10/2020 em 14:56, Naze disse:

    Uns dos problemas das maiorias dos otserv casual que estão online é o autoloot, alguns com erros e defeito na checagem dos containers e sempre consumindo muito por ser em lua fazendo checagens de tile, corpo, itens e etc. Por isso decidi da uma contribuição a essa comunidade que me evoluiu bastante um autoloot diretamente na source na função que insere os itens no corpo, otimizando em 100% na hr da entrega do item, e não tendo problemas ocasionais como corpos sobre corpos ou varias bags.

 

     Esse sistema já é bem comum quando comprado, mas gratuito acredito que ainda não tinha disponível, então fiz esse totalmente do 0 na source tfs 0.4 rev 3999 (do yan) e passei para Otx corrigindo alguns erros de compatibilidade.

    

    Atenção na instalação! Qualquer problema pra compilar que envolva as linhas presente no código verifique novamente se instalou corretamente antes de pedir ajuda para evitar flood. Qualquer bug, erro ou mal funcionamento encontrado pode postar que estarei corrigindo, mas não irei customizar a seu agrado, você consegue fazer isso sozinho com atenção e calma, e se precisa de ajuda é só posta as duvidas.

 

Imagens do Sistema:

  Ocultar conteúdo

autoloot3.PNGautoloot.PNGautoloot.PNGautoloot2.PNG

 

Características: 


-> Otimizado executando apenas funções necessarias
-> Comandos simples e praticos
  -> !autoloot on/off  //Autoloot estara sempre ligado, e caso queria desliga use '!autoloot off'
  -> !autoloot bank/bag //Define para onde ira o dinheiro coletado, direto banco ou no inventario
  -> !autoloot list //Lista todos itens adicionados para coleta
  -> !autoloot clear/clean //Remove todos itens da lista
  -> !autoloot add, name item, name item, ... //Adiciona itens na lista, podendo adicionar quantos quiser de uma vez. Ele retorna um messagem dizendo os itens que foram adicionados e os que deram erro e não foram adicionados, talvez por escrito errado, ja existente na lista, na lista de bloquados, etc.
  -> !autoloot remove, item name, item name, ... //Remove itens da lista, com a mesma logica do add.
-> Opções configuravel pelo Config.lua
  -> AutoLoot_MoneyIDs //IDs dos Itens Moedas do servidor como gold coins, platinium coins, crystal coins.
  -> AutoLoot_BlockIDs //IDs dos itens bloqueados para autoloot
  -> AutoLoot_MaxItem //Quantidade maxima de itens para adicionar a lista
-> Sistema livres de bugs ou logs de erros.

 

Instalação:

Toda instalação será feita na source, exceto por 1 linha em talkactions.xml e 3 variáveis no config.lua

 

Otx :

  Mostrar conteúdo oculto

 

Localize no arquivo "configmanager.h" os enum de string:



enum string_config_t
		{
			DUMMY_STR = 0,
			CONFIG_FILE,
			MAP_NAME,
			HOUSE_RENT_PERIOD,

 

E adicione:



enum string_config_t
		{
			AUTOLOOT_BLOCKIDS, //autoloot by naze#3578
			AUTOLOOT_MONEYIDS, //autoloot by naze#3578
			DUMMY_STR = 0,
			CONFIG_FILE,
			MAP_NAME,
			HOUSE_RENT_PERIOD,

 

No mesmo arquivo localize o enum de number:



enum number_config_t
		{
			LOGIN_TRIES = 0,
			RETRY_TIMEOUT,
			LOGIN_TIMEOUT,
			LOGIN_PORT,

 

E adicione:



enum number_config_t
		{
			AUTOLOOT_MAXITEM, //autoloot by naze#3578
			LOGIN_TRIES = 0,
			RETRY_TIMEOUT,
			LOGIN_TIMEOUT,
			LOGIN_PORT,

 

Localize no arquivo "configmanager.cpp" :



	m_confString[MAP_AUTHOR] = getGlobalString("mapAuthor", "Unknown");
	m_confNumber[LOGIN_TRIES] = getGlobalNumber("loginTries", 3);

 

 

E adicione:



	m_confString[AUTOLOOT_BLOCKIDS] = getGlobalString("AutoLoot_BlockIDs", "");	//autoloot by naze#3578
	m_confString[AUTOLOOT_MONEYIDS] = getGlobalString("AutoLoot_MoneyIDs", "2148;2152;2160"); //autoloot by naze#3578
	m_confNumber[AUTOLOOT_MAXITEM] = getGlobalNumber("AutoLoot_MaxItem", 100); //autoloot by naze#3578
	m_confString[MAP_AUTHOR] = getGlobalString("mapAuthor", "Unknown");
	m_confNumber[LOGIN_TRIES] = getGlobalNumber("loginTries", 3);

 

Localize no arquivo "iologindata.cpp" :



//load storage map
	query.str("");
	query << "SELECT `key`, `value` FROM `player_storage` WHERE `player_id` = " << player->getGUID();
	if((result = db->storeQuery(query.str())))
	{
		do
			player->setStorage(result->getDataString("key"), result->getDataString("value"));
		while(result->next());
		result->free();
	}

 

E adicione a baixo :



	//load autoloot
	query.str("");
    query << "SELECT `autoloot_list` FROM `player_autoloot` WHERE `player_id` = " << player->getGUID();
    if ((result = db->storeQuery(query.str()))) {
        unsigned long lootListSize;
        const char* autoLootList = result->getDataStream("autoloot_list", lootListSize);
        // PropStream &propStream;
		PropStream propStream;
        propStream.init(autoLootList, lootListSize);

        uint16_t value;
        uint16_t item = propStream.getType<uint16_t>(value);
        while (item) {
            player->addAutoLoot(value);
            item = propStream.getType<uint16_t>(value);
        }
    }
	player->updateStatusAutoLoot(true);
	std::string msg = g_config.getString(ConfigManager::AUTOLOOT_MONEYIDS);
	StringVec strVector = explodeString(msg, ";");
	for(StringVec::iterator it = strVector.begin(); it != strVector.end(); ++it) {
		uint16_t id = atoi((*it).c_str());
		player->addAutoLoot(id);
	}

 

ficando dessa forma:

  Mostrar conteúdo oculto











	//load storage map
	query.str("");
	query << "SELECT `key`, `value` FROM `player_storage` WHERE `player_id` = " << player->getGUID();
	if((result = db->storeQuery(query.str())))
	{
		do
			player->setStorage(result->getDataString("key"), result->getDataString("value"));
		while(result->next());
		result->free();
	}

	//load autoloot
	query.str("");
    query << "SELECT `autoloot_list` FROM `player_autoloot` WHERE `player_id` = " << player->getGUID();
    if ((result = db->storeQuery(query.str()))) {
        unsigned long lootListSize;
        const char* autoLootList = result->getDataStream("autoloot_list", lootListSize);
        // PropStream &propStream;
		PropStream propStream;
        propStream.init(autoLootList, lootListSize);

        uint16_t value;
        uint16_t item = propStream.getType<uint16_t>(value);
        while (item) {
            player->addAutoLoot(value);
            item = propStream.getType<uint16_t>(value);
        }
    }
	player->updateStatusAutoLoot(true);
	std::string msg = g_config.getString(ConfigManager::AUTOLOOT_MONEYIDS);
	StringVec strVector = explodeString(msg, ";");
	for(StringVec::iterator it = strVector.begin(); it != strVector.end(); ++it) {
		uint16_t id = atoi((*it).c_str());
		player->addAutoLoot(id);
	}

 

 

No mesmo arquivo localize :



	query.str("");
	//save vip list
	if(!g_config.getBool(ConfigManager::VIPLIST_PER_PLAYER))
		query << "DELETE FROM `account_viplist` WHERE `account_id` = " << player->getAccount() << " AND `world_id` = " << g_config.getNumber(ConfigManager::WORLD_ID);
	else
		query << "DELETE FROM `player_viplist` WHERE `player_id` = " << player->getGUID();

	if(!db->query(query.str()))
		return false;

e acima adicione: 



//save autoloot
	query.str("");
	query << "DELETE FROM `player_autoloot` WHERE `player_id` = " << player->getGUID();
	if(!db->query(query.str()))
		return false;

	PropWriteStream PWS_AutoLoot;
	std::list<uint16_t> autoLootList = player->getAutoLoot();
    for (std::list<uint16_t>::iterator it = autoLootList.begin(); it != autoLootList.end(); ++it) {
		PWS_AutoLoot.addShort(*it);
    }

	uint32_t PWS_Size = 0;
	const char* autoLoot = PWS_AutoLoot.getStream(PWS_Size);

	query.str("");
	stmt.setQuery("INSERT INTO `player_autoloot` (`player_id`, `autoloot_list`) VALUES ");
    query << player->getGUID() << ',' << db->escapeBlob(autoLoot, PWS_Size);
    if (!stmt.addRow(query)) {
        return false;
    }
    if (!stmt.execute()) {
        return false;
    }

 

ficando dessa forma:

  Mostrar conteúdo oculto







//save autoloot
	query.str("");
	query << "DELETE FROM `player_autoloot` WHERE `player_id` = " << player->getGUID();
	if(!db->query(query.str()))
		return false;

	PropWriteStream PWS_AutoLoot;
	std::list<uint16_t> autoLootList = player->getAutoLoot();
    for (std::list<uint16_t>::iterator it = autoLootList.begin(); it != autoLootList.end(); ++it) {
		PWS_AutoLoot.addShort(*it);
    }

	uint32_t PWS_Size = 0;
	const char* autoLoot = PWS_AutoLoot.getStream(PWS_Size);

	query.str("");
	stmt.setQuery("INSERT INTO `player_autoloot` (`player_id`, `autoloot_list`) VALUES ");
    query << player->getGUID() << ',' << db->escapeBlob(autoLoot, PWS_Size);
    if (!stmt.addRow(query)) {
        return false;
    }
    if (!stmt.execute()) {
        return false;
    }
      
    query.str("");
	//save vip list
	if(!g_config.getBool(ConfigManager::VIPLIST_PER_PLAYER))
		query << "DELETE FROM `account_viplist` WHERE `account_id` = " << player->getAccount() << " AND `world_id` = " << g_config.getNumber(ConfigManager::WORLD_ID);
	else
		query << "DELETE FROM `player_viplist` WHERE `player_id` = " << player->getGUID();

	if(!db->query(query.str()))
		return false;

 

 

Agora no arquivo "monsters.cpp" localize toda a função "dropLoot" :  (ATENÇÃO: não confunda com "monster.cpp")



void MonsterType::dropLoot(Container* corpse)
{
	ItemList items;
	for(LootItems::const_iterator it = lootItems.begin(); it != lootItems.end() && !corpse->full(); ++it)
	{
		items = createLoot(*it);
		if(items.empty())
			continue;

		for(ItemList::iterator iit = items.begin(); iit != items.end(); ++iit)
		{
			Item* tmpItem = *iit;
			if(Container* container = tmpItem->getContainer())
			{
				if(createChildLoot(container, *it))
					corpse->__internalAddThing(tmpItem);
				else
					delete container;
			}
			else
				corpse->__internalAddThing(tmpItem);
		}
	}

	corpse->__startDecaying();
	uint32_t ownerId = corpse->getCorpseOwner();
	if(!ownerId)
		return;

	Player* owner = g_game.getPlayerByGuid(ownerId);
	if(!owner)
		return;

	LootMessage_t message = lootMessage;
	if(message == LOOTMSG_IGNORE)
		message = (LootMessage_t)g_config.getNumber(ConfigManager::LOOT_MESSAGE);

	if(message < LOOTMSG_PLAYER)
		return;

	std::stringstream ss;
	ss << "Loot of " << nameDescription << ": " << corpse->getContentDescription() << ".";
	if(owner->getParty() && message > LOOTMSG_PLAYER)
		owner->getParty()->broadcastMessage((MessageClasses)g_config.getNumber(ConfigManager::LOOT_MESSAGE_TYPE), ss.str());
	else if(message == LOOTMSG_PLAYER || message == LOOTMSG_BOTH)
		owner->sendTextMessage((MessageClasses)g_config.getNumber(ConfigManager::LOOT_MESSAGE_TYPE), ss.str());
}

 

e substitua com atenção ela toda por essa:



void MonsterType::dropLoot(Container* corpse)
{	
	uint32_t money = 0;
	ItemList items;
	std::stringstream str;
	for(LootItems::const_iterator it = lootItems.begin(); it != lootItems.end() && !corpse->full(); ++it)
	{
		items = createLoot(*it);
		if(items.empty())
			continue;

		for(ItemList::iterator iit = items.begin(); iit != items.end(); ++iit)
		{
			Item* tmpItem = *iit;
			if(Container* container = tmpItem->getContainer())
			{
				Player* tmpPlayer = g_game.getPlayerByGuid(corpse->getCorpseOwner());
				if(createChildLoot(container, (*it), money, str, tmpPlayer)) {
					corpse->__internalAddThing(tmpItem);
				} else {
					delete container;
				}
			}
			else {
				bool LootCatch = false;
				Player* tmpPlayer = g_game.getPlayerByGuid(corpse->getCorpseOwner());
				if(tmpPlayer) {
					if(tmpPlayer->statusAutoLoot() == "On") {
						LootCatch = tmpPlayer->checkAutoLoot(tmpItem->getID());
						if(LootCatch) {
							if(tmpPlayer->isMoneyAutoLoot(tmpItem, money)) {
								continue;
							}
							g_game.internalPlayerAddItem(NULL, tmpPlayer, tmpItem);
							str << " " << tmpItem->getNameDescription() << ",";
							continue;
						}
					}
				}
				corpse->__internalAddThing(tmpItem);
			}
		}
	}

	corpse->__startDecaying();
	uint32_t ownerId = corpse->getCorpseOwner();
	if(!ownerId)
		return;

	Player* owner = g_game.getPlayerByGuid(ownerId);
	if(!owner)
		return;

	if(money != 0) {
		if(owner->statusAutoMoneyCollect() == "Bank"){
			owner->balance += money;
		} else {
			g_game.addMoney(owner, money);
		}
		str << " " << money << "x gold coins.";
	} else {
		str << " nothing gold coins.";
	}

	LootMessage_t message = lootMessage;
	if(message == LOOTMSG_IGNORE)
		message = (LootMessage_t)g_config.getNumber(ConfigManager::LOOT_MESSAGE);

	if(message < LOOTMSG_PLAYER)
		return;

	std::stringstream ss;
	ss << "Loot of " << nameDescription << ": " << corpse->getContentDescription() << ".";
	if(owner->statusAutoLoot()  == "On") {
		ss << "\nAutoLoot Colleted:" << str.str();
	}
	if(owner->getParty() && message > LOOTMSG_PLAYER)
		owner->getParty()->broadcastMessage((MessageClasses)g_config.getNumber(ConfigManager::LOOT_MESSAGE_TYPE), ss.str());
	else if(message == LOOTMSG_PLAYER || message == LOOTMSG_BOTH)
		owner->sendTextMessage((MessageClasses)g_config.getNumber(ConfigManager::LOOT_MESSAGE_TYPE), ss.str());
}

 

No mesmo arquivo localize a função a baixo chamada "createChildLoot": 



bool MonsterType::createChildLoot(Container* parent, const LootBlock& lootBlock)
{
	LootItems::const_iterator it = lootBlock.childLoot.begin();
	if(it == lootBlock.childLoot.end())
		return true;

	ItemList items;
	for(; it != lootBlock.childLoot.end() && !parent->full(); ++it)
	{
		items = createLoot(*it);
		if(items.empty())
			continue;

		for(ItemList::iterator iit = items.begin(); iit != items.end(); ++iit)
		{
			Item* tmpItem = *iit;
			if(Container* container = tmpItem->getContainer())
			{
				if(createChildLoot(container, *it))
					parent->__internalAddThing(tmpItem);
				else
					delete container;
			}
			else
				parent->__internalAddThing(tmpItem);
		}
	}

	return !parent->empty();
}

E substitua por essa:



bool MonsterType::createChildLoot(Container* parent, const LootBlock& lootBlock, uint32_t& money, std::stringstream& str, Player* player)
{
	LootItems::const_iterator it = lootBlock.childLoot.begin();
	if(it == lootBlock.childLoot.end())
		return true;

	ItemList items;
	for(; it != lootBlock.childLoot.end() && !parent->full(); ++it)
	{
		items = createLoot(*it);
		if(items.empty())
			continue;

		for(ItemList::iterator iit = items.begin(); iit != items.end(); ++iit)
		{
			Item* tmpItem = *iit;
			if(Container* container = tmpItem->getContainer())
			{
				if(createChildLoot(container, *it, money, str, player))
					parent->__internalAddThing(tmpItem);
				else
					delete container;
			}
			else {
				bool LootCatch = false;
				if(player && (player->statusAutoLoot() == "On")) {
					LootCatch = player->checkAutoLoot(tmpItem->getID());
				}
				if(LootCatch) {
					if(player->isMoneyAutoLoot(tmpItem, money)) {
						continue;
					}
					g_game.internalPlayerAddItem(NULL, player, tmpItem);
					str << " " << tmpItem->getNameDescription() << ",";
					continue;
				}
					parent->__internalAddThing(tmpItem);
			}
		}
	}

	return !parent->empty();
}

 

Agora no arquivo "monsters.h" altera apenas uma linha:

Encontre:



bool createChildLoot(Container* parent, const LootBlock& lootBlock);

e troque por:



bool createChildLoot(Container* parent, const LootBlock& lootBlock, uint32_t& money, std::stringstream& str, Player* player);

 

Agora no arquivo "player.h" encontre nas funções public:



		void learnInstantSpell(const std::string& name);
		void unlearnInstantSpell(const std::string& name);
		bool hasLearnedInstantSpell(const std::string& name) const;

E adicione abaixo



		//Autoloot by: Naze
		std::list<uint16_t> getAutoLoot() {
			return AutoLoot;
		}
		void clearAutoLoot() {
			AutoLoot.clear();
		}
		void addAutoLoot(uint16_t id);
		void removeAutoLoot(uint16_t id);
		bool limitAutoLoot();
		bool checkAutoLoot(uint16_t id);
		bool isMoneyAutoLoot(Item* item, uint32_t& count);
		std::string statusAutoLoot() {
			return (autoLootStatus ? "On" : "Off");
		}
		void updateStatusAutoLoot(bool status){
			autoLootStatus = status;
		}
		std::string statusAutoMoneyCollect() {
			return (autoMoneyCollect ? "Bank" : "Bag");
		}
		void updateMoneyCollect(bool status) {
			autoMoneyCollect = status;
		}

 

 

Localize no mesmo arquivo as declarações private: 



	private:
		bool is_spectating;
		bool talkState[13];
		bool inventoryAbilities[SLOT_LAST];
		bool pzLocked;

e adicione 3 variáveis:



	private:
		bool autoLootStatus; //autoloot by naze
		bool autoMoneyCollect; //autoloot by naze
		std::list<uint16_t> AutoLoot; //autoloot by naze
		bool is_spectating;
		bool talkState[13];
		bool inventoryAbilities[SLOT_LAST];
		bool pzLocked;

 

Agora no arquivo "player.cpp" localize no começo a função:



Player::Player(const std::string& _name, ProtocolGame* p):
	Creature(), transferContainer(ITEM_LOCKER), name(_name), nameDescription(_name), client(p)
{
	if(client)
		client->setPlayer(this);

	pzLocked = isConnecting = addAttackSkillPoint = requestedOutfit = false;
	saving = true;

	lastAttackBlockType = BLOCK_NONE;

 

e adicione: 



Player::Player(const std::string& _name, ProtocolGame* p):
	Creature(), transferContainer(ITEM_LOCKER), name(_name), nameDescription(_name), client(p)
{
	if(client)
		client->setPlayer(this);

	pzLocked = isConnecting = addAttackSkillPoint = requestedOutfit = false;
	saving = true;
	autoLootStatus = true; //autoloot by naze
	autoMoneyCollect = true; //autoloot by naze

	lastAttackBlockType = BLOCK_NONE;

 

Ainda em "player.cpp" vá até as ultimas função: 



void Player::sendCritical() const
{
	if(g_config.getBool(ConfigManager::DISPLAY_CRITICAL_HIT))
		g_game.addAnimatedText(getPosition(), COLOR_DARKRED, "CRITICAL!");
}

void Player::setPlayerExtraAttackSpeed(uint32_t speed)
{
	extraAttackSpeed = speed;
}

 

e adicione abaixo: 



void Player::addAutoLoot(uint16_t id) {
	if(checkAutoLoot(id)) {
		return;
	}
	AutoLoot.push_back(id);
}

void Player::removeAutoLoot(uint16_t id) {
	if(checkAutoLoot(id)) {
		return;
	}
	AutoLoot.remove(id);
}

bool Player::limitAutoLoot() {
	std::list<uint16_t> list = getAutoLoot();
	if((uint16_t)list.size() >= g_config.getNumber(ConfigManager::AUTOLOOT_MAXITEM)) {
		return true;
	}
	return false;
}

bool Player::checkAutoLoot(uint16_t id) {
	if(Item::items[id].isContainer()) {
		return true;
	}
	std::string msg = g_config.getString(ConfigManager::AUTOLOOT_BLOCKIDS);
	StringVec strVector = explodeString(msg, ";");
	for(StringVec::iterator it = strVector.begin(); it != strVector.end(); ++it) {
		if(atoi((*it).c_str()) == id) {
			return true;
		}
	}
	for(std::list<uint16_t>::iterator it = AutoLoot.begin(); it != AutoLoot.end(); ++it) {
		if((*it) == id) {
			return true;
		}
	}
	return false;
}

bool Player::isMoneyAutoLoot(Item* item, uint32_t& count) {
	bool isMoney = false;
	std::string msg = g_config.getString(ConfigManager::AUTOLOOT_MONEYIDS);
	StringVec strVector = explodeString(msg, ";");
	for(StringVec::iterator it = strVector.begin(); it != strVector.end(); ++it) {
		if(item->getID() == atoi((*it).c_str())) {
			isMoney = true;
			break;
		}
	}
	if(!isMoney) {
		return false;
    }
  
	count += item->getWorth();
	return true;
}

 

Ficando dessa forma:

  Mostrar conteúdo oculto











void Player::sendCritical() const
{
	if(g_config.getBool(ConfigManager::DISPLAY_CRITICAL_HIT))
		g_game.addAnimatedText(getPosition(), COLOR_DARKRED, "CRITICAL!");
}

void Player::setPlayerExtraAttackSpeed(uint32_t speed)
{
	extraAttackSpeed = speed;
}

void Player::addAutoLoot(uint16_t id) {
	if(checkAutoLoot(id)) {
		return;
	}
	AutoLoot.push_back(id);
}

void Player::removeAutoLoot(uint16_t id) {
	if(checkAutoLoot(id)) {
		return;
	}
	AutoLoot.remove(id);
}

bool Player::limitAutoLoot() {
	std::list<uint16_t> list = getAutoLoot();
	if((uint16_t)list.size() >= g_config.getNumber(ConfigManager::AUTOLOOT_MAXITEM)) {
		return true;
	}
	return false;
}

bool Player::checkAutoLoot(uint16_t id) {
	if(Item::items[id].isContainer()) {
		return true;
	}
	std::string msg = g_config.getString(ConfigManager::AUTOLOOT_BLOCKIDS);
	StringVec strVector = explodeString(msg, ";");
	for(StringVec::iterator it = strVector.begin(); it != strVector.end(); ++it) {
		if(atoi((*it).c_str()) == id) {
			return true;
		}
	}
	for(std::list<uint16_t>::iterator it = AutoLoot.begin(); it != AutoLoot.end(); ++it) {
		if((*it) == id) {
			return true;
		}
	}
	return false;
}

bool Player::isMoneyAutoLoot(Item* item, uint32_t& count) {
	bool isMoney = false;
	std::string msg = g_config.getString(ConfigManager::AUTOLOOT_MONEYIDS);
	StringVec strVector = explodeString(msg, ";");
	for(StringVec::iterator it = strVector.begin(); it != strVector.end(); ++it) {
		if(item->getID() == atoi((*it).c_str())) {
			isMoney = true;
			break;
		}
	}
	if(!isMoney)
		return false;
	
	count += item->getWorth();
	return true;
}

 

 

Agora quase finalizando no arquivo "talkactions.h" localize:



		static TalkFunction diagnostics;
		static TalkFunction addSkill;
		static TalkFunction ghost;
		static TalkFunction software;

 

E adicione:




		static TalkFunction diagnostics;
		static TalkFunction addSkill;
		static TalkFunction autoLoot; //autoloot by naze
		static TalkFunction ghost;
		static TalkFunction software;

 

Encontre no arquivo "talkactions.cpp" :



	else if(m_functionName == "diagnostics")
		m_function = diagnostics;
	else if(m_functionName == "addskill")
		m_function = addSkill;
	else if(m_functionName == "ghost")
		m_function = ghost;
	else if(m_functionName == "software")
		m_function = software;

 

E adicione o seguinte: 



	else if(m_functionName == "diagnostics")
		m_function = diagnostics;
	else if(m_functionName == "addskill")
		m_function = addSkill;	
	else if(m_functionName == "autoloot") //autoloot by naze
		m_function = autoLoot;	
	else if(m_functionName == "ghost")
		m_function = ghost;
	else if(m_functionName == "software")
		m_function = software;

 

Ainda em "talkactions.cpp" encontre o começo de ghost:



bool TalkAction::ghost(Creature* creature, const std::string&, const std::string&)
{
	Player* player = creature->getPlayer();
	if(!player)
		return false;

 E adicione a cima a seguinte função:



bool TalkAction::autoLoot(Creature* creature, const std::string&, const std::string& param)
{
	Player* player = creature->getPlayer();
	if(!player)
		return false;

	StringVec params = explodeString(param, ",");
	std::stringstream info;
	if(params[0] == "on" or params[0] == "off") {
		player->updateStatusAutoLoot((params[0] == "on" ? true : false));
		info << "Autoloot-> Status: " << (player->statusAutoLoot()) << ".";
		player->sendTextMessage(MSG_STATUS_CONSOLE_BLUE, info.str());
		return true;
	}
	if(params[0] == "clear" or params[0] == "clean") {
		player->clearAutoLoot();
		info << "Autoloot-> Todos itens removidos.";
		player->sendTextMessage(MSG_STATUS_CONSOLE_BLUE, info.str());
		return true;
	}
	if(params[0] == "list" or params[0] == "lista") {
		std::list<uint16_t> list = player->getAutoLoot();
		std::list<uint16_t>::iterator it = list.begin();
		std::string msg = g_config.getString(ConfigManager::AUTOLOOT_MONEYIDS);
		StringVec strVector = explodeString(msg, ";");
		for(StringVec::iterator itt = strVector.begin(); itt != strVector.end(); ++itt) {
			++it;
		}
		uint16_t i = 1;
		for(; it != list.end(); ++it) {	
			info << i << ": " << Item::items[(*it)].name << std::endl;
			++i;
		}
		player->sendFYIBox((info.str() == "" ? "Nada Adicionado." : info.str()));
		return true;
	}
	if(params.size() <= 1) {
		info << "_____Perfect AutoLoot System_____\nAutoLoot Status: " << player->statusAutoLoot() << "\nAutoMoney Mode: " << player->statusAutoMoneyCollect() << "\n\nComandos:\n!autoloot on/off\n!autoloot money, bank/bag\n!autoloot add, item name, item name, item name...\n!autoloot remove, item name, item name, item name...\n!autoloot list\n!autoloot clear\n\n\n (Sistema livre de bugs e gratuito no TibiaKing!)";
		player->sendFYIBox(info.str());
		return true;
	}

	if(params[0] == "money") {
		for(StringVec::iterator it = params.begin(); it != params.end(); ++it) {
			if((*it) == "money") {
				continue;
			}
			char param[150];
			sprintf(param, "%s", (*it).c_str());
			int len = strlen(param);
			for (int i = 0, pos = 0; i < len; i++, pos++) {
				if (param[0] == ' '){
					pos++;
				}
				param[i] = param[pos];
			}
			if((strcmp(param, "bank") == 0) or (strcmp(param, "bag") == 0)) {
				player->updateMoneyCollect((strcmp(param, "bank") == 0) ? true : false);
				info << "AutoMoney-> Collect Mode: " << (player->statusAutoMoneyCollect()) << ".";
				player->sendTextMessage(MSG_STATUS_CONSOLE_BLUE, info.str());
				return true;
			}
		}
	}

	if(params[0] == "add") {
		std::stringstream add, err;
		uint8_t addCount = 0, errCount = 0;
		std::stringstream ss;
		for(StringVec::iterator it = params.begin(); it != params.end(); ++it) {
			if((*it) == "add") {
				continue;
			}
			char name[150];
			sprintf(name, "%s", (*it).c_str());
			int len = strlen(name);
			for (int i = 0, pos = 0; i < len; i++, pos++) {
				if (name[0] == ' '){
					pos++;
				}
				name[i] = name[pos];
			}
			int32_t itemId = Item::items.getItemIdByName(name);
			if(!player->checkAutoLoot(itemId)) {
				if(itemId > 0) {
					std::string str = addCount > 0 ? ", " : "";
					++addCount;
					add << str << name;
					player->addAutoLoot(itemId);
					continue;
				}
			}
			std::string str = errCount > 0 ? ", " : "";
			++errCount;
			err << str << name;
		}
		ss << "AutoLoot-> Adicionados: " << ((add.str() == "") ? "Nenhum" : add.str()) << ". Erros: " << ((err.str() == "") ? "Nenhum" : err.str()) << ".";
		player->sendTextMessage(MSG_STATUS_CONSOLE_BLUE, ss.str());
		return true;
	}

	if(params[0] == "remove") {
		std::stringstream remove, err;
		uint8_t removeCount = 0, errCount = 0;
		std::stringstream ss;
		for(StringVec::iterator it = params.begin(); it != params.end(); ++it) {
			if((*it) == "remove") {
				continue;
			}
			char name[150];
			sprintf(name, "%s", (*it).c_str());
			int len = strlen(name);
			for (int i = 0, pos = 0; i < len; i++, pos++) {
				if (name[0] == ' '){
					pos++;
				}
				name[i] = name[pos];
			}
			int32_t itemId = Item::items.getItemIdByName(name);
			if(player->checkAutoLoot(itemId)) {
				if(itemId > 0) {
					std::string str = removeCount > 0 ? ", " : "";
					++removeCount;
					remove << str << name;
					player->removeAutoLoot(itemId);
					continue;
				}
			}
			std::string str = errCount > 0 ? ", " : "";
			++errCount;
			err << str << name;
		}
		ss << "AutoLoot-> Removidos: " << ((remove.str() == "") ? "Nenhum" : remove.str()) << ". Erros: " << ((err.str() == "") ? "Nenhum" : err.str()) << ".";
		player->sendTextMessage(MSG_STATUS_CONSOLE_BLUE, ss.str());
		return true;
	}
	
	return true;
}

 

 

Com isso toda parte na source está instalada, agora vá até seu config.lua e adicione onde achar melhor as seguintes linhas:



AutoLoot_BlockIDs = "" -- adicione ids separado por ; ex: "1111;2222;3333"
AutoLoot_MoneyIDs = "2148;2152;2160" -- adicione os ids dos itens moeda, caso seja os 3 normais pode retirar essa linha
AutoLoot_MaxItem = 100 --  quantidade de itens maximo na lista

 

Agora para finalizar abra o data/talkactions/talkactions.xml e adicione a seguinte tag:



	<talkaction words="/autoloot;!autoloot" event="function" value="autoloot"/>

 

E execute a seguinte query em seu banco de dados:



CREATE TABLE player_autoloot (
    id int NOT NULL AUTO_INCREMENT,
    player_id int NOT NULL,
    autoloot_list blob,
    PRIMARY KEY (id)
);


 

 

Link para TFS -> https://tibiaking.com/forums/topic/101079-otimizado-autoloot-in-sources-for-tfs-036-tfs-04/

 

Caso ocorra algum erro na compilação so mandar que ajudo a resolver, testei apenas em uma otx que tenho então nao sei se pode sugir outros problemas. Nas versões atual da Otx para servidores 10+ não ira funcionar pois algumas funções são diferente e não irei corrigir agora, em breve passo o mesmo pra tfs 1.3 e otx3.

 

Esse sistema foi totalmente feito por mim, mas dou créditos também ao @Mathias Kenfi por me ajudar muito na evolução em lua/c++ e a tabela sql é a mesma usada no quick autoloot 1.3 postado por Pedriinz

Depois que compilei a source, ao ligar o servidor a distro fecha e aparece seguimentation fail algo assim, será que fiz algo errado?

Postado
  • Autor
Em 30/11/2020 em 09:56, .HuRRiKaNe disse:

Depois que compilei a source, ao ligar o servidor a distro fecha e aparece seguimentation fail algo assim, será que fiz algo errado?

Ctz, tenta reinstalar o sistema, ou usa gdb para ver que função ta errada. 

  • 1 month later...
Postado

boa tarde naze, estou tendo esse problema na hora de compilar

/home/Baiak/sources# make
g++ -c -march=native -mtune=native -I"." -I"/usr/include/lua5.1" -I"/usr/include                                                                                        /mysql" -I"/usr/include/libxml2" -DBOOST_DISABLE_ASSERTS -DNDEBUG -Werror -Wall                                                                                         -Ofast -ggdb3 -std=c++11 -pthread -lpthread -fno-strict-aliasing -o obj/monsters                                                                                        .o monsters.cpp
monsters.cpp: In member function ‘bool MonsterType::createChildLoot(Container*,                                                                                         const LootBlock&, uint32_t&, std::stringstream&, Player*)’:
monsters.cpp:137:12: error: cannot convert ‘ItemList {aka std::__cxx11::list<Ite                                                                                        m*>}’ to ‘Item*’ in assignment
   if(items = createLoot(*it)) {
            ^
monsters.cpp: In member function ‘void MonsterType::dropLoot(Container*)’:
monsters.cpp:179:12: error: cannot convert ‘ItemList {aka std::__cxx11::list<Ite                                                                                        m*>}’ to ‘Item*’ in assignment
   if(items = createLoot(*it)) {
            ^
monsters.cpp:193:68: error: suggest parentheses around assignment used as truth                                                                                         value [-Werror=parentheses]
     if(tmpPlayer = g_game.getPlayerByGuid(corpse->getCorpseOwner())) {
                                                                    ^
monsters.cpp: At global scope:
monsters.cpp:249:3: error: ‘owner’ does not name a type
   owner->getStorage("lootch", value);
   ^
monsters.cpp:250:3: error: expected unqualified-id before ‘if’
   if (value == "-1")
   ^
monsters.cpp:252:3: error: expected unqualified-id before ‘else’
   else
   ^
monsters.cpp:254:2: error: expected declaration before ‘}’ token
  }
  ^
cc1plus: all warnings being treated as errors
Makefile:40: recipe for target 'obj/monsters.o' failed
make: *** [obj/monsters.o] Error 1
 

 

 

 

OBSV: já usei o metodo lá que vc comentou no post da TFS, ai deu esse error em cima..

poderia ajudar?

Participe da conversa

Você pode postar agora e se cadastrar mais tarde. Se você tem uma conta, faça o login para postar com sua conta.

Visitante
Responder

Quem Está Navegando 0

  • Nenhum usuário registrado visualizando esta página.

Estatísticas dos Fóruns

  • Tópicos 96.9k
  • Posts 519.6k

Informação Importante

Confirmação de Termo