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

Solved How does the monster's drop rate work?

Lizard Helper

New Member
Joined
Apr 24, 2010
Messages
10
Reaction score
2
First, I apologize if it's the wrong place to ask. I've been looking around but find no answer.

I'm trying to adjust the drop rate of creatures' loot so that it's similar to Tibia's. The problem is I don't know how to do that. If I want monster to drop an item say 10% of the time, or 100%, or 50%. If anyone could either give a quick explanation or point me to an already existing tutorial or similar, I'd be very grateful.
 
Last edited:
From source code:
Code:
uint16_t Monsters::getLootRandom()
{
	return (uint16_t)std::ceil((double)random_range(0, MAX_LOOTCHANCE) / g_config.getDouble(ConfigManager::RATE_LOOT));
}

&

Code:
Item* MonsterType::createLoot(const LootBlock& lootBlock)
{
	uint16_t item = lootBlock.ids[0], random = Monsters::getLootRandom();
	if(lootBlock.ids.size() > 1)
		item = lootBlock.ids[random_range((size_t)0, lootBlock.ids.size() - 1)];

	Item* tmpItem = NULL;
	if(Item::items[item].stackable)
	{
		if(random < lootBlock.chance)
			tmpItem = Item::CreateItem(item, (random % lootBlock.count + 1));
	}
	else if(random < lootBlock.chance)
		tmpItem = Item::CreateItem(item, 0);

	if(!tmpItem)
		return NULL;

	if(lootBlock.subType != -1)
		tmpItem->setSubType(lootBlock.subType);

	if(lootBlock.actionId != -1)
		tmpItem->setActionId(lootBlock.actionId, false);

	if(lootBlock.uniqueId != -1)
		tmpItem->setUniqueId(lootBlock.uniqueId);

	if(!lootBlock.text.empty())
		tmpItem->setText(lootBlock.text);

	return tmpItem;
}

&

MAX_LOOTCHANCE is 100000
 
Back
Top