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

TFS 1.X+ (TFS 1.3) How does MonsterType:addLoot() work?

Lava Titan

Developer
Joined
Jul 25, 2009
Messages
1,529
Solutions
1
Reaction score
85
Location
Portugal
I tried multiple ways to make this work but I can't seem to get how the function works

Lua:
MonsterType(Rat):addLoot()


MonsterType(Rat):addLoot(2160)


MonsterType(Rat):addLoot(2160, 1)


MonsterType(Rat):addLoot(ItemType(2160, 1))

But it's always returning nil, how is the function supposed to work?

Also I found in sources there is something like Loot()

and I tried

Lua:
MonsterType(Rat):addLoot(Loot(2160, 1))

My objective is to do a RevScript that adds loot to a list of creatures that I choose, so when you kill those creatures they give normal XML loot + Lua script loot
 
Solution
monsterType:addLoot(loot) expect a table as a parameter

example:
Lua:
monsterType:addLoot({id = 2023, chance = 0.1})
monsterType:addLoot({id = 2148, maxCount = 100, chance = 100})
these tables are always added, so be careful, or you will end up with a rat that will give thousands of objects if you call this function every so often
that is why it is only called, in the configuration of the monster type

and of course follow the advice of @Xikini, the MonsterType(name) constructor expects a string variable as a parameter

If your purpose is to make certain monsters, depending on certain conditions, drop some extra things, then better use the function Monster:onDropLoot(corpse) event since...
I tried multiple ways to make this work but I can't seem to get how the function works

Lua:
MonsterType(Rat):addLoot()


MonsterType(Rat):addLoot(2160)


MonsterType(Rat):addLoot(2160, 1)


MonsterType(Rat):addLoot(ItemType(2160, 1))

But it's always returning nil, how is the function supposed to work?

Also I found in sources there is something like Loot()

and I tried

Lua:
MonsterType(Rat):addLoot(Loot(2160, 1))

My objective is to do a RevScript that adds loot to a list of creatures that I choose, so when you kill those creatures they give normal XML loot + Lua script loot
I don't really have the time to test, but I know you want to put rat in quotations, like this "rat"
 
monsterType:addLoot(loot) expect a table as a parameter

example:
Lua:
monsterType:addLoot({id = 2023, chance = 0.1})
monsterType:addLoot({id = 2148, maxCount = 100, chance = 100})
these tables are always added, so be careful, or you will end up with a rat that will give thousands of objects if you call this function every so often
that is why it is only called, in the configuration of the monster type

and of course follow the advice of @Xikini, the MonsterType(name) constructor expects a string variable as a parameter

If your purpose is to make certain monsters, depending on certain conditions, drop some extra things, then better use the function Monster:onDropLoot(corpse) event since monsterType:addLoot(loot) was not created for that purpose, as this affects all monsters of this type, and not just the one you are killing
 
Last edited:
Solution
Back
Top