• Vote in May Mapping Competition to select a winner!
  • 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
2,718
Best answers
7
Reaction score
1,678
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:

Eldin

Eldin Projects
Premium User
Joined
Jun 12, 2008
Messages
1,331
Best answers
0
Reaction score
581
Location
Sweden
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:
OP
zbizu

zbizu

Legendary OT User
Joined
Nov 22, 2010
Messages
2,718
Best answers
7
Reaction score
1,678
Location
Poland
if you get same loot pattern everytime you restart the server, above
Code:
local extra_loot = {
add
Code:
math.randomseed(os.time())
 

Eldin

Eldin Projects
Premium User
Joined
Jun 12, 2008
Messages
1,331
Best answers
0
Reaction score
581
Location
Sweden
I just hit my face abit, its perfect. <3

Kind Regards,
Eldin.
 
Last edited:

hakrai

Member
Joined
Feb 3, 2008
Messages
46
Best answers
0
Reaction score
5
Just add countMax like this

Code:
{id = 2152, count = 1, countMax = 2,chance = 40000}, -- 40%
 
OP
zbizu

zbizu

Legendary OT User
Joined
Nov 22, 2010
Messages
2,718
Best answers
7
Reaction score
1,678
Location
Poland
Does it still work after this commit?
Could somebody test it?
 

lolada24

New Member
Joined
Jan 27, 2015
Messages
3
Best answers
0
Reaction score
0
would not get a function that checks who gave most damage in monster and give the best loot for it?
 

RazorBlade

Retired Snek
Joined
Nov 7, 2009
Messages
2,040
Best answers
3
Reaction score
599
Location
Canada
Testing on commit #675, does not work. set chance to 100000, killed a few hundred dragons, no luck.
 
OP
zbizu

zbizu

Legendary OT User
Joined
Nov 22, 2010
Messages
2,718
Best answers
7
Reaction score
1,678
Location
Poland
try newer
 
OP
zbizu

zbizu

Legendary OT User
Joined
Nov 22, 2010
Messages
2,718
Best answers
7
Reaction score
1,678
Location
Poland
but tfs repo has 1,9k commits ;o
 

RazorBlade

Retired Snek
Joined
Nov 7, 2009
Messages
2,040
Best answers
3
Reaction score
599
Location
Canada
I'm pulling off the nightlies

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

bradette19

Member
Joined
May 25, 2011
Messages
98
Best answers
0
Reaction score
6
Location
Canada
This error happen when the creature can't be looted. Anything to do with this ?
 

imkingran

Learning everyday.
Premium User
Joined
Jan 15, 2014
Messages
1,268
Best answers
21
Reaction score
393

imkingran

Learning everyday.
Premium User
Joined
Jan 15, 2014
Messages
1,268
Best answers
21
Reaction score
393
Still have the error, where do I add this, below what?
Add it to data/global.lua and then /reload global, then /reload creaturescripts and try it again.
 
Top