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

CreatureEvent [TFS 1.1] Extra loot system

zbizu

Legendary OT User
Joined
Nov 22, 2010
Messages
3,323
Solutions
26
Reaction score
2,690
Location
Poland
Based on @Eldin 's request
It adds items randomly to killed monsters. Configurable group of monsters and chance

events.xml
(this line exist in your file already, just set enabled to "1")
Code:
<event class="Creature" method="onTargetCombat" enabled="1" />

creature.lua event
below:
Code:
function Creature:onTargetCombat(target)
add:
Code:
	if not self then return true end
	if self:isPlayer() and target:isMonster() then
		target:registerEvent("extra_loot_d")
	end

creaturescripts.xml
Code:
<event type="death" name="extra_loot_d" script="extra_loot.lua"/>

extra_loot.lua creaturescript
Code:
local extra_loot = {
	{hasName = "dragon", items = {
		{id = 2152, count = 2, chance = 40000}, -- 40%
		{id = 2160, countMax = 4, chance = 10000}
	}},
	{items = {
		{id = 2365, chance = 10000},
		{id = 2392, chance = 1000}
	}},
}

function Container:addExtraLoot(c, t)
	if t.hasName then
		local cn = c:getName():lower()
		local cm = t.hasName:lower()
		if not cn:match(cm) then
			return true
		end
	end
	
	for i = 1, #t.items do
		local count = 1
		if t.items[i].count then
			if t.items[i].countMax then
				count = math.random(t.items[i].count, t.items[i].countMax)
			else
				count = t.items[i].count
			end
		else
			if t.items[i].countMax then
				count = math.random(1, t.items[i].countMax)
			end
		end
		
		if math.random(0, 100000) <= t.items[i].chance then
			self:addItem(t.items[i].id, count)
		end
	end
end

function onDeath(creature, corpse, killer, mostDamage, unjustified, mostDamage_unjustified)
	if not creature:isMonster() then return true end
	if corpse and corpse:isContainer() then
		for i = 1, #extra_loot do
			corpse:addExtraLoot(creature, extra_loot[i])
		end
	end
	return true
end
 
Last edited:
Awesome! Thank You zbizu!
Will add this to Rookville to drop Potions, Premium Tokens and ofcourse your Slot System Items! :D
(Now I don't need to update monsters seperatly every time I upgrade my server <3)

Kind Regards,
Eldin.

Edit: Added to Rookville, what a relief, thank you.
 
Last edited:
if you get same loot pattern everytime you restart the server, above
Code:
local extra_loot = {
add
Code:
math.randomseed(os.time())
 
I just hit my face abit, its perfect. <3

Kind Regards,
Eldin.
 
Last edited:
Just add countMax like this

Code:
{id = 2152, count = 1, countMax = 2,chance = 40000}, -- 40%
 
Does it still work after this commit?
Could somebody test it?
 
would not get a function that checks who gave most damage in monster and give the best loot for it?
 
Testing on commit #675, does not work. set chance to 100000, killed a few hundred dragons, no luck.
 
I'm pulling off the nightlies

I also have my data folder up to data from the git
 
Back
Top